@yasaswy.nagavolu/agents 0.29.0 → 0.30.1
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/README.md +9 -0
- package/bin/cli.js +62 -4
- package/content/agents/synth-auditor.md +59 -0
- package/content/hooks/conclusion-scribe/README.md +31 -22
- package/content/hooks/conclusion-scribe/conclusion_scribe_hook.py +145 -45
- package/content/hooks/conclusion-scribe/test_conclusion_scribe_hook.py +274 -0
- package/content/hooks/worktree-registry/README.md +51 -0
- package/content/hooks/worktree-registry/test_worktree_registry.py +340 -0
- package/content/hooks/worktree-registry/worktree_registry.py +322 -0
- package/content/manifest.json +204 -5
- package/content/mods/handoff/.claude-plugin/plugin.json +1 -1
- package/content/mods/handoff/HINT-PEEK.md +36 -0
- package/content/mods/handoff/README.md +5 -5
- package/content/mods/handoff/hooks/register.js +59 -2
- package/content/mods/handoff/lib/hint.mjs +34 -0
- package/content/mods/handoff/lib/peek.mjs +67 -0
- package/content/mods/handoff/lib/policy.mjs +1 -0
- package/content/mods/handoff/tests/e2e/run_e2e.py +3 -0
- package/content/mods/handoff/tests/e2e/tui_hint_peek_e2e.py +116 -0
- package/content/mods/handoff/tests/handoff.test.ts +34 -2
- package/content/mods/handoff/tests/hint.test.mjs +70 -0
- package/content/mods/handoff/tests/peek.test.mjs +103 -0
- package/content/mods/handoff/tests/register-hint-peek.test.mjs +292 -0
- package/content/mods/handoff/tests/template.test.mjs +1 -1
- package/content/mods/model-routing/.claude-plugin/plugin.json +2 -2
- package/content/mods/model-routing/README.md +20 -3
- package/content/mods/model-routing/hooks/register.js +26 -5
- package/content/mods/model-routing/lib/route.mjs +72 -1
- package/content/mods/model-routing/tests/e2e/run_routing_e2e.py +5 -2
- package/content/mods/model-routing/tests/e2e/run_workflow_e2e.py +158 -0
- package/content/mods/model-routing/tests/register.test.mjs +54 -2
- package/content/mods/model-routing/tests/route.test.mjs +93 -4
- package/content/mods/model-routing/tests/routing.test.ts +28 -0
- package/content/mods/model-routing/tests/workflow_parity.mjs +14 -0
- package/content/proxy/README.md +8 -4
- package/content/proxy/agent_model_guard.py +21 -5
- package/content/proxy/bg_process_reaper_hook.py +7 -9
- package/content/proxy/bg_process_register_hook.py +13 -13
- package/content/proxy/bg_process_registry.py +120 -32
- package/content/proxy/chat_inbox_hook.py +39 -9
- package/content/proxy/chat_ledger.py +161 -13
- package/content/proxy/chromium_gpu.py +65 -0
- package/content/proxy/execution_worker_review_gate.py +837 -23
- package/content/proxy/handover_ledger_hook.py +36 -9
- package/content/proxy/html_mocker_monitor_guard.py +3 -3
- package/content/proxy/html_mocker_subagent_guard.py +1 -1
- package/content/proxy/litellm/call_feed.ps1 +1 -0
- package/content/proxy/litellm/call_log.py +3 -0
- package/content/proxy/log_retention.py +203 -0
- package/content/proxy/mem_sampler.py +171 -8
- package/content/proxy/memory_first_hook.py +41 -1
- package/content/proxy/memory_reclaim.py +5 -4
- package/content/proxy/models_config.py +2 -1
- package/content/proxy/portal/README.md +7 -0
- package/content/proxy/portal/aggregator.py +4 -1
- package/content/proxy/portal/portal_wait.ps1 +42 -0
- package/content/proxy/portal/register-autostart.ps1 +3 -1
- package/content/proxy/portal/start-portal.ps1 +13 -2
- package/content/proxy/portal/supervise_portal_hidden.vbs +4 -2
- package/content/proxy/proc_policy.py +71 -14
- package/content/proxy/project_resolver.py +3 -1
- package/content/proxy/route_lock.py +424 -7
- package/content/proxy/routing_escalation_hook.py +3 -1
- package/content/proxy/routing_log.py +20 -2
- package/content/proxy/routing_post_hook.py +3 -1
- package/content/proxy/spine_sweep.py +143 -0
- package/content/proxy/tracking_sweep.py +78 -0
- package/content/proxy/video_encoder.py +96 -0
- package/content/scripts/backfill_armed_repos.py +78 -0
- package/content/scripts/gitlab_api.py +2 -1
- package/content/scripts/review_pass.py +256 -0
- package/content/scripts/test_review_pass.py +262 -0
- package/content/scripts/tests/test_gitlab_api_utf8.py +33 -0
- package/content/scripts/validate_violations_schema.py +133 -0
- package/content/skills/README.md +5 -1
- package/content/skills/android-emulator/SKILL.md +43 -0
- package/content/skills/android-emulator/emulator_launch.py +255 -0
- package/content/skills/android-emulator/tests/test_emulator_launch.py +176 -0
- package/content/skills/ci-runner/SKILL.md +5 -0
- package/content/skills/disk-cleanup/SKILL.md +2 -2
- package/content/skills/disk-cleanup/purge_walker.ps1 +15 -2
- package/content/skills/disk-cleanup/worktree_audit.ps1 +128 -30
- package/content/skills/edit-videos/SKILL.md +1 -1
- package/content/skills/edit-videos/engine/blur.py +5 -4
- package/content/skills/edit-videos/engine/ffmpeg_io.py +9 -0
- package/content/skills/edit-videos/engine/timeline.py +12 -11
- package/content/skills/edit-videos/tests/conftest.py +6 -0
- package/content/skills/edit-videos/tests/test_timeline.py +26 -0
- package/content/skills/graphic-novel-pipeline/SKILL.md +13 -13
- package/content/skills/graphic-novel-pipeline/reference.md +71 -4
- package/content/skills/graphic-novel-pipeline/scripts/comic_txt.py +1130 -0
- package/content/skills/graphic-novel-pipeline/scripts/comic_txt_html.py +417 -0
- package/content/skills/graphic-novel-pipeline/scripts/compile_prompts.py +13 -1
- package/content/skills/graphic-novel-pipeline/scripts/direction.py +81 -0
- package/content/skills/graphic-novel-pipeline/scripts/synth_audit.py +353 -0
- package/content/skills/graphic-novel-pipeline/scripts/workflow.py +212 -21
- package/content/skills/graphic-novel-pipeline/templates/comic_txt_FORMAT.md +140 -0
- package/content/skills/graphic-novel-pipeline/templates/workflow.json +36 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/comic_txt/WORLD.md +111 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/comic_txt/_audit/1_duty_audit.md +53 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/comic_txt/ch1_duty.md +849 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/plan/book_arc.json +45 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/plan/cast.json +2227 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/plan/novel_b/ch1_captions_draft.json +105 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/plan/novel_b/ch1_comic_txt_lock.json +24 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/plan/novel_b/ch1_parts.json +1220 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/project.json +308 -0
- package/content/skills/graphic-novel-pipeline/tests/fixtures/comic_txt_ch1/source/synth_txt/1_duty_part.txt +89 -0
- package/content/skills/graphic-novel-pipeline/tests/test_comic_txt.py +638 -0
- package/content/skills/graphic-novel-pipeline/tests/test_comic_txt_html.py +219 -0
- package/content/skills/graphic-novel-pipeline/tests/test_direction.py +128 -0
- package/content/skills/graphic-novel-pipeline/tests/test_synth_audit.py +214 -0
- package/content/skills/graphic-novel-pipeline/tests/test_workflow_chapter.py +284 -0
- package/content/skills/heavy-gate-runner/SKILL.md +1 -1
- package/content/skills/heavy-gate-runner/heavy_gate_runner.py +26 -5
- package/content/skills/heavy-gate-runner/tests/test_heavy_gate_runner.py +48 -0
- package/content/skills/html-mocker/SKILL.md +2 -1
- package/content/skills/html-mocker/mocker.py +18 -2
- package/content/skills/html-mocker/tests/test_mocker_renderer.py +45 -0
- package/content/skills/html-mocker/tests/test_software_renderer_default.py +6 -0
- package/content/skills/low-ram-advisor/SKILL.md +17 -2
- package/content/skills/low-ram-advisor/advisor.py +94 -15
- package/content/skills/low-ram-advisor/autofree.py +265 -0
- package/content/skills/low-ram-advisor/deep_report.py +553 -0
- package/content/skills/low-ram-advisor/memprobe.py +327 -0
- package/content/skills/low-ram-advisor/memwatch.py +265 -0
- package/content/skills/low-ram-advisor/pooltags.py +145 -0
- package/content/skills/low-ram-advisor/ram_prompt.py +74 -0
- package/content/skills/low-ram-advisor/tests/conftest.py +10 -0
- package/content/skills/low-ram-advisor/tests/test_advisor.py +2 -1
- package/content/skills/low-ram-advisor/tests/test_advisor_deep.py +45 -0
- package/content/skills/low-ram-advisor/tests/test_autofree.py +210 -0
- package/content/skills/low-ram-advisor/tests/test_deep_report.py +386 -0
- package/content/skills/low-ram-advisor/tests/test_deep_report_noise.py +286 -0
- package/content/skills/low-ram-advisor/tests/test_memwatch.py +200 -0
- package/content/skills/low-ram-advisor/tests/test_pooltags.py +96 -0
- package/content/skills/low-ram-advisor/tests/test_ram_prompt.py +102 -0
- package/content/skills/make-space/SKILL.md +17 -7
- package/content/skills/make-space/allowlist.json +10 -0
- package/content/skills/make-space/make_space.ps1 +94 -11
- package/content/skills/make-space/scratch_guard.ps1 +189 -0
- package/content/skills/make-space/space_guard.ps1 +14 -2
- package/content/skills/make-space/tests/conftest.py +8 -0
- package/content/skills/make-space/tests/test_scratch_cleanup.py +246 -0
- package/content/skills/make-space/tests/test_worktree_audit.py +153 -0
- package/content/skills/publish-article/SKILL.md +4 -0
- package/content/skills/publish-article/publish_article.py +24 -8
- package/content/skills/publish-article/tests/conftest.py +7 -0
- package/content/skills/publish-article/tests/test_publish_article.py +6 -0
- package/content/skills/ship-the-code/SKILL.md +5 -5
- package/content/skills/ship-the-code/ship.py +295 -53
- package/content/skills/ship-the-code/tests/test_ship.py +359 -0
- package/content/skills/ship-the-code/tests/test_ship_order.py +218 -0
- package/content/statusline/orchestration-line.ps1 +139 -0
- package/content/statusline/orchestration_line.py +184 -0
- package/content/statusline/statusline-command.ps1 +3 -1
- package/content/statusline/statusline-command.py +7 -1
- package/content/statusline/subagent-row-stats.ps1 +43 -0
- package/content/statusline/subagent-statusline-command.ps1 +6 -0
- package/content/statusline/subagent-statusline-command.py +12 -0
- package/content/statusline/subagent_row_stats.py +52 -0
- package/lib/claudeProfile.js +157 -0
- package/lib/codex-compatibility.json +1 -1
- package/lib/codex.js +3 -3
- package/lib/deployment.js +3 -1
- package/lib/doctor.js +6 -1
- package/lib/memSafety.js +1 -0
- package/lib/modelsUsage.js +1 -1
- package/lib/portalHealth.js +61 -0
- package/lib/releaseLock.js +149 -0
- package/lib/runner/args.js +16 -3
- package/lib/runner/budget.js +227 -0
- package/lib/runner/index.js +110 -4
- package/lib/runner/janitor.js +281 -0
- package/lib/runner/janitorPlan.js +166 -0
- package/lib/runner/janitorTask.js +57 -0
- package/lib/runner/jobs.js +32 -0
- package/lib/runner/managed.js +92 -0
- package/lib/runner/pool.js +281 -0
- package/lib/runner/profiles/linuxDocker.js +40 -7
- package/lib/runner/register_ci_janitor.ps1 +54 -0
- package/lib/staleCheckout.js +65 -0
- package/lib/update.js +15 -3
- package/package.json +1 -1
- package/templates/ci/README.md +11 -0
- package/templates/ci/base.yml +2 -0
package/README.md
CHANGED
|
@@ -91,6 +91,9 @@ agents-cli install
|
|
|
91
91
|
secrets --list` — see [Secrets](#secrets) below.
|
|
92
92
|
- `agents-cli update --yes` / `agents-cli update --bundle <key> --yes` — see
|
|
93
93
|
[Updating](#updating) below.
|
|
94
|
+
Run from a git checkout, `update` refuses (exit 1, nothing deployed) when HEAD is behind origin's default branch,
|
|
95
|
+
because it would deploy older files over newer ones; `--allow-stale` overrides, and an unreachable remote only warns.
|
|
96
|
+
`doctor` checks ledger hashes, not source drift, so it cannot detect a stale deploy.
|
|
94
97
|
- `agents-cli runner install --group-id <id> | --project-id <id>` — install a
|
|
95
98
|
ready GitLab CI runner on this machine (`linux-docker`, or `macos-shell` on
|
|
96
99
|
a Mac). `runner status` / `runner doctor` / `runner uninstall` check,
|
|
@@ -110,6 +113,10 @@ agents-cli install
|
|
|
110
113
|
`--scan-root <dir>` checks every git repo directly under `<dir>` instead of the cwd repo. `install` and `update`
|
|
111
114
|
accept the same `--scan-root` plus `--fix-project-hooks` and report (or fix) bare project hooks after the run.
|
|
112
115
|
Paste-ready fix from inside any repo: `npx -y @yasaswy.nagavolu/agents@latest doctor --fix`.
|
|
116
|
+
On Windows it also reports a hard-coded `claude` alias or function in the PowerShell profiles
|
|
117
|
+
(`Documents/PowerShell` and `Documents/WindowsPowerShell`), which bypasses the `%APPDATA%/npm` shims and ignores every
|
|
118
|
+
Claude Code upgrade; `--fix` (and every `install`/`update`) replaces it with a managed `claude` function that follows the
|
|
119
|
+
`claude.cmd` shim, after a `.bak-<date>` backup.
|
|
113
120
|
It also fails on Python hook launch problems: a hook or statusline command starting with a bare `python`/`python3`/`py`
|
|
114
121
|
token (the Microsoft Store stub makes it fail), a missing `hooks/pyrun.js` launcher, an unresolvable interpreter, and a
|
|
115
122
|
WindowsApps python stub ahead of a real interpreter on PATH; `--fix` rewrites the bare tokens to
|
|
@@ -131,6 +138,8 @@ agents-cli install
|
|
|
131
138
|
(Claude Code only matches `Edit(<path>)` for file writes); `--fix`, the `project_hook_repair.js` hook and the
|
|
132
139
|
`--fix-project-hooks` flag of `install`/`update` rewrite them to `Edit(<path>)` in `settings.local.json` with duplicates
|
|
133
140
|
dropped, a committed `settings.json` is reported and never edited, bare `Write`/`NotebookEdit` are left alone.
|
|
141
|
+
- `agents-cli update --repair` — also restores files whose source did not change but whose deployed copy differs from the install record (update otherwise keeps those as local edits, even with `--theirs`; Codex update names them and points here). Covers the Claude and Codex targets.
|
|
142
|
+
- `agents-cli release-lock <status|acquire|phase|release> [--pid N] [--phase P]` — the lock `tools/release.ps1` holds from its first gate to its end (`~/.claude/state/release.lock`: pid, start time, phase). While a live lock exists, `update` into the default `~/.claude` (no `--target-dir`/`--codex-dir`) and `ship.py`'s global sync refuse with exit 3, because the release's dogfood gate fails on any write into the real `~/.claude`. A lock whose pid is dead, or older than 6 hours, is stale and ignored. Skipped under `NODE_ENV=test` unless `AGENTS_CLI_RELEASE_LOCK_CHECK=1`.
|
|
134
143
|
- `agents-cli sampler <status|register|unregister> [--dry-run] [--target-dir <path>]` — the hidden `ClaudeMemSampler` Windows logon task of the memory-safety stack. `install` and `update` register or start it on their own when the stack is installed (idempotent, hidden, default `~/.claude` install only, skipped under `NODE_ENV=test`; `--no-scheduled-tasks` or `AGENTS_CLI_NO_SCHEDULED_TASKS=1` skips it). `--dry-run` runs `register_mem_sampler.ps1` with `-WhatIf` and changes nothing. `doctor` adds a "Memory-safety stack" block (task, wired hooks, budget file, newest sample in `logs/mem-samples.jsonl`) and exits 1 on a missing task, an unwired hook, an invalid budget file or a stale sample. See [`docs/memory-safety.md`](../../docs/memory-safety.md).
|
|
135
144
|
- `agents-cli --help` — show usage
|
|
136
145
|
|
package/bin/cli.js
CHANGED
|
@@ -44,6 +44,10 @@ const pythonHooks = require('../lib/pythonHooks');
|
|
|
44
44
|
const pyrun = require('../lib/pyrun');
|
|
45
45
|
const { checkModVersions } = require('../lib/claudeVersion');
|
|
46
46
|
const memSafety = require('../lib/memSafety');
|
|
47
|
+
const portalHealth = require('../lib/portalHealth');
|
|
48
|
+
const { staleCheckoutGate } = require('../lib/staleCheckout');
|
|
49
|
+
const releaseLock = require('../lib/releaseLock');
|
|
50
|
+
const claudeProfile = require('../lib/claudeProfile');
|
|
47
51
|
|
|
48
52
|
const PACKAGE_ROOT = path.join(__dirname, '..');
|
|
49
53
|
// One styler for the whole process: colors on only for a real TTY stdout
|
|
@@ -90,6 +94,8 @@ Usage:
|
|
|
90
94
|
The hidden ClaudeMemSampler task of the memory-safety stack (Windows).
|
|
91
95
|
install/update register it on their own for the default ~/.claude install;
|
|
92
96
|
--dry-run runs the registration script with -WhatIf and changes nothing
|
|
97
|
+
agents-cli release-lock <status|acquire|phase|release> [--pid N] [--phase P]
|
|
98
|
+
The lock tools/release.ps1 holds while a release runs; update into ~/.claude refuses while it is live
|
|
93
99
|
agents-cli runner <sub> [flags] Install and manage a self-hosted GitLab CI runner (see "Flags for runner")
|
|
94
100
|
agents-cli --help Show this help
|
|
95
101
|
|
|
@@ -136,6 +142,10 @@ Flags for update:
|
|
|
136
142
|
--json Print a machine-readable summary instead of prose
|
|
137
143
|
--theirs Non-interactive: resolve every file conflict by taking the new source
|
|
138
144
|
--keep-mine Non-interactive: resolve every file conflict by keeping your on-disk version
|
|
145
|
+
--repair Also restore files whose source did not change but whose deployed copy differs from the
|
|
146
|
+
install record (normally kept as local edits); use when doctor reports drift
|
|
147
|
+
--allow-stale Update even when this checkout is behind origin's default branch (default: refused;
|
|
148
|
+
doctor checks ledger hashes, not source drift, so it cannot catch a stale deploy)
|
|
139
149
|
|
|
140
150
|
Update compares each installed file's source hash, ledger hash, and on-disk
|
|
141
151
|
hash: a file no one has touched since install is silently overwritten when
|
|
@@ -172,10 +182,12 @@ Flags for runner:
|
|
|
172
182
|
runner status | doctor | uninstall Check, diagnose (docker, PAT scopes, online) or remove it
|
|
173
183
|
runner attach | detach --project-id <id> Enable/disable the saved runners on a project (--no-cloud on
|
|
174
184
|
attach also turns off cloud runners for it)
|
|
185
|
+
runner pool --pool-file <spec> [--apply] Merge runners into one capped pool (dry run without --apply; refuses while a job runs)
|
|
186
|
+
runner janitor [--dry-run] [--watch] Remove finished job containers, per-job volumes and unused images; --watch cleans after every job
|
|
175
187
|
runner init-project [--profile node|python|docker|macos|blank] [--write] [--attach --project-id <id>]
|
|
176
188
|
Write a .gitlab-ci.yml that uses the shared templates (dry run unless --write)
|
|
177
189
|
--profile <auto|linux|macos> Install profile (default auto); --name, --tags, --concurrent, --url, --image,
|
|
178
|
-
--cache-volume, --protected, --run-untagged/--no-run-untagged, --dry-run
|
|
190
|
+
--cache-volume, --job-memory <size>, --job-cpus <n>, --no-janitor, --fix (doctor), --protected, --run-untagged/--no-run-untagged, --dry-run
|
|
179
191
|
--json Print a machine-readable result (never contains a token or PAT)
|
|
180
192
|
Needs a GitLab PAT in GITLAB_RUNNER_PAT (or GITLAB_TOKEN): set it with "agents-cli secrets".
|
|
181
193
|
Exit codes: 0 ok, 1 a step failed, 2 usage error.
|
|
@@ -198,6 +210,10 @@ whose script file is missing, and a bare (non-launcher) project hook command, wh
|
|
|
198
210
|
and so blocks every tool call when it is a PreToolUse hook. A launcher-form hook with a missing file fails open but is still
|
|
199
211
|
reported. Without --fix nothing is modified.
|
|
200
212
|
|
|
213
|
+
doctor also checks the PowerShell profiles (Documents/PowerShell and Documents/WindowsPowerShell) for a hard-coded claude alias or
|
|
214
|
+
function, which bypasses the %APPDATA%/npm shims and so ignores every Claude Code upgrade. --fix (and every install/update) replaces it
|
|
215
|
+
with a managed claude function that follows the shim, after a .bak-<date> backup. Windows only.
|
|
216
|
+
|
|
201
217
|
doctor also fails on Python hook launch problems: a hook or statusline command in <target>/settings.json or the
|
|
202
218
|
project settings that starts with a bare python/python3/py token (the Microsoft Store stub makes it fail), a
|
|
203
219
|
hooks/pyrun.js launcher that is not installed, an interpreter that does not resolve, and a WindowsApps python stub
|
|
@@ -1009,7 +1025,7 @@ async function runSecrets(argv) {
|
|
|
1009
1025
|
}
|
|
1010
1026
|
|
|
1011
1027
|
function parseUpdateArgs(argv) {
|
|
1012
|
-
const args = { bundle: null, yes: false, targetDir: null, targetConfig: null, json: false, theirs: false, keepMine: false, noScheduledTasks: false };
|
|
1028
|
+
const args = { bundle: null, yes: false, targetDir: null, targetConfig: null, json: false, theirs: false, keepMine: false, noScheduledTasks: false, allowStale: false, repair: false };
|
|
1013
1029
|
for (let i = 0; i < argv.length; i += 1) {
|
|
1014
1030
|
const arg = argv[i];
|
|
1015
1031
|
if (arg === '--bundle') {
|
|
@@ -1031,6 +1047,10 @@ function parseUpdateArgs(argv) {
|
|
|
1031
1047
|
args.keepMine = true;
|
|
1032
1048
|
} else if (arg === '--no-scheduled-tasks') {
|
|
1033
1049
|
args.noScheduledTasks = true;
|
|
1050
|
+
} else if (arg === '--allow-stale') {
|
|
1051
|
+
args.allowStale = true;
|
|
1052
|
+
} else if (arg === '--repair') {
|
|
1053
|
+
args.repair = true;
|
|
1034
1054
|
} else {
|
|
1035
1055
|
throw new UpdateError(`Unknown update flag: ${arg}`);
|
|
1036
1056
|
}
|
|
@@ -1048,7 +1068,7 @@ function summarizeBundleUpdate(b) {
|
|
|
1048
1068
|
const parts = [];
|
|
1049
1069
|
if (b.overwritten.length) parts.push(`${b.overwritten.length} overwritten`);
|
|
1050
1070
|
if (b.reinstalled.length) parts.push(`${b.reinstalled.length} reinstalled`);
|
|
1051
|
-
if (b.kept.length) parts.push(`${b.kept.length} kept (locally edited, no upstream change)`);
|
|
1071
|
+
if (b.kept.length) parts.push(`${b.kept.length} kept (locally edited, no upstream change; update --repair restores the source copy)`);
|
|
1052
1072
|
if (b.removedUpstream.length) parts.push(`${b.removedUpstream.length} removed (no longer shipped)`);
|
|
1053
1073
|
if (b.keptUpstreamUserEdited.length) {
|
|
1054
1074
|
parts.push(`${b.keptUpstreamUserEdited.length} kept-but-untracked (removed upstream, locally edited)`);
|
|
@@ -1096,12 +1116,15 @@ async function runUpdate(argv) {
|
|
|
1096
1116
|
const strategy = args.theirs ? 'theirs' : args.keepMine ? 'keep-mine' : undefined;
|
|
1097
1117
|
|
|
1098
1118
|
try {
|
|
1119
|
+
const stale = staleCheckoutGate(path.dirname(loadManifest(PACKAGE_ROOT).manifestPath), { allowStale: args.allowStale });
|
|
1120
|
+
if (stale !== null) return stale;
|
|
1099
1121
|
const result = await updateBundles({
|
|
1100
1122
|
packageRoot: PACKAGE_ROOT,
|
|
1101
1123
|
bundleKey: args.bundle,
|
|
1102
1124
|
targetBase: args.targetDir,
|
|
1103
1125
|
cliVersion: pkg.version,
|
|
1104
1126
|
strategy,
|
|
1127
|
+
repair: args.repair,
|
|
1105
1128
|
mcpConfigPath: args.targetConfig,
|
|
1106
1129
|
});
|
|
1107
1130
|
|
|
@@ -1275,6 +1298,18 @@ Project hooks (${step.findings.length} finding(s), ${step.repos.length} repo(s)
|
|
|
1275
1298
|
}
|
|
1276
1299
|
}
|
|
1277
1300
|
|
|
1301
|
+
function printClaudeProfileReport(report, { fixRequested }) {
|
|
1302
|
+
for (const f of report.fixed) console.log(`\nInstalled the claude shim launcher in ${f.file} (backup: ${f.backup}); open a new terminal tab or run \`. $PROFILE\` to load it.`);
|
|
1303
|
+
if (report.findings.length === 0 || report.fixed.length > 0) return;
|
|
1304
|
+
console.log(`\nPowerShell profile claude command (${report.findings.length} finding(s)):`);
|
|
1305
|
+
for (const f of report.findings) console.log(` ${claudeProfile.describeProfileFinding(f)}`);
|
|
1306
|
+
if (!fixRequested) console.log(` Fix: ${claudeProfile.FIX_COMMAND}`);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
function claudeProfileStep(targetBase, fix) {
|
|
1310
|
+
return claudeProfile.checkClaudeProfile({ home: path.dirname(targetBase), fix });
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1278
1313
|
function printPythonLaunchReport(py) {
|
|
1279
1314
|
if (py.fixed.length > 0) {
|
|
1280
1315
|
console.log(`\nRewrote ${py.fixed.length} bare python hook command(s) to the pyrun launcher:`);
|
|
@@ -1358,6 +1393,7 @@ async function withProjectHookStep(argv, run, { healBypass = false } = {}) {
|
|
|
1358
1393
|
if (step.error) console.error(step.error);
|
|
1359
1394
|
printProjectHookReport(step, { fixRequested: opts.fix });
|
|
1360
1395
|
const targetBase = opts.targetDir || defaultTargetBase();
|
|
1396
|
+
printClaudeProfileReport(claudeProfileStep(targetBase, healBypass || opts.fix), { fixRequested: opts.fix });
|
|
1361
1397
|
printBypassOnlyReport(bypassOnly.checkBypassOnly({ targetBase, fix: healBypass || opts.fix }));
|
|
1362
1398
|
printModeDriftReport(
|
|
1363
1399
|
modeDrift.checkModeDrift({
|
|
@@ -1422,13 +1458,15 @@ function runDoctor(argv) {
|
|
|
1422
1458
|
console.error(py.error);
|
|
1423
1459
|
return 1;
|
|
1424
1460
|
}
|
|
1461
|
+
const profileStep = claudeProfileStep(scope.targetBase, args.fix);
|
|
1425
1462
|
const { fixed } = hooks;
|
|
1463
|
+
result.claudeProfile = profileStep;
|
|
1426
1464
|
result.projectHooks = { repos: hooks.repos, findings: hooks.findings, fixed };
|
|
1427
1465
|
result.modeDrift = { globalMode: modes.globalMode, findings: modes.findings, fixed: modes.fixed };
|
|
1428
1466
|
result.bypassOnly = { file: bypass.file, findings: bypass.findings, fixed: bypass.fixed, error: bypass.error };
|
|
1429
1467
|
result.permissionRules = { findings: rules.findings, fixed: rules.fixed };
|
|
1430
1468
|
result.pythonLaunch = { files: py.files, findings: py.findings, fixed: py.fixed, missingLaunchers: py.missingLaunchers, interpreter: py.interpreter, stubs: py.stubs };
|
|
1431
|
-
result.healthy = result.healthy && hooks.findings.length === 0 && bypass.findings.length === 0 && !bypass.error && modes.findings.length === 0 && rules.findings.length === 0 && py.healthy;
|
|
1469
|
+
result.healthy = result.healthy && hooks.findings.length === 0 && bypass.findings.length === 0 && !bypass.error && modes.findings.length === 0 && rules.findings.length === 0 && py.healthy && (profileStep.findings.length === 0 || profileStep.fixed.length > 0);
|
|
1432
1470
|
|
|
1433
1471
|
if (args.json) {
|
|
1434
1472
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -1437,6 +1475,7 @@ function runDoctor(argv) {
|
|
|
1437
1475
|
|
|
1438
1476
|
const printProjectHooks = () => printProjectHookReport(hooks, { fixRequested: args.fix });
|
|
1439
1477
|
const printModeDrift = () => {
|
|
1478
|
+
printClaudeProfileReport(profileStep, { fixRequested: args.fix });
|
|
1440
1479
|
printBypassOnlyReport(bypass);
|
|
1441
1480
|
printModeDriftReport(modes);
|
|
1442
1481
|
printRuleMigrationReport(rules);
|
|
@@ -1474,6 +1513,14 @@ function runDoctor(argv) {
|
|
|
1474
1513
|
for (const w of m.warnings) console.log(` ${mark('skip')} ${w}`);
|
|
1475
1514
|
};
|
|
1476
1515
|
|
|
1516
|
+
const printPortal = () => {
|
|
1517
|
+
const p = result.portal;
|
|
1518
|
+
if (!p) return;
|
|
1519
|
+
console.log('\nUsage portal:');
|
|
1520
|
+
for (const line of portalHealth.describePortal(p)) console.log(` ${line}`);
|
|
1521
|
+
for (const f of p.findings) console.log(` ${mark('fail')} ${f}`);
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1477
1524
|
const printRoutingMod = () => {
|
|
1478
1525
|
if (!result.routingMod) return;
|
|
1479
1526
|
console.log('\nModel routing:');
|
|
@@ -1489,6 +1536,7 @@ function runDoctor(argv) {
|
|
|
1489
1536
|
printMemoryIndex();
|
|
1490
1537
|
printRoutingMod();
|
|
1491
1538
|
printMemorySafety();
|
|
1539
|
+
printPortal();
|
|
1492
1540
|
printModeDrift();
|
|
1493
1541
|
return 0;
|
|
1494
1542
|
}
|
|
@@ -1511,6 +1559,7 @@ function runDoctor(argv) {
|
|
|
1511
1559
|
printMemoryIndex();
|
|
1512
1560
|
printRoutingMod();
|
|
1513
1561
|
printMemorySafety();
|
|
1562
|
+
printPortal();
|
|
1514
1563
|
printProjectHooks();
|
|
1515
1564
|
printPythonLaunchReport(py);
|
|
1516
1565
|
printModeDrift();
|
|
@@ -1562,6 +1611,11 @@ function runSampler(argv) {
|
|
|
1562
1611
|
|
|
1563
1612
|
async function main(argv, { captureSelection = false } = {}) {
|
|
1564
1613
|
const [command, ...rest] = argv;
|
|
1614
|
+
if (command === 'update' && !rest.includes('--target-dir') && !rest.includes('--codex-dir')) {
|
|
1615
|
+
const refused = releaseLock.releaseLockGate({ action: 'update' });
|
|
1616
|
+
if (refused !== null) return refused;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1565
1619
|
if (['install','update','uninstall','doctor'].includes(command)) {
|
|
1566
1620
|
const parsed = require('../lib/deployment').parseDeploymentArgs(rest);
|
|
1567
1621
|
if (parsed.runtime !== 'claude') return require('../lib/deployment').runDeployment({command,argv:rest,packageRoot:PACKAGE_ROOT,cliVersion:pkg.version,runPrimary:async args=>{
|
|
@@ -1574,6 +1628,10 @@ async function main(argv, { captureSelection = false } = {}) {
|
|
|
1574
1628
|
rest.splice(0,rest.length,...parsed.args);
|
|
1575
1629
|
}
|
|
1576
1630
|
|
|
1631
|
+
if (command === 'release-lock') {
|
|
1632
|
+
return releaseLock.runReleaseLockCommand(rest);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1577
1635
|
if (command === '--version' || command === '-v') {
|
|
1578
1636
|
console.log(pkg.version);
|
|
1579
1637
|
return 0;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: synth-auditor
|
|
3
|
+
description: Audits one chapter's organised synth text against its raw voice transcript and adds every missing detail, additively, with a verified audit table.
|
|
4
|
+
model: claude-sonnet-5-5[1m]
|
|
5
|
+
role: worker
|
|
6
|
+
effort: high
|
|
7
|
+
tools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash']
|
|
8
|
+
dispatch_tier: mandatory-review
|
|
9
|
+
user-invokable: false
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# synth-auditor
|
|
13
|
+
|
|
14
|
+
One job per dispatch: for one chapter N, find every detail in the raw transcript that the synth lacks, add it to the synth
|
|
15
|
+
without changing what is there, and write the audit table. Stage `source -> comic_txt` of graphic-novel-pipeline.
|
|
16
|
+
|
|
17
|
+
## Input
|
|
18
|
+
|
|
19
|
+
A dispatch with `goal:` and `task:` naming the chapter and the project root. Files, relative to the root:
|
|
20
|
+
|
|
21
|
+
| File | Role |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `source/raw_text/N_*.txt` | Voice transcript, unordered, speech-to-text errors. Line numbers are physical file lines |
|
|
24
|
+
| `source/synth_txt/N_*.txt` | Organised synth: beats `[n]` with Story (video), Speaker's reading, Terms; CARRIES FORWARD; OPEN / UNCLEAR |
|
|
25
|
+
| `comic_txt/_audit/N_<slug>_audit.md` | Your output table |
|
|
26
|
+
|
|
27
|
+
## Work
|
|
28
|
+
|
|
29
|
+
1. Read the whole raw file, then the whole synth. Walk the raw file line by line; for each idea, name, example, joke,
|
|
30
|
+
hedge, question, number or reaction ask: is it in the synth beat where it belongs?
|
|
31
|
+
2. Repeated narration (the video text appears several times) is checked once. Verbal tics and session meta
|
|
32
|
+
("okay", "next section") are filler: log them, add nothing.
|
|
33
|
+
3. Edit the synth, additive only:
|
|
34
|
+
- Never delete, reword, reorder or reflow an existing line. Append a sentence to the end of the right line, or insert a
|
|
35
|
+
new line inside the right beat (` Speaker's reading (added): ...`).
|
|
36
|
+
- Use the beat's own labels: narrator text goes in `Story (video)`, the speaker's own words in `Speaker's reading`.
|
|
37
|
+
- End every addition with its source tag: `(raw L5)` or `(raw p1 L1, p2 L15)` for a chapter with two raw files.
|
|
38
|
+
- Keep the speaker's hedges and wording. Keep short quotes in double quotes.
|
|
39
|
+
4. Garbled, cut-off or unknown words: never repair silently. Add a bullet to OPEN / UNCLEAR:
|
|
40
|
+
`- Raw line N: "exact words" - what is unclear, likely reading [?]`. A guess inside a beat carries `[?]`.
|
|
41
|
+
5. Write the audit table (rows in raw order). Columns: raw location, quote, target beat, action.
|
|
42
|
+
- Raw location: `L5`, `L1, L5`, or `p2 L15` with two raw files.
|
|
43
|
+
- Quote: 3 to 25 words, copied from the raw file inside double quotes. Use ` ... ` to skip words; each part must be
|
|
44
|
+
verbatim. Case and punctuation may differ; words may not.
|
|
45
|
+
- Target beat: `[n] story`, `[n] reading` or `OPEN`.
|
|
46
|
+
- Action: `added`, `added ("short detail")`, `flagged-uncertain (why)` or `skipped-filler (why)`.
|
|
47
|
+
- End with a counts line: found, added, flagged, skipped.
|
|
48
|
+
6. Run `python ~/.claude/skills/graphic-novel-pipeline/scripts/synth_audit.py check --chapter N` from the root. Exit 0 is
|
|
49
|
+
required. Fix your edits or your table (not the base lines) until it passes. Read the `warn` lines too.
|
|
50
|
+
|
|
51
|
+
## Never
|
|
52
|
+
|
|
53
|
+
- Invent a detail, merge a flagged phrase into a beat as fact, or fill a gap from outside knowledge.
|
|
54
|
+
- Edit anything except the synth file and the audit table. Never commit.
|
|
55
|
+
|
|
56
|
+
## Return
|
|
57
|
+
|
|
58
|
+
`READY_TO_COMMIT` with files and the check summary line (rows, added confirmed, warnings), or `BLOCKED` with the failing
|
|
59
|
+
check output. The main loop reviews the diff.
|
|
@@ -1,35 +1,52 @@
|
|
|
1
1
|
# conclusion-scribe hook
|
|
2
2
|
|
|
3
|
-
A Claude Code **Stop hook** that makes conclusive responses get
|
|
4
|
-
just spoken
|
|
3
|
+
A Claude Code **Stop and SessionEnd hook** that makes conclusive responses get
|
|
4
|
+
**filed, not just spoken** -- silently, in the background, never blocking a turn.
|
|
5
|
+
Three deterministic stages, all in code:
|
|
5
6
|
|
|
6
|
-
1. **Detect**
|
|
7
|
+
1. **Detect** -- regex, no judgment: the final assistant message is
|
|
7
8
|
"conclusion-shaped" if it contains a commit SHA + ship-language
|
|
8
9
|
(shipped/fixed/live/pushed/committed/green/mandate/closed/deployed), or a
|
|
9
10
|
GitLab issue URL.
|
|
10
|
-
2. **
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
3. **
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
2. **Facts** -- the hook script itself (not an LLM) extracts commits, issue,
|
|
12
|
+
project and HEAD, then posts a facts-only note to the referenced GitLab issue
|
|
13
|
+
and writes a one-brain memory. Dedup key: (project, issue, HEAD sha).
|
|
14
|
+
3. **Prose** -- a detached Haiku worker adds a short summary to that record.
|
|
15
|
+
|
|
16
|
+
| Event | Role | Budget |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `Stop` | Files facts synchronously after every turn; reports earlier background failures once | 30 s |
|
|
19
|
+
| `SessionEnd` | Final flush: re-checks the last assistant message (tail read of the transcript) and hands a conclusive one to a detached `--flush-worker`; prints nothing (CC discards SessionEnd output) | CC allows 1.5 s; the hook returns in well under that |
|
|
20
|
+
|
|
21
|
+
Stop and SessionEnd share the dedup key and an atomic claim (`_claim_entry`), so a
|
|
22
|
+
conclusion is filed once whichever runs first; the second becomes a no-op. A
|
|
23
|
+
claim older than 60 s counts as abandoned. SessionEnd covers sessions that end
|
|
24
|
+
without a Stop for the last message (interrupt, `/clear`, resume, logout, `-p`
|
|
25
|
+
exit). A filing warning in the flush worker goes to the background-failure log and
|
|
26
|
+
is reported by the next session's first Stop.
|
|
27
|
+
|
|
28
|
+
All streams, files and child-process pipes are UTF-8 (`errors="replace"`), so a non-ASCII character such as an arrow cannot fail the Haiku stage under a Windows legacy code page.
|
|
16
29
|
|
|
17
30
|
## Install (plug and play)
|
|
18
31
|
|
|
19
32
|
1. Copy `conclusion_scribe_hook.py` to `~/.claude/hooks/`.
|
|
20
33
|
2. Create `~/.claude/hooks/conclusion-scribe.env` from
|
|
21
|
-
`conclusion-scribe.env.example`
|
|
34
|
+
`conclusion-scribe.env.example` -- your project map, token source, and
|
|
22
35
|
memory endpoint live there, never in the code.
|
|
23
|
-
3. Wire into `~/.claude/settings.json
|
|
36
|
+
3. Wire into `~/.claude/settings.json` (the `self-conclusion-scribe` bundle does
|
|
37
|
+
this for you):
|
|
24
38
|
|
|
25
39
|
```json
|
|
26
40
|
"Stop": [{"hooks": [{"type": "command",
|
|
27
41
|
"command": "node <home>/.claude/hooks/pyrun.js <home>/.claude/hooks/conclusion_scribe_hook.py",
|
|
28
|
-
"timeout": 30}]}]
|
|
42
|
+
"timeout": 30}]}],
|
|
43
|
+
"SessionEnd": [{"hooks": [{"type": "command",
|
|
44
|
+
"command": "node <home>/.claude/hooks/pyrun.js <home>/.claude/hooks/conclusion_scribe_hook.py",
|
|
45
|
+
"timeout": 5}]}]
|
|
29
46
|
```
|
|
30
47
|
|
|
31
|
-
Sessions started after wiring fire it automatically. No config
|
|
32
|
-
fails open (detect
|
|
48
|
+
Sessions started after wiring fire it automatically. No config -> the hook
|
|
49
|
+
fails open (detect works; filing legs no-op).
|
|
33
50
|
|
|
34
51
|
## PROJECT_MAP auto-discovery
|
|
35
52
|
|
|
@@ -65,14 +82,6 @@ notifications/initialized → tools/call `remember` with `Mcp-Session-Id`);
|
|
|
65
82
|
point it at any MCP server exposing a `remember` tool, or leave it
|
|
66
83
|
unconfigured to skip the leg.
|
|
67
84
|
|
|
68
|
-
## scribe block schema
|
|
69
|
-
|
|
70
|
-
```scribe
|
|
71
|
-
{"summary": "2-4 sentence conclusion", "commits": ["<sha>"],
|
|
72
|
-
"tests": "<result>", "issue": "<repo>#<iid>", "tags": ["..."],
|
|
73
|
-
"project": "<project-or-null>"}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
85
|
## Tests
|
|
77
86
|
|
|
78
87
|
`SCRIBE_HOOK_DRY_RUN=1` stubs both filing legs; `SCRIBE_HOOK_CONFIG` points
|
|
@@ -53,6 +53,8 @@ GITLAB_TOKEN is resolved via the shared agents_env.get_secret() contract
|
|
|
53
53
|
(live env var, then <base>/agents.env, then a project-root .env) rather than
|
|
54
54
|
this file — see agents_env.py's module docstring for the exact order.
|
|
55
55
|
|
|
56
|
+
SessionEnd re-checks the last message and files via a detached --flush-worker, sharing Stop's dedup claim.
|
|
57
|
+
|
|
56
58
|
Set SCRIBE_HOOK_DRY_RUN=1 to print planned GitLab/one-brain actions to
|
|
57
59
|
stderr instead of calling out (used by tests) -- the background Haiku
|
|
58
60
|
subprocess is unaffected by DRY_RUN (no shared-state side effects of its
|
|
@@ -199,6 +201,10 @@ DRY_RUN = os.environ.get("SCRIBE_HOOK_DRY_RUN") == "1"
|
|
|
199
201
|
NO_PROSE = os.environ.get("SCRIBE_HOOK_NO_PROSE") == "1"
|
|
200
202
|
|
|
201
203
|
|
|
204
|
+
SESSION_END_TAIL_BYTES = 2 * 1024 * 1024
|
|
205
|
+
FLUSH_TEXT_CHARS = 60000
|
|
206
|
+
|
|
207
|
+
|
|
202
208
|
def _sha_looks_real(token: str) -> bool:
|
|
203
209
|
"""A real git SHA is hex but not all-digit -- see SHA_RE docstring."""
|
|
204
210
|
return any(c in "abcdef" for c in token)
|
|
@@ -268,7 +274,7 @@ def _head_sha(cwd: str | None) -> str | None:
|
|
|
268
274
|
try:
|
|
269
275
|
proc = headless_run(
|
|
270
276
|
["git", "-C", cwd, "rev-parse", "--short=12", "HEAD"],
|
|
271
|
-
capture_output=True,
|
|
277
|
+
capture_output=True, encoding="utf-8", errors="replace", timeout=5,
|
|
272
278
|
)
|
|
273
279
|
except Exception:
|
|
274
280
|
return None
|
|
@@ -494,6 +500,28 @@ def _put_entry(key: str, entry: dict) -> None:
|
|
|
494
500
|
pass
|
|
495
501
|
|
|
496
502
|
|
|
503
|
+
CLAIM_STALE_SECONDS = 60
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def _claim_abandoned(entry: dict) -> bool:
|
|
507
|
+
return bool(entry.get("claim_only")) and time.time() - entry.get("claimed_at", 0) > CLAIM_STALE_SECONDS
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def _claim_entry(key: str, claim: dict) -> tuple[dict, bool]:
|
|
511
|
+
"""Stores `claim` unless a live entry or fresh claim exists; returns (entry, claimed); fails open as claimed."""
|
|
512
|
+
try:
|
|
513
|
+
with _FileLock(_state_lock_path(), timeout=LOCK_TIMEOUT_MAIN_THREAD_SECONDS):
|
|
514
|
+
state = _load_state()
|
|
515
|
+
existing = state.get(key)
|
|
516
|
+
if existing is not None and not _claim_abandoned(existing):
|
|
517
|
+
return existing, False
|
|
518
|
+
state[key] = claim
|
|
519
|
+
_save_state(state)
|
|
520
|
+
except Exception:
|
|
521
|
+
pass
|
|
522
|
+
return claim, True
|
|
523
|
+
|
|
524
|
+
|
|
497
525
|
def _update_state_entry(key: str, **fields) -> None:
|
|
498
526
|
"""Locked read-LATEST-modify-write of a single existing entry's fields
|
|
499
527
|
-- used by the background worker (_run_finish_worker) to record
|
|
@@ -819,9 +847,10 @@ def _haiku_summarize(text: str) -> tuple[str | None, str | None]:
|
|
|
819
847
|
fh.write('{"hooks":{}}')
|
|
820
848
|
env = os.environ.copy()
|
|
821
849
|
env["CLAUDE_HOOK_CHILD"] = "1"
|
|
850
|
+
env["CLAUDE_CODE_FORK_SUBAGENT"] = "0"
|
|
822
851
|
proc = headless_run(
|
|
823
|
-
[claude_exe, "-p", "--model", HAIKU_MODEL, "--settings", tmp_settings],
|
|
824
|
-
input=prompt, capture_output=True,
|
|
852
|
+
[claude_exe, "-p", "--permission-mode", "dontAsk", "--model", HAIKU_MODEL, "--settings", tmp_settings],
|
|
853
|
+
input=prompt, capture_output=True, encoding="utf-8", errors="replace",
|
|
825
854
|
timeout=HAIKU_TIMEOUT_SECONDS, env=env,
|
|
826
855
|
)
|
|
827
856
|
if proc.returncode != 0:
|
|
@@ -844,23 +873,9 @@ def _haiku_summarize(text: str) -> tuple[str | None, str | None]:
|
|
|
844
873
|
pass
|
|
845
874
|
|
|
846
875
|
|
|
847
|
-
def
|
|
848
|
-
"""
|
|
849
|
-
script in --finish-worker mode as a detached child. Never raises -- if
|
|
850
|
-
spawning fails, the facts-only record already filed by the caller
|
|
851
|
-
stands, and prose is simply never attached."""
|
|
852
|
-
if NO_PROSE:
|
|
853
|
-
return
|
|
876
|
+
def _spawn_detached(mode: str, state: dict) -> None:
|
|
877
|
+
"""Launches this script in `mode` (--finish-worker / --flush-worker) as a detached child; never raises."""
|
|
854
878
|
try:
|
|
855
|
-
state = {
|
|
856
|
-
"key": key,
|
|
857
|
-
"issue": entry.get("issue"),
|
|
858
|
-
"note_id": entry.get("note_id"),
|
|
859
|
-
"project": entry.get("project"),
|
|
860
|
-
"facts_body": entry.get("facts_body"),
|
|
861
|
-
"tags": tags,
|
|
862
|
-
"text": text[-6000:],
|
|
863
|
-
}
|
|
864
879
|
cache_dir = _state_path().parent
|
|
865
880
|
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
866
881
|
fd, state_path = tempfile.mkstemp(prefix="scribe_worker_", suffix=".json", dir=str(cache_dir))
|
|
@@ -874,7 +889,7 @@ def _spawn_prose_worker(key: str, entry: dict, text: str, tags: list[str]) -> No
|
|
|
874
889
|
else:
|
|
875
890
|
kwargs["start_new_session"] = True
|
|
876
891
|
headless_popen(
|
|
877
|
-
[sys.executable, str(Path(__file__).resolve()),
|
|
892
|
+
[sys.executable, str(Path(__file__).resolve()), mode, state_path],
|
|
878
893
|
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
|
879
894
|
close_fds=True, **kwargs,
|
|
880
895
|
)
|
|
@@ -882,6 +897,25 @@ def _spawn_prose_worker(key: str, entry: dict, text: str, tags: list[str]) -> No
|
|
|
882
897
|
pass
|
|
883
898
|
|
|
884
899
|
|
|
900
|
+
def _spawn_prose_worker(key: str, entry: dict, text: str, tags: list[str]) -> None:
|
|
901
|
+
"""Fire-and-forget prose stage; on spawn failure the facts-only record stands."""
|
|
902
|
+
if NO_PROSE:
|
|
903
|
+
return
|
|
904
|
+
_spawn_detached("--finish-worker", {
|
|
905
|
+
"key": key,
|
|
906
|
+
"issue": entry.get("issue"),
|
|
907
|
+
"note_id": entry.get("note_id"),
|
|
908
|
+
"project": entry.get("project"),
|
|
909
|
+
"facts_body": entry.get("facts_body"),
|
|
910
|
+
"tags": tags,
|
|
911
|
+
"text": text[-6000:],
|
|
912
|
+
})
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
def _spawn_flush_worker(text: str, cwd: str | None) -> None:
|
|
916
|
+
_spawn_detached("--flush-worker", {"text": text[-FLUSH_TEXT_CHARS:], "cwd": cwd})
|
|
917
|
+
|
|
918
|
+
|
|
885
919
|
def _run_finish_worker(state_path: str) -> None:
|
|
886
920
|
"""Entry point for `python conclusion_scribe_hook.py --finish-worker
|
|
887
921
|
<state_file>`. Runs detached, outside any Claude Code hook lifecycle:
|
|
@@ -932,34 +966,54 @@ def _run_finish_worker(state_path: str) -> None:
|
|
|
932
966
|
|
|
933
967
|
# --- Stop-event entry point --------------------------------------------------
|
|
934
968
|
|
|
969
|
+
def _last_text_in_lines(lines) -> str:
|
|
970
|
+
last = ""
|
|
971
|
+
for line in lines:
|
|
972
|
+
try:
|
|
973
|
+
evt = json.loads(line)
|
|
974
|
+
except Exception:
|
|
975
|
+
continue
|
|
976
|
+
msg = evt.get("message") or {}
|
|
977
|
+
if msg.get("role") != "assistant":
|
|
978
|
+
continue
|
|
979
|
+
parts = msg.get("content")
|
|
980
|
+
if isinstance(parts, list):
|
|
981
|
+
text = "".join(
|
|
982
|
+
p.get("text", "") for p in parts
|
|
983
|
+
if isinstance(p, dict) and p.get("type") == "text"
|
|
984
|
+
)
|
|
985
|
+
elif isinstance(parts, str):
|
|
986
|
+
text = parts
|
|
987
|
+
else:
|
|
988
|
+
continue
|
|
989
|
+
if text.strip():
|
|
990
|
+
last = text
|
|
991
|
+
return last
|
|
992
|
+
|
|
993
|
+
|
|
935
994
|
def _last_assistant_text(transcript_path: str) -> str:
|
|
936
995
|
"""Last assistant message's concatenated text blocks, streamed."""
|
|
937
|
-
last = ""
|
|
938
996
|
try:
|
|
939
997
|
with open(transcript_path, "r", encoding="utf-8", errors="replace") as fh:
|
|
940
|
-
|
|
941
|
-
try:
|
|
942
|
-
evt = json.loads(line)
|
|
943
|
-
except Exception:
|
|
944
|
-
continue
|
|
945
|
-
msg = evt.get("message") or {}
|
|
946
|
-
if msg.get("role") != "assistant":
|
|
947
|
-
continue
|
|
948
|
-
parts = msg.get("content")
|
|
949
|
-
if isinstance(parts, list):
|
|
950
|
-
text = "".join(
|
|
951
|
-
p.get("text", "") for p in parts
|
|
952
|
-
if isinstance(p, dict) and p.get("type") == "text"
|
|
953
|
-
)
|
|
954
|
-
elif isinstance(parts, str):
|
|
955
|
-
text = parts
|
|
956
|
-
else:
|
|
957
|
-
continue
|
|
958
|
-
if text.strip():
|
|
959
|
-
last = text
|
|
998
|
+
return _last_text_in_lines(fh)
|
|
960
999
|
except OSError:
|
|
961
1000
|
return ""
|
|
962
|
-
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
def _last_assistant_text_tail(transcript_path: str, max_bytes: int = SESSION_END_TAIL_BYTES) -> str:
|
|
1004
|
+
"""Last assistant text from only the file's last `max_bytes` (keeps SessionEnd under 1.5 s)."""
|
|
1005
|
+
try:
|
|
1006
|
+
with open(transcript_path, "rb") as fh:
|
|
1007
|
+
fh.seek(0, os.SEEK_END)
|
|
1008
|
+
start = max(0, fh.tell() - max_bytes)
|
|
1009
|
+
fh.seek(start)
|
|
1010
|
+
data = fh.read()
|
|
1011
|
+
except OSError:
|
|
1012
|
+
return ""
|
|
1013
|
+
if start > 0:
|
|
1014
|
+
nl = data.find(b"\n")
|
|
1015
|
+
data = data[nl + 1:] if nl >= 0 else b""
|
|
1016
|
+
return _last_text_in_lines(data.decode("utf-8", errors="replace").splitlines())
|
|
963
1017
|
|
|
964
1018
|
|
|
965
1019
|
def _file_conclusion(text: str, cwd: str | None) -> str | None:
|
|
@@ -967,8 +1021,12 @@ def _file_conclusion(text: str, cwd: str | None) -> str | None:
|
|
|
967
1021
|
event. Returns a systemMessage string (never raises, never blocks)."""
|
|
968
1022
|
facts = _extract_facts(text, cwd)
|
|
969
1023
|
key = _dedup_key(facts, text)
|
|
970
|
-
|
|
971
|
-
is_new =
|
|
1024
|
+
claim = {"filed_at": datetime.now(timezone.utc).isoformat(), "claim_only": True, "claimed_at": time.time()}
|
|
1025
|
+
entry, is_new = _claim_entry(key, claim)
|
|
1026
|
+
|
|
1027
|
+
if not is_new and entry.get("claim_only"):
|
|
1028
|
+
where = facts.get("issue") or facts.get("project") or "one-brain only"
|
|
1029
|
+
return f"[scribe] duplicate work item -> {where}; filing already in progress."
|
|
972
1030
|
|
|
973
1031
|
if is_new:
|
|
974
1032
|
note_id = _post_gitlab_note(facts["issue"], _facts_note_body(facts)) if facts.get("issue") else None
|
|
@@ -1018,12 +1076,48 @@ def _file_conclusion(text: str, cwd: str | None) -> str | None:
|
|
|
1018
1076
|
return msg
|
|
1019
1077
|
|
|
1020
1078
|
|
|
1079
|
+
def _session_end_flush(data: dict) -> None:
|
|
1080
|
+
text = _last_assistant_text_tail(data.get("transcript_path") or "")
|
|
1081
|
+
if text and _is_conclusive(text):
|
|
1082
|
+
_spawn_flush_worker(text, data.get("cwd") or None)
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
def _run_flush_worker(state_path: str) -> None:
|
|
1086
|
+
"""`--flush-worker <state_file>`: files via the claim-guarded Stop path; warnings go to the failure log."""
|
|
1087
|
+
try:
|
|
1088
|
+
state = json.loads(Path(state_path).read_text(encoding="utf-8"))
|
|
1089
|
+
except Exception:
|
|
1090
|
+
return
|
|
1091
|
+
try:
|
|
1092
|
+
os.unlink(state_path)
|
|
1093
|
+
except OSError:
|
|
1094
|
+
pass
|
|
1095
|
+
text = state.get("text") or ""
|
|
1096
|
+
if not text or not _is_conclusive(text):
|
|
1097
|
+
return
|
|
1098
|
+
msg = _file_conclusion(text, state.get("cwd") or None)
|
|
1099
|
+
if msg and "WARNING:" in msg:
|
|
1100
|
+
_record_failure(None, "session_end_flush", msg.split("WARNING:", 1)[1].strip())
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
def _force_utf8_streams() -> None:
|
|
1104
|
+
for stream in (sys.stdin, sys.stdout, sys.stderr):
|
|
1105
|
+
try:
|
|
1106
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
1107
|
+
except (AttributeError, ValueError):
|
|
1108
|
+
pass
|
|
1109
|
+
|
|
1110
|
+
|
|
1021
1111
|
def _safe_main() -> None:
|
|
1022
1112
|
try:
|
|
1023
1113
|
data = json.loads(sys.stdin.read() or "{}")
|
|
1024
1114
|
except Exception:
|
|
1025
1115
|
return
|
|
1026
|
-
|
|
1116
|
+
event = data.get("hook_event_name")
|
|
1117
|
+
if event == "SessionEnd":
|
|
1118
|
+
_session_end_flush(data)
|
|
1119
|
+
return
|
|
1120
|
+
if event != "Stop":
|
|
1027
1121
|
return
|
|
1028
1122
|
parts = []
|
|
1029
1123
|
# Checked on EVERY Stop event, not only conclusive ones, so a background
|
|
@@ -1044,11 +1138,17 @@ def _safe_main() -> None:
|
|
|
1044
1138
|
|
|
1045
1139
|
|
|
1046
1140
|
if __name__ == "__main__":
|
|
1141
|
+
_force_utf8_streams()
|
|
1047
1142
|
if len(sys.argv) > 2 and sys.argv[1] == "--finish-worker":
|
|
1048
1143
|
try:
|
|
1049
1144
|
_run_finish_worker(sys.argv[2])
|
|
1050
1145
|
except Exception:
|
|
1051
1146
|
pass # never wedge -- facts were already filed synchronously
|
|
1147
|
+
elif len(sys.argv) > 2 and sys.argv[1] == "--flush-worker":
|
|
1148
|
+
try:
|
|
1149
|
+
_run_flush_worker(sys.argv[2])
|
|
1150
|
+
except Exception:
|
|
1151
|
+
pass
|
|
1052
1152
|
else:
|
|
1053
1153
|
try:
|
|
1054
1154
|
_safe_main()
|