teamsmith 0.4.7 → 0.4.8

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 (42) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +11 -0
  4. package/skills/teamsmith/SKILL.md +12 -8
  5. package/skills/teamsmith/references/config.md +11 -12
  6. package/skills/teamsmith/scripts/lib/cmd-review.sh +21 -33
  7. package/skills/teamsmith/scripts/lib/common.sh +1 -1
  8. package/skills/teamsmith/scripts/panel/README.md +35 -33
  9. package/skills/teamsmith/scripts/panel/panel.js +217 -199
  10. package/skills/teamsmith/scripts/panel/src/App.tsx +221 -66
  11. package/skills/teamsmith/scripts/panel/src/layout.ts +139 -302
  12. package/skills/teamsmith/scripts/panel/src/project-settings.ts +46 -0
  13. package/skills/teamsmith/scripts/panel/src/strings/en.ts +71 -205
  14. package/skills/teamsmith/scripts/panel/src/strings/index.ts +3 -5
  15. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +72 -204
  16. package/skills/teamsmith/scripts/panel/src/types.ts +23 -4
  17. package/skills/teamsmith/scripts/strings/commands.tsv +1 -1
  18. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +7 -0
  19. package/skills/teamsmith/templates/pm-prompt.md.tmpl +10 -6
  20. package/skills/teamsmith/tests/help-surface.sh +75 -7
  21. package/skills/teamsmith/tests/install-shape.sh +7 -7
  22. package/skills/teamsmith/tests/key-replies-ui.sh +11 -5
  23. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +2 -0
  24. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +255 -90
  25. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +181 -61
  26. package/skills/teamsmith/tests/lib/model-routing-roles.sh +125 -67
  27. package/skills/teamsmith/tests/lib/reply-fixture.sh +14 -9
  28. package/skills/teamsmith/tests/lib/tmp-root.sh +1 -1
  29. package/skills/teamsmith/tests/loop-inventory.tsv +2 -0
  30. package/skills/teamsmith/tests/panel-b2.sh +91 -31
  31. package/skills/teamsmith/tests/panel-p21.sh +607 -1162
  32. package/skills/teamsmith/tests/panel-strings.mjs +21 -113
  33. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +65 -38
  34. package/skills/teamsmith/tests/remind-adversarial-faults.sh +64 -12
  35. package/skills/teamsmith/tests/remind-adversarial-real.sh +13 -12
  36. package/skills/teamsmith/tests/remind-tool-real.mjs +159 -112
  37. package/skills/teamsmith/tests/remind-tool-real.sh +178 -3
  38. package/skills/teamsmith/tests/section-paths.tsv +10 -10
  39. package/skills/teamsmith/tests/smoke.sh +108 -114
  40. package/skills/teamsmith/tests/task-model-routing.sh +57 -26
  41. package/skills/teamsmith/tests/tmp-hygiene.sh +1 -1
  42. package/skills/teamsmith-init/SKILL.md +1 -1
@@ -3,31 +3,19 @@
3
3
  //
4
4
  // node skills/teamsmith/tests/panel-strings.mjs [tree]
5
5
  //
6
- // Checks, in order:
7
- // 2. every value is a non-empty string and the `{placeholder}` sets match per key;
8
- // 3. no CJK ideograph survives in the panel sources outside `src/strings/**` (comments are
9
- // stripped first) — visible text comes from the tables, not from literals;
10
- // 4. the contract-key labels (M49): every key of the owning command's schema
11
- // (`skills/teamsmith/scripts/lib/cmd-config.sh`) has a non-empty `label_<KEY>` in **both**
12
- // tables, no label names a key the schema does not carry (no stale half), the label is not
13
- // the key spelled differently, and it fits the row's label column.
14
- // 5. the contract-group labels (P30): the same schema rows' tenth column (`group`) is a closed
15
- // ASCII token, and every token one of them uses has a non-empty `group_<token>` in **both**
16
- // tables while no `group_` label names a token no row uses (both directions).
17
- // 6. the fixture marker is data (P266): the schema rows that carry the declared `fixture-only: `
18
- // marker in their free-text column are read here (the fixture side may read the schema, the
19
- // panel body must not) and the panel sources outside `src/strings/**` must name none of those
20
- // keys and must not mention the owning command's schema at all — the view learns what to hide
21
- // from the read's own `route` payload and never from a baked-in key list (§4.3).
6
+ // Checks: non-empty values and matching placeholders; selected-operation key labels and
7
+ // displayed settings/source references in both languages. Complete CLI schema/group/fixture
8
+ // metadata stays in config-cli.sh; adding an excluded key/group requires no UI label.
9
+ // The inherited source-literal walk below is unchanged by this settings-only change.
22
10
  //
