@sockulags/agent-os 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +102 -49
  2. package/cli/doctor.mjs +307 -0
  3. package/cli/index.mjs +328 -151
  4. package/cli/index.test.mjs +406 -9
  5. package/package.json +5 -6
  6. package/plugins/agent-os-core/.claude-plugin/plugin.json +18 -0
  7. package/plugins/agent-os-core/.codex-plugin/plugin.json +24 -0
  8. package/plugins/agent-os-core/skills/capture-intent/SKILL.md +65 -0
  9. package/plugins/agent-os-core/skills/capture-intent/references/intent-template.md +47 -0
  10. package/plugins/agent-os-core/skills/explain-work/SKILL.md +42 -0
  11. package/{skills → plugins/agent-os-core/skills}/list-skills/SKILL.md +13 -6
  12. package/{skills → plugins/agent-os-core/skills}/plain-voice/SKILL.md +7 -4
  13. package/plugins/agent-os-core/skills/plan-work/SKILL.md +133 -0
  14. package/plugins/agent-os-core/skills/plan-work/references/elicitation.md +32 -0
  15. package/plugins/agent-os-core/skills/plan-work/references/map.md +108 -0
  16. package/plugins/agent-os-core/skills/plan-work/references/spec-template.md +64 -0
  17. package/plugins/agent-os-core/skills/record-lesson/SKILL.md +47 -0
  18. package/plugins/agent-os-core/skills/scope-guard/SKILL.md +53 -0
  19. package/{skills → plugins/agent-os-core/skills}/verify-before-done/SKILL.md +6 -2
  20. package/plugins/agent-os-dev/.claude-plugin/plugin.json +18 -0
  21. package/plugins/agent-os-dev/.codex-plugin/plugin.json +24 -0
  22. package/plugins/agent-os-dev/hooks/hooks.json +42 -0
  23. package/{skills → plugins/agent-os-dev/skills}/batch-work/SKILL.md +9 -4
  24. package/{skills → plugins/agent-os-dev/skills}/batch-work/references/manifest.md +8 -0
  25. package/{skills → plugins/agent-os-dev/skills}/check-work/SKILL.md +31 -14
  26. package/{skills/deliver-work/workflow.md → plugins/agent-os-dev/skills/deliver-work/SKILL.md} +85 -17
  27. package/plugins/agent-os-dev/skills/design-work/SKILL.md +145 -0
  28. package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.mjs +233 -0
  29. package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.test.mjs +73 -0
  30. package/plugins/agent-os-dev/skills/diagnose-before-fix/SKILL.md +29 -0
  31. package/{skills → plugins/agent-os-dev/skills}/dispatch-next/SKILL.md +10 -4
  32. package/plugins/agent-os-dev/skills/init-agent-os/SKILL.md +121 -0
  33. package/plugins/agent-os-dev/skills/init-agent-os/policy.md +88 -0
  34. package/plugins/agent-os-dev/skills/init-agent-os/references/guards.md +39 -0
  35. package/{skills → plugins/agent-os-dev/skills}/init-agent-os/references/repository-init.md +41 -9
  36. package/plugins/agent-os-dev/skills/init-agent-os/references/review-template.md +35 -0
  37. package/plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs +187 -0
  38. package/plugins/agent-os-dev/skills/init-agent-os/templates/agent-review.yml +59 -0
  39. package/plugins/agent-os-dev/skills/init-agent-os/templates/lint-intents.yml +30 -0
  40. package/{skills → plugins/agent-os-dev/skills}/proportional-testing/SKILL.md +1 -1
  41. package/plugins/agent-os-dev/skills/quality-ratchet/SKILL.md +103 -0
  42. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/project-controls.md +31 -3
  43. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.mjs +145 -0
  44. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.test.mjs +158 -0
  45. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.mjs +372 -0
  46. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.test.mjs +138 -0
  47. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.mjs +322 -0
  48. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.test.mjs +172 -0
  49. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.mjs +59 -8
  50. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.test.mjs +134 -8
  51. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.mjs +296 -22
  52. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.test.mjs +114 -6
  53. package/plugins/agent-os-dev/skills/shape-work/SKILL.md +124 -0
  54. package/plugins/agent-os-dev/skills/shape-work/references/implementation-issues.md +143 -0
  55. package/{skills/chart-work → plugins/agent-os-dev/skills/shape-work}/references/prototypes.md +11 -13
  56. package/plugins/agent-os-dev/skills/simplify/SKILL.md +91 -0
  57. package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.mjs +166 -0
  58. package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.test.mjs +49 -0
  59. package/policy.md +53 -20
  60. package/hooks/hooks.json +0 -17
  61. package/skills/chart-work/SKILL.md +0 -42
  62. package/skills/chart-work/references/elicitation.md +0 -25
  63. package/skills/chart-work/references/map.md +0 -84
  64. package/skills/deliver-work/SKILL.md +0 -12
  65. package/skills/diagnose-before-fix/SKILL.md +0 -24
  66. package/skills/explain-work/SKILL.md +0 -27
  67. package/skills/guide-me/SKILL.md +0 -36
  68. package/skills/init-agent-os/SKILL.md +0 -54
  69. package/skills/init-agent-os/scripts/policy-block.ps1 +0 -87
  70. package/skills/notice-lesson/SKILL.md +0 -20
  71. package/skills/quality-ratchet/SKILL.md +0 -72
  72. package/skills/record-lesson/SKILL.md +0 -31
  73. package/skills/scope-guard/SKILL.md +0 -32
  74. package/skills/shape-work/SKILL.md +0 -48
  75. package/skills/shape-work/references/implementation-issues.md +0 -69
  76. package/skills/shape-work/references/mockups.md +0 -23
  77. package/skills/simplifier/SKILL.md +0 -35
  78. package/skills/simplifier/agents/openai.yaml +0 -2
  79. package/skills/simplifier-audit/SKILL.md +0 -30
  80. package/skills/simplifier-review/SKILL.md +0 -40
  81. package/skills/understand-work/SKILL.md +0 -31
  82. package/skills/understand-work/agents/openai.yaml +0 -2
  83. package/skills/writing-skills/SKILL.md +0 -68
  84. package/skills/writing-skills/agents/openai.yaml +0 -2
  85. /package/{skills/batch-work → plugins/agent-os-core/skills/capture-intent}/agents/openai.yaml +0 -0
  86. /package/{skills/chart-work → plugins/agent-os-core/skills/explain-work}/agents/openai.yaml +0 -0
  87. /package/{skills/deliver-work → plugins/agent-os-core/skills/list-skills}/agents/openai.yaml +0 -0
  88. /package/{skills → plugins/agent-os-core/skills}/plain-voice/references/tells.md +0 -0
  89. /package/{skills/dispatch-next → plugins/agent-os-core/skills/plan-work}/agents/openai.yaml +0 -0
  90. /package/{skills/explain-work → plugins/agent-os-dev/skills/batch-work}/agents/openai.yaml +0 -0
  91. /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/manifest-hash.mjs +0 -0
  92. /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/test-manifest-hash.mjs +0 -0
  93. /package/{skills → plugins/agent-os-dev/skills}/check-work/references/findings.md +0 -0
  94. /package/{skills/guide-me → plugins/agent-os-dev/skills/deliver-work}/agents/openai.yaml +0 -0
  95. /package/{skills/init-agent-os → plugins/agent-os-dev/skills/design-work}/agents/openai.yaml +0 -0
  96. /package/{skills/list-skills → plugins/agent-os-dev/skills/dispatch-next}/agents/openai.yaml +0 -0
  97. /package/{skills/record-lesson → plugins/agent-os-dev/skills/init-agent-os}/agents/openai.yaml +0 -0
  98. /package/{skills → plugins/agent-os-dev/skills}/proportional-testing/references/strategy.md +0 -0
  99. /package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/structure.md +0 -0
  100. /package/{skills → plugins/agent-os-dev/skills}/shape-work/agents/openai.yaml +0 -0
  101. /package/{skills/simplifier-audit → plugins/agent-os-dev/skills/simplify}/agents/openai.yaml +0 -0
