harnessed 5.0.9 → 5.0.11
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/CHANGELOG.md +17 -0
- package/bin/harnessed-inject-state.mjs +1 -1
- package/bin/harnessed-update-reminder-worker.mjs +1 -1
- package/bin/harnessed-update-reminder.mjs +1 -1
- package/dist/cli.mjs +7 -28
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/manifests/SCHEMA.md +1 -1
- package/manifests/skill-packs/planning-with-files.yaml +6 -0
- package/manifests/tools/playwright-cli.yaml +13 -7
- package/package.json +1 -1
- package/bin/harnessed-stop-hook.mjs +0 -311
- package/manifests/optional/stop-hook-recover.yaml +0 -53
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/index.ts"],"names":[],"mappings":";AAAA,IAAA,eAAA,GAAA;AAAA,EAEE,OAAA,EAAW,
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/index.ts"],"names":[],"mappings":";AAAA,IAAA,eAAA,GAAA;AAAA,EAEE,OAAA,EAAW,QA+Gb,CAAA;;;AC5GO,IAAM,UAAU,eAAA,CAAI","file":"index.mjs","sourcesContent":["{\n \"name\": \"harnessed\",\n \"version\": \"5.0.11\",\n \"description\": \"AI coding harness package manager + composition orchestrator\",\n \"type\": \"module\",\n \"license\": \"Apache-2.0\",\n \"author\": \"easyinplay\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/easyinplay/harnessed.git\"\n },\n \"homepage\": \"https://github.com/easyinplay/harnessed#readme\",\n \"bugs\": \"https://github.com/easyinplay/harnessed/issues\",\n \"keywords\": [\n \"claude-code\",\n \"ai-harness\",\n \"package-manager\",\n \"composition\",\n \"skill-pack\",\n \"mcp\",\n \"orchestrator\"\n ],\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"packageManager\": \"pnpm@10.12.0\",\n \"bin\": {\n \"harnessed\": \"./dist/cli.mjs\",\n \"harnessed-inject-state\": \"./bin/harnessed-inject-state.mjs\"\n },\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"default\": \"./dist/index.mjs\"\n },\n \"./schemas\": {\n \"types\": \"./dist/schemas/index.d.ts\",\n \"import\": \"./dist/schemas/index.mjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"bin\",\n \"manifests\",\n \"messages\",\n \"workflows\",\n \"routing\",\n \"config-templates\",\n \"schemas\",\n \"CHANGELOG.md\",\n \"README.md\",\n \"README-en.md\",\n \"README-zh.md\",\n \"LICENSE\",\n \"NOTICE\",\n \"THIRD-PARTY-NOTICES.md\"\n ],\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"tsc --noEmit && tsup && node ./scripts/build-hooks.mjs\",\n \"prepack\": \"npm run build\",\n \"build:hooks\": \"node ./scripts/build-hooks.mjs\",\n \"build:schema\": \"node ./scripts/build-schema.mjs\",\n \"validate:schema\": \"node ./scripts/validate-schema.mjs\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run --passWithNoTests\",\n \"test:watch\": \"vitest\",\n \"test:coverage\": \"vitest run --coverage --passWithNoTests\",\n \"test:codex-live\": \"node ./scripts/codex-live/run.mjs\",\n \"bench\": \"vitest bench --run\",\n \"bench:runtime\": \"node scripts/benchmark-runtime.mjs\",\n \"test:runtime-channels\": \"node scripts/runtime-channel-smoke.mjs\",\n \"test:docs\": \"node --test tests/docs/install-channels.contract.mjs\",\n \"lint\": \"biome check .\",\n \"lint:fix\": \"biome check --write .\",\n \"format\": \"biome format --write .\",\n \"build:binary\": \"bun scripts/build-binary.mjs\"\n },\n \"dependencies\": {\n \"@anthropic-ai/claude-agent-sdk\": \"0.3.142\",\n \"@clack/prompts\": \"^0.10.1\",\n \"@sinclair/typebox\": \"^0.34.49\",\n \"ajv\": \"^8.20.0\",\n \"ajv-errors\": \"^3.0.0\",\n \"ajv-formats\": \"^3.0.1\",\n \"commander\": \"^13.0.0\",\n \"diff\": \"^9.0.0\",\n \"expr-eval\": \"^2.0.2\",\n \"picocolors\": \"^1.1.1\",\n \"proper-lockfile\": \"^4.1.2\",\n \"smol-toml\": \"^1.9.1\",\n \"undici\": \"^8.12.1\",\n \"yaml\": \"^2.9.0\"\n },\n \"devDependencies\": {\n \"@biomejs/biome\": \"^2.0.0\",\n \"@types/node\": \"^22.10.0\",\n \"@types/proper-lockfile\": \"^4.1.4\",\n \"@vitest/coverage-v8\": \"^4.0.0\",\n \"esbuild\": \"0.27.7\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.0\",\n \"vitest\": \"^4.0.0\"\n },\n \"pnpm\": {\n \"onlyBuiltDependencies\": [\n \"esbuild\"\n ]\n }\n}\n","// Main library entry — re-exports public APIs.\n// phase 1.1 batch 1: skeleton only; schema validator wired in batch 2 (T3+).\n\nimport pkg from '../package.json' with { type: 'json' }\n\nexport const VERSION = pkg.version\n"]}
|
package/manifests/SCHEMA.md
CHANGED
|
@@ -60,7 +60,7 @@ spec: {...} # 见 § 3
|
|
|
60
60
|
| `platforms` | ✅ | enum[] | 至少 1 个:`linux` / `darwin` / `win32`,去重 |
|
|
61
61
|
| `harness_overrides.codex.install` | optional | object | v4.14.0 — codex 平台整块替换 install(复用 § 4 install 判别 union;runInstall dispatch 前按 detectPlatform().id 合并) |
|
|
62
62
|
| `harness_overrides.codex.uninstall` | optional | object | Phase 69 Task 3:复用主 `uninstall` shape,`cmd` 为非空必填 string,`cleanup_paths` 为可选 string[],禁止额外字段。uninstall plan 整块选择该声明,但 selection 不证明 ownership,也不自动授权执行 |
|
|
63
|
-
| `harness_overrides.codex.verify` | optional | object | v4.14.0 — codex 平台替换 verify(缺省沿用主 verify);无 override 的 `cc-plugin-marketplace` 在非 claude 平台 → `harness-mismatch` 诚实跳过。v16.0 Phase 64(ADR 0041)起 `cc-hook-add` 在 codex 上不再需要 override:first-party hook(`inject-state` / `check-docs`)生成本地 codex 插件 `harnessed-<name>@harnessed-local` 安装;无 codex port 的 hook(`stop-hook`
|
|
63
|
+
| `harness_overrides.codex.verify` | optional | object | v4.14.0 — codex 平台替换 verify(缺省沿用主 verify);无 override 的 `cc-plugin-marketplace` 在非 claude 平台 → `harness-mismatch` 诚实跳过。v16.0 Phase 64(ADR 0041)起 `cc-hook-add` 在 codex 上不再需要 override:first-party hook(`inject-state` / `check-docs`)生成本地 codex 插件 `harnessed-<name>@harnessed-local` 安装;无 codex port 的 hook 仍 `harness-mismatch`(`stop-hook` 组件已退役,不再有随包 manifest;`hook_event` 的 `Stop` 枚举值保留,供第三方 manifest 使用) |
|
|
64
64
|
|
|
65
65
|
---
|
|
66
66
|
|
|
@@ -47,6 +47,12 @@ spec:
|
|
|
47
47
|
method: npx-skill-installer
|
|
48
48
|
cmd: "npx --yes skills@latest add OthmanAdi/planning-with-files --copy -y"
|
|
49
49
|
npm_version: ^1.5.7
|
|
50
|
+
# The skill target is exactly `planning-with-files` (one repo segment ==
|
|
51
|
+
# one skill dir). Declaring it makes the target set provable, so the
|
|
52
|
+
# ownership guard stops refusing the install and the component reports
|
|
53
|
+
# already-installed instead of failing the whole setup.
|
|
54
|
+
installs_skills:
|
|
55
|
+
- planning-with-files
|
|
50
56
|
idempotent_check: "test -d ~/.agents/skills/planning-with-files || test -d ~/.claude/skills/planning-with-files"
|
|
51
57
|
verify:
|
|
52
58
|
# A Claude skill cannot supply Codex helpers. verifySkillRuntime additionally
|
|
@@ -18,9 +18,13 @@ spec:
|
|
|
18
18
|
install_type: npm
|
|
19
19
|
install:
|
|
20
20
|
method: npm-cli
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
# The version is a RANGE, not an exact pin: the CLI is verified by capability
|
|
22
|
+
# (see spec.verify), and an exact pin turned every host that already had a
|
|
23
|
+
# newer 0.1.x patch into a red component. The range is quoted so cmd.exe does
|
|
24
|
+
# not eat the caret as an escape character.
|
|
25
|
+
cmd: "npm install -g \"@playwright/cli@^0.1.22\" && playwright-cli install-browser chromium"
|
|
26
|
+
npm_version: ^0.1.22
|
|
27
|
+
idempotent_check: 'playwright-cli --version | grep -E "^0\.1\.(2[2-9]|[3-9][0-9]|[0-9]{3,})$"'
|
|
24
28
|
verify:
|
|
25
29
|
# npm-cli runs this in neutralCwd, outside the user's project.
|
|
26
30
|
# Read-only metadata verification; never start a browser or daemon here.
|
|
@@ -37,7 +41,9 @@ spec:
|
|
|
37
41
|
if (/^### Error/m.test(result.stdout)) throw new Error("Playwright CLI reported an error");
|
|
38
42
|
return result.stdout;
|
|
39
43
|
}
|
|
40
|
-
|
|
44
|
+
const version = run(["--version"]).trim();
|
|
45
|
+
const release = /^0\.1\.(\d+)$/.exec(version);
|
|
46
|
+
if (!release || Number(release[1]) < 22) throw new Error("Expected playwright-cli 0.1.22 or a newer 0.1.x, got " + version);
|
|
41
47
|
const dryRun = run(["install-browser", "chromium", "--dry-run"]);
|
|
42
48
|
if (!/\(playwright chromium v\d+\)/.test(dryRun) || !/^\s*Install location:\s*\S.*$/m.test(dryRun)) throw new Error("Chromium installation metadata is missing");
|
|
43
49
|
const listed = run(["install-browser", "chromium", "--list"]);
|
|
@@ -61,14 +67,14 @@ spec:
|
|
|
61
67
|
expected_exit_code: 0
|
|
62
68
|
uninstall:
|
|
63
69
|
cmd: "npm uninstall -g @playwright/cli"
|
|
64
|
-
# Playwright CLI 0.1.
|
|
70
|
+
# Playwright CLI 0.1.x has no uninstall-browser command. Its ms-playwright
|
|
65
71
|
# cache is shared by every Playwright installation on the host, so harnessed
|
|
66
72
|
# deliberately leaves browser binaries in place rather than deleting data it
|
|
67
73
|
# cannot safely attribute to this component.
|
|
68
74
|
upstream_health:
|
|
69
75
|
stability: unstable
|
|
70
|
-
last_check: "2026-
|
|
71
|
-
last_known_good_version: "0.1.
|
|
76
|
+
last_check: "2026-11-02"
|
|
77
|
+
last_known_good_version: "0.1.23"
|
|
72
78
|
fallback_action: warn
|
|
73
79
|
signed_by: easyinplay
|
|
74
80
|
platforms:
|
package/package.json
CHANGED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// biome-ignore-all format: esbuild-generated (hook drift gate owns this file)
|
|
3
|
-
// biome-ignore-all lint: esbuild-generated
|
|
4
|
-
// biome-ignore-all assist/source/organizeImports: esbuild-generated
|
|
5
|
-
|
|
6
|
-
// src/checkpoint/stopHookMain.ts
|
|
7
|
-
import { createHash } from "node:crypto";
|
|
8
|
-
import {
|
|
9
|
-
existsSync as existsSync2,
|
|
10
|
-
mkdirSync,
|
|
11
|
-
readFileSync as readFileSync2,
|
|
12
|
-
writeFileSync,
|
|
13
|
-
} from 'node:fs'
|
|
14
|
-
import { join as join2 } from 'node:path'
|
|
15
|
-
|
|
16
|
-
// src/platform/ablation.ts
|
|
17
|
-
function isAblated(env = process.env) {
|
|
18
|
-
return env.HARNESSED_OFF === '1'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/platform/platform.ts
|
|
22
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
23
|
-
import { homedir } from 'node:os'
|
|
24
|
-
import { join } from 'node:path'
|
|
25
|
-
function claudeDescriptor(home = homedir()) {
|
|
26
|
-
const claudeHome = join(home, '.claude')
|
|
27
|
-
return {
|
|
28
|
-
id: 'claude',
|
|
29
|
-
homeDir: claudeHome,
|
|
30
|
-
stateRoot: join(claudeHome, 'harnessed'),
|
|
31
|
-
settingsPath: join(claudeHome, 'settings.json'),
|
|
32
|
-
skillsDir: join(claudeHome, 'skills'),
|
|
33
|
-
commandsDir: join(claudeHome, 'commands'),
|
|
34
|
-
pluginsRegistry: join(claudeHome, 'plugins', 'installed_plugins.json'),
|
|
35
|
-
// mcpConfigPath is a SIBLING of `.claude` (`<home>/.claude.json`), based on
|
|
36
|
-
// the same home base — not a child of homeDir.
|
|
37
|
-
mcpConfigPath: join(home, '.claude.json'),
|
|
38
|
-
// claude writes its env keys into JSON settings.json (capability present).
|
|
39
|
-
supportsEnvKeyWrite: true,
|
|
40
|
-
// Claude Code exposes the active session id to Bash-invoked CLI + hooks.
|
|
41
|
-
sessionIdEnv: 'CLAUDE_CODE_SESSION_ID',
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function codexDescriptor(home = homedir()) {
|
|
45
|
-
const codexHome = join(home, '.codex')
|
|
46
|
-
const configToml = join(codexHome, 'config.toml')
|
|
47
|
-
return {
|
|
48
|
-
id: 'codex',
|
|
49
|
-
homeDir: codexHome,
|
|
50
|
-
stateRoot: join(codexHome, 'harnessed'),
|
|
51
|
-
settingsPath: null,
|
|
52
|
-
// SHARED convention dir, NOT <homeDir>/skills.
|
|
53
|
-
skillsDir: join(home, '.agents', 'skills'),
|
|
54
|
-
commandsDir: join(codexHome, 'prompts'),
|
|
55
|
-
pluginsRegistry: null,
|
|
56
|
-
mcpConfigPath: configToml,
|
|
57
|
-
supportsEnvKeyWrite: false,
|
|
58
|
-
// Measured on codex-cli 0.154: codex shells carry it, equal to hook session_id.
|
|
59
|
-
sessionIdEnv: 'CODEX_SESSION_ID',
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
var HOST_IDS = ['claude', 'codex']
|
|
63
|
-
function isHostId(id) {
|
|
64
|
-
return HOST_IDS.includes(id)
|
|
65
|
-
}
|
|
66
|
-
function descriptorFor(id, home = homedir()) {
|
|
67
|
-
return id === 'codex' ? codexDescriptor(home) : claudeDescriptor(home)
|
|
68
|
-
}
|
|
69
|
-
function configuredHome(envVar) {
|
|
70
|
-
const value = process.env[envVar]?.trim()
|
|
71
|
-
return value || void 0
|
|
72
|
-
}
|
|
73
|
-
function descriptorForConfiguredHome(id, home = homedir()) {
|
|
74
|
-
const descriptor = descriptorFor(id, home)
|
|
75
|
-
const nativeHome = configuredHome(id === 'codex' ? 'CODEX_HOME' : 'CLAUDE_CONFIG_DIR')
|
|
76
|
-
if (nativeHome === void 0) return descriptor
|
|
77
|
-
if (id === 'codex') {
|
|
78
|
-
return {
|
|
79
|
-
...descriptor,
|
|
80
|
-
homeDir: nativeHome,
|
|
81
|
-
stateRoot: join(nativeHome, 'harnessed'),
|
|
82
|
-
commandsDir: join(nativeHome, 'prompts'),
|
|
83
|
-
mcpConfigPath: join(nativeHome, 'config.toml'),
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
...descriptor,
|
|
88
|
-
homeDir: nativeHome,
|
|
89
|
-
stateRoot: join(nativeHome, 'harnessed'),
|
|
90
|
-
settingsPath: join(nativeHome, 'settings.json'),
|
|
91
|
-
skillsDir: join(nativeHome, 'skills'),
|
|
92
|
-
commandsDir: join(nativeHome, 'commands'),
|
|
93
|
-
pluginsRegistry: join(nativeHome, 'plugins', 'installed_plugins.json'),
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function detectPlatform(home = homedir()) {
|
|
97
|
-
const resolved = resolveHost(home)
|
|
98
|
-
const override = process.env.HARNESSED_ROOT_OVERRIDE
|
|
99
|
-
if (override !== void 0 && override !== '') return { ...resolved, stateRoot: override }
|
|
100
|
-
return resolved
|
|
101
|
-
}
|
|
102
|
-
function resolveHost(home) {
|
|
103
|
-
return resolveHostWithReason(home).descriptor
|
|
104
|
-
}
|
|
105
|
-
function resolveHostWithReason(home = homedir()) {
|
|
106
|
-
const claudeHome = configuredHome('CLAUDE_CONFIG_DIR')
|
|
107
|
-
const codexHome = configuredHome('CODEX_HOME')
|
|
108
|
-
const envPlatform = process.env.HARNESSED_PLATFORM?.trim()
|
|
109
|
-
const explicitHost = envPlatform !== void 0 && isHostId(envPlatform) ? envPlatform : void 0
|
|
110
|
-
if (explicitHost === void 0 && claudeHome !== void 0 && codexHome !== void 0) {
|
|
111
|
-
throw new Error('both CLAUDE_CONFIG_DIR and CODEX_HOME are set; pass --platform claude|codex')
|
|
112
|
-
}
|
|
113
|
-
const base = descriptorForConfiguredHome('claude', home)
|
|
114
|
-
const codex = descriptorForConfiguredHome('codex', home)
|
|
115
|
-
const skipped = []
|
|
116
|
-
if (envPlatform !== void 0 && envPlatform !== '') {
|
|
117
|
-
const d = isHostId(envPlatform) ? descriptorForConfiguredHome(envPlatform, home) : void 0
|
|
118
|
-
if (d) {
|
|
119
|
-
return {
|
|
120
|
-
descriptor: d,
|
|
121
|
-
reason: { kind: 'env-platform', envVar: 'HARNESSED_PLATFORM', value: envPlatform },
|
|
122
|
-
skipped,
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
skipped.push({ kind: 'env-platform-unknown', envVar: 'HARNESSED_PLATFORM', value: envPlatform })
|
|
126
|
-
}
|
|
127
|
-
if (claudeHome !== void 0 || codexHome !== void 0) {
|
|
128
|
-
const id = claudeHome !== void 0 ? 'claude' : 'codex'
|
|
129
|
-
return {
|
|
130
|
-
descriptor: id === 'claude' ? base : codex,
|
|
131
|
-
reason: {
|
|
132
|
-
kind: 'env-platform',
|
|
133
|
-
envVar: id === 'claude' ? 'CLAUDE_CONFIG_DIR' : 'CODEX_HOME',
|
|
134
|
-
value: id === 'claude' ? claudeHome : codexHome,
|
|
135
|
-
},
|
|
136
|
-
skipped,
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const inClaude = Boolean(process.env.CLAUDE_CODE_SESSION_ID?.trim())
|
|
140
|
-
const inCodex = Boolean(process.env.CODEX_SESSION_ID?.trim())
|
|
141
|
-
if (inClaude !== inCodex) {
|
|
142
|
-
return {
|
|
143
|
-
descriptor: inClaude ? base : codex,
|
|
144
|
-
reason: {
|
|
145
|
-
kind: 'host-session-env',
|
|
146
|
-
envVar: inClaude ? 'CLAUDE_CODE_SESSION_ID' : 'CODEX_SESSION_ID',
|
|
147
|
-
},
|
|
148
|
-
skipped,
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (inClaude && inCodex) skipped.push({ kind: 'host-session-env-ambiguous' })
|
|
152
|
-
for (const pinRoot of [codex.stateRoot, base.stateRoot]) {
|
|
153
|
-
const pinPath = join(pinRoot, '.platform')
|
|
154
|
-
try {
|
|
155
|
-
const value = readFileSync(pinPath, 'utf8').trim()
|
|
156
|
-
const d = isHostId(value) ? descriptorForConfiguredHome(value, home) : void 0
|
|
157
|
-
if (d) return { descriptor: d, reason: { kind: 'platform-pin', pinPath, value }, skipped }
|
|
158
|
-
skipped.push({ kind: 'platform-pin-unknown', pinPath, value })
|
|
159
|
-
} catch {}
|
|
160
|
-
}
|
|
161
|
-
try {
|
|
162
|
-
if (existsSync(base.homeDir)) {
|
|
163
|
-
return {
|
|
164
|
-
descriptor: base,
|
|
165
|
-
reason: { kind: 'directory-probe', probedDir: base.homeDir },
|
|
166
|
-
skipped,
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (existsSync(codex.homeDir)) {
|
|
170
|
-
return {
|
|
171
|
-
descriptor: codex,
|
|
172
|
-
reason: { kind: 'directory-probe', probedDir: codex.homeDir },
|
|
173
|
-
skipped,
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
} catch {}
|
|
177
|
-
return { descriptor: base, reason: { kind: 'fallback' }, skipped }
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// src/checkpoint/modeBDetect.ts
|
|
181
|
-
var TAIL_WINDOW = 200
|
|
182
|
-
var INVOKE_RE = /<invoke name="/g
|
|
183
|
-
var PARAM_RE = /<parameter name="/g
|
|
184
|
-
function stripCode(s) {
|
|
185
|
-
return s.replace(/```[\s\S]*?```/g, '').replace(/`[^`]*`/g, '')
|
|
186
|
-
}
|
|
187
|
-
function lastIndexOfRe(s, re) {
|
|
188
|
-
let last = -1
|
|
189
|
-
re.lastIndex = 0
|
|
190
|
-
for (let m = re.exec(s); m !== null; m = re.exec(s)) last = m.index
|
|
191
|
-
return last
|
|
192
|
-
}
|
|
193
|
-
function detectModeB(content) {
|
|
194
|
-
if (!Array.isArray(content) || content.length === 0) return false
|
|
195
|
-
if (content.some((b) => b && b.type === 'tool_use')) return false
|
|
196
|
-
const text = content
|
|
197
|
-
.filter((b) => b && b.type === 'text' && typeof b.text === 'string')
|
|
198
|
-
.map((b) => b.text)
|
|
199
|
-
.join('\n')
|
|
200
|
-
if (text.length === 0) return false
|
|
201
|
-
const stripped = stripCode(text)
|
|
202
|
-
if (stripped.length === 0) return false
|
|
203
|
-
const invokeAt = lastIndexOfRe(stripped, INVOKE_RE)
|
|
204
|
-
const paramAt = lastIndexOfRe(stripped, PARAM_RE)
|
|
205
|
-
if (invokeAt < 0 || paramAt < 0) return false
|
|
206
|
-
const lastTag = Math.max(invokeAt, paramAt)
|
|
207
|
-
return stripped.length - lastTag <= TAIL_WINDOW
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// src/checkpoint/stopHookMain.ts
|
|
211
|
-
var MAX_RETRIES = 2
|
|
212
|
-
function stateRoot() {
|
|
213
|
-
return detectPlatform().stateRoot
|
|
214
|
-
}
|
|
215
|
-
function messageSig(content) {
|
|
216
|
-
const text = content
|
|
217
|
-
.filter((b) => b && b.type === 'text' && typeof b.text === 'string')
|
|
218
|
-
.map((b) => b.text)
|
|
219
|
-
.join('\n')
|
|
220
|
-
return createHash('sha256').update(text).digest('hex').slice(0, 16)
|
|
221
|
-
}
|
|
222
|
-
function lastAssistantContent(transcriptPath) {
|
|
223
|
-
try {
|
|
224
|
-
if (!transcriptPath || !existsSync2(transcriptPath)) return null
|
|
225
|
-
const buf = readFileSync2(transcriptPath)
|
|
226
|
-
const slice = buf.length > 262144 ? buf.subarray(buf.length - 262144) : buf
|
|
227
|
-
const lines = slice.toString('utf8').split('\n')
|
|
228
|
-
for (let i = lines.length - 1; i >= 0; i--) {
|
|
229
|
-
const line = (lines[i] ?? '').trim()
|
|
230
|
-
if (!line) continue
|
|
231
|
-
let obj
|
|
232
|
-
try {
|
|
233
|
-
obj = JSON.parse(line)
|
|
234
|
-
} catch {
|
|
235
|
-
continue
|
|
236
|
-
}
|
|
237
|
-
if (obj && obj.type === 'assistant') {
|
|
238
|
-
const content = obj.message?.content ?? obj.content
|
|
239
|
-
return Array.isArray(content) ? content : null
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
} catch {}
|
|
243
|
-
return null
|
|
244
|
-
}
|
|
245
|
-
function retryStore(sessionId) {
|
|
246
|
-
const id = createHash('sha256')
|
|
247
|
-
.update(String(sessionId ?? 'nosession'))
|
|
248
|
-
.digest('hex')
|
|
249
|
-
.slice(0, 16)
|
|
250
|
-
return join2(stateRoot(), 'stop-hook-retries', `${id}.json`)
|
|
251
|
-
}
|
|
252
|
-
function readRetry(path) {
|
|
253
|
-
try {
|
|
254
|
-
if (!existsSync2(path)) return { sig: '', count: 0 }
|
|
255
|
-
const j = JSON.parse(readFileSync2(path, 'utf8'))
|
|
256
|
-
return { sig: typeof j.sig === 'string' ? j.sig : '', count: Number(j.count) || 0 }
|
|
257
|
-
} catch {
|
|
258
|
-
return { sig: '', count: 0 }
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function writeRetry(path, sig, count) {
|
|
262
|
-
try {
|
|
263
|
-
mkdirSync(join2(path, '..'), { recursive: true })
|
|
264
|
-
writeFileSync(path, JSON.stringify({ sig, count }), 'utf8')
|
|
265
|
-
return true
|
|
266
|
-
} catch {
|
|
267
|
-
return false
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function readStdin() {
|
|
271
|
-
return new Promise((resolve) => {
|
|
272
|
-
let data = ''
|
|
273
|
-
if (process.stdin.isTTY) return resolve('')
|
|
274
|
-
process.stdin.setEncoding('utf8')
|
|
275
|
-
process.stdin.on('data', (c) => {
|
|
276
|
-
data += c
|
|
277
|
-
})
|
|
278
|
-
process.stdin.on('end', () => resolve(data))
|
|
279
|
-
process.stdin.on('error', () => resolve(data))
|
|
280
|
-
setTimeout(() => resolve(data), 2e3).unref?.()
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
async function main() {
|
|
284
|
-
if (isAblated()) return
|
|
285
|
-
const raw = await readStdin()
|
|
286
|
-
let payload
|
|
287
|
-
try {
|
|
288
|
-
payload = JSON.parse(raw)
|
|
289
|
-
} catch {
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
if (payload.stop_hook_active === true) return
|
|
293
|
-
const content = lastAssistantContent(payload.transcript_path)
|
|
294
|
-
if (!content || !detectModeB(content)) return
|
|
295
|
-
const sig = messageSig(content)
|
|
296
|
-
const store = retryStore(payload.session_id)
|
|
297
|
-
const prev = readRetry(store)
|
|
298
|
-
const count = prev.sig === sig ? prev.count : 0
|
|
299
|
-
if (count >= MAX_RETRIES) return
|
|
300
|
-
const saved = writeRetry(store, sig, count + 1)
|
|
301
|
-
if (!saved) return
|
|
302
|
-
process.stdout.write(
|
|
303
|
-
`${JSON.stringify({
|
|
304
|
-
decision: 'block',
|
|
305
|
-
reason:
|
|
306
|
-
'MODE-B tool corruption detected: your previous message emitted a tool call as plain text (the opening delimiter was mis-sampled to a garbage word). Re-emit that exact same tool call now as a real tool call \u2014 content unchanged.',
|
|
307
|
-
})}
|
|
308
|
-
`,
|
|
309
|
-
)
|
|
310
|
-
}
|
|
311
|
-
main().catch(() => {})
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# yaml-language-server: $schema=../../schemas/manifest.v1.schema.json
|
|
2
|
-
# 4.30.0 (issue #6) — opt-in Stop hook auto-recovering silent "mode-B" tool-call
|
|
3
|
-
# corruption. Claude Code occasionally mis-samples the tool-open delimiter into a
|
|
4
|
-
# garbage word so the whole <invoke>…</invoke> block is emitted as PLAIN TEXT: no
|
|
5
|
-
# tool runs, no error, the turn just ends and the model gets no failure signal —
|
|
6
|
-
# today the only recovery is the user manually typing "retry". This Stop hook runs
|
|
7
|
-
# bin/harnessed-stop-hook.mjs at every turn end; on detecting the mode-B signature
|
|
8
|
-
# (tool-call tags in the assistant message's TEXT content, tail-anchored, no
|
|
9
|
-
# structured tool_use this turn) it returns {"decision":"block", reason} to hand
|
|
10
|
-
# the model one fresh turn to re-emit the call — no user prompt needed. Loop guard:
|
|
11
|
-
# stop_hook_active + a per-(session, message-signature) retry cap of 2. Fail-soft:
|
|
12
|
-
# any error or non-match exits 0 silently (a Stop hook must never wedge turn end).
|
|
13
|
-
# Opt-in (manifests/optional/) because it is a defensive net most useful on long/
|
|
14
|
-
# large-context sessions where the corruption rate climbs. Idempotent.
|
|
15
|
-
apiVersion: harnessed/v1
|
|
16
|
-
kind: Manifest
|
|
17
|
-
metadata:
|
|
18
|
-
name: stop-hook-recover
|
|
19
|
-
display_name: Tool-Call Auto-Recovery (Stop hook)
|
|
20
|
-
description: Opt-in Stop hook that auto-retries silently corrupted tool calls (emitted as plain text; issue #6) so the user stops typing "retry".
|
|
21
|
-
upstream:
|
|
22
|
-
source: stop-hook-recover
|
|
23
|
-
homepage: https://github.com/easyinplay/harnessed
|
|
24
|
-
repository: https://github.com/easyinplay/harnessed.git
|
|
25
|
-
license: MIT
|
|
26
|
-
notice: First-party harnessed hook (4.30.0, issue #6).
|
|
27
|
-
spec:
|
|
28
|
-
type: cc-hook
|
|
29
|
-
component_type: command
|
|
30
|
-
category: meta
|
|
31
|
-
install_type: hook
|
|
32
|
-
install:
|
|
33
|
-
method: cc-hook-add
|
|
34
|
-
cmd: "node bin/harnessed-stop-hook.mjs"
|
|
35
|
-
hook_event: Stop
|
|
36
|
-
hook_command: "node bin/harnessed-stop-hook.mjs"
|
|
37
|
-
idempotent_check: "grep -q harnessed-stop-hook ~/.claude/settings.json"
|
|
38
|
-
verify:
|
|
39
|
-
cmd: "grep -q harnessed-stop-hook ~/.claude/settings.json"
|
|
40
|
-
timeout_ms: 5000
|
|
41
|
-
expected_exit_code: 0
|
|
42
|
-
uninstall:
|
|
43
|
-
cmd: "true"
|
|
44
|
-
upstream_health:
|
|
45
|
-
stability: beta
|
|
46
|
-
last_check: "2026-07-13"
|
|
47
|
-
last_known_good_version: "0.1.0"
|
|
48
|
-
fallback_action: warn
|
|
49
|
-
signed_by: easyinplay
|
|
50
|
-
platforms:
|
|
51
|
-
- linux
|
|
52
|
-
- darwin
|
|
53
|
-
- win32
|