osborn 0.9.279 → 0.9.280

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,6 +82,12 @@ export declare const NAMED_AGENTS: {
82
82
  model: string;
83
83
  prompt: string;
84
84
  };
85
+ steward: {
86
+ description: string;
87
+ tools: string[];
88
+ model: string;
89
+ prompt: string;
90
+ };
85
91
  reviewer: {
86
92
  description: string;
87
93
  tools: string[];
@@ -21,6 +21,7 @@ import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, statSy
21
21
  import { join, dirname, resolve, basename } from 'node:path';
22
22
  import { fileURLToPath } from 'node:url';
23
23
  import { homedir, loadavg, totalmem, freemem, cpus } from 'node:os';
24
+ import { stewardGate, SIGNOFF_COMMAND } from './steward-gate.js';
24
25
  // Directory of this module — used to locate co-located prompt files (e.g., turn-shape reminder).
25
26
  const __claudeLlmDir = dirname(fileURLToPath(import.meta.url));
26
27
  const TURN_SHAPE_REMINDER_PATH = join(__claudeLlmDir, 'prompts', 'turn-shape-reminder.md');
@@ -784,6 +785,93 @@ export const NAMED_AGENTS = {
784
785
  'Return a self-contained brief; the orchestrator passes it directly to the writer.',
785
786
  ].join('\n'),
786
787
  },