@@ -1,9 +1,11 @@
1
1
  import fs from 'node:fs'
2
+ import os from 'node:os'
2
3
  import path from 'node:path'
3
- import { createHash } from 'node:crypto'
4
+ import { createHash, randomUUID } from 'node:crypto'
4
5
  import { spawnSync } from 'node:child_process'
5
6
 
6
7
  export const POLICY_PATH = '.agent-os/quality.json'
8
+ export const DEFAULT_TRUST_STORE = path.join(os.homedir(), '.agent-os', 'trusted-controls.json')
7
9
  const SIGNALS = {
8
10
  'type-escape': /@ts-(?:ignore|nocheck|expect-error)\b|:\s*any\b|\bas\s+any\b/,
9
11
  'lint-disable': /eslint-disable|@SuppressWarnings\b/,
@@ -29,7 +31,7 @@ export function readPolicy(root) {
29
31
  const file = path.join(root, POLICY_PATH)
30
32
  if (!fs.existsSync(file)) return { schema: 1, checks: [], blockSignals: [], protectedFiles: [] }
31
33
  const policy = JSON.parse(fs.readFileSync(file, 'utf8'))
32
- exactKeys(policy, ['schema', 'checks', 'blockSignals', 'protectedFiles'], 'quality policy')
34
+ exactKeys(policy, ['schema', 'checks', 'blockSignals', 'protectedFiles', 'complexity'], 'quality policy')
33
35
  if (policy.schema !== 1 || !Array.isArray(policy.checks)) throw new Error('Quality policy requires schema 1 and checks')
34
36
  const ids = new Set()
35
37
  for (const check of policy.checks) {
@@ -54,9 +56,18 @@ export function readPolicy(root) {
54
56
  }
55
57
  policy.blockSignals ??= []
56
58
  policy.protectedFiles ??= []
57
- if (!Array.isArray(policy.blockSignals) || policy.blockSignals.some(name => !Object.hasOwn(SIGNALS, name))) {
59
+ if (!Array.isArray(policy.blockSignals) ||
60
+ policy.blockSignals.some(name => !Object.hasOwn(SIGNALS, name) && name !== 'complexity')) {
58
61
  throw new Error('Unknown blockSignals rule')
59
62
  }
63
+ if (policy.complexity !== undefined) {
64
+ exactKeys(policy.complexity, ['threshold'], 'complexity')
65
+ const { threshold } = policy.complexity
66
+ if (!Number.isInteger(threshold) || threshold < 1 || threshold > 200) throw new Error('complexity.threshold must be an integer between 1 and 200')
67
+ }
68
+ if (policy.blockSignals.includes('complexity') && !policy.complexity) {
69
+ throw new Error('The complexity blockSignals rule requires complexity.threshold')
70
+ }
60
71
  if (!Array.isArray(policy.protectedFiles) || !policy.protectedFiles.every(relativeFile)) throw new Error('Invalid protectedFiles')
61
72
  return policy
62
73
  }
@@ -123,17 +134,56 @@ function executable(root, name, env) {
123
134
  throw new Error(`Executable unavailable: ${name}`)
124
135
  }
125
136
 
126
- export function prepareControls(root, files, env = process.env) {
127
- const policy = readPolicy(root)
128
- const fileIdentity = files.map(file => [file.path, file.kind, file.hash, file.mode])
129
- const environment = identity(Object.entries(env).sort(([a], [b]) => a.localeCompare(b)))
137
+ // The declared controls: the policy plus the protected files that implement it.
138
+ export function controlSignature(root, policy = readPolicy(root)) {
130
139
  const protectedIdentity = [POLICY_PATH, ...policy.protectedFiles].map(name => {
131
140
  try { return [name, inputHash(root, name)] } catch (error) {
132
141
  if (error.code === 'ENOENT') return [name, null]
133
142
  throw error
134
143
  }
135
144
  })
136
- const signature = identity({ policy, protectedIdentity })
145
+ return identity({ policy, protectedIdentity })
146
+ }
147
+
148
+ // A repository's quality.json can name any program, and check runs it with the developer's
149
+ // environment. The developer trusts each repository's declared controls once per signature from an
150
+ // interactive terminal before check runs them. The store lives outside every repository.
151
+ function readTrustStore(file) {
152
+ try {
153
+ const value = JSON.parse(fs.readFileSync(file, 'utf8'))
154
+ if (value?.schema === 1 && value.trusted && typeof value.trusted === 'object' && !Array.isArray(value.trusted)) return value
155
+ } catch {
156
+ // A missing or unreadable store trusts nothing.
157
+ }
158
+ return { schema: 1, trusted: {} }
159
+ }
160
+
161
+ const trustKey = (repository, signature) => identity({ repository, signature })
162
+
163
+ export function controlsTrusted(repository, signature, trustStore = DEFAULT_TRUST_STORE) {
164
+ return Object.hasOwn(readTrustStore(trustStore).trusted, trustKey(repository, signature))
165
+ }
166
+
167
+ export function recordControlsTrust(repository, signature, checks, trustStore = DEFAULT_TRUST_STORE) {
168
+ const store = readTrustStore(trustStore)
169
+ store.trusted[trustKey(repository, signature)] = {
170
+ repository, trustedAt: new Date().toISOString(), commands: checks.map(check => [check.id, check.command])
171
+ }
172
+ fs.mkdirSync(path.dirname(trustStore), { recursive: true })
173
+ const temporary = `${trustStore}.${randomUUID()}.tmp`
174
+ try {
175
+ fs.writeFileSync(temporary, JSON.stringify(store, null, 2) + '\n')
176
+ fs.renameSync(temporary, trustStore)
177
+ } finally {
178
+ if (fs.existsSync(temporary)) fs.rmSync(temporary, { force: true })
179
+ }
180
+ }
181
+
182
+ export function prepareControls(root, files, env = process.env) {
183
+ const policy = readPolicy(root)
184
+ const fileIdentity = files.map(file => [file.path, file.kind, file.hash, file.mode])
185
+ const environment = identity(Object.entries(env).sort(([a], [b]) => a.localeCompare(b)))
186
+ const signature = controlSignature(root, policy)
137
187
  const checks = policy.checks.map(check => {
138
188
  try {
139
189
  if (check.cache && files.some(file => !['file', 'missing'].includes(file.kind))) {
@@ -179,6 +229,7 @@ export function blockingControls(report) {
179
229
  if (!report) return []
180
230
  return [
181
231
  ...(report.policyChanged ? ['quality policy changed: restore it or explicitly acknowledge the authorized change'] : []),
232
+ ...(report.untrusted ? ['project controls are not trusted on this machine: the developer must run trust in an interactive terminal'] : []),
182
233
  ...(report.stale ? ['inputs changed during verification; run check again'] : []),
183
234
  ...report.results.filter(result => result.required && result.status !== 'passed').map(result => `${result.id}: ${result.status}`),
184
235
  ...report.signals.filter(signal => signal.required).map(signal => `${signal.path}:${signal.line} ${signal.rule}`)
@@ -2,11 +2,18 @@ import assert from 'node:assert/strict'
2
2
  import fs from 'node:fs'
3
3
  import os from 'node:os'
4
4
  import path from 'node:path'
5
- import { execFileSync } from 'node:child_process'
6
- import test from 'node:test'
7
- import { begin, check, hook, clear } from './quality-delta.mjs'
5
+ import { execFileSync, spawnSync } from 'node:child_process'
6
+ import test, { after } from 'node:test'
7
+ import { fileURLToPath } from 'node:url'
8
+ import { begin, check, finish, hook, clear, controlsTrustPlan, trustControls } from './quality-delta.mjs'
8
9
 
9
- const options = { detect: () => ({}) }
10
+ const trustRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-trust-'))
11
+ after(() => fs.rmSync(trustRoot, { recursive: true, force: true }))
12
+ const trustStore = path.join(trustRoot, 'trusted-controls.json')
13
+ const options = { detect: () => ({}), trustStore }
14
+ // CI=true trusts every control, so trust tests run as a developer machine.
15
+ const developerEnv = { ...process.env, CI: '' }
16
+ const trust = root => trustControls(controlsTrustPlan(root), { trustStore })
10
17
  function fixture(t, checks = [], extra = {}) {
11
18
  const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-controls-'))
12
19
  t.after(() => fs.rmSync(root, { recursive: true, force: true }))
@@ -19,6 +26,7 @@ function fixture(t, checks = [], extra = {}) {
19
26
  write('tools/version', '1')
20
27
  write('source.ts', 'export const value = 1\n')
21
28
  write('verify.cjs', "const fs = require('fs'); fs.appendFileSync('counter', 'x'); if (fs.readFileSync('source.ts', 'utf8').includes('BROKEN')) process.exit(1)")
29
+ trust(root)
22
30
  return { root, write, policy: JSON.parse(fs.readFileSync(path.join(root, '.agent-os/quality.json'))), count: () => fs.readFileSync(path.join(root, 'counter'), 'utf8').length }
23
31
  }
24
32
  const required = { id: 'verify', command: ['node', 'verify.cjs'], required: true }
@@ -39,6 +47,27 @@ test('required failures block repeatedly; fixed code passes and Stop never rerun
39
47
  assert.ok(fs.existsSync(started.statePath + '.report.json'))
40
48
  })
41
49
 
50
+ test('an unfixable required failure releases Stop to the user after the bounded limit', t => {
51
+ const f = fixture(t, [required])
52
+ begin(f.root, options)
53
+ f.write('source.ts', 'BROKEN')
54
+ assert.equal(check(f.root, options).status, 'blocked')
55
+ assert.equal(hook(f.root, { stop_hook_active: false }).decision, 'block')
56
+ assert.equal(hook(f.root, { stop_hook_active: true }).decision, 'block')
57
+ assert.equal(hook(f.root, { stop_hook_active: true }).decision, 'block')
58
+ const released = hook(f.root, { stop_hook_active: true })
59
+ assert.equal(released.decision, undefined)
60
+ assert.match(released.systemMessage, /verify: failed/)
61
+ assert.equal(hook(f.root, { stop_hook_active: false }).decision, undefined)
62
+
63
+ f.write('source.ts', 'BROKEN again')
64
+ assert.equal(check(f.root, options).status, 'blocked')
65
+ assert.equal(hook(f.root, { stop_hook_active: true }).decision, 'block')
66
+ f.write('source.ts', 'export const value = 3')
67
+ assert.equal(check(f.root, options).status, 'ok')
68
+ assert.deepEqual(hook(f.root), {})
69
+ })
70
+
42
71
  test('advisory failures and new exception signals do not gate delivery', t => {
43
72
  const f = fixture(t, [{ ...required, required: false }])
44
73
  f.write('source.ts', '// @ts-ignore\nexport const value = 1')
@@ -91,6 +120,19 @@ test('dynamic checks and failed static checks are never reused', t => {
91
120
  }
92
121
  })
93
122
 
123
+ test('finish keeps the baseline while a required control fails and closes it once it passes', t => {
124
+ const f = fixture(t, [required])
125
+ const started = begin(f.root, options)
126
+ f.write('source.ts', 'BROKEN')
127
+ const refused = finish(f.root, options)
128
+ assert.equal(refused.closed, false)
129
+ assert.equal(refused.evidence.status, 'blocked')
130
+ assert.equal(fs.existsSync(started.statePath), true)
131
+ f.write('source.ts', 'export const value = 4')
132
+ assert.equal(finish(f.root, options).closed, true)
133
+ assert.equal(fs.existsSync(started.statePath), false)
134
+ })
135
+
94
136
  test('policy changes require explicit acknowledgement and cannot be cleared silently', t => {
95
137
  const f = fixture(t, [required], { protectedFiles: ['verify.cjs'] })
96
138
  begin(f.root, options)
@@ -98,11 +140,72 @@ test('policy changes require explicit acknowledgement and cannot be cleared sile
98
140
  assert.equal(check(f.root, options).status, 'blocked')
99
141
  assert.throws(() => clear(f.root), /Policy changed|policy changed/)
100
142
  assert.equal(hook(f.root).decision, 'block')
101
- const accepted = check(f.root, { ...options, acceptPolicyChange: 'Authorized replacement of obsolete check' })
102
- assert.equal(accepted.status, 'ok')
143
+ const accepted = check(f.root, { ...options, env: developerEnv, acceptPolicyChange: 'Authorized replacement of obsolete check' })
103
144
  assert.match(accepted.controls.policyAcknowledgement.reason, /Authorized/)
104
- assert.match(check(f.root, options).controls.policyAcknowledgement.reason, /Authorized/)
105
- assert.deepEqual(hook(f.root), {})
145
+ // The acknowledged policy is a new signature, so its commands need the developer's trust again.
146
+ assert.equal(accepted.status, 'blocked')
147
+ assert.ok(accepted.controls.untrusted)
148
+ trust(f.root)
149
+ const trusted = check(f.root, { ...options, env: developerEnv })
150
+ assert.equal(trusted.status, 'ok')
151
+ assert.match(trusted.controls.policyAcknowledgement.reason, /Authorized/)
152
+ assert.deepEqual(hook(f.root, {}, { env: developerEnv }), {})
153
+ })
154
+
155
+ test('untrusted repository commands never run and block delivery until the developer trusts them', t => {
156
+ const f = fixture(t, [required])
157
+ const untrustedStore = path.join(trustRoot, `untrusted-${Date.now()}.json`)
158
+ const untrusted = { ...options, env: developerEnv, trustStore: untrustedStore }
159
+ const started = begin(f.root, untrusted)
160
+ const evidence = check(f.root, untrusted)
161
+ assert.equal(evidence.status, 'blocked')
162
+ assert.deepEqual(evidence.controls.results, [])
163
+ assert.deepEqual(evidence.controls.untrusted.commands, [{ id: 'verify', command: ['node', 'verify.cjs'] }])
164
+ const trustRootArgument = evidence.controls.untrusted.trustCommand.match(/ trust --root "(.*)"$/)?.[1]
165
+ assert.equal(fs.realpathSync(trustRootArgument), fs.realpathSync(f.root))
166
+ assert.equal(evidence.controls.untrusted.trustCommand.startsWith('& '), process.platform === 'win32')
167
+ assert.equal(fs.existsSync(path.join(f.root, 'counter')), false)
168
+ assert.equal(finish(f.root, untrusted).closed, false)
169
+ // Untrusted controls are the developer's decision, so Stop lets the turn end at once.
170
+ const released = hook(f.root, { stop_hook_active: false }, { env: developerEnv })
171
+ assert.equal(released.decision, undefined)
172
+ assert.match(released.systemMessage, /not trusted on this machine.*verify \["node","verify\.cjs"\].* trust --root /)
173
+
174
+ trustControls(controlsTrustPlan(f.root), { trustStore: untrustedStore })
175
+ assert.equal(finish(f.root, untrusted).closed, true)
176
+ assert.equal(f.count(), 1)
177
+ assert.equal(fs.existsSync(started.statePath), false)
178
+ })
179
+
180
+ test('a CI environment runs declared controls without a trust record', t => {
181
+ const f = fixture(t, [required])
182
+ const env = { ...process.env, CI: 'true' }
183
+ const untrusted = { ...options, env, trustStore: path.join(trustRoot, `ci-${Date.now()}.json`) }
184
+ begin(f.root, untrusted)
185
+ const evidence = check(f.root, untrusted)
186
+ assert.equal(evidence.status, 'ok')
187
+ assert.equal(evidence.controls.untrusted, null)
188
+ assert.equal(f.count(), 1)
189
+ })
190
+
191
+ test('trust is shared by linked worktrees of the same repository', t => {
192
+ const f = fixture(t, [required])
193
+ execFileSync('git', ['-C', f.root, '-c', 'user.name=t', '-c', 'user.email=t@t', 'add', '.'])
194
+ execFileSync('git', ['-C', f.root, '-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'fixture'])
195
+ const linked = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-controls-linked-'))
196
+ fs.rmSync(linked, { recursive: true })
197
+ t.after(() => fs.rmSync(linked, { recursive: true, force: true }))
198
+ execFileSync('git', ['-C', f.root, 'worktree', 'add', '-q', '-b', 'linked', linked])
199
+ assert.equal(controlsTrustPlan(linked).repository, controlsTrustPlan(f.root).repository)
200
+ })
201
+
202
+ test('the trust command refuses to record trust without an interactive terminal', t => {
203
+ const f = fixture(t, [required])
204
+ const runner = path.join(path.dirname(fileURLToPath(import.meta.url)), 'quality-delta.mjs')
205
+ const result = spawnSync(process.execPath, [runner, 'trust', '--root', f.root], { encoding: 'utf8', input: 'y\n' })
206
+ assert.equal(result.status, 2)
207
+ assert.match(result.stdout, /verify \(required\): \["node","verify.cjs"\]/)
208
+ assert.match(result.stderr, /interactive terminal/)
106
209
  })
107
210
 
108
211
  test('missing executable, missing tool inputs, timeout, and malformed policy cannot report success', t => {
@@ -173,3 +276,26 @@ test('external executable permission changes invalidate a cached pass', { skip:
173
276
  assert.equal(hook(f.root).decision, 'block')
174
277
  assert.equal(check(f.root, options).status, 'blocked')
175
278
  })
279
+
280
+ test('stale control evidence is bounded at Stop', t => {
281
+ const f = fixture(t, [required])
282
+ begin(f.root, options)
283
+ assert.equal(check(f.root, options).status, 'ok')
284
+ const env = { ...process.env, CONTROL_FIXTURE: 'changed after check' }
285
+ assert.match(hook(f.root, { stop_hook_active: false }, { env }).reason, /control evidence is stale/)
286
+ assert.equal(hook(f.root, { stop_hook_active: true }, { env }).decision, 'block')
287
+ assert.equal(hook(f.root, { stop_hook_active: true }, { env }).decision, 'block')
288
+ assert.match(hook(f.root, { stop_hook_active: true }, { env }).systemMessage, /still stale/)
289
+ })
290
+
291
+ test('a released stale-check block does not use up the failing-controls budget', t => {
292
+ const f = fixture(t, [required])
293
+ begin(f.root, options)
294
+ f.write('source.ts', 'BROKEN')
295
+ assert.equal(hook(f.root, { stop_hook_active: false }).decision, 'block')
296
+ assert.equal(hook(f.root, { stop_hook_active: true }).decision, 'block')
297
+ assert.equal(hook(f.root, { stop_hook_active: true }).decision, 'block')
298
+ assert.match(hook(f.root, { stop_hook_active: true }).systemMessage, /has not run/)
299
+ assert.equal(check(f.root, options).status, 'blocked')
300
+ assert.match(hook(f.root, { stop_hook_active: false }).reason, /Project controls block delivery/)
301
+ })