@opengsd/gsd-core 1.16.0 → 1.18.0
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-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -2
- package/.opencode/plugins/gsd-core.js +251 -1
- package/.opencode/plugins/gsd-statusline/tui.tsx +55 -0
- package/GEMINI.md +1 -1
- package/agents/gsd-advisor-researcher.compact.md +1 -1
- package/agents/gsd-advisor-researcher.md +1 -1
- package/agents/gsd-assumptions-analyzer.compact.md +1 -1
- package/agents/gsd-assumptions-analyzer.md +1 -1
- package/agents/gsd-code-fixer.compact.md +1 -1
- package/agents/gsd-code-fixer.md +1 -1
- package/agents/gsd-code-reviewer.compact.md +1 -1
- package/agents/gsd-code-reviewer.md +1 -1
- package/agents/gsd-codebase-mapper.compact.md +1 -1
- package/agents/gsd-codebase-mapper.md +1 -1
- package/agents/gsd-debug-session-manager.compact.md +6 -0
- package/agents/gsd-debug-session-manager.md +6 -0
- package/agents/gsd-debugger.md +1 -1
- package/agents/gsd-doc-verifier.compact.md +4 -4
- package/agents/gsd-doc-verifier.md +4 -3
- package/agents/gsd-doc-writer.compact.md +23 -5
- package/agents/gsd-doc-writer.md +19 -6
- package/agents/gsd-eval-auditor.compact.md +1 -1
- package/agents/gsd-eval-auditor.md +1 -1
- package/agents/gsd-executor.md +7 -3
- package/agents/gsd-integration-checker.compact.md +1 -1
- package/agents/gsd-integration-checker.md +1 -1
- package/agents/gsd-nyquist-auditor.compact.md +1 -1
- package/agents/gsd-nyquist-auditor.md +1 -1
- package/agents/gsd-phase-researcher.md +1 -1
- package/agents/gsd-plan-checker.md +2 -1
- package/agents/gsd-planner.md +5 -4
- package/agents/gsd-project-researcher.compact.md +1 -1
- package/agents/gsd-project-researcher.md +1 -1
- package/agents/gsd-research-synthesizer.compact.md +5 -5
- package/agents/gsd-research-synthesizer.md +5 -5
- package/agents/gsd-roadmapper.compact.md +1 -1
- package/agents/gsd-roadmapper.md +1 -1
- package/agents/gsd-security-auditor.compact.md +1 -1
- package/agents/gsd-security-auditor.md +1 -1
- package/agents/gsd-ui-auditor.compact.md +1 -1
- package/agents/gsd-ui-auditor.md +1 -1
- package/agents/gsd-ui-checker.compact.md +1 -1
- package/agents/gsd-ui-checker.md +1 -1
- package/agents/gsd-ui-researcher.compact.md +13 -1
- package/agents/gsd-ui-researcher.md +28 -1
- package/agents/gsd-verifier.md +1 -1
- package/bin/gsd-mcp-server.js +3 -1
- package/bin/install.js +398 -95
- package/commands/gsd/code-review.md +8 -0
- package/commands/gsd/pause-work.md +1 -1
- package/gsd-core/bin/gsd-tools.cjs +34 -12
- package/gsd-core/bin/lib/adr-parser.cjs +37 -5
- package/gsd-core/bin/lib/capability-ledger.cjs +25 -0
- package/gsd-core/bin/lib/capability-lock.cjs +29 -7
- package/gsd-core/bin/lib/capability-registry.cjs +138 -80
- package/gsd-core/bin/lib/capability-source.cjs +3 -1
- package/gsd-core/bin/lib/capability-state.cjs +6 -3
- package/gsd-core/bin/lib/capability-validator.cjs +8 -5
- package/gsd-core/bin/lib/capability-writer.cjs +2 -1
- package/gsd-core/bin/lib/commands.cjs +33 -9
- package/gsd-core/bin/lib/config-loader.cjs +3 -3
- package/gsd-core/bin/lib/decision-coverage-support.cjs +19 -0
- package/gsd-core/bin/lib/gate-context-drift.cjs +5 -4
- package/gsd-core/bin/lib/gate-decision-coverage-plan.cjs +15 -0
- package/gsd-core/bin/lib/gate-decision-coverage-verify.cjs +13 -0
- package/gsd-core/bin/lib/gate-predicate-evaluator.cjs +23 -3
- package/gsd-core/bin/lib/gate-predicate.cjs +8 -12
- package/gsd-core/bin/lib/gate-tdd-review-checkpoint.cjs +60 -5
- package/gsd-core/bin/lib/gate-ui-safety.cjs +2 -1
- package/gsd-core/bin/lib/graphify.cjs +3 -2
- package/gsd-core/bin/lib/init.cjs +43 -16
- package/gsd-core/bin/lib/install-effort-resolver.cjs +2 -2
- package/gsd-core/bin/lib/install-engine.cjs +11 -0
- package/gsd-core/bin/lib/install-model-override-resolver.cjs +4 -3
- package/gsd-core/bin/lib/install-profiles.cjs +5 -3
- package/gsd-core/bin/lib/install-shadow-report.cjs +12 -0
- package/gsd-core/bin/lib/installer-migrations/011-opencode-mcp-no-prompts.cjs +99 -0
- package/gsd-core/bin/lib/installer-migrations.cjs +54 -1
- package/gsd-core/bin/lib/jsonc-edit.cjs +418 -0
- package/gsd-core/bin/lib/loop-host-contract.cjs +2 -1
- package/gsd-core/bin/lib/mcp-server.cjs +5 -1
- package/gsd-core/bin/lib/opencode-mcp-entry.cjs +39 -0
- package/gsd-core/bin/lib/opencode-version.cjs +486 -0
- package/gsd-core/bin/lib/phase.cjs +141 -11
- package/gsd-core/bin/lib/quick-batch-dispatch.cjs +2 -1
- package/gsd-core/bin/lib/report-parser.cjs +57 -1
- package/gsd-core/bin/lib/review-lane-invocation.cjs +40 -0
- package/gsd-core/bin/lib/review-reviewer-selection.cjs +20 -1
- package/gsd-core/bin/lib/roadmap.cjs +56 -5
- package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +142 -6
- package/gsd-core/bin/lib/runtime-homes.cjs +18 -0
- package/gsd-core/bin/lib/runtime-hooks-surface.cjs +58 -3
- package/gsd-core/bin/lib/runtime-slash.cjs +13 -0
- package/gsd-core/bin/lib/shell-command-projection.cjs +2 -0
- package/gsd-core/bin/lib/smart-entry.cjs +100 -53
- package/gsd-core/bin/lib/state-document.cjs +37 -3
- package/gsd-core/bin/lib/state-transition.cjs +98 -19
- package/gsd-core/bin/lib/state.cjs +544 -126
- package/gsd-core/bin/lib/task-command-router.cjs +2 -3
- package/gsd-core/bin/lib/tdd-red-evidence.cjs +5 -0
- package/gsd-core/bin/lib/tdd-test-files.cjs +42 -0
- package/gsd-core/bin/lib/update-context.cjs +18 -1
- package/gsd-core/bin/lib/verification.cjs +107 -17
- package/gsd-core/bin/lib/verify.cjs +36 -1
- package/gsd-core/references/agent-contracts.md +1 -1
- package/gsd-core/references/agent-skills-bootstrap.md +26 -7
- package/gsd-core/references/git-integration.md +3 -3
- package/gsd-core/references/planner-reversibility.md +18 -4
- package/gsd-core/references/planner-verify-command-grounding.md +18 -0
- package/gsd-core/references/tdd.md +4 -3
- package/gsd-core/references/verifier-phase-gates.md +8 -1
- package/gsd-core/workflows/add-backlog.md +10 -2
- package/gsd-core/workflows/add-phase.md +5 -1
- package/gsd-core/workflows/add-tests.md +5 -1
- package/gsd-core/workflows/add-todo.md +5 -1
- package/gsd-core/workflows/ai-integration-phase.md +5 -1
- package/gsd-core/workflows/audit-milestone.md +21 -9
- package/gsd-core/workflows/autonomous/templates/minimal-context.md +41 -0
- package/gsd-core/workflows/autonomous.md +52 -64
- package/gsd-core/workflows/check-todos.md +5 -1
- package/gsd-core/workflows/code-review-fix.md +5 -1
- package/gsd-core/workflows/code-review.md +21 -2
- package/gsd-core/workflows/complete-milestone/detail/elaboration.md +5 -1
- package/gsd-core/workflows/complete-milestone.md +25 -5
- package/gsd-core/workflows/debug.md +5 -1
- package/gsd-core/workflows/diagnose-issues.md +5 -1
- package/gsd-core/workflows/discuss-phase/modes/chain.md +5 -1
- package/gsd-core/workflows/discuss-phase-assumptions.md +11 -3
- package/gsd-core/workflows/discuss-phase.md +5 -1
- package/gsd-core/workflows/docs-update/detail/elaboration.md +7 -6
- package/gsd-core/workflows/docs-update.md +27 -5
- package/gsd-core/workflows/edit-phase.md +5 -1
- package/gsd-core/workflows/eval-review.md +11 -3
- package/gsd-core/workflows/execute-phase/steps/codebase-drift-gate.md +5 -1
- package/gsd-core/workflows/execute-phase/steps/executor-isolation-dispatch.md +1 -1
- package/gsd-core/workflows/execute-phase/steps/post-merge-gate.md +12 -6
- package/gsd-core/workflows/execute-phase/steps/regression-gate-run.md +19 -2
- package/gsd-core/workflows/execute-phase/steps/regression-gate.md +18 -1
- package/gsd-core/workflows/execute-phase/steps/verify-phase-goal.md +5 -1
- package/gsd-core/workflows/execute-phase.md +40 -7
- package/gsd-core/workflows/execute-plan.md +8 -4
- package/gsd-core/workflows/extract-learnings.md +6 -2
- package/gsd-core/workflows/forensics.md +5 -1
- package/gsd-core/workflows/import.md +5 -1
- package/gsd-core/workflows/insert-phase.md +5 -1
- package/gsd-core/workflows/manager.md +10 -2
- package/gsd-core/workflows/map-codebase.md +5 -1
- package/gsd-core/workflows/milestone-summary.md +10 -2
- package/gsd-core/workflows/new-milestone.md +13 -5
- package/gsd-core/workflows/new-project.md +9 -5
- package/gsd-core/workflows/next.md +8 -4
- package/gsd-core/workflows/pause-work.md +3 -3
- package/gsd-core/workflows/plan-phase/steps/auto-advance-check.md +70 -0
- package/gsd-core/workflows/plan-phase/steps/chunked-planning-mode.md +5 -1
- package/gsd-core/workflows/plan-phase/steps/closed-phase-gate.md +6 -2
- package/gsd-core/workflows/plan-phase.md +41 -73
- package/gsd-core/workflows/plan-review-convergence.md +17 -5
- package/gsd-core/workflows/plant-seed.md +8 -4
- package/gsd-core/workflows/progress.md +6 -2
- package/gsd-core/workflows/quick-batch.md +5 -1
- package/gsd-core/workflows/quick.md +22 -7
- package/gsd-core/workflows/remove-phase.md +5 -1
- package/gsd-core/workflows/resume-project.md +19 -11
- package/gsd-core/workflows/review.md +6 -2
- package/gsd-core/workflows/scan.md +5 -1
- package/gsd-core/workflows/secure-phase.md +6 -2
- package/gsd-core/workflows/settings.md +3 -3
- package/gsd-core/workflows/ship.md +13 -10
- package/gsd-core/workflows/thread.md +10 -2
- package/gsd-core/workflows/transition.md +5 -1
- package/gsd-core/workflows/ui-phase.md +5 -1
- package/gsd-core/workflows/ui-review.md +6 -2
- package/gsd-core/workflows/ultraplan-phase.md +5 -1
- package/gsd-core/workflows/update.md +5 -1
- package/gsd-core/workflows/validate-phase.md +6 -2
- package/gsd-core/workflows/verify-work/detail/elaboration.md +1 -1
- package/gsd-core/workflows/verify-work/steps/mvp-uat-framing.md +5 -1
- package/gsd-core/workflows/verify-work.md +11 -3
- package/hooks/dist/gsd-agent-isolation-guard.js +3 -1
- package/hooks/dist/gsd-check-update.js +26 -20
- package/hooks/dist/gsd-context-monitor.js +14 -5
- package/hooks/dist/gsd-cursor-subagent-start.js +2 -1
- package/hooks/dist/gsd-secret-read-guard.js +189 -15
- package/hooks/dist/gsd-statusline.js +321 -22
- package/hooks/dist/gsd-validate-commit.sh +27 -5
- package/hooks/gsd-agent-isolation-guard.js +3 -1
- package/hooks/gsd-check-update.js +26 -20
- package/hooks/gsd-context-monitor.js +14 -5
- package/hooks/gsd-cursor-subagent-start.js +2 -1
- package/hooks/gsd-secret-read-guard.js +189 -15
- package/hooks/gsd-statusline.js +321 -22
- package/hooks/gsd-validate-commit.sh +27 -5
- package/package.json +1 -1
- package/scripts/audit-workflow-script-paths.cjs +1 -1
- package/scripts/diagnose-validate-commit-in-tier.cjs +270 -0
- package/scripts/diagnose-validate-commit-phases.cjs +348 -0
- package/scripts/diagnose-windows-spawn-watcher.cjs +317 -0
- package/scripts/docs-guard-registry.cjs +2 -0
- package/scripts/gen-capability-registry.cjs +7 -1
- package/scripts/gen-loop-host-contract.cjs +4 -1
- package/scripts/lib/macos-conformance-tier.generated.cjs +13 -0
- package/scripts/lib/platform-conformance-tier.generated.cjs +26 -0
- package/scripts/lint-phase-arg-assignment.cjs +2 -2
- package/scripts/lint-workflow-shellcheck-baseline.json +16 -16
- package/scripts/mutation-matrix.cjs +3 -1
- package/scripts/release-tarball-smoke.cjs +15 -7
- package/scripts/xtrace-phase-timing.cjs +205 -0
- package/skills/gsd-code-review/SKILL.md +8 -0
- package/skills/gsd-pause-work/SKILL.md +1 -1
- package/vscode/package.json +1 -1
package/hooks/gsd-statusline.js
CHANGED
|
@@ -170,6 +170,303 @@ function readStateFileOrNull(statePath) {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
/**
|
|
174
|
+
* The env vars Claude Code itself consults to switch auto-compaction off, and
|
|
175
|
+
* the values it accepts as true. Both are taken from the shipped binary's own
|
|
176
|
+
* resolution — `Boolean(truthy(DISABLE_COMPACT) || DISABLE_AUTO_COMPACT)`, and
|
|
177
|
+
* only when that is false does `autoCompactEnabled` decide — rather than
|
|
178
|
+
* guessed: an invented name reads as "not disabled" forever, which is exactly
|
|
179
|
+
* the defect this gate exists to close.
|
|
180
|
+
*
|
|
181
|
+
* The truthy set applies to both keys: in the binary (claude 2.1.292) the
|
|
182
|
+
* second operand is the env registry's `D.bool()` field, which runs the same
|
|
183
|
+
* `["1","true","yes","on"]` helper as `DISABLE_COMPACT`.
|
|
184
|
+
*/
|
|
185
|
+
const AUTO_COMPACT_DISABLE_ENV_KEYS = ['DISABLE_AUTO_COMPACT', 'DISABLE_COMPACT'];
|
|
186
|
+
const AUTO_COMPACT_ENV_TRUTHY = ['1', 'true', 'yes', 'on'];
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Is Claude Code's auto-compact switched off for this session? When it is,
|
|
190
|
+
* the auto-compact buffer is ordinary usable context, so the meter's 100% is
|
|
191
|
+
* the model window — otherwise the bar pins at 100% early and the last of
|
|
192
|
+
* the window is invisible.
|
|
193
|
+
*
|
|
194
|
+
* The sources and their precedence mirror Claude Code's own resolution —
|
|
195
|
+
* either env var wins over the setting, and only then does the setting decide:
|
|
196
|
+
* 1. env: DISABLE_AUTO_COMPACT, or DISABLE_COMPACT (which switches off
|
|
197
|
+
* manual `/compact` as well). Truthy is `1` / `true` / `yes` / `on`,
|
|
198
|
+
* trimmed and case-insensitive — Claude Code's own accepted set.
|
|
199
|
+
* 2. <dir>/.claude/settings.local.json, <dir>/.claude/settings.json
|
|
200
|
+
* 3. (CLAUDE_CONFIG_DIR || ~/.claude)/settings.local.json, settings.json
|
|
201
|
+
* reading the boolean `autoCompactEnabled`. Fail-soft: anything unreadable
|
|
202
|
+
* or absent means "not disabled" (current behaviour).
|
|
203
|
+
*/
|
|
204
|
+
function isAutoCompactDisabled(dir, env = process.env) {
|
|
205
|
+
for (const key of AUTO_COMPACT_DISABLE_ENV_KEYS) {
|
|
206
|
+
const v = env[key];
|
|
207
|
+
if (typeof v === 'string' && AUTO_COMPACT_ENV_TRUTHY.includes(v.trim().toLowerCase())) return true;
|
|
208
|
+
}
|
|
209
|
+
return readClaudeSetting(dir, env, 'autoCompactEnabled', v => typeof v === 'boolean') === false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The first value of `key` that `accept` takes, reading the Claude Code
|
|
214
|
+
* settings files highest precedence first:
|
|
215
|
+
* <dir>/.claude/settings.local.json, <dir>/.claude/settings.json,
|
|
216
|
+
* (CLAUDE_CONFIG_DIR || ~/.claude)/settings.local.json, settings.json.
|
|
217
|
+
* Fail-soft: an absent or unparseable file is skipped; nothing found is
|
|
218
|
+
* `undefined`.
|
|
219
|
+
*/
|
|
220
|
+
function readClaudeSetting(dir, env, key, accept) {
|
|
221
|
+
// Lazy: stop at the first file that answers, so a lower file is never read.
|
|
222
|
+
for (const file of claudeSettingsPaths(dir, env)) {
|
|
223
|
+
const settings = readSettingsFile(file);
|
|
224
|
+
if (settings && accept(settings[key])) return settings[key];
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The parsed Claude Code settings files, highest precedence first. An absent,
|
|
231
|
+
* unparseable or non-object file is left out.
|
|
232
|
+
*/
|
|
233
|
+
function readClaudeSettingsFiles(dir, env) {
|
|
234
|
+
return claudeSettingsPaths(dir, env).map(readSettingsFile).filter(Boolean);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A settings file larger than this is treated as absent. Claude Code's own
|
|
239
|
+
* settings files are a few kilobytes; the cap keeps a hostile project's
|
|
240
|
+
* `.claude/settings.json` from bloating a read that runs on every render.
|
|
241
|
+
*/
|
|
242
|
+
const SETTINGS_FILE_MAX_BYTES = 1024 * 1024;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The parsed settings object in `file`, or null. Only a regular file of at
|
|
246
|
+
* most SETTINGS_FILE_MAX_BYTES is read: the project's `.claude/` is
|
|
247
|
+
* repository content, and a FIFO there would block the statusline forever.
|
|
248
|
+
* The file is opened non-blocking and checked through its own descriptor,
|
|
249
|
+
* so the check and the read see the same file, and at most the checked size
|
|
250
|
+
* is read: a file that grew or shrank after the check is absent. A symlink
|
|
251
|
+
* is followed — a settings file linked in from a dotfiles repo is ordinary.
|
|
252
|
+
*/
|
|
253
|
+
function readSettingsFile(file) {
|
|
254
|
+
let fd;
|
|
255
|
+
try {
|
|
256
|
+
fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NONBLOCK || 0));
|
|
257
|
+
const st = fs.fstatSync(fd);
|
|
258
|
+
if (!st.isFile() || st.size > SETTINGS_FILE_MAX_BYTES) return null;
|
|
259
|
+
// One byte past the checked size, so growth after the check shows as a longer read.
|
|
260
|
+
const buf = Buffer.alloc(st.size + 1);
|
|
261
|
+
let n = 0;
|
|
262
|
+
for (let r; n < buf.length && (r = fs.readSync(fd, buf, n, buf.length - n, n)) > 0;) n += r;
|
|
263
|
+
if (n !== st.size) return null;
|
|
264
|
+
const settings = JSON.parse(buf.toString('utf8', 0, n));
|
|
265
|
+
return settings && typeof settings === 'object' && !Array.isArray(settings) ? settings : null;
|
|
266
|
+
} catch (e) {
|
|
267
|
+
return null; // absent, unreadable or unparseable — keep looking
|
|
268
|
+
} finally {
|
|
269
|
+
if (fd !== undefined) {
|
|
270
|
+
try { fs.closeSync(fd); } catch (e) { /* already closed */ }
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The Claude Code settings file paths, highest precedence first:
|
|
277
|
+
* <dir>/.claude/settings.local.json, <dir>/.claude/settings.json,
|
|
278
|
+
* (CLAUDE_CONFIG_DIR || ~/.claude)/settings.local.json, settings.json.
|
|
279
|
+
*/
|
|
280
|
+
function claudeSettingsPaths(dir, env) {
|
|
281
|
+
const candidates = [];
|
|
282
|
+
if (dir) {
|
|
283
|
+
candidates.push(path.join(dir, '.claude', 'settings.local.json'));
|
|
284
|
+
candidates.push(path.join(dir, '.claude', 'settings.json'));
|
|
285
|
+
}
|
|
286
|
+
let claudeDir;
|
|
287
|
+
try {
|
|
288
|
+
claudeDir = env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
|
289
|
+
} catch (e) {
|
|
290
|
+
claudeDir = null;
|
|
291
|
+
}
|
|
292
|
+
if (claudeDir) {
|
|
293
|
+
candidates.push(path.join(claudeDir, 'settings.local.json'));
|
|
294
|
+
candidates.push(path.join(claudeDir, 'settings.json'));
|
|
295
|
+
}
|
|
296
|
+
return candidates;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Claude Code's settings key for a model: its canonical name, which also
|
|
301
|
+
* matches the dated, `[1m]`, Bedrock and Vertex spellings of it
|
|
302
|
+
* (`claude-opus-5-5[1m]`, `us.anthropic.claude-opus-5-5-v1:0` and
|
|
303
|
+
* `claude-opus-5-5@20260101` all key as `claude-opus-5-5`). A Bedrock
|
|
304
|
+
* revision suffix is stripped only after a version or date segment, so a
|
|
305
|
+
* model whose own name ends in `-v<n>` (`anthropic.claude-v2`) keeps it.
|
|
306
|
+
* The rules repeat until nothing changes, so a key is its own key: one pass
|
|
307
|
+
* left `x[1m][1m]` as `x[1m]`. Lowercasing runs once, before the loop (it
|
|
308
|
+
* can lengthen a string: `İ` becomes two characters); inside the loop every
|
|
309
|
+
* rule only removes characters, so it ends. A key longer than
|
|
310
|
+
* MODEL_KEY_MAX_LENGTH is no model's — '' — which also bounds the loop's
|
|
311
|
+
* work on a hostile settings file. '' for a non-string.
|
|
312
|
+
*/
|
|
313
|
+
const MODEL_KEY_MAX_LENGTH = 256;
|
|
314
|
+
|
|
315
|
+
function canonicalModelKey(id) {
|
|
316
|
+
if (typeof id !== 'string') return '';
|
|
317
|
+
let key = id.toLowerCase();
|
|
318
|
+
if (key.length > MODEL_KEY_MAX_LENGTH) return '';
|
|
319
|
+
for (let prev; prev !== key;) {
|
|
320
|
+
prev = key;
|
|
321
|
+
key = key.trim()
|
|
322
|
+
.replace(/(?:\[1m\])+$/, '')
|
|
323
|
+
.replace(/^(?:[a-z]+\.)?anthropic\./, '')
|
|
324
|
+
.replace(/(\d)-v\d+(?::\d+)?$/, '$1')
|
|
325
|
+
.replace(/@\d{8}$/, '')
|
|
326
|
+
.replace(/-\d{8}$/, '');
|
|
327
|
+
}
|
|
328
|
+
return key;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function isAutoCompactWindowValue(v) {
|
|
332
|
+
return v === 'auto' ||
|
|
333
|
+
(Number.isInteger(v) && v >= AUTO_COMPACT_WINDOW_MIN && v <= AUTO_COMPACT_WINDOW_MAX);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The `autoCompactWindow` setting for this model, merged across the settings
|
|
338
|
+
* files the way Claude Code merges it (claude 2.1.292): lowest precedence
|
|
339
|
+
* first, each file's `modelSettings.<model>.autoCompactWindow` entries
|
|
340
|
+
* layer over the lower files', and a file that sets a top-level
|
|
341
|
+
* `autoCompactWindow` replaces the default and drops the lower files'
|
|
342
|
+
* per-model entries. The model's own entry wins over the default.
|
|
343
|
+
* `/autocompact` saves the per-model entry; older versions saved the
|
|
344
|
+
* top-level one. `"auto"` (Claude Code's tuned window) and an absent setting
|
|
345
|
+
* are null, so the caller falls back to the model window. An invalid value
|
|
346
|
+
* is treated as absent.
|
|
347
|
+
*/
|
|
348
|
+
function readAutoCompactWindowSetting(dir, env, modelId) {
|
|
349
|
+
let fallback;
|
|
350
|
+
let byModel = {};
|
|
351
|
+
for (const settings of readClaudeSettingsFiles(dir, env).reverse()) {
|
|
352
|
+
const own = {};
|
|
353
|
+
const perModel = settings.modelSettings;
|
|
354
|
+
if (perModel && typeof perModel === 'object' && !Array.isArray(perModel)) {
|
|
355
|
+
for (const [name, entry] of Object.entries(perModel)) {
|
|
356
|
+
const v = entry && typeof entry === 'object' ? entry.autoCompactWindow : undefined;
|
|
357
|
+
if (!isAutoCompactWindowValue(v)) continue;
|
|
358
|
+
const key = canonicalModelKey(name);
|
|
359
|
+
// A canonically spelled key wins over another spelling of it.
|
|
360
|
+
if (name === key || !Object.hasOwn(own, key)) own[key] = v;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (isAutoCompactWindowValue(settings.autoCompactWindow)) {
|
|
364
|
+
fallback = settings.autoCompactWindow;
|
|
365
|
+
byModel = own;
|
|
366
|
+
} else {
|
|
367
|
+
byModel = { ...byModel, ...own };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const key = canonicalModelKey(modelId);
|
|
371
|
+
const value = key && Object.hasOwn(byModel, key) ? byModel[key] : fallback;
|
|
372
|
+
return Number.isInteger(value) ? value : null;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Where Claude Code auto-compacts (#4985). The meter's 100% is this token
|
|
377
|
+
* count, so it has to be resolved the way Claude Code resolves it:
|
|
378
|
+
*
|
|
379
|
+
* window CLAUDE_CODE_AUTO_COMPACT_WINDOW (an unparseable or non-positive
|
|
380
|
+
* value is ignored; capped at 1M, raised to 100k), else the
|
|
381
|
+
* `autoCompactWindow` setting `/autocompact` saves, per model or
|
|
382
|
+
* top-level (an integer in 100k–1M; see
|
|
383
|
+
* readAutoCompactWindowSetting), else the model window. Always
|
|
384
|
+
* capped at the model window.
|
|
385
|
+
* threshold window − min(model max output, 20,000) − 13,000, lowered to
|
|
386
|
+
* floor((window − 20,000) × pct / 100) when
|
|
387
|
+
* CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (0 < pct ≤ 100) is lower.
|
|
388
|
+
*
|
|
389
|
+
* `/context` shows the 33,000 as "Autocompact buffer". The hardcoded 16.5%
|
|
390
|
+
* this replaces is 33,000 / 200,000, so it was right only on a 200K window
|
|
391
|
+
* with nothing configured. Every current model's max output is at least
|
|
392
|
+
* 20,000, so the reserve is taken as 20,000.
|
|
393
|
+
*
|
|
394
|
+
* Not visible to a statusline, so not modelled: the `--autocompact` launch
|
|
395
|
+
* flag, managed-policy settings, and Claude Code's server-side and per-model
|
|
396
|
+
* window defaults (what `"auto"` resolves to). Those sessions fall back to
|
|
397
|
+
* the model window.
|
|
398
|
+
*/
|
|
399
|
+
const AUTO_COMPACT_WINDOW_MIN = 100_000;
|
|
400
|
+
const AUTO_COMPACT_WINDOW_MAX = 1_000_000;
|
|
401
|
+
const AUTO_COMPACT_OUTPUT_RESERVE = 20_000;
|
|
402
|
+
const AUTO_COMPACT_SUMMARY_BUFFER = 13_000;
|
|
403
|
+
|
|
404
|
+
function parseAutoCompactWindowEnv(raw) {
|
|
405
|
+
if (typeof raw !== 'string' || raw.trim() === '') return null;
|
|
406
|
+
const s = raw.trim();
|
|
407
|
+
const n = /^\d[\d_,]*$/.test(s) ? parseInt(s.replace(/[_,]/g, ''), 10) : parseInt(s, 10);
|
|
408
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
409
|
+
return Math.max(AUTO_COMPACT_WINDOW_MIN, Math.min(AUTO_COMPACT_WINDOW_MAX, n));
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* The token count at which Claude Code auto-compacts this session, or null
|
|
414
|
+
* when auto-compaction is off (see isAutoCompactDisabled).
|
|
415
|
+
*/
|
|
416
|
+
function resolveAutoCompactThreshold(modelWindow, dir, env = process.env, modelId) {
|
|
417
|
+
if (!(modelWindow > 0) || isAutoCompactDisabled(dir, env)) return null;
|
|
418
|
+
let window = parseAutoCompactWindowEnv(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW);
|
|
419
|
+
if (window === null) {
|
|
420
|
+
window = readAutoCompactWindowSetting(dir, env, modelId) ?? modelWindow;
|
|
421
|
+
}
|
|
422
|
+
const effective = Math.min(window, modelWindow) - AUTO_COMPACT_OUTPUT_RESERVE;
|
|
423
|
+
let threshold = effective - AUTO_COMPACT_SUMMARY_BUFFER;
|
|
424
|
+
const pct = parseFloat(env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE);
|
|
425
|
+
if (Number.isFinite(pct) && pct > 0 && pct <= 100) {
|
|
426
|
+
threshold = Math.min(threshold, Math.floor(effective * (pct / 100)));
|
|
427
|
+
}
|
|
428
|
+
return threshold > 0 ? threshold : null;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* The context meter, in one scale: `used` + `remaining` = 100, where 100% is
|
|
433
|
+
* the auto-compact threshold, or the model window when compaction is off.
|
|
434
|
+
* `usedTokens` is Claude Code's own count (input + cache creation + cache
|
|
435
|
+
* read of the last turn, the sum /context reports) and `limitTokens` the
|
|
436
|
+
* token count 100% stands for.
|
|
437
|
+
*
|
|
438
|
+
* Taken from token counts, not by re-scaling `remaining_percentage`: that
|
|
439
|
+
* value is already rounded against the model window, which loses up to 5,000
|
|
440
|
+
* tokens on a 1M model. Without `current_usage` the tokens are recovered
|
|
441
|
+
* from the percentage; without `context_window_size` the window is unknown,
|
|
442
|
+
* so the meter shows Claude Code's own percentage unscaled. Returns null
|
|
443
|
+
* when there is no usage yet.
|
|
444
|
+
*/
|
|
445
|
+
function contextMeter(contextWindow, dir, env = process.env, modelId) {
|
|
446
|
+
if (!contextWindow || typeof contextWindow !== 'object') return null;
|
|
447
|
+
const size = Number(contextWindow.context_window_size);
|
|
448
|
+
const usage = contextWindow.current_usage;
|
|
449
|
+
const remainingPct = contextWindow.remaining_percentage;
|
|
450
|
+
if (size > 0) {
|
|
451
|
+
let usedTokens = null;
|
|
452
|
+
if (usage && typeof usage === 'object') {
|
|
453
|
+
usedTokens = (Number(usage.input_tokens) || 0) +
|
|
454
|
+
(Number(usage.cache_creation_input_tokens) || 0) +
|
|
455
|
+
(Number(usage.cache_read_input_tokens) || 0);
|
|
456
|
+
} else if (remainingPct != null) {
|
|
457
|
+
usedTokens = Math.round(((100 - remainingPct) * size) / 100);
|
|
458
|
+
}
|
|
459
|
+
if (usedTokens !== null) {
|
|
460
|
+
const limitTokens = resolveAutoCompactThreshold(size, dir, env, modelId) ?? size;
|
|
461
|
+
const used = Math.max(0, Math.min(100, Math.round((usedTokens / limitTokens) * 100)));
|
|
462
|
+
return { used, remaining: 100 - used, usedTokens, limitTokens };
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (remainingPct == null) return null;
|
|
466
|
+
const used = Math.max(0, Math.min(100, Math.round(100 - remainingPct)));
|
|
467
|
+
return { used, remaining: 100 - used, usedTokens: null, limitTokens: null };
|
|
468
|
+
}
|
|
469
|
+
|
|
173
470
|
/**
|
|
174
471
|
* Walk up from dir looking for .planning/STATE.md (flat mode). If an ancestor
|
|
175
472
|
* has no flat STATE.md but IS in workstream mode (.planning/workstreams/
|
|
@@ -830,28 +1127,22 @@ function runStatusline() {
|
|
|
830
1127
|
const model = compactModelName(data.model?.display_name || 'Claude');
|
|
831
1128
|
const dir = data.workspace?.current_dir || process.cwd();
|
|
832
1129
|
const session = data.session_id || '';
|
|
833
|
-
const remaining = data.context_window?.remaining_percentage;
|
|
834
1130
|
|
|
835
1131
|
// Read .planning config once — used by the context meter (token suffix)
|
|
836
1132
|
// and the last-command/position block below. Fail-soft to {}.
|
|
837
1133
|
let cfg = {};
|
|
838
1134
|
try { cfg = readGsdConfig(dir); } catch (e) {}
|
|
839
1135
|
|
|
840
|
-
// Context window display
|
|
841
|
-
//
|
|
842
|
-
//
|
|
843
|
-
// (
|
|
844
|
-
// the
|
|
845
|
-
|
|
846
|
-
const
|
|
847
|
-
const AUTO_COMPACT_BUFFER_PCT = acw > 0
|
|
848
|
-
? Math.min(100, Math.max(0, (1 - acw / totalCtx) * 100))
|
|
849
|
-
: 16.5;
|
|
1136
|
+
// Context window display: USED percentage of the auto-compact threshold,
|
|
1137
|
+
// so 100% is where Claude Code compacts — resolved from
|
|
1138
|
+
// CLAUDE_CODE_AUTO_COMPACT_WINDOW, the `autoCompactWindow` setting, or the
|
|
1139
|
+
// model window (#2219, #4985). With auto-compact disabled (#4844) 100% is
|
|
1140
|
+
// the model window. Project settings are read from workspace.project_dir,
|
|
1141
|
+
// Claude Code's launch directory, not the current directory.
|
|
1142
|
+
const meter = contextMeter(data.context_window, data.workspace?.project_dir || dir, process.env, data.model?.id);
|
|
850
1143
|
let ctx = '';
|
|
851
|
-
if (
|
|
852
|
-
|
|
853
|
-
const usableRemaining = Math.max(0, ((remaining - AUTO_COMPACT_BUFFER_PCT) / (100 - AUTO_COMPACT_BUFFER_PCT)) * 100);
|
|
854
|
-
const used = Math.max(0, Math.min(100, Math.round(100 - usableRemaining)));
|
|
1144
|
+
if (meter) {
|
|
1145
|
+
const { used } = meter;
|
|
855
1146
|
|
|
856
1147
|
// Write context metrics to bridge file for the context-monitor PostToolUse hook.
|
|
857
1148
|
// The monitor reads this file to inject agent-facing warnings when context is low.
|
|
@@ -861,15 +1152,20 @@ function runStatusline() {
|
|
|
861
1152
|
if (sessionSafe) {
|
|
862
1153
|
try {
|
|
863
1154
|
const bridgePath = path.join(os.tmpdir(), `claude-ctx-${session}.json`);
|
|
864
|
-
//
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
//
|
|
868
|
-
|
|
1155
|
+
// The bridge is on the bar's scale: remaining_percentage counts down
|
|
1156
|
+
// to the auto-compact threshold, so the monitor's WARNING/CRITICAL
|
|
1157
|
+
// fire before compaction rather than after it (#4985). The token
|
|
1158
|
+
// counts let its message match /context, which is what #2451 kept
|
|
1159
|
+
// the bridge raw for; they are absent when the payload has no
|
|
1160
|
+
// context_window_size.
|
|
869
1161
|
const bridgeData = JSON.stringify({
|
|
870
1162
|
session_id: session,
|
|
871
|
-
remaining_percentage: remaining,
|
|
872
|
-
used_pct:
|
|
1163
|
+
remaining_percentage: meter.remaining,
|
|
1164
|
+
used_pct: used,
|
|
1165
|
+
...(meter.usedTokens !== null && {
|
|
1166
|
+
used_tokens: meter.usedTokens,
|
|
1167
|
+
threshold_tokens: meter.limitTokens,
|
|
1168
|
+
}),
|
|
873
1169
|
timestamp: Math.floor(Date.now() / 1000)
|
|
874
1170
|
});
|
|
875
1171
|
fs.writeFileSync(bridgePath, bridgeData);
|
|
@@ -1097,6 +1393,9 @@ module.exports = {
|
|
|
1097
1393
|
readStateHeadCommits, parseRevListCounts, deriveStateFreshness,
|
|
1098
1394
|
formatStateFreshness, resolveStatuslineOptions,
|
|
1099
1395
|
renderBracketPhaseDisplay, renderBracketMilestoneDisplay,
|
|
1396
|
+
isAutoCompactDisabled, AUTO_COMPACT_DISABLE_ENV_KEYS, AUTO_COMPACT_ENV_TRUTHY,
|
|
1397
|
+
resolveAutoCompactThreshold, contextMeter, SETTINGS_FILE_MAX_BYTES,
|
|
1398
|
+
parseAutoCompactWindowEnv, canonicalModelKey, isAutoCompactWindowValue,
|
|
1100
1399
|
};
|
|
1101
1400
|
|
|
1102
1401
|
/**
|
|
@@ -39,6 +39,27 @@ cleanup_temp_files() {
|
|
|
39
39
|
}
|
|
40
40
|
trap cleanup_temp_files EXIT
|
|
41
41
|
|
|
42
|
+
# The first line of $1 (everything before the first newline), matched BYTE-wise.
|
|
43
|
+
#
|
|
44
|
+
# `${1%%$'\n'*}` is a longest-suffix glob match, and on bash 3.2 (macOS's
|
|
45
|
+
# /bin/bash) in a multibyte locale such as en_US.UTF-8 it costs ~3.5 s on a
|
|
46
|
+
# 112KB value (#5473, measured inside the macOS conformance job: the same hook
|
|
47
|
+
# on the same 114750-byte command took ~5.6 s under LC_ALL=en_US.UTF-8 and
|
|
48
|
+
# ~0.55 s under LC_ALL=C, and a trace put 3.5 s of it on this expansion). A
|
|
49
|
+
# newline is the same single byte in every locale, so matching it byte-wise
|
|
50
|
+
# changes no result.
|
|
51
|
+
#
|
|
52
|
+
# ONLY call this inside a command substitution, `SUBJECT=$(gsd_first_line "$MSG")`:
|
|
53
|
+
# the substitution's subshell is what keeps LC_ALL=C from leaking into the rest
|
|
54
|
+
# of the hook, whose regexes and length arithmetic keep the caller's locale. A
|
|
55
|
+
# substitution is a fork with no pipe between two processes, so it keeps the
|
|
56
|
+
# property the pure-expansion form was chosen for (no `head -1` SIGPIPE race
|
|
57
|
+
# under `set -euo pipefail`, #4429); printf is a builtin, so no exec either.
|
|
58
|
+
gsd_first_line() {
|
|
59
|
+
LC_ALL=C
|
|
60
|
+
printf '%s' "${1%%$'\n'*}"
|
|
61
|
+
}
|
|
62
|
+
|
|
42
63
|
# The 10 built-in Conventional Commits types — the SINGLE declaration (#3811
|
|
43
64
|
# review finding: this was previously hand-typed a second time inside the
|
|
44
65
|
# node -e script below, a generative-fix-divergence risk per CLAUDE.md's
|
|
@@ -575,18 +596,19 @@ if [ "$CLASSIFY_STATUS" = "0" ]; then
|
|
|
575
596
|
SUBJECT=$(GIT_CMD_LIB="$HOOK_DIR/lib/git-cmd.js" MSG="$MSG" node -e "
|
|
576
597
|
const {resolveCommitSubject}=require(process.env.GIT_CMD_LIB);
|
|
577
598
|
process.stdout.write(resolveCommitSubject(process.env.MSG));
|
|
578
|
-
" 2>/dev/null) || SUBJECT
|
|
599
|
+
" 2>/dev/null) || SUBJECT=$(gsd_first_line "$MSG")
|
|
579
600
|
else
|
|
580
|
-
# Pure parameter expansion, not
|
|
601
|
+
# Pure parameter expansion (in gsd_first_line), not
|
|
602
|
+
# `echo "$MSG" | head -1`: that pipeline
|
|
581
603
|
# raced a SIGPIPE under `set -euo pipefail` whenever $MSG had a body
|
|
582
604
|
# (the common case) — `head -1` can close its read end as soon as it
|
|
583
605
|
# has the first line, and if `echo`'s write lands after that close,
|
|
584
606
|
# `echo` dies with signal 13 (exit 141), which is NOT suppressed by
|
|
585
607
|
# `set -e` and aborted the whole hook intermittently (observed in
|
|
586
|
-
# tests/hooks-opt-in.test.cjs's --fixup=HEAD "round 7" case).
|
|
587
|
-
#
|
|
608
|
+
# tests/hooks-opt-in.test.cjs's --fixup=HEAD "round 7" case). No pipe
|
|
609
|
+
# means no race surface. Equivalent to
|
|
588
610
|
# `head -1` for single-line, multi-line, and trailing-newline input.
|
|
589
|
-
SUBJECT
|
|
611
|
+
SUBJECT=$(gsd_first_line "$MSG")
|
|
590
612
|
fi
|
|
591
613
|
# Single source of truth for the accepted commit-type list (#3811): the
|
|
592
614
|
# 10 built-ins plus whatever passed the safe-token filter above. Both the
|
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@ const AUDIT_FINDING = Object.freeze({
|
|
|
24
24
|
// Match `${GSD_HOME}` or `${GSD_HOME:-...}` followed by a /-rooted path
|
|
25
25
|
// ending in .cjs/.js/.sh. The path is captured verbatim (relative to
|
|
26
26
|
// the install root).
|
|
27
|
-
const REF_RE = /\$\{GSD_HOME(?::-[^}]*)?\}\/([A-Za-z0-9_./-]+\.(?:cjs|js|sh))/g;
|
|
27
|
+
const REF_RE = /\$\{GSD_HOME(?::-[^}]*)?\}\/([A-Za-z0-9_./-]+\.(?:cjs|js|sh)(?![A-Za-z0-9_]))/g;
|
|
28
28
|
|
|
29
29
|
function listWorkflowFiles(dir) {
|
|
30
30
|
if (!fs.existsSync(dir)) return [];
|