788
+ steward: {
789
+ description: [
790
+ 'Codebase-steward agent (Sonnet). NOT GROUNDED: reads the repo and its git history directly. Owns duplication and regressions, not features. Use (1) on a PLAN before',
791
+ 'any code is written, to answer "does this already exist?" for every new function, route, module, table or',
792
+ 'feature; (2) on the DIFF after the writer and tester, to refactor it to reuse existing code, cut what is not',
793
+ 'needed, and map every changed symbol to its callers. Returns CLEAN, REFACTORED or BLOCK. Never reviews its own refactor.',
794
+ ].join(' '),
795
+ tools: ['Read', 'Glob', 'Grep', 'Bash', 'Edit', 'Write', 'MultiEdit'],
796
+ model: 'sonnet',
797
+ prompt: [
798
+ 'You are Osborn\'s steward agent. You own the codebase: you are responsible for duplication and regressions,',
799
+ 'not for features. Bloat compounds: every duplicate widens the code that agents and people must read, which',
800
+ 'causes more misses and more duplicates. You debloat new code and protect existing code.',
801
+ '',
802
+ '## Principles',
803
+ '- Proven code wins. Code that already works is trusted over anything new. If a change avoids, replaces or',
804
+ ' changes the behaviour of existing working code, state why; with no strong reason, keep and reuse it.',
805
+ '- Extend before you create. Prefer a parameter, option or small branch on an existing function over a new',
806
+ ' module, route, table or helper. A brand-new module is the last resort and needs a written reason.',
807
+ '- Know why before you add: before adding a guard, check, retry, helper or option, find what already handles it.',
808
+ '- Rule of three. A second near-copy may stay if extracting it would mean guessing the shared shape; note it.',
809
+ ' A third copy may not: consolidate all three into one shared function in this change.',
810
+ '- Scope: act only on the diff (or plan) and on the code it duplicates. Never rewrite untouched code.',
811
+ '',
812
+ '## Plan mode (the task gives you a plan, no diff yet)',
813
+ 'For every new function, route, module, table, config or feature in the plan, search the repo (Grep/Glob,',
814
+ 'git log -S) for something that already does it. Return a reuse map: each item → existing thing to reuse or',
815
+ 'extend, or a one-line net-new reason. Do not edit files in plan mode.',
816
+ '',
817
+ '## History first (both modes)',
818
+ 'Git history, GitHub issues and PR descriptions are the project\'s memory and decision log; there is no separate',
819
+ 'ledger. Compute these for the touched files; never assume which files are hotspots, they move over time.',
820
+ '- Churn: `git log --since=60.days --oneline -- <file>`: how often it changes and how many of those were fixes.',
821
+ '- Re-touched lines: `git log --since=30.days -L <a>,<a+b>:<file>` using the OLD-side range (-a,b) of each hunk',
822
+ ' of `git diff HEAD`; skip files new in the diff. Lines a recent fix already changed mean a repeat.',
823
+ '- Coupling: `git log --since=60.days --full-diff --name-only --format= -- <file> | sort | uniq -c | sort -rn | head`.',
824
+ ' A usual partner missing from the diff is a likely regression, especially across a client/server boundary.',
825
+ '- Prior decisions: `git log -S <symbol>` / `--grep <topic>`; `gh issue list --state all --search "<topic>"` and',
826
+ ' `gh pr list --state all --search "<topic>"` (skip if gh is absent). Earlier PRs\' "Why" sections are the',
827
+ ' decision records.',
828
+ '',
829
+ '## Diff mode (after the writer)',
830
+ '0. `git status`, `git diff HEAD --stat`, `git diff HEAD` (include untracked files). Count lines added/removed.',
831
+ ' Then run History first on the touched files. Classify the change: a new isolated feature, or a change to',
832
+ ' existing working code. The budget in step 8 applies to the second; a feature is judged by "does it exist?".',
833
+ '1. Reuse first: for every added function, class, route, module, table or config, search for existing logic',
834
+ ' that does the same or nearly the same. If found, EDIT the diff to reuse or extend it instead (a second',
835
+ ' near-copy may stay per the rule of three).',
836
+ '2. Net-new must be justified: anything still new gets a one-line reason nothing existing fits.',
837
+ '3. Surgical diff: remove unreachable guards, speculative options, dead branches and duplicated validation.',
838
+ ' If the diff mixes unrelated concerns (a fix, a refactor, a version bump), say which belong in a separate change.',
839
+ '4. Regressions: for every changed or removed symbol, find its callers and consumers (routes, schedulers,',
840
+ ' frontend, docs, tests, client/server messages) and confirm each still works. Flag any behaviour change',
841
+ ' for an existing caller (status codes, response shapes, stored values, message fields).',
842
+ '5. Decisions: do not silently undo a decision found in history, PRs or the project\'s docs; name any it reverses.',
843
+ '6. Single source of truth: if the diff adds a second copy of a rule (validation, error codes, config,',
844
+ ' constants), merge it into the existing copy.',
845
+ '7. Repeats: if the change re-touches lines a fix changed in the last 30 days, or follows up an earlier issue,',
846
+ ' write the chain (#A → #B → this) and the root cause with its evidence (a measurement, log or reproduction),',
847
+ ' taken from the task, the linked issue or the commit message. If the only change is a wider timeout, a retry,',
848
+ ' a fallback, a delay or a guard and no cause is given anywhere, that is a symptom fix: BLOCK and ask for the',
849
+ ' cause. In a high-churn file, recommend moving the touched part where it belongs as a separate change.',
850
+ '8. Budget: on existing working code aim for lines added ≤ lines removed (tests excluded) within the diff;',
851
+ ' growth needs a NET-NEW reason. Do not cut untouched code to meet it.',
852
+ '9. New dependencies: a new package needs a reason and a check that no existing dependency already does it.',
853
+ '',
854
+ '## Bash',
855
+ 'Read-only inspection (git diff/log/show/grep, gh issue/pr list|view, tsc --noEmit, tests) plus the sign-off',
856
+ 'command below. Never commit, push, reset, checkout, stash or delete. Your edits are file edits only.',
857
+ '',
858
+ '## Sign-off',
859
+ 'After a CLEAN or REFACTORED verdict in diff mode, run this from the repository root to record your sign-off',
860
+ 'for this exact content (any later edit invalidates it; the commit/push/PR gate checks it):',
861
+ ' ' + SIGNOFF_COMMAND,
862
+ 'Never sign off on BLOCK. If you REFACTORED, the orchestrator re-runs the tests and the reviewer, not you.',
863
+ '',
864
+ '## What to return',
865
+ 'VERDICT: CLEAN | REFACTORED | BLOCK — <one line>',
866
+ 'REUSE MAP: <new item> → <existing item reused/extended> | NET-NEW: <reason>',
867
+ 'REMOVED: <what you cut and why> (or none)',
868
+ 'REGRESSION MAP: <changed symbol> → <callers> → <ok / broken + why>',
869
+ 'LINES: +<added> -<removed> before → +<added> -<removed> after',
870
+ 'HISTORY: churn of touched files, re-touched lines, coupled files, related issues/PRs (one line each)',
871
+ 'ROOT CAUSE: for a fix, the cause and its evidence, or the chain it ends (omit for a pure feature)',
872
+ 'For BLOCK, name the decision a human has to make.',
873
+ ].join('\n'),
874
+ },
787
875
  reviewer: {
788
876
  description: [
789
877
  'Code-review agent (Sonnet). Use for: the VERIFY step in a generator-verifier loop — after the',
@@ -989,6 +1077,7 @@ const WRITE_RULES = {
989
1077
  writer: 'anywhere',
990
1078
  tester: { extensions: /\.(test|spec)\.[jt]sx?$/, label: 'test', matchBasename: true },
991
1079
  reviewer: { extensions: /\.(md|markdown|mdx|txt|rst|adoc)$/i, label: 'documentation' },
1080
+ steward: 'anywhere', // refactors the writer's diff in place
992
1081
  };
993
1082
  /**
994
1083
  * Path is inside the per-session sandbox workspace. Used by decideWrite's
@@ -1047,9 +1136,17 @@ export const VERIFIER_CHAIN = {
1047
1136
  parallelAtStart: ['tester'],
1048
1137
  afterReminder: 'The writer sub-agent just finished. Before you finalize, you MUST now use the Task tool to: ' +
1049
1138
  "(1) RUN the tester's tests against the new implementation and report PASS/FAIL; " +
1050
- '(2) dispatch the `reviewer` on the diff for a VERDICT. ' +
1051
- 'If tests FAIL or the reviewer REJECTs, dispatch the `writer` to fix and then re-verify — ' +
1052
- 'at most 2 fix rounds, after which surface the outcome to the user rather than looping.',
1139
+ '(2) dispatch the `steward` on the diff (diff mode), passing the task and, for a fix, its root cause and evidence — it refactors toward reuse and returns CLEAN, REFACTORED or BLOCK; ' +
1140
+ "(3) if it REFACTORED, RUN the tests again; (4) dispatch the `reviewer` on the final diff for a VERDICT. " +
1141
+ 'If the steward returns BLOCK, stop and ask the user the decision it names. ' +
1142
+ 'If tests FAIL or the reviewer REJECTs, dispatch the `writer` to fix and then re-verify (steward included) — ' +
1143
+ 'at most 2 fix rounds, after which surface the outcome to the user rather than looping. ' +
1144
+ "In any PR description, put the steward's ROOT CAUSE under Why, and its NET-NEW and REMOVED lists under those headings.",
1145
+ },
1146
+ planner: {
1147
+ afterReminder: 'The planner sub-agent just finished. Before the writer starts, use the Task tool to dispatch the `steward` ' +
1148
+ 'in PLAN MODE on that plan: for every new function, route, module, table or feature it answers "does this already exist?". ' +
1149
+ 'Give the writer the plan WITH the steward\'s reuse map.',
1053
1150
  },
1054
1151
  researcher: {
1055
1152
  afterReminder: 'The researcher sub-agent just finished. Before you finalize, you MUST now use the Task tool to ' +
@@ -2552,6 +2649,18 @@ class ClaudeLLMStream extends llm.LLMStream {
2552
2649
  }
2553
2650
  console.log(`🔧 Tool call ${turnToolCallCount} (speak-cadence ${SPEAK_CADENCE_N}, ceiling ${TOOL_HARD_CEILING || 'off'}): ${toolName}`);
2554
2651
  }
2652
+ // Steward sign-off gate (#218): a commit, push or PR whose content the steward has
2653
+ // not signed off is reported (advise, default) or refused (OSBORN_STEWARD_MODE=block).
2654
+ let stewardNote = null; // advise mode: rides the allow tail below
2655
+ if (toolName === 'Bash') {
2656
+ const gate = await stewardGate(String(toolInput.command || ''), this.#opts.workingDirectory || process.cwd());
2657
+ if (gate.decision === 'deny') {
2658
+ this.#eventEmitter.emit('tool_blocked', { name: toolName, reason: gate.message });
2659
+ return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny' }, reason: gate.message };
2660
+ }
2661
+ if (gate.decision === 'advise')
2662
+ stewardNote = gate.message ?? null;
2663
+ }
2555
2664
  // Write/Edit/MultiEdit access control — plain WRITE_RULES lookup
2556
2665
  // keyed by agent name (see decideWrite). Same behavior the old
2557
2666
  // hardcoded per-role branches had, now in one visible place.
@@ -2610,10 +2719,12 @@ class ClaudeLLMStream extends llm.LLMStream {
2610
2719
  // Consume an armed spoken-progress nudge on this allowed main-agent tool call:
2611
2720
  // inject it as NON-BLOCKING additionalContext (the model reads it; the tool still
2612
2721
  // runs). Riding the allow tail guarantees one clean, non-deny injection site.
2613
- if (pendingSpeakNudge && !agentType) {
2722
+ const nudge = pendingSpeakNudge && !agentType ? speakProgressNudge(turnToolCallCount) : null;
2723
+ if (nudge)
2614
2724
  pendingSpeakNudge = false;
2615
- return { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: speakProgressNudge(turnToolCallCount) } };
2616
- }
2725
+ const context = [stewardNote, nudge].filter(Boolean).join('\n\n');
2726
+ if (context)
2727
+ return { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: context } };
2617
2728
  return {};
2618
2729
  }]
2619
2730
  }],
@@ -47,7 +47,7 @@ export type MeetingRoster = MeetingAgentDef[];
47
47
  * coupling this leaf module to the LLM module — the runtime can override at
48
48
  * startup via setRoster(Object.keys(NAMED_AGENTS)).
49
49
  */
50
- export declare const DEFAULT_AGENT_NAMES: readonly ["osborn", "researcher", "reasoner", "writer", "planner", "reviewer", "tester"];
50
+ export declare const DEFAULT_AGENT_NAMES: readonly ["osborn", "researcher", "reasoner", "writer", "planner", "reviewer", "tester", "steward"];
51
51
  /** The orchestrator's canonical id — the main agent / "the bot" itself. An
52
52
  * utterance addressed to it is NOT routed to a Tier-2 worker (the orchestrator
53
53
  * already IS the turn's handler); only a NON-orchestrator target is routable. */
@@ -45,6 +45,7 @@ export const DEFAULT_AGENT_NAMES = [
45
45
  'planner',
46
46
  'reviewer',
47
47
  'tester',
48
+ 'steward',
48
49
  ];
49
50
  /** The orchestrator's canonical id — the main agent / "the bot" itself. An
50
51
  * utterance addressed to it is NOT routed to a Tier-2 worker (the orchestrator
@@ -111,13 +111,14 @@ THE SUB-AGENTS:
111
111
  · reasoner (Opus) — architecture decisions, complex tradeoffs, implementation planning. Read-only.
112
112
  · writer (Sonnet) — ALL file changes outside the workspace. The ONLY agent with write access outside the workspace.
113
113
  · tester (Sonnet) — TDD verifier. Dispatched IN PARALLEL with the writer: writes tests from the SPEC, blind to the writer's implementation. After the writer finishes, its tests are RUN against the new code (PASS/FAIL).
114
- · reviewer (Sonnet) — dispatched AFTER the writer completes: reads the diff and returns VERDICT: ACCEPT/REJECT.
115
- · NEVER use the SDK's built-in 'general-purpose' agent — it is not configured for this project and will hit write blocks. Always pick researcher, reasoner, writer, tester, or reviewer explicitly.
114
+ · steward (Sonnet) — owns duplication and regressions. On a plan: "does this already exist?" for each new thing. On the writer's diff (after the tests): refactors to reuse existing code, cuts what is not needed, checks callers; returns CLEAN / REFACTORED / BLOCK. It never reviews its own refactor.
115
+ · reviewer (Sonnet) — dispatched AFTER the writer (and the steward): reads the diff and returns VERDICT: ACCEPT/REJECT.
116
+ · NEVER use the SDK's built-in 'general-purpose' agent — it is not configured for this project and will hit write blocks. Always pick researcher, reasoner, planner, writer, tester, steward, or reviewer explicitly.
116
117
 
117
118
  DIVISION OF LABOR — follow this chain by default for any substantive or code task:
118
- researcher (gather facts) → after the researcher returns on a substantive question, dispatch the `reasoner` GATE to judge whether the research is complete and well-sourced (GATE: PASS / NEEDS-MORE); on NEEDS-MORE send the researcher back with the named gaps and re-gate (at most 2 rounds) → planner (step plan for multi-step work) → THEN dispatch writer AND tester IN THE SAME STEP, in parallel: the writer executes the plan while the tester writes tests from the spec, blind to the implementation (TDD) → after the writer returns, RUN the tester's tests against the new code AND dispatch the reviewer on the diff → on test-FAIL or REJECT, send the writer back to fix and re-verify (at most 2 rounds) → you synthesize and speak.
119
+ researcher (gather facts) → after the researcher returns on a substantive question, dispatch the `reasoner` GATE to judge whether the research is complete and well-sourced (GATE: PASS / NEEDS-MORE); on NEEDS-MORE send the researcher back with the named gaps and re-gate (at most 2 rounds) → planner (step plan for multi-step work) → steward on the plan (reuse map) → THEN dispatch writer AND tester IN THE SAME STEP, in parallel: the writer executes the plan while the tester writes tests from the spec, blind to the implementation (TDD) → after the writer returns, RUN the tester's tests against the new code → dispatch the steward on the diff (if it REFACTORED, run the tests again; on BLOCK, ask the user) → dispatch the reviewer on the final diff → on test-FAIL or REJECT, send the writer back to fix and re-verify (at most 2 rounds) → you synthesize and speak.
119
120
  For a quick factual lookup: researcher only → you speak (a trivial lookup needs no gate).
120
- NEVER skip verification — it is symmetric across both flows: the reasoner GATE after substantive research, and the tester+reviewer after a code change. Both are the same pattern (generate → an INDEPENDENT agent verifies before you rely on it). Dispatch the tester IN PARALLEL with the writer (not after) so tests are written independently of the code.
121
+ NEVER skip verification — it is symmetric across both flows: the reasoner GATE after substantive research, and the tester + steward + reviewer after a code change. Both are the same pattern (generate → an INDEPENDENT agent verifies before you rely on it). Dispatch the tester IN PARALLEL with the writer (not after) so tests are written independently of the code.
121
122
  You may OVERRIDE this chain at any time — stop a running agent, inject, or reorder — because you can see each task's live state. The chain is the default, not a cage.
122
123
  Surfacing findings and communicating to the user is YOUR job, not a sub-agent's.
123
124
  </turn-shape>
package/dist/prompts.js CHANGED
@@ -553,15 +553,15 @@ RECOMMENDATION (if applicable):
553
553
  <role>
554
554
  You are an orchestrator with specialist sub-agents. You verify everything via tools before stating it. You are thorough, parallel-capable, and source-disciplined.
555
555
 
556
- You have three named agents available via the Task tool:
556
+ Your named agents, via the Task tool (planner, tester, steward and reviewer appear in the chain below):
557
557
  · researcher — Sonnet, fast information gathering. Use for: reading multiple files, web research, finding patterns.
558
558
  · reasoner — Opus, deep analysis. Use for: architecture decisions, complex tradeoffs, implementation planning.
559
559
  · writer — Sonnet, file changes. Use for: ALL file creation, editing, modification. Verifies before and after changes.
560
560
 
561
561
  DIVISION OF LABOR — follow this chain by default for any substantive or code task:
562
- researcher (gather facts) → planner (write a step plan for multi-step work) → writer (execute the plan) → tester AND reviewer in parallel (verify the change) → you synthesize and speak.
562
+ researcher (gather facts) → planner (write a step plan for multi-step work) → steward on the plan ("does this already exist?") → writer (execute the plan) + tester → steward on the diff (reuse existing code, cut what is not needed, check callers) → re-run tests if the steward refactored → reviewer → you synthesize and speak.
563
563
  For a quick factual query: researcher only → you speak.
564
- NEVER skip tester and reviewer after a code change.
564
+ NEVER skip tester, steward and reviewer after a code change. The steward never reviews its own refactor: the reviewer always runs after it.
565
565
  You may OVERRIDE this chain at any time — stop a running agent, inject a step, or reorder — because you can see each task's live state. The chain is the default, not a cage.
566
566
  Surfacing findings and communicating to the user is YOUR job, not a sub-agent's.
567
567
 
@@ -0,0 +1,17 @@
1
+ export type StewardMode = 'advise' | 'block' | 'off';
2
+ export type GitAction = 'commit' | 'push' | 'pr';
3
+ export declare const MARKER_FILE = "osborn-steward";
4
+ export declare const TREE_COMMAND: string;
5
+ export declare const SIGNOFF_COMMAND = "T=$(sh -c 'I=$(mktemp -u) && { GIT_INDEX_FILE=$I git read-tree HEAD 2>/dev/null || GIT_INDEX_FILE=$I git read-tree --empty; } && GIT_INDEX_FILE=$I git add -A && GIT_INDEX_FILE=$I git write-tree; S=$?; rm -f \"$I\"; exit $S') && echo \"$T\" > \"$(git rev-parse --git-dir)/osborn-steward\"";
6
+ export declare function stewardMode(env?: Record<string, string | undefined>): StewardMode;
7
+ /** The git action a shell command performs, and the directory it runs in (a leading `cd X &&` or `git -C X`). */
8
+ export declare function gitAction(cmd: string, cwd: string): {
9
+ action: GitAction;
10
+ dir: string;
11
+ } | null;
12
+ export type GateResult = {
13
+ decision: 'allow' | 'advise' | 'deny';
14
+ message?: string;
15
+ };
16
+ /** Check a Bash command against the steward sign-off. Never throws: an unreadable repo is allowed. */
17
+ export declare function stewardGate(cmd: string, cwd: string, mode?: StewardMode): Promise<GateResult>;
@@ -0,0 +1,75 @@
1
+ // Steward sign-off gate (#218). The steward agent records the tree it approved;
2
+ // a commit, push or PR whose tree differs is reported (advise) or refused (block).
3
+ // The marker is a git TREE id, so it covers the content, not a commit sha that
4
+ // does not exist yet when the steward runs (it runs before the commit).
5
+ // Scope: the Osborn agent's own sessions. This repo's dev tooling has its own
6
+ // pre-PR gate (.claude/hooks/pre-pr-gate.py); the two do not share a marker.
7
+ import { execFile } from 'node:child_process';
8
+ import { existsSync } from 'node:fs';
9
+ import { readFile } from 'node:fs/promises';
10
+ import { isAbsolute, join, resolve } from 'node:path';
11
+ import { promisify } from 'node:util';
12
+ const run = promisify(execFile);
13
+ export const MARKER_FILE = 'osborn-steward';
14
+ // Tree of the working tree (tracked + untracked, .gitignore respected), built in a
15
+ // throwaway index so the real index is left alone. Works in a repo with no commits.
16
+ export const TREE_COMMAND = `I=$(mktemp -u) && { GIT_INDEX_FILE=$I git read-tree HEAD 2>/dev/null || GIT_INDEX_FILE=$I git read-tree --empty; } && ` +
17
+ `GIT_INDEX_FILE=$I git add -A && GIT_INDEX_FILE=$I git write-tree; S=$?; rm -f "$I"; exit $S`;
18
+ // Run in the repo root after a CLEAN or REFACTORED verdict.
19
+ export const SIGNOFF_COMMAND = `T=$(sh -c '${TREE_COMMAND}') && echo "$T" > "$(git rev-parse --git-dir)/${MARKER_FILE}"`;
20
+ export function stewardMode(env = process.env) {
21
+ const m = (env.OSBORN_STEWARD_MODE || 'advise').toLowerCase();
22
+ return m === 'block' || m === 'off' ? m : 'advise';
23
+ }
24
+ // Only a command in command position counts: not `grep "git push"` or `echo "... git commit"`.
25
+ const AT = String.raw `(?:^|[;&|(\n]\s*)`;
26
+ const GIT_OPTS = String.raw `(?:\s+-[Cc]\s+\S+)*`;
27
+ /** The git action a shell command performs, and the directory it runs in (a leading `cd X &&` or `git -C X`). */
28
+ export function gitAction(cmd, cwd) {
29
+ const action = new RegExp(`${AT}gh\\s+pr\\s+create\\b`).test(cmd) ? 'pr'
30
+ : new RegExp(`${AT}git${GIT_OPTS}\\s+push\\b`).test(cmd) ? 'push'
31
+ : new RegExp(`${AT}git${GIT_OPTS}\\s+commit\\b`).test(cmd) ? 'commit'
32
+ : null;
33
+ if (!action)
34
+ return null;
35
+ const cd = cmd.match(/^\s*cd\s+("[^"]+"|'[^']+'|\S+)\s*&&/);
36
+ const gitC = cmd.match(/\bgit\s+-C\s+("[^"]+"|'[^']+'|\S+)/);
37
+ const raw = (gitC?.[1] ?? cd?.[1])?.replace(/^["']|["']$/g, '');
38
+ const dir = raw ? (isAbsolute(raw) ? raw : resolve(cwd, raw.replace(/^~(?=\/|$)/, process.env.HOME || '~'))) : cwd;
39
+ return { action, dir };
40
+ }
41
+ const git = async (dir, args) => (await run('git', args, { cwd: dir })).stdout.trim();
42
+ const workingTree = async (dir) => (await run('sh', ['-c', TREE_COMMAND], { cwd: dir })).stdout.trim();
43
+ /** Is the content this action ships the content the steward signed off? */
44
+ async function signedFor(dir, action, marker) {
45
+ // A commit ships the working tree (`git add -A && git commit` is checked before the add runs).
46
+ if (action === 'commit')
47
+ return (await workingTree(dir)) === marker;
48
+ // Push / PR ship HEAD: signed if HEAD is exactly the signed tree, or nothing tracked
49
+ // changed since and the working tree still matches (untracked leftovers allowed).
50
+ if ((await git(dir, ['rev-parse', 'HEAD^{tree}'])) === marker)
51
+ return true;
52
+ const trackedClean = await run('git', ['diff', '--quiet', 'HEAD'], { cwd: dir }).then(() => true, () => false);
53
+ return trackedClean && (await workingTree(dir)) === marker;
54
+ }
55
+ /** Check a Bash command against the steward sign-off. Never throws: an unreadable repo is allowed. */
56
+ export async function stewardGate(cmd, cwd, mode = stewardMode()) {
57
+ if (mode === 'off')
58
+ return { decision: 'allow' };
59
+ const hit = gitAction(cmd, cwd);
60
+ if (!hit || !existsSync(hit.dir))
61
+ return { decision: 'allow' };
62
+ try {
63
+ const markerPath = join(await git(hit.dir, ['rev-parse', '--absolute-git-dir']), MARKER_FILE);
64
+ const marker = existsSync(markerPath) ? (await readFile(markerPath, 'utf8')).trim() : '';
65
+ if (marker && await signedFor(hit.dir, hit.action, marker))
66
+ return { decision: 'allow' };
67
+ }
68
+ catch {
69
+ return { decision: 'allow' };
70
+ }
71
+ const what = hit.action === 'pr' ? 'opening this PR' : `this ${hit.action}`;
72
+ const message = `The steward has not signed off on the code in ${what}: run the \`steward\` agent on the change first ` +
73
+ `(it records its sign-off for this exact content; any later edit needs a new sign-off).`;
74
+ return mode === 'block' ? { decision: 'deny', message } : { decision: 'advise', message };
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osborn",
3
- "version": "0.9.279",
3
+ "version": "0.9.280",
4
4
  "description": "Voice AI coding assistant - local agent that connects to Osborn frontend",
5
5
  "type": "module",
6
6
  "bin": {