23
11
  // The tables are plain ESM, so they are copied to a temp dir as `.mjs` and imported with the plain
24
12
  // JS runtime this script runs on; no TypeScript loader (or bundler) is involved.
25
13
  //
26
14
  // Exit: 0 all three checks pass, 1 at least one failed (the message names the key/file).
27
15
 
28
- import { copyFileSync, existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs'
16
+ import { copyFileSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs'
29
17
  import { tmpdir } from 'node:os'
30
- import { dirname, join, relative } from 'node:path'
18
+ import { join, relative } from 'node:path'
31
19
  import { pathToFileURL } from 'node:url'
32
20
 
33
21
  const tree = process.argv[2] || process.cwd()
@@ -100,104 +88,24 @@ try {
100
88
  if (hits.length) {
101
89
  }
102
90
 
103
- // 4. The contract-key labels: the schema is the single source of the row set (the view reads it
104
- // at render time), the labels are the row's human identity — so the two must line up exactly,
105
- // in both directions. The assertion is falsifiable by deleting one label (a missing key) or by
106
- // leaving one behind after the schema drops a key (a stale label).
107
- const schemaFile = join(tree, 'skills/teamsmith/scripts/lib/cmd-config.sh')
108
- if (!existsSync(schemaFile)) {
109
- console.log(`skip: ${relative(tree, schemaFile)} is not in this tree (schema-label check not run)`)
110
- } else {
111
- const schemaBody = /^team_config_schema\(\)\s*\{[\s\S]*?\nEOF\n/m.exec(readFileSync(schemaFile, 'utf8'))
112
- const schemaKeys = schemaBody ? [...schemaBody[0].matchAll(/^(TEAM_[A-Z0-9_]+)\|/gm)].map((m) => m[1]) : []
113
- if (!schemaKeys.length) fail(`${relative(tree, schemaFile)}: no schema key parsed from team_config_schema()`)
114
- const LABEL_PREFIX = 'label_'
115
- const labelled = (table) => Object.keys(table).filter((k) => k.startsWith(LABEL_PREFIX)).map((k) => k.slice(LABEL_PREFIX.length))
116
- // The row's label column (`layout.ts` SETTINGS_LABEL_W); a longer label is cut mid-word there.
117
- const cells = (value) => [...String(value)].reduce((n, ch) => n + (/[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff00-\uffef]/.test(ch) ? 2 : 1), 0)
118
- for (const [name, table] of [
119
- ['zh', zh],
120
- ['en', en],
121
- ]) {
122
- const have = new Set(labelled(table))
123
- const missing = schemaKeys.filter((k) => !have.has(k))
124
- if (missing.length) fail(`${name}: no label for schema key(s) [ ${missing.join(', ')} ]`)
91
+ // Selected presentation references replace the retired full-schema/group-label bijection.
92
+ const presentation = readFileSync(join(srcDir, 'project-settings.ts'), 'utf8')
93
+ const keys = [...new Set(presentation.match(/TEAM_[A-Z0-9_]+/g))]
94
+ const body = walk(srcDir).map((file) => stripComments(readFileSync(file, 'utf8'))).join('\n')
95
+ const references = [...new Set([...body.matchAll(/\b(?:s|strings|stringsRef\.current|ctx\.s)\.((?:settings|setting|seatSource)[A-Z]\w*)/g)].map((m) => m[1]))]
96
+ for (const [name, table] of [['zh', zh], ['en', en]]) {
97
+ for (const key of keys) {
98
+ if (!table['label_' + key]) fail(`${name}: missing selected-operation label_${key}`)
125
99
  }
126
- for (const [name, table] of [
127
- ['zh', zh],
128
- ['en', en],
129
- ]) {
130
- for (const key of labelled(table)) {
131
- const label = table[LABEL_PREFIX + key]
132
- if (!schemaKeys.includes(key)) fail(`${name}.${LABEL_PREFIX}${key} names no schema key (stale label)`)
133
- }
134
- }
135
- if (schemaKeys.length) console.log(`ok: contract-key labels — ${schemaKeys.length} schema keys covered in zh and en`)
136
-
137
- // P30/D2: the functional-group bijection. The schema row's tenth column is the only place a
138
- // group token is declared; the visible heading is `group_<token>` in the tables. Both
139
- // directions are failures: a row token with no label (the tables lag the schema) and a label
140
- // no row uses (a stale group). The token's shape is asserted here too, so a malformed tenth
141
- // field is red in the fast gate as well as in config-cli.sh's groups walk.
142
- const GROUP_PREFIX = 'group_'
143
- const GROUP_SHAPE = /^[a-z][a-z0-9-]*$/
144
- const rows = [...(schemaBody ? schemaBody[0].matchAll(/^(TEAM_[A-Z0-9_]+)\|(.+)$/gm) : [])].map((m) => ({
145
- key: m[1],
146
- // Everything after the key: class|kind|spec|form|default|danger|route|suggest|group — the
147
- // tenth column is this array's ninth element (index 8).
148
- fields: m[2].split('|'),
149
- }))
150
- const tokens = new Set()
151
- for (const row of rows) {
152
- const token = String(row.fields[8] ?? '')
153
- if (!token) {
154
- fail(`${row.key}: schema row declares no group (its tenth field is missing) — the tables' group labels cannot line up`)
155
- continue
156
- }
157
- if (!GROUP_SHAPE.test(token)) fail(`${row.key}: group token ${JSON.stringify(token)} does not match ^[a-z][a-z0-9-]*$`)
158
- tokens.add(token)
159
- }
160
- for (const [name, table] of [
161
- ['zh', zh],
162
- ['en', en],
163
- ]) {
164
- for (const token of [...tokens].sort()) {
165
- const value = table[GROUP_PREFIX + token]
166
- if (typeof value !== 'string' || value.length === 0) fail(`${name}: no ${GROUP_PREFIX}${token} label for the group the schema rows carry`)
167
- }
168
- for (const key of Object.keys(table).filter((k) => k.startsWith(GROUP_PREFIX))) {
169
- if (!tokens.has(key.slice(GROUP_PREFIX.length))) fail(`${name}.${key} names no group any schema row uses (stale label)`)
170
- }
171
- }
172
- if (rows.length) console.log(`ok: contract-group labels — ${tokens.size} schema group tokens covered in zh and en`)
173
-
174
- // 6. P266 (panel-plain-language, tasks.md §4.3): the fixture marker is data. This script reads
175
- // the schema (the fixture side may); the panel body — everything but the label tables — must
176
- // not, and must name no marked key: the hiding rule reads the marker off the read's payload.
177
- // Falsifiable by the mutation "hiding is a hardcoded name list" (a name shows up here) or by
178
- // pointing the view at the schema.
179
- const MARKER = 'fixture-only: '
180
- const fixtureKeys = rows.filter((row) => String(row.fields[6] ?? '').startsWith(MARKER)).map((row) => row.key)
181
- if (!fixtureKeys.length) {
182
- fail(`no schema row carries the declared marker ${JSON.stringify(MARKER)} in its route column (memory-and-deps owns it)`)
183
- }
184
- if (!fixtureKeys.length) {
185
- // nothing to cross-check
186
- } else {
187
- const bodyText = walk(srcDir)
188
- .map((file) => stripComments(readFileSync(file, 'utf8')))
189
- .join('\n')
190
- const tokens = ['cmd-config.sh', 'team_config_schema', ...fixtureKeys]
191
- const named = tokens.filter((token) => bodyText.includes(token))
192
- if (named.length) {
193
- fail(
194
- `the panel body names [ ${named.join(', ')} ] — it must read fixture-only keys from the read's \`route\`, not from the schema or a key list`,
195
- )
196
- } else {
197
- console.log(`ok: fixture marker is data — ${fixtureKeys.length} marked key(s), none named in the panel body`)
198
- }
100
+ for (const ref of references) {
101
+ if (!table[ref]) fail(`${name}: missing displayed reference ${ref}`)
199
102
  }
200
103
  }
104
+ for (const key of new Set([...zhKeys, ...enKeys])) {
105
+ if (!(key in zh) || !(key in en)) fail(`${key}: language field missing`)
106
+ }
107
+ console.log(`ok: selected settings references — ${keys.length} key labels; ${references.length} displayed references`)
108
+
201
109
  } finally {
202
110
  rmSync(tmp, { recursive: true, force: true })
203
111
  }
@@ -2,14 +2,44 @@
2
2
  // P444: real SIGKILL injection around Reminder intent/observation and writeAtomic boundaries.
3
3
  // Faults exist only in per-case scratch copies. Recovery always runs the unmodified production helper.
4
4
  import assert from 'node:assert/strict'
5
- import { spawnSync } from 'node:child_process'
6
- import { appendFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
7
- import { dirname, join, resolve } from 'node:path'
5
+ import { spawn, spawnSync } from 'node:child_process'
6
+ import { once } from 'node:events'
7
+ import { cpSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
8
+ import { constants } from 'node:os'
9
+ import { dirname, join } from 'node:path'
8
10
  import { fileURLToPath } from 'node:url'
9
- import { setTimeout as delay } from 'node:timers/promises'
11
+ import { setImmediate as immediate, setTimeout as delay } from 'node:timers/promises'
10
12
 
11
13
  const tests = dirname(fileURLToPath(import.meta.url)), skill = dirname(tests)
12
- const root = mkdtempSync('/var/tmp/p444-remind-faults-'), home = join(root, 'home'), tmp = join(root, 'tmp')
14
+ if (!process.env._P444_WORK) {
15
+ // The owner skips the shell-only fingerprint for a direct driver invocation.
16
+ const owner = spawn('bash', [join(tests, 'remind-adversarial-faults.sh'), ...process.argv.slice(2)], {
17
+ env: { ...process.env, _P444_NODE: process.execPath }, stdio: 'inherit',
18
+ })
19
+ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => owner.kill(signal))
20
+ const [code, signal] = await once(owner, 'exit')
21
+ process.exit(code ?? 128 + constants.signals[signal])
22
+ }
23
+
24
+ let stopSignal
25
+ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { stopSignal ??= signal })
26
+ function checkStop() {
27
+ if (stopSignal) process.exit(128 + constants.signals[stopSignal])
28
+ }
29
+ async function stopPoint() {
30
+ // Give pending signals a poll turn even when returning from a command in a callback.
31
+ await immediate()
32
+ await immediate()
33
+ checkStop()
34
+ }
35
+ async function runSync(bin, args, options) {
36
+ checkStop()
37
+ try { return spawnSync(bin, args, options) }
38
+ finally { await stopPoint() }
39
+ }
40
+
41
+ const root = process.env._P444_WORK, home = join(root, 'home'), tmp = join(root, 'tmp')
42
+ delete process.env._P444_WORK
13
43
  mkdirSync(home, { recursive: true }); mkdirSync(tmp, { recursive: true })
14
44
  const runner = process.execPath, team = join(skill, 'scripts/team'), original = join(skill, 'scripts/state-authority.mjs')
15
45
  const env = { ...process.env, HOME: home, TMPDIR: tmp }
@@ -18,41 +48,42 @@ let passed = 0, failed = 0
18
48
  const stateFile = repo => join(repo, '.pi/team/state/reminders/state.json')
19
49
  const snap = repo => JSON.parse(readFileSync(stateFile(repo), 'utf8'))
20
50
  const lastBatch = repo => snap(repo).batches.at(-1)
21
- const run = (bin, args, options = {}) => {
22
- const result = spawnSync(bin, args, { encoding: 'utf8', env, ...options })
51
+ const run = async (bin, args, options = {}) => {
52
+ const result = await runSync(bin, args, { encoding: 'utf8', env, ...options })
23
53
  assert.equal(result.error, undefined, `${bin}: ${result.error}`)
24
54
  return result
25
55
  }
26
56
  const good = (result, label) => assert.equal(result.status, 0, `${label}: ${result.stdout}${result.stderr}`)
27
- function newRepo(name) {
57
+ async function newRepo(name) {
28
58
  const repo = join(root, name); mkdirSync(repo, { recursive: true })
29
- good(run('git', ['init', '-q', repo]), 'git init')
30
- good(run('git', ['-C', repo, '-c', 'user.name=fixture', '-c', 'user.email=fixture@example.invalid',
59
+ good(await run('git', ['init', '-q', repo]), 'git init')
60
+ good(await run('git', ['-C', repo, '-c', 'user.name=fixture', '-c', 'user.email=fixture@example.invalid',
31
61
  'commit', '-q', '--allow-empty', '-m', 'fixture']), 'git commit')
32
62
  return repo
33
63
  }
34
- function authority(helper, repo, args, label = 'authority') {
35
- const result = run(runner, [helper, '--cli', repo, join(repo, '.pi/team/state'), ...args],
64
+ async function authority(helper, repo, args, label = 'authority') {
65
+ const result = await run(runner, [helper, '--cli', repo, join(repo, '.pi/team/state'), ...args],
36
66
  { cwd: repo, stdio: ['ignore', 'pipe', 'pipe'] })
37
67
  writeFileSync(join(repo, 'last-authority.txt'), (result.stdout ?? '') + (result.stderr ?? ''))
38
68
  return result
39
69
  }
40
- function goodAuthority(helper, repo, args, label) {
41
- const result = authority(helper, repo, args, label)
70
+ async function goodAuthority(helper, repo, args, label) {
71
+ const result = await authority(helper, repo, args, label)
42
72
  good(result, `${label}: ${readFileSync(join(repo, 'last-authority.txt'), 'utf8')}`)
43
73
  return JSON.parse(result.stdout)
44
74
  }
45
- function setup(op, point) {
46
- const repo = newRepo(`${op}-${point}`)
47
- const add = run('bash', [team, '--root', repo, 'remind', 'add', '--after', '1s', '--message', `P444 ${op} ${point}`], { cwd: repo })
75
+ async function setup(op, point) {
76
+ const repo = await newRepo(`${op}-${point}`)
77
+ const add = await run('bash', [team, '--root', repo, 'remind', 'add', '--after', '1s', '--message', `P444 ${op} ${point}`], { cwd: repo })
48
78
  good(add, 'real one-second Reminder create')
49
- goodAuthority(original, repo, ['standby-on', '--reason', 'G1', '--json'], 'G1')
79
+ await goodAuthority(original, repo, ['standby-on', '--reason', 'G1', '--json'], 'G1')
50
80
  return repo
51
81
  }
52
82
  async function admit(repo) {
53
83
  await delay(1100) // Real due time; the fixture never rewrites a clock or a callback timestamp.
84
+ await stopPoint()
54
85
  const started = new Date(Date.now() - 10000).toISOString()
55
- const result = run(runner, [join(skill, 'scripts/remind-tick.mjs'), '--root', repo, '--state-dir', join(repo, '.pi/team/state'),
86
+ const result = await run(runner, [join(skill, 'scripts/remind-tick.mjs'), '--root', repo, '--state-dir', join(repo, '.pi/team/state'),
56
87
  '--pulse-started', started, '--json'], { cwd: repo, stdio: ['ignore', 'pipe', 'pipe'] })
57
88
  good(result, `due admission: ${result.stdout}${result.stderr}`)
58
89
  assert.equal(snap(repo).reminders[0].phase, 'queued')
@@ -99,13 +130,13 @@ function p444Fault(point, op, value) {
99
130
  return join(dir, 'state-authority.mjs')
100
131
  }
101
132
  async function runCase(op, point) {
102
- const repo = setup(op, point)
103
- await admit(repo)
104
- const intent = op === 'remind-intent' ? null : makeIntent(repo)
133
+ const repo = await setup(op, point)
134
+ await admit(repo) // runSync has yielded and checked for stop before the next write or injection.
135
+ const intent = op === 'remind-intent' ? null : await makeIntent(repo)
105
136
  const helper = faultyHelper(op, point), mark = join(repo, 'fault-mark.txt')
106
137
  const requestEnv = { ...env, P444_FAULT_OP: op, P444_KILL_POINT: point, P444_FAULT_MARK: mark }
107
138
  const args = op === 'remind-intent' ? ['remind-intent', '--session', 'p444-session', '--pid', '4242'] : observeArgs(intent)
108
- const result = spawnSync(runner, [helper, '--cli', repo, join(repo, '.pi/team/state'), ...args],
139
+ const result = await runSync(runner, [helper, '--cli', repo, join(repo, '.pi/team/state'), ...args],
109
140
  { cwd: repo, env: requestEnv, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
110
141
  assert.notEqual(result.status, 0, `${op} ${point}: injected process must die`)
111
142
  assert.equal(readFileSync(mark, 'utf8').trim(), point, `${op} ${point}: exact death point reached`)
@@ -114,12 +145,12 @@ async function runCase(op, point) {
114
145
  if (op === 'remind-intent') {
115
146
  if (committed) {
116
147
  assert.equal(current.batches.length, 1); assert.equal(current.reminders[0].phase, 'intent')
117
- const recovered = goodAuthority(original, repo, args, 'restart with original helper')
148
+ const recovered = await goodAuthority(original, repo, args, 'restart with original helper')
118
149
  assert.equal(recovered.action, 'wait', 'a durable intent is not sendable again after restart')
119
150
  assert.equal(snap(repo).batches.length, 1)
120
151
  } else {
121
152
  assert.equal(current.batches.length, 0); assert.equal(current.reminders[0].phase, 'queued')
122
- const recovered = goodAuthority(original, repo, args, 'restart with original helper')
153
+ const recovered = await goodAuthority(original, repo, args, 'restart with original helper')
123
154
  assert.equal(recovered.action, 'send', 'a pre-intent crash remains eligible once')
124
155
  assert.equal(snap(repo).batches.length, 1)
125
156
  }
@@ -134,9 +165,9 @@ async function runCase(op, point) {
134
165
  assert.equal(current.standby.on, true); assert.equal(current.batches[0].right, 'unspent')
135
166
  assert.equal(current.audit.filter(entry => entry.op === 'remind-observed').length, 0)
136
167
  }
137
- goodAuthority(original, repo, ['standby-off', '--json'], 'manual off before fresh G2')
138
- goodAuthority(original, repo, ['standby-on', '--reason', 'fresh G2', '--json'], 'fresh G2')
139
- const replay = goodAuthority(original, repo, observeArgs(intent), 'original-helper replay')
168
+ await goodAuthority(original, repo, ['standby-off', '--json'], 'manual off before fresh G2')
169
+ await goodAuthority(original, repo, ['standby-on', '--reason', 'fresh G2', '--json'], 'fresh G2')
170
+ const replay = await goodAuthority(original, repo, observeArgs(intent), 'original-helper replay')
140
171
  assert.equal(replay.outcome, committed ? 'duplicate' : 'observed')
141
172
  assert.equal(replay.standby, committed ? undefined : 'generation-ambiguous')
142
173
  current = snap(repo)
@@ -148,16 +179,12 @@ async function runCase(op, point) {
148
179
  }
149
180
 
150
181
  const points = ['before-apply', 'after-apply', 'before-file-fsync', 'after-file-fsync', 'after-rename', 'after-dir-fsync']
151
- try {
152
- const lock = run('flock', ['--version'])
153
- assert.equal(lock.status, 0, 'flock is required; missing evidence is a failure, not SKIP')
154
- for (const op of ['remind-intent', 'remind-observe']) for (const point of points) {
155
- try { await runCase(op, point); console.log(`FAULT PASS ${op} ${point}`); passed++ }
156
- catch (error) { console.error(`FAULT FAIL ${op} ${point}: ${error.stack}`); failed++ }
157
- }
158
- } finally {
159
- if (process.env.P444_KEEP) console.log(`kept fault evidence=${root}`)
160
- else rmSync(root, { recursive: true, force: true })
182
+ const lock = await run('flock', ['--version'])
183
+ assert.equal(lock.status, 0, 'flock is required; missing evidence is a failure, not SKIP')
184
+ for (const op of ['remind-intent', 'remind-observe']) for (const point of points) {
185
+ try { await runCase(op, point); await stopPoint(); console.log(`FAULT PASS ${op} ${point}`); passed++ }
186
+ catch (error) { await stopPoint(); console.error(`FAULT FAIL ${op} ${point}: ${error.stack}`); failed++ }
161
187
  }
188
+ await stopPoint()
162
189
  console.log(`fault-matrix: passed=${passed} failed=${failed}`)
163
190
  if (failed) process.exitCode = 1
@@ -5,18 +5,70 @@ HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
5
  SKILL="$(cd -P "$HERE/.." && pwd)"
6
6
  # shellcheck source=lib/main-team-fingerprint.sh
7
7
  . "$HERE/lib/main-team-fingerprint.sh"
8
- # shellcheck source=../scripts/lib/common.sh
9
- . "$SKILL/scripts/lib/common.sh"
10
- REAL_MAIN="$(main_team_project_root "$SKILL")"
11
- STAMP="$(main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team")"
12
- BEFORE="$(mktemp "$(team_tmp_root)/.teamsmith-p444-fault-before.XXXXXX")" || exit 3
13
- AFTER="$(mktemp "$(team_tmp_root)/.teamsmith-p444-fault-after.XXXXXX")" || { rm -f "$BEFORE"; exit 3; }
14
- printf '%s\n' "$STAMP" >"$BEFORE"
15
- node "$HERE/remind-adversarial-faults.mjs" "$@"
16
- RC=$?
17
- main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$AFTER"
18
- VIOL="$(main_team_violations "$BEFORE" "$AFTER")"
19
- rm -f "$BEFORE" "$AFTER"
8
+ # shellcheck source=lib/tmp-root.sh
9
+ . "$HERE/lib/tmp-root.sh"
10
+
11
+ ROOT= DRIVER= DRIVER_START=unknown STOP=
12
+ cleanup() {
13
+ local rc=$?
14
+ trap '' INT TERM
15
+ if [[ -n "$DRIVER" ]]; then
16
+ # Let the tracked driver finish its active synchronous command before reclaiming the work.
17
+ if [[ "$DRIVER_START" != unknown ]] && _tmp_root_proc_alive "$DRIVER" "$DRIVER_START"; then
18
+ kill -TERM "$DRIVER"
19
+ fi
20
+ # The stopped driver may return nonzero; preserve the owner's result.
21
+ wait "$DRIVER" || :
22
+ fi
23
+ if [[ -n "$ROOT" ]]; then
24
+ if [[ "$TEAM_TMP_KEEP" == 1 ]]; then printf 'kept fault evidence=%s\n' "$ROOT"; fi
25
+ # The driver has exited; the helper must not signal the former PID.
26
+ rm -f -- "$TMP_ROOT_PIDFILE" || exit "$((rc == 0 ? 3 : rc))"
27
+ tmp_root_reap_all
28
+ fi
29
+ exit "$rc"
30
+ }
31
+ trap cleanup EXIT
32
+ # Don't enter cleanup between starting a child and recording its identity.
33
+ trap 'STOP=${STOP:-130}' INT
34
+ trap 'STOP=${STOP:-143}' TERM
35
+
36
+ TEAM_TMP_KEEP=0
37
+ if [[ -n "${P444_KEEP:-}" ]]; then TEAM_TMP_KEEP=1; fi
38
+ ROOT="$(tmp_root_create remind-faults)" || exit 3
39
+ printf 'remind-adversarial-faults: work=%s %s\n' "$ROOT" "$(team_tmp_root_note)"
40
+ TMP_ROOT_PIDFILE="$ROOT/.driver.pid"
41
+
42
+ # A direct Node invocation uses the same lifetime without the shell entry's fingerprint.
43
+ DIRECT_NODE="${_P444_NODE:-}"
44
+ unset _P444_NODE
45
+ if [[ -z "$DIRECT_NODE" ]]; then
46
+ REAL_MAIN="$(main_team_project_root "$SKILL")"
47
+ BEFORE="$ROOT/.main-before"
48
+ AFTER="$ROOT/.main-after"
49
+ main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$BEFORE" || exit 3
50
+ fi
51
+
52
+ [[ -z "$STOP" ]] || exit "$STOP"
53
+ _P444_WORK="$ROOT" "${DIRECT_NODE:-node}" "$HERE/remind-adversarial-faults.mjs" "$@" <&0 &
54
+ DRIVER=$!
55
+ if ! DRIVER_START="$(_tmp_root_proc_start "$DRIVER")"; then
56
+ # A child that has already exited has no live identity to record.
57
+ DRIVER_START=unknown
58
+ else
59
+ tmp_root_track_pid "$DRIVER" remind-fault-driver || exit 3
60
+ fi
61
+ trap 'exit 130' INT
62
+ trap 'exit 143' TERM
63
+ [[ -z "$STOP" ]] || exit "$STOP"
64
+ RC=0
65
+ wait "$DRIVER" || RC=$?
66
+ DRIVER=
67
+ [[ -z "$DIRECT_NODE" ]] || exit "$RC"
68
+
69
+ main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$AFTER" || exit 3
70
+ VIOL="$(main_team_violations "$BEFORE" "$AFTER")" || exit 3
71
+ rm -f -- "$BEFORE" "$AFTER" || exit 3
20
72
  if [ -n "$VIOL" ]; then
21
73
  printf 'remind-adversarial-faults: 主项目 .pi/team 出现非白名单变化:%s\n' "$VIOL" >&2
22
74
  RC=1
@@ -5,23 +5,24 @@ HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
5
  SKILL="$(cd -P "$HERE/.." && pwd)"
6
6
  # shellcheck source=lib/main-team-fingerprint.sh
7
7
  . "$HERE/lib/main-team-fingerprint.sh"
8
- # shellcheck source=../scripts/lib/common.sh
9
- . "$SKILL/scripts/lib/common.sh"
8
+ # shellcheck source=remind-tool-real.sh
9
+ . "$HERE/remind-tool-real.sh"
10
+
11
+ remind_tool_real_prepare || exit $?
10
12
  REAL_MAIN="$(main_team_project_root "$SKILL")"
11
- STAMP="$(main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team")"
12
- BEFORE="$(mktemp "$(team_tmp_root)/.teamsmith-p444-real-before.XXXXXX")" || exit 3
13
- AFTER="$(mktemp "$(team_tmp_root)/.teamsmith-p444-real-after.XXXXXX")" || { rm -f "$BEFORE"; exit 3; }
14
- printf '%s\n' "$STAMP" >"$BEFORE"
15
- export P442_EVIDENCE="${P442_EVIDENCE:-$(mktemp -d "$(team_tmp_root)/teamsmith-p444-real-evidence-$(team_project_ns).XXXXXX")}"
16
- node "$HERE/remind-tool-real.mjs" --select=adversarial,death "$@"
13
+ BEFORE="$remind_root/.main-before"
14
+ AFTER="$remind_root/.main-after"
15
+ main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$BEFORE" || exit 3
16
+ remind_tool_real_run --select=adversarial,death "$@"
17
17
  RC=$?
18
- main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$AFTER"
19
- VIOL="$(main_team_violations "$BEFORE" "$AFTER")"
20
- rm -f "$BEFORE" "$AFTER"
18
+ # Setup errors also return through the owner's EXIT cleanup.
19
+ main_team_snapshot "${REAL_MAIN:-/nonexistent}/.pi/team" >"$AFTER" || exit 3
20
+ VIOL="$(main_team_violations "$BEFORE" "$AFTER")" || exit 3
21
+ rm -f -- "$BEFORE" "$AFTER" || exit 3
21
22
  if [ -n "$VIOL" ]; then
22
23
  printf 'remind-adversarial-real: 主项目 .pi/team 出现非白名单变化:%s\n' "$VIOL" >&2
23
24
  RC=1
24
25
  elif [ "$RC" -eq 0 ]; then
25
- printf 'remind-adversarial-real: isolation=ok evidence=%s\n' "$P442_EVIDENCE"
26
+ printf 'remind-adversarial-real: isolation=ok evidence=%s\n' "$remind_evidence"
26
27
  fi
27
28
  exit "$RC"