harnessed 4.49.0 → 4.49.2
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/bin/harnessed-check-docs.mjs +456 -0
- package/dist/cli.mjs +955 -262
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/manifests/skill-packs/gsd.yaml +39 -5
- package/manifests/skill-packs/gstack.yaml +9 -7
- package/manifests/skill-packs/planning-with-files.yaml +9 -1
- package/manifests/skill-packs/ui-ux-pro-max.yaml +15 -1
- package/manifests/tools/playwright-cli.yaml +66 -0
- package/manifests/tools/playwright-test.yaml +7 -5
- package/manifests/tools/webapp-testing.yaml +86 -0
- package/messages/en.json +2 -0
- package/messages/zh-Hans.json +2 -0
- package/package.json +1 -1
- package/workflows/capabilities.yaml +23 -5
- package/workflows/host-primitives.yaml +10 -1
- package/workflows/host-primitives.zh-Hans.yaml +10 -1
- package/workflows/role-prompts.yaml +3 -3
- package/workflows/role-prompts.zh-Hans.yaml +3 -3
|
@@ -0,0 +1,456 @@
|
|
|
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/cli/checkDocs.ts
|
|
7
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
8
|
+
import { join as join2 } from 'node:path'
|
|
9
|
+
|
|
10
|
+
// src/i18n/index.ts
|
|
11
|
+
import { readFileSync } from 'node:fs'
|
|
12
|
+
import { dirname, join, resolve } from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
|
|
15
|
+
// messages/en.json
|
|
16
|
+
var en_default = {
|
|
17
|
+
'setup.workflows_not_found': 'error: workflows directory not found at {{path}}',
|
|
18
|
+
'setup.nothing_to_install':
|
|
19
|
+
'setup: no workflow directories with SKILL.md found \u2014 nothing to install',
|
|
20
|
+
'setup.dry_run.header': '[dry-run] setup would install {{count}} workflow(s) to {{path}}:',
|
|
21
|
+
'setup.dry_run.run_hint': ' run without --dry-run to execute',
|
|
22
|
+
'setup.copy_failed': ' error: failed to copy {{name}}: {{message}}',
|
|
23
|
+
'setup.step_a_complete': 'Step A: {{count}} workflows installed to {{path}}',
|
|
24
|
+
'setup.step_a_render.complete': ' generated {{count}}/{{total}} command files',
|
|
25
|
+
'setup.step_a_render.warnings_header':
|
|
26
|
+
' [A.5] warnings \u2014 some capability cmds could not be fully resolved:',
|
|
27
|
+
'setup.step_c.created': ' [C] created {{path}} + enabled Agent Teams',
|
|
28
|
+
'setup.step_c.already_enabled': ' [C] Agent Teams already enabled ({{path}})',
|
|
29
|
+
'setup.step_c.enabled_backup':
|
|
30
|
+
' [C] enabled Agent Teams in {{path}} (backup saved \u2192 {{backupPath}})',
|
|
31
|
+
'setup.step_c.skipped': ' [C] Agent Teams enable skipped: {{message}}',
|
|
32
|
+
'setup.step_d.created': ' [D] created {{path}} + wrote env.HARNESSED_USER_LANG={{lang}}',
|
|
33
|
+
'setup.step_d.already_set':
|
|
34
|
+
' [D] env.HARNESSED_USER_LANG={{lang}} already set in {{path}} \u2014 respecting user override',
|
|
35
|
+
'setup.step_d.enabled_backup':
|
|
36
|
+
' [D] wrote env.HARNESSED_USER_LANG={{lang}} in {{path}} (backup saved \u2192 {{backupPath}})',
|
|
37
|
+
'setup.step_d.skipped': ' [D] User language write skipped: {{message}}',
|
|
38
|
+
'setup.step_b_complete':
|
|
39
|
+
'Upstream components: {{installed}} installed / {{already}} already-installed / {{skipped}} skipped / {{failed}} failed [{{seconds}}s]',
|
|
40
|
+
'setup.complete':
|
|
41
|
+
'setup complete \u2014 {{skills}} workflows + {{manifests}} base manifests configured',
|
|
42
|
+
'setup.mcp_hint': 'Run /mcp in Claude Code to verify MCP server connections.',
|
|
43
|
+
'setup.mcp_hint_codex': 'Run codex mcp list to verify MCP server connections.',
|
|
44
|
+
'setup.search_key_hint.header':
|
|
45
|
+
'\n\u26A0 Search MCP API keys missing \u2014 the server(s) below are installed but will fail at query time until the key is configured:',
|
|
46
|
+
'setup.search_key_hint.header_codex':
|
|
47
|
+
'\n\u26A0 Search MCP API keys not visible to this check: Codex checks only process env. Verify the tools first; if authentication fails, set the key in your shell environment.',
|
|
48
|
+
'setup.search_key_hint.line':
|
|
49
|
+
' {{server}}: set {{envVar}} \u2014 add it to the ~/.claude/settings.json "env" block (e.g. {"env": {"{{envVar}}": "<your-key>"}}) or export {{envVar}} in your shell',
|
|
50
|
+
'setup.search_key_hint.line_codex':
|
|
51
|
+
' {{server}}: set {{envVar}} in your shell environment (export {{envVar}}="<your-key>")',
|
|
52
|
+
'setup.optional_offer.ecc_note':
|
|
53
|
+
" ecc (bonus tier): installing it unlocks finer-grained scenario orchestration (per-language review/build expert routing etc.); the trade-off is ~20k+ tokens/session of static listing overhead \u2014 inherent to ECC's own scale (281 skills / 94 commands / 67 agents), not introduced by harnessed.",
|
|
54
|
+
'setup.bundled_summary':
|
|
55
|
+
'\nharnessed workflows bundled at <packageRoot>/workflows/ (share-only, read-only)',
|
|
56
|
+
'setup.bundled_location': '',
|
|
57
|
+
'setup.doctor_hint': '\nRun harnessed doctor to verify your environment.',
|
|
58
|
+
'agent_teams.missing_header':
|
|
59
|
+
'\n\u26A0\uFE0F Agent Teams not enabled \u2014 parallelism upgrade path unavailable',
|
|
60
|
+
'agent_teams.missing_fix': ' fix: claude config set env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS 1',
|
|
61
|
+
'agent_teams.missing_explanation':
|
|
62
|
+
' harnessed task parallelism uses Subagent or Agent Teams (CC 2.1.178+)',
|
|
63
|
+
'agent_teams.missing_nonblocking': ' non-blocking \u2014 auto-degrades to subagent fan-out\n',
|
|
64
|
+
'install.manifest_not_found': "error: manifest '{{name}}' not found",
|
|
65
|
+
'install.manifest_not_found.fix':
|
|
66
|
+
' fix: ensure manifests/tools/{{name}}.yaml, manifests/skill-packs/{{name}}.yaml, or manifests/optional/{{name}}.yaml exists',
|
|
67
|
+
'install.audit_hint': " fix: run 'harnessed audit' to inspect manifest issues",
|
|
68
|
+
'install.success': 'installed {{name}}',
|
|
69
|
+
'install.success_with_version': 'installed {{name}}@{{version}}',
|
|
70
|
+
'install.already_installed': 'already-installed {{name}} (idempotent check hit; nothing to do)',
|
|
71
|
+
'install.already_installed_with_version':
|
|
72
|
+
'already-installed {{name}}@{{version}} (idempotent check hit; nothing to do)',
|
|
73
|
+
'install.aborted': 'aborted: {{reason}}',
|
|
74
|
+
'uninstall.dry_run.preview': "[dry-run] would uninstall '{{name}}' via method '{{method}}'",
|
|
75
|
+
'uninstall.dry_run.run_hint': ' run without --dry-run to execute',
|
|
76
|
+
'uninstall.confirm.prompt': "Uninstall '{{name}}'? This cannot be undone.",
|
|
77
|
+
'uninstall.cancelled': 'aborted: user cancelled',
|
|
78
|
+
'uninstall.completed': 'uninstalled {{name}}',
|
|
79
|
+
'uninstall.unified.nothing': 'nothing to do \u2014 no harnessed artifacts found',
|
|
80
|
+
'uninstall.unified.header': 'harnessed uninstall will remove the following:',
|
|
81
|
+
'uninstall.unified.commands':
|
|
82
|
+
' Commands: {{count}} harnessed-generated slash command file(s) in ~/.claude/commands/',
|
|
83
|
+
'uninstall.unified.agent_roles':
|
|
84
|
+
' Agent roles: {{count}} harnessed-generated codex agent role file(s) in ~/.codex/agents/',
|
|
85
|
+
'uninstall.unified.skills':
|
|
86
|
+
' Skills: {{count}} workflow skill directory(ies) in ~/.claude/skills/',
|
|
87
|
+
'uninstall.unified.settings':
|
|
88
|
+
' Settings: harnessed env vars (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS, HARNESSED_USER_LANG) from ~/.claude/settings.json',
|
|
89
|
+
'uninstall.unified.hooks':
|
|
90
|
+
' Hooks: {{count}} harnessed Stop/UserPromptSubmit hook(s) in ~/.claude/settings.json',
|
|
91
|
+
'uninstall.unified.state_dir':
|
|
92
|
+
' State directory: ~/.claude/harnessed/ (includes backups, audit log, state, lock)',
|
|
93
|
+
'uninstall.unified.upstream_note':
|
|
94
|
+
'\nUpstream components (npm packages, MCP servers, CC plugins, git-cloned repos, npx skills) are NOT affected.',
|
|
95
|
+
'uninstall.unified.dry_run_hint':
|
|
96
|
+
'\n(dry-run \u2014 re-run without --dry-run to actually remove)',
|
|
97
|
+
'uninstall.unified.confirm':
|
|
98
|
+
"Remove harnessed's own files? Upstream components (npm packages, MCP servers, CC plugins, etc.) will NOT be affected. This cannot be undone.",
|
|
99
|
+
'uninstall.unified.removing': 'removing harnessed files...',
|
|
100
|
+
'uninstall.unified.removed_commands': ' removed {{count}} command file(s)',
|
|
101
|
+
'uninstall.unified.removed_agent_roles': ' removed {{count}} codex agent role file(s)',
|
|
102
|
+
'uninstall.unified.removed_skills': ' removed {{count}} skill directory(ies)',
|
|
103
|
+
'uninstall.unified.removed_settings': ' removed harnessed env vars from ~/.claude/settings.json',
|
|
104
|
+
'uninstall.unified.removed_hooks':
|
|
105
|
+
' removed {{count}} harnessed hook(s) from ~/.claude/settings.json',
|
|
106
|
+
'uninstall.unified.removed_state_dir': ' removed ~/.claude/harnessed/',
|
|
107
|
+
'uninstall.unified.partial_failure':
|
|
108
|
+
'\n{{count}} item(s) could not be removed (permission denied or already gone):',
|
|
109
|
+
'uninstall.unified.complete': "uninstall complete \u2014 harnessed's own files have been removed",
|
|
110
|
+
'uninstall.unified.cli_hint_header':
|
|
111
|
+
'\nto remove the harnessed CLI itself (the step above did not \u2014 it only cleared setup files):',
|
|
112
|
+
'uninstall.unified.cli_hint_binary':
|
|
113
|
+
' binary: delete {{path}}\n then remove {{dir}} from your PATH',
|
|
114
|
+
'uninstall.unified.cli_hint_npm': ' npm: npm uninstall -g harnessed',
|
|
115
|
+
'uninstall.unified.cli_hint_other':
|
|
116
|
+
" installed both ways? remove the other too \u2014 npm: 'npm uninstall -g harnessed' / binary: delete the exe + its bin dir from PATH",
|
|
117
|
+
'gc.invalid_duration': "error: invalid --older-than '{{value}}'",
|
|
118
|
+
'gc.invalid_duration.fix': ' fix: use format <N>{d|h|m|w} e.g. 30d / 24h / 60m / 4w',
|
|
119
|
+
'gc.no_backups': 'no backups found ({{root}} absent) \u2014 nothing to gc',
|
|
120
|
+
'gc.no_old_snapshots': 'no snapshots older than {{cutoff}} (kept {{keptCount}} most-recent)',
|
|
121
|
+
'gc.summary_will_delete': 'would delete {{count}} snapshot(s), ~{{sizeKb}} KB total:',
|
|
122
|
+
'gc.summary_deleting': 'deleting {{count}} snapshot(s), ~{{sizeKb}} KB total:',
|
|
123
|
+
'gc.dry_run_rerun_hint': '\n(dry-run \u2014 re-run without --dry-run to actually delete)',
|
|
124
|
+
'gc.ledger_will_prune':
|
|
125
|
+
'would prune {{count}} stale workflow slot(s) from the ledger (kept {{kept}}):',
|
|
126
|
+
'gc.ledger_pruned': 'pruned {{count}} stale workflow slot(s) from the ledger (kept {{kept}}):',
|
|
127
|
+
'doctor.summary.fail': '\nsome checks failed (see fix hints above)',
|
|
128
|
+
'doctor.summary.warn': '\nall checks ok (with warnings \u2014 see hints above)',
|
|
129
|
+
'doctor.summary.pass': '\nall checks passed',
|
|
130
|
+
'doctor.host_scope': 'host: {{host}} \u2014 {{applied}} of {{total}} checks apply\n',
|
|
131
|
+
'doctor.matrix.legend':
|
|
132
|
+
'\nn/a = the check is not declared for that host in the registry, so it was not run',
|
|
133
|
+
'check_docs.clean': 'documentation discipline: no violations',
|
|
134
|
+
'check_docs.state_line_limit':
|
|
135
|
+
'STATE.md is {{lines}} lines > the {{limit}}-line digest limit \u2014 archive older phase narrative to RETROSPECTIVE.md (override for one run: HARNESSED_ALLOW_LONG_STATE=1)',
|
|
136
|
+
'check_docs.state_key_decisions':
|
|
137
|
+
"{{count}} '\u5173\u952E\u51B3\u8BAE ship \u603B\u7ED3' section(s) > {{limit}} \u2014 keep only the current one; move the rest to RETROSPECTIVE.md",
|
|
138
|
+
'check_docs.state_errata':
|
|
139
|
+
"historical commentary '{{excerpt}}' belongs in RETROSPECTIVE.md, not in the STATE digest",
|
|
140
|
+
'check_docs.roadmap_narrative':
|
|
141
|
+
'closing narrative inlined in an overview doc ({{signals}}) \u2014 ROADMAP carries one line + a pointer per phase; narrative goes to SUMMARY / VERIFICATION',
|
|
142
|
+
'check_docs.summary_halt':
|
|
143
|
+
'\ndocumentation discipline: {{halt}} blocking + {{warn}} advisory violation(s)',
|
|
144
|
+
'check_docs.summary_warn':
|
|
145
|
+
'\ndocumentation discipline: {{warn}} advisory violation(s) (non-blocking)',
|
|
146
|
+
'backup.no_backups': 'no backups found ({{root}} absent)',
|
|
147
|
+
'backup.no_backups_empty': 'no backups found ({{root}} empty)',
|
|
148
|
+
'backup.total_snapshots': '\n{{count}} snapshot(s) total',
|
|
149
|
+
'rollback.metadata_unreadable': 'error: cannot read {{path}}: {{message}}',
|
|
150
|
+
'rollback.metadata_unreadable.fix':
|
|
151
|
+
" fix: run 'harnessed backup list' to see available timestamps",
|
|
152
|
+
'rollback.checksum_mismatch':
|
|
153
|
+
'error: backup checksum mismatch for {{target}} (expected {{expected}}, got {{actual}})',
|
|
154
|
+
'rollback.restored': 'restored {{count}} file(s) from {{timestamp}}',
|
|
155
|
+
'status.no_installs': 'no installs recorded ({{path}} absent or empty)',
|
|
156
|
+
'status.summary_installs': '\n{{count}} install(s) recorded',
|
|
157
|
+
'status.lock_held': '\nlock: held (since {{since}}){{staleSuffix}}',
|
|
158
|
+
'status.lock_held.stale_suffix': ' \u2014 STALE',
|
|
159
|
+
'status.lock_release_hint': ' to release: wait for process to finish or delete {{path}}',
|
|
160
|
+
'status.lock_free': '\nlock: free',
|
|
161
|
+
'here.no_workflow': 'no active workflow for this repo ({{path}} has no entry for cwd)',
|
|
162
|
+
'here.no_workflow.hint':
|
|
163
|
+
' to start: run a stage (e.g. `harnessed gates discuss`) or `harnessed run <workflow>`',
|
|
164
|
+
'audit_log.no_records_file': 'no audit records found ({{path}} does not exist)',
|
|
165
|
+
'audit_log.no_records_empty': 'no audit records found (audit.log is empty)',
|
|
166
|
+
'audit_log.jq_missing': '\u2717 jq not found in PATH \u2014 run: harnessed doctor',
|
|
167
|
+
'audit_log.tail_invalid': '\u2717 --tail must be a positive integer',
|
|
168
|
+
'audit_log.head_invalid': '\u2717 --head must be a positive integer',
|
|
169
|
+
'execute_task.require_task': 'error: --task <text> is required',
|
|
170
|
+
'execute_task.load_phases_failed':
|
|
171
|
+
'error: failed to load workflows/{{workflow}}/phases.yaml \u2014 {{message}}',
|
|
172
|
+
'execute_task.precommit_skipped':
|
|
173
|
+
'\u26A0\uFE0F before-commit pre-flight skipped ({{message}}); subagent will biome-check at commit time.',
|
|
174
|
+
'research.require_query': 'error: --query <text> is required',
|
|
175
|
+
'manifest_add.non_interactive_warn':
|
|
176
|
+
'[ee-5-gate] WARN: --non-interactive skips 5-question prompt (D-03 dry-run-only). plan-phase hard reject still applies.',
|
|
177
|
+
'manifest_add.dry_run_preview':
|
|
178
|
+
'[manifest-add] dry-run preview for upstream: {{upstream}} \u2192 {{path}}',
|
|
179
|
+
'manifest_add.empty_answer': 'error: EE-5 gate requires non-empty answer',
|
|
180
|
+
'manifest_add.gate_passed_wrote': '[manifest-add] EE-5 gate passed; wrote {{path}}',
|
|
181
|
+
'manifest_add.gate_passed_dry_run':
|
|
182
|
+
'[manifest-add] EE-5 gate passed (dry-run); would write {{path}}',
|
|
183
|
+
'resume.fail': '\u2717 {{error}}',
|
|
184
|
+
'resume.corrupt': '\u2717 {{error}}\n path: {{path}}',
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/i18n/index.ts
|
|
188
|
+
var currentLocale = null
|
|
189
|
+
var cache = {}
|
|
190
|
+
function mapToSupported(raw2) {
|
|
191
|
+
if (!raw2) return 'en'
|
|
192
|
+
if (/^zh([^a-z]|$)/i.test(raw2)) return 'zh-Hans'
|
|
193
|
+
return 'en'
|
|
194
|
+
}
|
|
195
|
+
function detectLocale() {
|
|
196
|
+
const raw2 =
|
|
197
|
+
process.env.HARNESSED_LANG ||
|
|
198
|
+
process.env.LC_ALL ||
|
|
199
|
+
process.env.LANG ||
|
|
200
|
+
process.env.LANGUAGE ||
|
|
201
|
+
safeIntlLocale()
|
|
202
|
+
return mapToSupported(raw2)
|
|
203
|
+
}
|
|
204
|
+
function safeIntlLocale() {
|
|
205
|
+
try {
|
|
206
|
+
return Intl.DateTimeFormat().resolvedOptions().locale
|
|
207
|
+
} catch {
|
|
208
|
+
return void 0
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
var wiredMessagesDirProvider = null
|
|
212
|
+
function messagesDir() {
|
|
213
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
214
|
+
const candidates = []
|
|
215
|
+
if (wiredMessagesDirProvider) {
|
|
216
|
+
try {
|
|
217
|
+
candidates.push(wiredMessagesDirProvider())
|
|
218
|
+
} catch {}
|
|
219
|
+
}
|
|
220
|
+
candidates.push(resolve(here, '..', '..', 'messages'), resolve(here, '..', 'messages'))
|
|
221
|
+
for (const c of candidates) {
|
|
222
|
+
try {
|
|
223
|
+
readFileSync(join(c, 'en.json'), 'utf8')
|
|
224
|
+
return c
|
|
225
|
+
} catch {}
|
|
226
|
+
}
|
|
227
|
+
return resolve(process.cwd(), 'messages')
|
|
228
|
+
}
|
|
229
|
+
function loadLocale(locale) {
|
|
230
|
+
if (cache[locale]) return cache[locale]
|
|
231
|
+
const path = join(messagesDir(), `${locale}.json`)
|
|
232
|
+
try {
|
|
233
|
+
const raw2 = readFileSync(path, 'utf8')
|
|
234
|
+
cache[locale] = JSON.parse(raw2)
|
|
235
|
+
} catch {
|
|
236
|
+
cache[locale] = locale === 'en' ? en_default : {}
|
|
237
|
+
}
|
|
238
|
+
return cache[locale]
|
|
239
|
+
}
|
|
240
|
+
function getLocale() {
|
|
241
|
+
if (currentLocale === null) currentLocale = detectLocale()
|
|
242
|
+
return currentLocale
|
|
243
|
+
}
|
|
244
|
+
function t(key, params) {
|
|
245
|
+
const locale = getLocale()
|
|
246
|
+
const primary = loadLocale(locale)
|
|
247
|
+
let template = primary[key]
|
|
248
|
+
if (template === void 0 && locale !== 'en') {
|
|
249
|
+
template = loadLocale('en')[key]
|
|
250
|
+
}
|
|
251
|
+
if (template === void 0) template = key
|
|
252
|
+
if (!params) return template
|
|
253
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_match, name) => {
|
|
254
|
+
const v = params[name]
|
|
255
|
+
return v === void 0 ? `{{${name}}}` : String(v)
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/platform/ablation.ts
|
|
260
|
+
function isAblated(env = process.env) {
|
|
261
|
+
return env.HARNESSED_OFF === '1'
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/cli/checkDocs.ts
|
|
265
|
+
var DEFAULT_MAX_STATE_LINES = 100
|
|
266
|
+
var KEY_DECISIONS_SECTION_RE = /^##\s+.*关键决议\s*ship\s*总结/gm
|
|
267
|
+
var KEY_DECISIONS_SECTION_LIMIT = 1
|
|
268
|
+
var HISTORICAL_ERRATA_RE = /W-[1-9]\s+errata|sister\s+review\s+M[1-9]\s+修正/
|
|
269
|
+
var ROADMAP_NARRATIVE_SIGNALS = [
|
|
270
|
+
{ id: 'commit-hash', test: hasCommitHash },
|
|
271
|
+
{ id: 'test-tally', test: (l) => /\b\d{2,}\s*\/\s*0\b/.test(l) },
|
|
272
|
+
{ id: 'ci-verdict', test: (l) => /\bCI\s+(green|red|绿|红)/i.test(l) },
|
|
273
|
+
{ id: 'lesson', test: (l) => /(教训|lesson\s*[::]|lessons?\s+learned)/i.test(l) },
|
|
274
|
+
]
|
|
275
|
+
function hasCommitHash(line) {
|
|
276
|
+
for (const m of line.matchAll(/\b[0-9a-f]{7,40}\b/g)) {
|
|
277
|
+
if (/\d/.test(m[0]) && /[a-f]/.test(m[0])) return true
|
|
278
|
+
}
|
|
279
|
+
return false
|
|
280
|
+
}
|
|
281
|
+
function read(cwd, rel) {
|
|
282
|
+
const p = join2(cwd, rel)
|
|
283
|
+
if (!existsSync(p)) return null
|
|
284
|
+
try {
|
|
285
|
+
return readFileSync2(p, 'utf8')
|
|
286
|
+
} catch {
|
|
287
|
+
return null
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function contentLines(content) {
|
|
291
|
+
const lines = content.split(/\r?\n/)
|
|
292
|
+
if (lines[lines.length - 1] === '') lines.pop()
|
|
293
|
+
return lines
|
|
294
|
+
}
|
|
295
|
+
function collectDocViolations(opts) {
|
|
296
|
+
const limit = opts.maxStateLines ?? DEFAULT_MAX_STATE_LINES
|
|
297
|
+
const out = []
|
|
298
|
+
const state = read(opts.cwd, join2('.planning', 'STATE.md'))
|
|
299
|
+
if (state !== null) {
|
|
300
|
+
const lines = contentLines(state)
|
|
301
|
+
if (lines.length > limit && !opts.allowLongState) {
|
|
302
|
+
out.push({
|
|
303
|
+
rule: 'state-digest-line-limit',
|
|
304
|
+
tier: 'halt',
|
|
305
|
+
file: '.planning/STATE.md',
|
|
306
|
+
message: t('check_docs.state_line_limit', { lines: lines.length, limit }),
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
const sections = state.match(KEY_DECISIONS_SECTION_RE) ?? []
|
|
310
|
+
if (sections.length > KEY_DECISIONS_SECTION_LIMIT) {
|
|
311
|
+
out.push({
|
|
312
|
+
rule: 'state-key-decisions-section-limit',
|
|
313
|
+
tier: 'warn',
|
|
314
|
+
file: '.planning/STATE.md',
|
|
315
|
+
message: t('check_docs.state_key_decisions', {
|
|
316
|
+
count: sections.length,
|
|
317
|
+
limit: KEY_DECISIONS_SECTION_LIMIT,
|
|
318
|
+
}),
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
for (let i = 0; i < lines.length; i++) {
|
|
322
|
+
const line = lines[i] ?? ''
|
|
323
|
+
if (HISTORICAL_ERRATA_RE.test(line)) {
|
|
324
|
+
out.push({
|
|
325
|
+
rule: 'state-historical-errata',
|
|
326
|
+
tier: 'warn',
|
|
327
|
+
file: '.planning/STATE.md',
|
|
328
|
+
line: i + 1,
|
|
329
|
+
message: t('check_docs.state_errata', { excerpt: line.trim().slice(0, 80) }),
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const roadmap = read(opts.cwd, join2('.planning', 'ROADMAP.md'))
|
|
335
|
+
if (roadmap !== null) {
|
|
336
|
+
const lines = contentLines(roadmap)
|
|
337
|
+
for (let i = 0; i < lines.length; i++) {
|
|
338
|
+
const line = lines[i] ?? ''
|
|
339
|
+
const hits = ROADMAP_NARRATIVE_SIGNALS.filter((s) => s.test(line)).map((s) => s.id)
|
|
340
|
+
if (hits.length > 0) {
|
|
341
|
+
out.push({
|
|
342
|
+
rule: 'roadmap-no-inline-narrative',
|
|
343
|
+
tier: 'warn',
|
|
344
|
+
file: '.planning/ROADMAP.md',
|
|
345
|
+
line: i + 1,
|
|
346
|
+
message: t('check_docs.roadmap_narrative', { signals: hits.join(', ') }),
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return out
|
|
352
|
+
}
|
|
353
|
+
function exitCodeFor(violations) {
|
|
354
|
+
if (violations.some((v) => v.tier === 'halt')) return 2
|
|
355
|
+
return violations.length > 0 ? 1 : 0
|
|
356
|
+
}
|
|
357
|
+
function shouldGateForHookPayload(raw2) {
|
|
358
|
+
if (!raw2.trim()) return false
|
|
359
|
+
let payload
|
|
360
|
+
try {
|
|
361
|
+
payload = JSON.parse(raw2)
|
|
362
|
+
} catch {
|
|
363
|
+
return false
|
|
364
|
+
}
|
|
365
|
+
if (payload?.tool_name !== 'Bash') return false
|
|
366
|
+
const cmd = payload.tool_input?.command
|
|
367
|
+
return typeof cmd === 'string' && /\bgit\s+(?:-\S+\s+)*commit\b/.test(cmd)
|
|
368
|
+
}
|
|
369
|
+
function codexHookOutput(code, lines) {
|
|
370
|
+
const text = lines.join('\n')
|
|
371
|
+
if (code === 2)
|
|
372
|
+
return JSON.stringify({
|
|
373
|
+
hookSpecificOutput: {
|
|
374
|
+
hookEventName: 'PreToolUse',
|
|
375
|
+
permissionDecision: 'deny',
|
|
376
|
+
permissionDecisionReason: text,
|
|
377
|
+
},
|
|
378
|
+
})
|
|
379
|
+
if (code === 1) return JSON.stringify({ systemMessage: text })
|
|
380
|
+
return null
|
|
381
|
+
}
|
|
382
|
+
async function readStdin() {
|
|
383
|
+
if (process.stdin.isTTY) return ''
|
|
384
|
+
try {
|
|
385
|
+
const chunks = []
|
|
386
|
+
for await (const c of process.stdin) chunks.push(c)
|
|
387
|
+
return Buffer.concat(chunks).toString('utf8')
|
|
388
|
+
} catch {
|
|
389
|
+
return ''
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async function runCheckDocsCommand(opts) {
|
|
393
|
+
if (opts.hook && isAblated()) process.exit(0)
|
|
394
|
+
if (opts.hook && !shouldGateForHookPayload(await readStdin())) process.exit(0)
|
|
395
|
+
const parsed = Number(opts.maxStateLines)
|
|
396
|
+
const violations = collectDocViolations({
|
|
397
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
398
|
+
...(Number.isFinite(parsed) && parsed > 0 ? { maxStateLines: parsed } : {}),
|
|
399
|
+
allowLongState: !!process.env.HARNESSED_ALLOW_LONG_STATE,
|
|
400
|
+
})
|
|
401
|
+
const code = exitCodeFor(violations)
|
|
402
|
+
const summary = code === 2 ? 'halt' : code === 1 ? 'warn' : 'pass'
|
|
403
|
+
if (opts.hook && opts.platform === 'codex') {
|
|
404
|
+
const lines = violations.map((v) => {
|
|
405
|
+
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`
|
|
406
|
+
return `${v.tier === 'halt' ? '\u2717' : '\u26A0'} ${where} [${v.rule}] ${v.message}`
|
|
407
|
+
})
|
|
408
|
+
const verdict = codexHookOutput(code, lines)
|
|
409
|
+
if (verdict !== null)
|
|
410
|
+
process.stdout.write(`${verdict}
|
|
411
|
+
`)
|
|
412
|
+
process.exit(0)
|
|
413
|
+
}
|
|
414
|
+
if (opts.json) {
|
|
415
|
+
console.log(JSON.stringify({ violations, summary, exit_code: code }, null, 2))
|
|
416
|
+
} else if (violations.length === 0) {
|
|
417
|
+
console.log(t('check_docs.clean'))
|
|
418
|
+
} else {
|
|
419
|
+
for (const v of violations) {
|
|
420
|
+
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`
|
|
421
|
+
console.error(`${v.tier === 'halt' ? '\u2717' : '\u26A0'} ${where} [${v.rule}] ${v.message}`)
|
|
422
|
+
}
|
|
423
|
+
console.error(
|
|
424
|
+
code === 2
|
|
425
|
+
? t('check_docs.summary_halt', {
|
|
426
|
+
halt: violations.filter((v) => v.tier === 'halt').length,
|
|
427
|
+
warn: violations.filter((v) => v.tier === 'warn').length,
|
|
428
|
+
})
|
|
429
|
+
: t('check_docs.summary_warn', { warn: violations.length }),
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
process.exit(code)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/cli/checkDocsHookMain.ts
|
|
436
|
+
var raw = process.argv.slice(2)
|
|
437
|
+
var args = raw[0] === 'check-docs' ? raw.slice(1) : raw
|
|
438
|
+
var value = (name) => {
|
|
439
|
+
const at = args.indexOf(`--${name}`)
|
|
440
|
+
if (at >= 0) return args[at + 1]
|
|
441
|
+
const prefix = `--${name}=`
|
|
442
|
+
return args.find((a) => a.startsWith(prefix))?.slice(prefix.length)
|
|
443
|
+
}
|
|
444
|
+
var has = (name) => args.includes(`--${name}`)
|
|
445
|
+
try {
|
|
446
|
+
await runCheckDocsCommand({
|
|
447
|
+
json: has('json'),
|
|
448
|
+
cwd: value('cwd'),
|
|
449
|
+
maxStateLines: value('max-state-lines'),
|
|
450
|
+
hook: has('hook'),
|
|
451
|
+
platform: value('platform'),
|
|
452
|
+
})
|
|
453
|
+
} catch (error) {
|
|
454
|
+
console.error(error.message)
|
|
455
|
+
process.exit(1)
|
|
456
|
+
}
|