-
Notifications
You must be signed in to change notification settings - Fork 2
feat(context): founder-context + per-squad alignment as first-class layers #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
a93f70e
4b96938
3b0885b
2f52d7f
e0e9e3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,8 +12,9 @@ | |||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import { existsSync, readFileSync, readdirSync, statSync } from 'fs'; | ||||||||||||||||||||||||||||||||||||||||
| import { join } from 'path'; | ||||||||||||||||||||||||||||||||||||||||
| import { findSquadsDir, loadSquad } from './squad-parser.js'; | ||||||||||||||||||||||||||||||||||||||||
| import { spawnSync } from 'child_process'; | ||||||||||||||||||||||||||||||||||||||||
| import { join, dirname } from 'path'; | ||||||||||||||||||||||||||||||||||||||||
|
Check warning on line 16 in src/lib/org-cycle.ts
|
||||||||||||||||||||||||||||||||||||||||
| import { findSquadsDir, loadSquad, findProjectRoot } from './squad-parser.js'; | ||||||||||||||||||||||||||||||||||||||||
| import { findMemoryDir } from './memory.js'; | ||||||||||||||||||||||||||||||||||||||||
| import { colors, bold, RESET, writeLine } from './terminal.js'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -158,6 +159,90 @@ | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Refresh founder context before an org cycle. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * Looks for the digest script at one of two paths (in order): | ||||||||||||||||||||||||||||||||||||||||
| * - .claude/hooks/founder-context-digest.py (preferred — version-controlled hook) | ||||||||||||||||||||||||||||||||||||||||
| * - scripts/founder-context-digest.py (fallback — for projects with a scripts/ dir) | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * Runs the script when `.agents/memory/company/founder-context.md` is missing | ||||||||||||||||||||||||||||||||||||||||
| * or older than `staleHours` (default 2h). On success, the digest writes: | ||||||||||||||||||||||||||||||||||||||||
| * - .agents/memory/company/founder-context.md (universal) | ||||||||||||||||||||||||||||||||||||||||
| * - .agents/memory/{squad}/founder-alignment.md (per-squad) | ||||||||||||||||||||||||||||||||||||||||
| * which `gatherSquadContext` then injects into every agent's prompt. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * Returns: | ||||||||||||||||||||||||||||||||||||||||
| * 'refreshed' — digest ran successfully and produced fresh files | ||||||||||||||||||||||||||||||||||||||||
| * 'fresh' — existing context is recent enough, no refresh needed | ||||||||||||||||||||||||||||||||||||||||
| * 'skipped' — no digest script found at expected paths; nothing to do | ||||||||||||||||||||||||||||||||||||||||
| * 'failed' — digest exited non-zero; org cycle should NOT proceed | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| export function refreshFounderContext( | ||||||||||||||||||||||||||||||||||||||||
| options: { staleHours?: number; force?: boolean } = {} | ||||||||||||||||||||||||||||||||||||||||
| ): 'refreshed' | 'fresh' | 'skipped' | 'failed' { | ||||||||||||||||||||||||||||||||||||||||
| const projectRoot = findProjectRoot(); | ||||||||||||||||||||||||||||||||||||||||
| if (!projectRoot) return 'skipped'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const candidatePaths = [ | ||||||||||||||||||||||||||||||||||||||||
| join(projectRoot, '.claude', 'hooks', 'founder-context-digest.py'), | ||||||||||||||||||||||||||||||||||||||||
| join(projectRoot, 'scripts', 'founder-context-digest.py'), | ||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||
| const digestScript = candidatePaths.find(p => existsSync(p)); | ||||||||||||||||||||||||||||||||||||||||
| if (!digestScript) return 'skipped'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const memoryDir = findMemoryDir(); | ||||||||||||||||||||||||||||||||||||||||
| const contextFile = memoryDir | ||||||||||||||||||||||||||||||||||||||||
| ? join(memoryDir, 'company', 'founder-context.md') | ||||||||||||||||||||||||||||||||||||||||
| : null; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const staleHours = options.staleHours ?? 2; | ||||||||||||||||||||||||||||||||||||||||
| const MS_PER_HOUR = 60 * 60 * 1000; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| let isStale = true; | ||||||||||||||||||||||||||||||||||||||||
| if (!options.force && contextFile && existsSync(contextFile)) { | ||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||
| const ageHours = (Date.now() - statSync(contextFile).mtimeMs) / MS_PER_HOUR; | ||||||||||||||||||||||||||||||||||||||||
| if (ageHours < staleHours) { | ||||||||||||||||||||||||||||||||||||||||
| isStale = false; | ||||||||||||||||||||||||||||||||||||||||
| writeLine( | ||||||||||||||||||||||||||||||||||||||||
| ` ${colors.dim}founder-context: fresh (${ageHours.toFixed(1)}h old, threshold ${staleHours}h)${RESET}` | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } catch { /* */ } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (!isStale) return 'fresh'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| writeLine(` ${colors.dim}founder-context: refreshing from CC sessions + git activity...${RESET}`); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+213
to
+217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e0e9e3e. Added python/python3 platform detection (win32→python, else python3) and result.error check with ETIMEDOUT distinction. |
||||||||||||||||||||||||||||||||||||||||
| // Two Claude calls (universal + per-squad block for all squads in one shot) | ||||||||||||||||||||||||||||||||||||||||
| // can take 5-8 min on large inputs. Cap at 12 min to be safe. | ||||||||||||||||||||||||||||||||||||||||
| const pythonCmd = process.platform === 'win32' ? 'python' : 'python3'; | ||||||||||||||||||||||||||||||||||||||||
| const result = spawnSync(pythonCmd, [digestScript], { | ||||||||||||||||||||||||||||||||||||||||
| cwd: projectRoot, | ||||||||||||||||||||||||||||||||||||||||
| stdio: 'inherit', | ||||||||||||||||||||||||||||||||||||||||
| timeout: 12 * 60 * 1000, | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (result.error) { | ||||||||||||||||||||||||||||||||||||||||
| const isTimeout = (result.error as NodeJS.ErrnoException).code === 'ETIMEDOUT'; | ||||||||||||||||||||||||||||||||||||||||
| writeLine( | ||||||||||||||||||||||||||||||||||||||||
| ` ${colors.yellow}founder-context: digest ${isTimeout ? 'timed out' : 'failed to start'}: ${result.error.message}${RESET}` | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| return 'failed'; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (result.status === 0) { | ||||||||||||||||||||||||||||||||||||||||
| writeLine(` ${colors.green}founder-context: refreshed${RESET}\n`); | ||||||||||||||||||||||||||||||||||||||||
| return 'refreshed'; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| writeLine( | ||||||||||||||||||||||||||||||||||||||||
| ` ${colors.yellow}founder-context: digest failed (exit ${result.status ?? '?'}). ` + | ||||||||||||||||||||||||||||||||||||||||
| `Org cycle blocked — agents would run without strategic alignment.${RESET}\n` | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| return 'failed'; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Display execution plan. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The founder context refresh is currently only wired into the
--orgcycle. However, the PR motivation mentions that single squad runs (e.g.,squads run intelligence) also benefit from this alignment. If a user runs a single squad and the context is missing or stale, they won't get the 'live' strategic state. Consider moving this refresh step so it applies to single squad runs as well, perhaps with a shorter timeout or only if the files are missing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e0e9e3e. Added best-effort refreshFounderContext call before single-squad execution (lazy import, never blocks, skips gracefully if no digest script).