osborn 0.9.278 → 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.
- package/.claude/skills/browser-apply/SKILL.md +35 -16
- package/.claude/skills/browser-apply/candidate.example.env +14 -0
- package/.claude/skills/browser-apply/fill.mjs +8 -0
- package/dist/claude-auth.d.ts +22 -0
- package/dist/claude-auth.js +63 -0
- package/dist/claude-llm.d.ts +6 -0
- package/dist/claude-llm.js +117 -6
- package/dist/config.d.ts +35 -0
- package/dist/config.js +12 -11
- package/dist/index.js +75 -69
- package/dist/meeting-addressing.d.ts +1 -1
- package/dist/meeting-addressing.js +1 -0
- package/dist/prompts/direct-mode-research.md +5 -4
- package/dist/prompts.js +3 -3
- package/dist/session-switch.d.ts +11 -37
- package/dist/session-switch.js +28 -52
- package/dist/steward-gate.d.ts +17 -0
- package/dist/steward-gate.js +75 -0
- package/package.json +1 -1
- package/dist/key-health.d.ts +0 -56
- package/dist/key-health.js +0 -93
|
@@ -29,7 +29,7 @@ This approach catches rendering issues, unexpected fields, and errors before the
|
|
|
29
29
|
|
|
30
30
|
## One-time setup (user does this once per machine)
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Candidate values (email, password, phone, address, work history, education) are filled by the `fill.mjs` helper, not by the MCP tools. The helper and the Playwright MCP must drive the SAME browser, which means both attach to one Chrome over CDP on loopback.
|
|
33
33
|
|
|
34
34
|
1. Secret file. The user creates it and types the values in their own editor (never ask for the values in chat, never write them yourself):
|
|
35
35
|
```bash
|
|
@@ -52,9 +52,9 @@ Secret fields (email, password, phone, address) are filled by the `fill.mjs` hel
|
|
|
52
52
|
## Step-by-Step Execution Pattern
|
|
53
53
|
|
|
54
54
|
### Step 0 — Check the helper, then open the browser
|
|
55
|
-
Run `node ~/.claude/skills/browser-apply/fill.mjs check` first. It prints variable names and `cdp: reachable` or `cdp: unreachable`, never values.
|
|
55
|
+
Run `node ~/.claude/skills/browser-apply/fill.mjs check` first. It prints variable names (including an `extra:` line listing every other `CANDIDATE_*` key the user set — work history, education, anything else) and `cdp: reachable` or `cdp: unreachable`, never values.
|
|
56
56
|
- File missing / refused: point the user at "One-time setup" step 1 and wait.
|
|
57
|
-
- `cdp: unreachable`: you can still navigate and
|
|
57
|
+
- `cdp: unreachable`: you can still navigate and click with the MCP tools, but every value from the secret file — email, password, phone, address, and every work-history and education field — must be typed by the user themselves. You have no copy of any of them; do not reconstruct one.
|
|
58
58
|
|
|
59
59
|
Use: `mcp__playwright__browser_navigate` with the applyManually URL
|
|
60
60
|
|
|
@@ -81,8 +81,11 @@ Fields to fill:
|
|
|
81
81
|
- Sponsorship: No
|
|
82
82
|
|
|
83
83
|
### Step 4 — My Experience
|
|
84
|
-
Snapshot → click Add for each job entry → fill title/company/dates/description
|
|
85
|
-
|
|
84
|
+
Snapshot → click Add for each job entry → fill title/company/dates/description
|
|
85
|
+
with the helper from `CANDIDATE_JOB_N_*` (see "Candidate Data") → save each →
|
|
86
|
+
screenshot. Then add education entries from `CANDIDATE_EDUCATION_N_*`.
|
|
87
|
+
Never type a job, employer, school or date you were not given by the helper; if
|
|
88
|
+
one is missing, ask the user rather than filling anything.
|
|
86
89
|
Ask user before clicking Next.
|
|
87
90
|
|
|
88
91
|
### Step 5 — Application Questions
|
|
@@ -113,14 +116,30 @@ Personal values are NOT stored in this skill. They live in a local secret file t
|
|
|
113
116
|
| Phone | `$CANDIDATE_PHONE` |
|
|
114
117
|
| Address line 1 | `$CANDIDATE_ADDRESS_LINE1` |
|
|
115
118
|
| City / State / Zip | `$CANDIDATE_CITY` / `$CANDIDATE_STATE` / `$CANDIDATE_ZIP` |
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
1
|
|
123
|
-
|
|
119
|
+
| Job N title / employer | `$CANDIDATE_JOB_N_TITLE` / `$CANDIDATE_JOB_N_COMPANY` |
|
|
120
|
+
| Job N dates | `$CANDIDATE_JOB_N_START` / `$CANDIDATE_JOB_N_END` |
|
|
121
|
+
| Job N description | `$CANDIDATE_JOB_N_DESCRIPTION` |
|
|
122
|
+
| Education N | `$CANDIDATE_EDUCATION_N_SCHOOL` / `$CANDIDATE_EDUCATION_N_DEGREE` / `$CANDIDATE_EDUCATION_N_FIELD` |
|
|
123
|
+
|
|
124
|
+
Work history and education go through the SAME mechanism as the fields above,
|
|
125
|
+
with `N` starting at 1 (`CANDIDATE_JOB_1_TITLE`, `CANDIDATE_JOB_2_TITLE`, …).
|
|
126
|
+
This skill ships NO employment or education values of its own (an earlier
|
|
127
|
+
version carried a literal list; it was removed because it made the skill submit
|
|
128
|
+
an employer that was not the user's), and you must never supply one:
|
|
129
|
+
|
|
130
|
+
- Run `fill.mjs check` and read its `extra:` line: that is exactly which
|
|
131
|
+
`CANDIDATE_JOB_*` / `CANDIDATE_EDUCATION_*` keys the user actually set. It
|
|
132
|
+
prints names only, never values.
|
|
133
|
+
- Fill every one of them with the helper, exactly like the other fields — never
|
|
134
|
+
by typing a value through `mcp__playwright__browser_type` / `browser_fill_form`.
|
|
135
|
+
- If a job or education entry the form asks for is not in the secret file, STOP
|
|
136
|
+
and ask the user to type that entry themselves or add the key. Do NOT invent,
|
|
137
|
+
infer, or carry over an employer, title, school, degree or date from anywhere
|
|
138
|
+
— not from the user's repo, résumé file, an earlier application, or your own
|
|
139
|
+
guess. A wrong employer on a submitted application is a false statement to
|
|
140
|
+
that employer.
|
|
141
|
+
- Numbers are not contiguous promises: stop at the first N with no
|
|
142
|
+
`CANDIDATE_JOB_N_TITLE`, and ask before adding more entries than the file has.
|
|
124
143
|
|
|
125
144
|
### Filling secret fields
|
|
126
145
|
Use the helper `fill.mjs` next to this SKILL.md (normally `~/.claude/skills/browser-apply/fill.mjs`). It reads `~/.osborn/candidate.env` itself (regular file, owned by you, mode 600) and attaches to the loopback CDP browser from "One-time setup". It fills only on an https page whose host EXACTLY equals `--confirm-host`. Inside the page, right before each field, it checks again that the field's own frame is https on that host. The password goes only into an `<input type="password">`. It prints `about to fill NAME on HOST` before each field and `filled NAME -> selector` after, never a value.
|
|
@@ -157,9 +176,9 @@ Rules:
|
|
|
157
176
|
| Address | `[data-automation-id="addressSection_addressLine1"]` | `CANDIDATE_ADDRESS_LINE1` (helper) |
|
|
158
177
|
| City | `[data-automation-id="addressSection_city"]` | `CANDIDATE_CITY` (helper) |
|
|
159
178
|
| Zip | `[data-automation-id="addressSection_postalCode"]` | `CANDIDATE_ZIP` (helper) |
|
|
160
|
-
| Job title | `[data-automation-id="jobTitle"]` |
|
|
161
|
-
| Company | `[data-automation-id="company"]` |
|
|
162
|
-
| Description | `[data-automation-id="description"]` |
|
|
179
|
+
| Job title | `[data-automation-id="jobTitle"]` | `CANDIDATE_JOB_N_TITLE` (helper) |
|
|
180
|
+
| Company | `[data-automation-id="company"]` | `CANDIDATE_JOB_N_COMPANY` (helper) |
|
|
181
|
+
| Description | `[data-automation-id="description"]` | `CANDIDATE_JOB_N_DESCRIPTION` (helper) |
|
|
163
182
|
| Next button | `[data-automation-id="bottom-navigation-next-btn"]` | - |
|
|
164
183
|
| Create Account | `[data-automation-id="click_filter"][aria-label="Create Account"]` | - |
|
|
165
184
|
|
|
@@ -12,5 +12,19 @@ CANDIDATE_CITY=YOUR_CITY
|
|
|
12
12
|
CANDIDATE_STATE=YOUR_STATE
|
|
13
13
|
CANDIDATE_ZIP=YOUR_ZIP
|
|
14
14
|
|
|
15
|
+
# Work history. The skill ships NO employment values: if a job is not here, the
|
|
16
|
+
# model must ask you instead of filling anything. Number the entries from 1 and
|
|
17
|
+
# add as many as you need (JOB_3, JOB_4, …); delete the ones you do not use.
|
|
18
|
+
CANDIDATE_JOB_1_TITLE=YOUR_JOB_TITLE
|
|
19
|
+
CANDIDATE_JOB_1_COMPANY=YOUR_EMPLOYER
|
|
20
|
+
CANDIDATE_JOB_1_START=YOUR_START_DATE
|
|
21
|
+
CANDIDATE_JOB_1_END=YOUR_END_DATE_OR_Present
|
|
22
|
+
CANDIDATE_JOB_1_DESCRIPTION=WHAT_YOU_DID
|
|
23
|
+
|
|
24
|
+
# Education, numbered the same way. Also ships empty on purpose.
|
|
25
|
+
CANDIDATE_EDUCATION_1_SCHOOL=YOUR_SCHOOL
|
|
26
|
+
CANDIDATE_EDUCATION_1_DEGREE=YOUR_DEGREE
|
|
27
|
+
CANDIDATE_EDUCATION_1_FIELD=YOUR_FIELD_OF_STUDY
|
|
28
|
+
|
|
15
29
|
# Optional: loopback CDP endpoint of the shared browser (non-loopback hosts are refused).
|
|
16
30
|
# CANDIDATE_CDP_URL=http://127.0.0.1:9222
|
|
@@ -269,8 +269,16 @@ export async function checkReport(path, fileEnv, fetchImpl = fetch) {
|
|
|
269
269
|
const set = EXPECTED_VARS.filter(k => fileEnv[k])
|
|
270
270
|
const missing = EXPECTED_VARS.filter(k => !fileEnv[k])
|
|
271
271
|
const cdp = cdpFrom(fileEnv)
|
|
272
|
+
// Anything else the user put in the file: work history, education, and any
|
|
273
|
+
// key a future form needs. Per-entry and open-ended, so deliberately not in
|
|
274
|
+
// EXPECTED_VARS (one job and no degree must not read as "missing"); listed by
|
|
275
|
+
// NAME so the model can see what it may fill and never invents an employer.
|
|
276
|
+
const extra = Object.keys(fileEnv)
|
|
277
|
+
.filter(k => k.startsWith('CANDIDATE_') && fileEnv[k] && !EXPECTED_VARS.includes(k) && !CONFIG_KEYS.includes(k))
|
|
278
|
+
.sort()
|
|
272
279
|
const lines = [`ok: ${path} is a regular file owned by you, mode 600`, `set: ${set.join(', ') || '(none)'}`]
|
|
273
280
|
if (missing.length) lines.push(`missing: ${missing.join(', ')}`)
|
|
281
|
+
lines.push(`extra: ${extra.join(', ') || '(none — ask the user for any work history, education or other field the form needs)'}`)
|
|
274
282
|
lines.push(`cdp: ${(await probeCdp(cdp, fetchImpl)) ? 'reachable' : 'unreachable'} (${cdp})`)
|
|
275
283
|
return lines
|
|
276
284
|
}
|
package/dist/claude-auth.d.ts
CHANGED
|
@@ -98,6 +98,28 @@ export declare function applyAuthFallback(): ActiveProvider;
|
|
|
98
98
|
* answering instead of the old hardcoded 'claude' (issue #87).
|
|
99
99
|
*/
|
|
100
100
|
export type ActiveProvider = 'claude' | 'anthropic' | 'zai' | 'openrouter' | 'none';
|
|
101
|
+
/** One fallback key's self-test result, as served on GET /health. */
|
|
102
|
+
export interface KeyHealthEntry {
|
|
103
|
+
provider: string;
|
|
104
|
+
status: 'ok' | 'failed' | 'expired';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A /v1/messages probe's HTTP status → key-health verdict, or null when the
|
|
108
|
+
* outcome is ambiguous: only a DEFINITIVE credential/billing failure earns a
|
|
109
|
+
* negative verdict, because a transient blip must never fabricate "No working
|
|
110
|
+
* model". 403 is deliberately ambiguous — a WAF/edge block or gateway throttle in
|
|
111
|
+
* front of api.z.ai or openrouter.ai answers 403 for a perfectly good key.
|
|
112
|
+
*/
|
|
113
|
+
export declare function classifyProbeStatus(httpStatus: number): 'ok' | 'failed' | 'expired' | null;
|
|
114
|
+
/**
|
|
115
|
+
* Fire ONE minimal request against the ACTIVE provider endpoint to confirm the
|
|
116
|
+
* configured key can really answer (#87, gap 5) — applyAuthFallback() picks a tier
|
|
117
|
+
* on key PRESENCE, which is not validity. Reads the env that function just set, so
|
|
118
|
+
* it tests exactly what query() will use; every fallback tier speaks native
|
|
119
|
+
* Anthropic Messages, so one request shape covers them. Returns null when there
|
|
120
|
+
* was nothing to test or the outcome was ambiguous — never a fabricated failure.
|
|
121
|
+
*/
|
|
122
|
+
export declare function probeActiveProviderKey(provider: string, env?: NodeJS.ProcessEnv, timeoutMs?: number): Promise<KeyHealthEntry | null>;
|
|
101
123
|
/**
|
|
102
124
|
* Clear the fallback redirect (z.ai house pass or OpenRouter) — but ONLY if
|
|
103
125
|
* applyAuthFallback() set it. Called from the auth onComplete path so a user who later finishes real
|
package/dist/claude-auth.js
CHANGED
|
@@ -349,6 +349,69 @@ export function applyAuthFallback() {
|
|
|
349
349
|
console.warn('[auth-fallback] no Claude login, no ANTHROPIC_API_KEY, no Z_AI key, and no OPENROUTER_API_KEY — agent may be unauthenticated');
|
|
350
350
|
return 'none';
|
|
351
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* A /v1/messages probe's HTTP status → key-health verdict, or null when the
|
|
354
|
+
* outcome is ambiguous: only a DEFINITIVE credential/billing failure earns a
|
|
355
|
+
* negative verdict, because a transient blip must never fabricate "No working
|
|
356
|
+
* model". 403 is deliberately ambiguous — a WAF/edge block or gateway throttle in
|
|
357
|
+
* front of api.z.ai or openrouter.ai answers 403 for a perfectly good key.
|
|
358
|
+
*/
|
|
359
|
+
export function classifyProbeStatus(httpStatus) {
|
|
360
|
+
if (httpStatus >= 200 && httpStatus < 300)
|
|
361
|
+
return 'ok';
|
|
362
|
+
if (httpStatus === 429)
|
|
363
|
+
return 'ok';
|
|
364
|
+
if (httpStatus === 401)
|
|
365
|
+
return 'expired';
|
|
366
|
+
if (httpStatus === 402)
|
|
367
|
+
return 'failed';
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Fire ONE minimal request against the ACTIVE provider endpoint to confirm the
|
|
372
|
+
* configured key can really answer (#87, gap 5) — applyAuthFallback() picks a tier
|
|
373
|
+
* on key PRESENCE, which is not validity. Reads the env that function just set, so
|
|
374
|
+
* it tests exactly what query() will use; every fallback tier speaks native
|
|
375
|
+
* Anthropic Messages, so one request shape covers them. Returns null when there
|
|
376
|
+
* was nothing to test or the outcome was ambiguous — never a fabricated failure.
|
|
377
|
+
*/
|
|
378
|
+
export async function probeActiveProviderKey(provider, env = process.env, timeoutMs = 8000) {
|
|
379
|
+
const base = (cleanEnvKey(env.ANTHROPIC_BASE_URL) || 'https://api.anthropic.com').replace(/\/$/, '');
|
|
380
|
+
const authToken = cleanEnvKey(env.ANTHROPIC_AUTH_TOKEN);
|
|
381
|
+
const apiKey = cleanEnvKey(env.ANTHROPIC_API_KEY);
|
|
382
|
+
// Nothing to test — no credential configured for the active endpoint.
|
|
383
|
+
if (!authToken && !apiKey)
|
|
384
|
+
return null;
|
|
385
|
+
const headers = {
|
|
386
|
+
'content-type': 'application/json',
|
|
387
|
+
'anthropic-version': '2023-06-01',
|
|
388
|
+
};
|
|
389
|
+
// Fallback redirects (z.ai / OpenRouter) authenticate with a bearer AUTH_TOKEN;
|
|
390
|
+
// a user's own Anthropic key uses x-api-key. applyAuthFallback sets exactly one.
|
|
391
|
+
if (authToken)
|
|
392
|
+
headers['authorization'] = `Bearer ${authToken}`;
|
|
393
|
+
else
|
|
394
|
+
headers['x-api-key'] = apiKey;
|
|
395
|
+
const body = JSON.stringify({
|
|
396
|
+
model: cleanEnvKey(env.ANTHROPIC_MODEL),
|
|
397
|
+
max_tokens: 1,
|
|
398
|
+
messages: [{ role: 'user', content: 'hi' }],
|
|
399
|
+
});
|
|
400
|
+
try {
|
|
401
|
+
const r = await fetch(`${base}/v1/messages`, {
|
|
402
|
+
method: 'POST',
|
|
403
|
+
headers,
|
|
404
|
+
body,
|
|
405
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
406
|
+
});
|
|
407
|
+
const verdict = classifyProbeStatus(r.status);
|
|
408
|
+
return verdict ? { provider, status: verdict } : null;
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
// Network error / timeout — ambiguous, never a fabricated verdict.
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
352
415
|
/**
|
|
353
416
|
* Clear the fallback redirect (z.ai house pass or OpenRouter) — but ONLY if
|
|
354
417
|
* applyAuthFallback() set it. Called from the auth onComplete path so a user who later finishes real
|
package/dist/claude-llm.d.ts
CHANGED
package/dist/claude-llm.js
CHANGED
|
@@ -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 `
|
|
1051
|
-
|
|
1052
|
-
'
|
|
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
|
-
|
|
2722
|
+
const nudge = pendingSpeakNudge && !agentType ? speakProgressNudge(turnToolCallCount) : null;
|
|
2723
|
+
if (nudge)
|
|
2614
2724
|
pendingSpeakNudge = false;
|
|
2615
|
-
|
|
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
|
}],
|
package/dist/config.d.ts
CHANGED
|
@@ -162,6 +162,41 @@ export interface ClaudeSessionEntry {
|
|
|
162
162
|
filePath: string;
|
|
163
163
|
fileSize: number;
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Reverse a project slug back to a path — LAST-RESORT fallback only.
|
|
167
|
+
*
|
|
168
|
+
* Claude's slug encoding (`/` → `-`, `.` → `-`) is LOSSY: you can't tell from a
|
|
169
|
+
* slug whether a given `-` was originally `/`, `.`, or a literal `-` inside a
|
|
170
|
+
* directory name like `pensive-bohr`. So this function cannot reliably
|
|
171
|
+
* round-trip an arbitrary path.
|
|
172
|
+
*
|
|
173
|
+
* Strategy: produce the naive guess (with a small `--` → `/.` improvement for
|
|
174
|
+
* dot-directories like `.claude`), then VALIDATE it with `existsSync`. If the
|
|
175
|
+
* guess doesn't exist, return empty string — that way the caller knows the
|
|
176
|
+
* reverse failed and can fall back cleanly instead of passing a broken path
|
|
177
|
+
* to `child_process.spawn` and crashing with ENOENT.
|
|
178
|
+
*
|
|
179
|
+
* The primary source of cwd is `extractCwd()` which reads the actual cwd from
|
|
180
|
+
* the JSONL file. This function is only reached when that fails.
|
|
181
|
+
*/
|
|
182
|
+
export declare function slugToPath(slug: string): string;
|
|
183
|
+
/**
|
|
184
|
+
* Extract cwd from the first JSONL entry that carries a `cwd` field.
|
|
185
|
+
*
|
|
186
|
+
* Previously: read only the first 8KB and only accepted `type === 'user'`. That
|
|
187
|
+
* broke for sessions whose first JSONL entry was larger than 8KB — e.g. a
|
|
188
|
+
* `queue-operation` containing pasted email/page text. readline never emits the
|
|
189
|
+
* `line` event for an incomplete final chunk, so the scan finds nothing,
|
|
190
|
+
* `listAllClaudeSessions` falls through to the lossy `slugToPath` reverse, and
|
|
191
|
+
* the mangled path ends up as a `cwd` passed to `child_process.spawn`, producing
|
|
192
|
+
* the misleading "Claude Code executable not found" error (see MEMORY bug #11).
|
|
193
|
+
*
|
|
194
|
+
* Now: stream line-by-line with no byte cap, short-circuit on the first entry
|
|
195
|
+
* with a `cwd` field regardless of `type` (every `user` / `attachment` /
|
|
196
|
+
* `assistant` / `system` entry in a Claude JSONL session carries `cwd`, so the
|
|
197
|
+
* scan finishes in the first few KB of any normal session).
|
|
198
|
+
*/
|
|
199
|
+
export declare function extractCwd(filePath: string): Promise<string>;
|
|
165
200
|
export declare function invalidateSessionListCache(): void;
|
|
166
201
|
/**
|
|
167
202
|
* Scan ALL Claude Code projects for sessions.
|
package/dist/config.js
CHANGED
|
@@ -561,8 +561,9 @@ function scanPreviewLines(text, skipFirstPartial) {
|
|
|
561
561
|
* gate and (b) the LAST user message. So: small files are read whole (exact);
|
|
562
562
|
* large files read a bounded HEAD (gate + density sample + first turn/title) +
|
|
563
563
|
* TAIL (last user message, last activity), turning a hundreds-of-MB parse into
|
|
564
|
-
* ~192KB. messageCount becomes an estimate for large files — it's display-only
|
|
565
|
-
* and
|
|
564
|
+
* ~192KB. messageCount becomes an estimate for large files — it's display-only,
|
|
565
|
+
* and is derived from BOTH samples because a compacted transcript can have no
|
|
566
|
+
* countable turn in the head at all.
|
|
566
567
|
*/
|
|
567
568
|
async function getSessionPreview(filePath, fileSize) {
|
|
568
569
|
const HEAD = 64 * 1024;
|
|
@@ -603,10 +604,10 @@ async function getSessionPreview(filePath, fileSize) {
|
|
|
603
604
|
const head = scanPreviewLines(headBuf.toString('utf8', 0, hn), false);
|
|
604
605
|
const tail = scanPreviewLines(tailBuf.toString('utf8', 0, tn), true);
|
|
605
606
|
const lastMessage = tail.lastUser ?? head.lastUser;
|
|
606
|
-
//
|
|
607
|
-
//
|
|
608
|
-
const
|
|
609
|
-
const messageCount =
|
|
607
|
+
// Density from BOTH samples: a compacted transcript opens with a
|
|
608
|
+
// compact_boundary plus tool records, so head.count alone can be 0.
|
|
609
|
+
const sampled = head.count + tail.count;
|
|
610
|
+
const messageCount = sampled > 0 ? Math.max(3, Math.round(size * sampled / (hn + tn))) : 3;
|
|
610
611
|
return {
|
|
611
612
|
lastMessage,
|
|
612
613
|
title: tail.aiTitle ?? head.aiTitle ?? head.firstUser,
|
|
@@ -656,7 +657,7 @@ export function sessionExists(sessionId, projectPath) {
|
|
|
656
657
|
* The primary source of cwd is `extractCwd()` which reads the actual cwd from
|
|
657
658
|
* the JSONL file. This function is only reached when that fails.
|
|
658
659
|
*/
|
|
659
|
-
function slugToPath(slug) {
|
|
660
|
+
export function slugToPath(slug) {
|
|
660
661
|
// Naive reverse: leading `-` → `/`, `--` → `/.`, remaining `-` → `/`.
|
|
661
662
|
// The `--` → `/.` pass handles dot-prefixed directories like `.claude`.
|
|
662
663
|
const guess = slug
|
|
@@ -683,7 +684,7 @@ const UUID_JSONL_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]
|
|
|
683
684
|
* `assistant` / `system` entry in a Claude JSONL session carries `cwd`, so the
|
|
684
685
|
* scan finishes in the first few KB of any normal session).
|
|
685
686
|
*/
|
|
686
|
-
async function extractCwd(filePath) {
|
|
687
|
+
export async function extractCwd(filePath) {
|
|
687
688
|
return new Promise((resolve) => {
|
|
688
689
|
const fileStream = createReadStream(filePath);
|
|
689
690
|
const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity });
|
|
@@ -726,9 +727,9 @@ const SESSION_LIST_TTL_MS = 300_000;
|
|
|
726
727
|
export function invalidateSessionListCache() {
|
|
727
728
|
_sessionListCache = null;
|
|
728
729
|
}
|
|
729
|
-
//
|
|
730
|
-
//
|
|
731
|
-
const SESSION_MANIFEST_VERSION =
|
|
730
|
+
// Older manifests are discarded on load. v2: sanitized preview fields. v3: the
|
|
731
|
+
// large-file messageCount estimate changed, and unchanged files are never re-read.
|
|
732
|
+
const SESSION_MANIFEST_VERSION = 3;
|
|
732
733
|
function sessionManifestPath() {
|
|
733
734
|
return join(homedir(), '.claude', 'session-manifest.json');
|
|
734
735
|
}
|