teamsmith 0.4.6 → 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 (91) hide show
  1. package/README.md +6 -6
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +35 -0
  4. package/skills/teamsmith/SKILL.md +43 -30
  5. package/skills/teamsmith/extension/team-bg.ts +5 -3
  6. package/skills/teamsmith/extension/team-inbox-watch.ts +14 -3
  7. package/skills/teamsmith/extension/team-notify.ts +20 -13
  8. package/skills/teamsmith/extension/team-remind.ts +189 -0
  9. package/skills/teamsmith/extension/team-reply.ts +4 -7
  10. package/skills/teamsmith/references/config.md +11 -12
  11. package/skills/teamsmith/references/migration.md +101 -0
  12. package/skills/teamsmith/references/openspec.md +43 -27
  13. package/skills/teamsmith/references/protocol.md +26 -15
  14. package/skills/teamsmith/references/reminders.md +153 -161
  15. package/skills/teamsmith/references/troubleshooting.md +12 -7
  16. package/skills/teamsmith/references/workflows.md +84 -31
  17. package/skills/teamsmith/scripts/lib/cmd-agents.sh +10 -4
  18. package/skills/teamsmith/scripts/lib/cmd-project.sh +88 -6
  19. package/skills/teamsmith/scripts/lib/cmd-remind.sh +88 -2
  20. package/skills/teamsmith/scripts/lib/cmd-review.sh +61 -35
  21. package/skills/teamsmith/scripts/lib/cmd-watch.sh +48 -11
  22. package/skills/teamsmith/scripts/lib/common.sh +83 -13
  23. package/skills/teamsmith/scripts/panel/README.md +35 -33
  24. package/skills/teamsmith/scripts/panel/panel.js +217 -199
  25. package/skills/teamsmith/scripts/panel/src/App.tsx +221 -66
  26. package/skills/teamsmith/scripts/panel/src/data.ts +71 -15
  27. package/skills/teamsmith/scripts/panel/src/layout.ts +159 -310
  28. package/skills/teamsmith/scripts/panel/src/main.tsx +83 -21
  29. package/skills/teamsmith/scripts/panel/src/project-settings.ts +46 -0
  30. package/skills/teamsmith/scripts/panel/src/strings/en.ts +71 -205
  31. package/skills/teamsmith/scripts/panel/src/strings/index.ts +3 -5
  32. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +72 -204
  33. package/skills/teamsmith/scripts/panel/src/types.ts +23 -4
  34. package/skills/teamsmith/scripts/remind-capability.mjs +261 -0
  35. package/skills/teamsmith/scripts/remind-store.mjs +55 -24
  36. package/skills/teamsmith/scripts/remind-tick.mjs +5 -2
  37. package/skills/teamsmith/scripts/reply-capture.mjs +8 -9
  38. package/skills/teamsmith/scripts/state-authority.mjs +72 -6
  39. package/skills/teamsmith/scripts/strings/commands.tsv +1 -1
  40. package/skills/teamsmith/scripts/team +1 -0
  41. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +18 -8
  42. package/skills/teamsmith/templates/DECISIONS.md.tmpl +2 -2
  43. package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +3 -3
  44. package/skills/teamsmith/templates/PROTOCOL.md.tmpl +19 -14
  45. package/skills/teamsmith/templates/memory-seed.md.tmpl +2 -2
  46. package/skills/teamsmith/templates/pm-prompt.md.tmpl +41 -25
  47. package/skills/teamsmith/templates/report.md.tmpl +33 -0
  48. package/skills/teamsmith/tests/bg-ledger-harness.mjs +217 -33
  49. package/skills/teamsmith/tests/bg-ledger.sh +24 -10
  50. package/skills/teamsmith/tests/checkout-shape-probe.sh +7 -6
  51. package/skills/teamsmith/tests/fixtures/remind-adversarial-delay.ts +27 -0
  52. package/skills/teamsmith/tests/fixtures/remind-tool-provider.ts +65 -0
  53. package/skills/teamsmith/tests/help-surface.sh +78 -12
  54. package/skills/teamsmith/tests/install-shape.sh +7 -7
  55. package/skills/teamsmith/tests/isolation-ledger.sh +6 -2
  56. package/skills/teamsmith/tests/key-replies-ui.sh +64 -5
  57. package/skills/teamsmith/tests/key-replies.sh +307 -106
  58. package/skills/teamsmith/tests/lib/main-team-fingerprint.sh +2 -0
  59. package/skills/teamsmith/tests/lib/model-routing-boundary.sh +255 -90
  60. package/skills/teamsmith/tests/lib/model-routing-expansion.sh +181 -61
  61. package/skills/teamsmith/tests/lib/model-routing-roles.sh +125 -67
  62. package/skills/teamsmith/tests/lib/reply-fixture.sh +14 -9
  63. package/skills/teamsmith/tests/lib/routes-pages.sh +243 -0
  64. package/skills/teamsmith/tests/lib/tmp-root.sh +1 -1
  65. package/skills/teamsmith/tests/loop-inventory.tsv +3 -0
  66. package/skills/teamsmith/tests/panel-b2.sh +91 -31
  67. package/skills/teamsmith/tests/panel-b3-stub.sh +9 -2
  68. package/skills/teamsmith/tests/panel-p21.sh +607 -1162
  69. package/skills/teamsmith/tests/panel-strings.mjs +21 -113
  70. package/skills/teamsmith/tests/remind-adversarial-faults.mjs +190 -0
  71. package/skills/teamsmith/tests/remind-adversarial-faults.sh +78 -0
  72. package/skills/teamsmith/tests/remind-adversarial-real.sh +28 -0
  73. package/skills/teamsmith/tests/remind-cli.sh +108 -3
  74. package/skills/teamsmith/tests/remind-delivery-node.mjs +13 -0
  75. package/skills/teamsmith/tests/remind-delivery.sh +123 -35
  76. package/skills/teamsmith/tests/remind-lifecycle.sh +197 -0
  77. package/skills/teamsmith/tests/remind-pulse.sh +199 -0
  78. package/skills/teamsmith/tests/remind-recovery-real.sh +5 -0
  79. package/skills/teamsmith/tests/remind-recovery-unit.sh +118 -0
  80. package/skills/teamsmith/tests/remind-tool-node.mjs +159 -0
  81. package/skills/teamsmith/tests/remind-tool-real.mjs +801 -0
  82. package/skills/teamsmith/tests/remind-tool-real.sh +180 -0
  83. package/skills/teamsmith/tests/reply-capture-real.mjs +93 -2
  84. package/skills/teamsmith/tests/routes.sh +213 -293
  85. package/skills/teamsmith/tests/section-paths.tsv +19 -17
  86. package/skills/teamsmith/tests/smoke.sh +583 -133
  87. package/skills/teamsmith/tests/state-authority.sh +152 -8
  88. package/skills/teamsmith/tests/task-model-routing.sh +57 -26
  89. package/skills/teamsmith/tests/tmp-hygiene.sh +1 -1
  90. package/skills/teamsmith-init/SKILL.md +5 -5
  91. package/skills/teamsmith/tests/fixtures/delivery-truth-real/__pycache__/judge-second.cpython-313.pyc +0 -0
@@ -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
  }
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env node
2
+ // P444: real SIGKILL injection around Reminder intent/observation and writeAtomic boundaries.
3
+ // Faults exist only in per-case scratch copies. Recovery always runs the unmodified production helper.
4
+ import assert from 'node:assert/strict'
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'
10
+ import { fileURLToPath } from 'node:url'
11
+ import { setImmediate as immediate, setTimeout as delay } from 'node:timers/promises'
12
+
13
+ const tests = dirname(fileURLToPath(import.meta.url)), skill = dirname(tests)
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
43
+ mkdirSync(home, { recursive: true }); mkdirSync(tmp, { recursive: true })
44
+ const runner = process.execPath, team = join(skill, 'scripts/team'), original = join(skill, 'scripts/state-authority.mjs')
45
+ const env = { ...process.env, HOME: home, TMPDIR: tmp }
46
+ for (const key of Object.keys(env)) if (key.startsWith('TEAM_') || key === 'TMUX' || key === 'TMUX_PANE') delete env[key]
47
+ let passed = 0, failed = 0
48
+ const stateFile = repo => join(repo, '.pi/team/state/reminders/state.json')
49
+ const snap = repo => JSON.parse(readFileSync(stateFile(repo), 'utf8'))
50
+ const lastBatch = repo => snap(repo).batches.at(-1)
51
+ const run = async (bin, args, options = {}) => {
52
+ const result = await runSync(bin, args, { encoding: 'utf8', env, ...options })
53
+ assert.equal(result.error, undefined, `${bin}: ${result.error}`)
54
+ return result
55
+ }
56
+ const good = (result, label) => assert.equal(result.status, 0, `${label}: ${result.stdout}${result.stderr}`)
57
+ async function newRepo(name) {
58
+ const repo = join(root, name); mkdirSync(repo, { recursive: true })
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',
61
+ 'commit', '-q', '--allow-empty', '-m', 'fixture']), 'git commit')
62
+ return repo
63
+ }
64
+ async function authority(helper, repo, args, label = 'authority') {
65
+ const result = await run(runner, [helper, '--cli', repo, join(repo, '.pi/team/state'), ...args],
66
+ { cwd: repo, stdio: ['ignore', 'pipe', 'pipe'] })
67
+ writeFileSync(join(repo, 'last-authority.txt'), (result.stdout ?? '') + (result.stderr ?? ''))
68
+ return result
69
+ }
70
+ async function goodAuthority(helper, repo, args, label) {
71
+ const result = await authority(helper, repo, args, label)
72
+ good(result, `${label}: ${readFileSync(join(repo, 'last-authority.txt'), 'utf8')}`)
73
+ return JSON.parse(result.stdout)
74
+ }
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 })
78
+ good(add, 'real one-second Reminder create')
79
+ await goodAuthority(original, repo, ['standby-on', '--reason', 'G1', '--json'], 'G1')
80
+ return repo
81
+ }
82
+ async function admit(repo) {
83
+ await delay(1100) // Real due time; the fixture never rewrites a clock or a callback timestamp.
84
+ await stopPoint()
85
+ const started = new Date(Date.now() - 10000).toISOString()
86
+ const result = await run(runner, [join(skill, 'scripts/remind-tick.mjs'), '--root', repo, '--state-dir', join(repo, '.pi/team/state'),
87
+ '--pulse-started', started, '--json'], { cwd: repo, stdio: ['ignore', 'pipe', 'pipe'] })
88
+ good(result, `due admission: ${result.stdout}${result.stderr}`)
89
+ assert.equal(snap(repo).reminders[0].phase, 'queued')
90
+ }
91
+ function makeIntent(repo) {
92
+ return goodAuthority(original, repo, ['remind-intent', '--session', 'p444-session', '--pid', '4242'], 'original intent')
93
+ }
94
+ function observeArgs(intent) {
95
+ return ['remind-observe', '--id', intent.batch.id, '--nonce', intent.batch.nonce,
96
+ '--session', 'p444-session', '--members', JSON.stringify(intent.batch.members)]
97
+ }
98
+ function faultyHelper(op, point) {
99
+ const dir = join(root, `helper-${op}-${point}`); mkdirSync(dir, { recursive: true })
100
+ cpSync(original, join(dir, 'state-authority.mjs')); cpSync(join(skill, 'scripts/remind-store.mjs'), join(dir, 'remind-store.mjs'))
101
+ const file = join(dir, 'state-authority.mjs'), source = readFileSync(file, 'utf8')
102
+ const fault = `
103
+ function p444Fault(point, op, value) {
104
+ if (process.env.P444_KILL_POINT !== point || process.env.P444_FAULT_OP !== op) return;
105
+ if (value) {
106
+ const auditOp = op === 'remind-intent' ? 'remind-intent' : 'remind-observed';
107
+ if (!value.audit?.some(entry => entry.op === auditOp)) return;
108
+ }
109
+ fs.appendFileSync(process.env.P444_FAULT_MARK, point + '\\n');
110
+ process.kill(process.pid, 'SIGKILL');
111
+ }
112
+ `
113
+ const atomicAnchor = 'function writeAtomic(file, value) {'
114
+ assert.equal(source.split(atomicAnchor).length, 2, 'writeAtomic injection anchor')
115
+ let changed = source.replace(atomicAnchor, `${fault}\n${atomicAnchor}`)
116
+ const anchors = [
117
+ [" const before = JSON.stringify(snapshot);", " p444Fault('before-apply', request.op, null);\n const before = JSON.stringify(snapshot);"],
118
+ [" const result = apply(snapshot, request, Date.now(), state);", " const result = apply(snapshot, request, Date.now(), state);\n p444Fault('after-apply', request.op, snapshot);"],
119
+ [" fs.writeFileSync(fd, JSON.stringify(value) + '\\n', 'utf8');", " fs.writeFileSync(fd, JSON.stringify(value) + '\\n', 'utf8');\n p444Fault('before-file-fsync', request.op, value);"],
120
+ [" fs.fsyncSync(fd);", " fs.fsyncSync(fd);\n p444Fault('after-file-fsync', request.op, value);"],
121
+ [" fs.renameSync(tmp, file);\n fsyncDir(dir);", " fs.renameSync(tmp, file);\n p444Fault('after-rename', request.op, value);\n fsyncDir(dir);\n p444Fault('after-dir-fsync', request.op, value);"],
122
+ ]
123
+ for (const [oldText, newText] of anchors) {
124
+ assert.equal(changed.split(oldText).length, 2, `fault anchor ${oldText}`)
125
+ changed = changed.replace(oldText, newText)
126
+ }
127
+ // writeAtomic has no request parameter; the scratch-only shim receives the selected operation via env.
128
+ changed = changed.replaceAll('request.op, value', 'process.env.P444_FAULT_OP, value')
129
+ writeFileSync(file, changed)
130
+ return join(dir, 'state-authority.mjs')
131
+ }
132
+ async function runCase(op, point) {
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)
136
+ const helper = faultyHelper(op, point), mark = join(repo, 'fault-mark.txt')
137
+ const requestEnv = { ...env, P444_FAULT_OP: op, P444_KILL_POINT: point, P444_FAULT_MARK: mark }
138
+ const args = op === 'remind-intent' ? ['remind-intent', '--session', 'p444-session', '--pid', '4242'] : observeArgs(intent)
139
+ const result = await runSync(runner, [helper, '--cli', repo, join(repo, '.pi/team/state'), ...args],
140
+ { cwd: repo, env: requestEnv, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
141
+ assert.notEqual(result.status, 0, `${op} ${point}: injected process must die`)
142
+ assert.equal(readFileSync(mark, 'utf8').trim(), point, `${op} ${point}: exact death point reached`)
143
+ const committed = point === 'after-rename' || point === 'after-dir-fsync'
144
+ let current = snap(repo)
145
+ if (op === 'remind-intent') {
146
+ if (committed) {
147
+ assert.equal(current.batches.length, 1); assert.equal(current.reminders[0].phase, 'intent')
148
+ const recovered = await goodAuthority(original, repo, args, 'restart with original helper')
149
+ assert.equal(recovered.action, 'wait', 'a durable intent is not sendable again after restart')
150
+ assert.equal(snap(repo).batches.length, 1)
151
+ } else {
152
+ assert.equal(current.batches.length, 0); assert.equal(current.reminders[0].phase, 'queued')
153
+ const recovered = await goodAuthority(original, repo, args, 'restart with original helper')
154
+ assert.equal(recovered.action, 'send', 'a pre-intent crash remains eligible once')
155
+ assert.equal(snap(repo).batches.length, 1)
156
+ }
157
+ assert.equal(snap(repo).standby.on, true, 'intent and recovery never clear Standby')
158
+ } else {
159
+ if (committed) {
160
+ assert.equal(current.batches[0].phase, 'observed'); assert.equal(current.reminders[0].phase, 'observed')
161
+ assert.equal(current.standby.on, false); assert.equal(current.batches[0].rightSpentBy, 'wake')
162
+ assert.equal(current.audit.filter(entry => entry.op === 'remind-observed').length, 1)
163
+ } else {
164
+ assert.equal(current.batches[0].phase, 'intent'); assert.equal(current.reminders[0].phase, 'intent')
165
+ assert.equal(current.standby.on, true); assert.equal(current.batches[0].right, 'unspent')
166
+ assert.equal(current.audit.filter(entry => entry.op === 'remind-observed').length, 0)
167
+ }
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')
171
+ assert.equal(replay.outcome, committed ? 'duplicate' : 'observed')
172
+ assert.equal(replay.standby, committed ? undefined : 'generation-ambiguous')
173
+ current = snap(repo)
174
+ assert.equal(current.standby.on, true); assert.equal(current.standby.generation, 2)
175
+ assert.equal(current.audit.filter(entry => entry.op === 'remind-observed').length, 1)
176
+ }
177
+ writeFileSync(join(repo, 'recovery-receipt.json'), JSON.stringify({ op, point, committed,
178
+ restart: snap(repo) }, null, 2))
179
+ }
180
+
181
+ const points = ['before-apply', 'after-apply', 'before-file-fsync', 'after-file-fsync', 'after-rename', 'after-dir-fsync']
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++ }
187
+ }
188
+ await stopPoint()
189
+ console.log(`fault-matrix: passed=${passed} failed=${failed}`)
190
+ if (failed) process.exitCode = 1
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env bash
2
+ # P444: real process-death injection around intent/observation atomic commits.
3
+ set -uo pipefail
4
+ HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+ SKILL="$(cd -P "$HERE/.." && pwd)"
6
+ # shellcheck source=lib/main-team-fingerprint.sh
7
+ . "$HERE/lib/main-team-fingerprint.sh"
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
72
+ if [ -n "$VIOL" ]; then
73
+ printf 'remind-adversarial-faults: 主项目 .pi/team 出现非白名单变化:%s\n' "$VIOL" >&2
74
+ RC=1
75
+ elif [ "$RC" -eq 0 ]; then
76
+ printf 'remind-adversarial-faults: isolation=ok\n'
77
+ fi
78
+ exit "$RC"
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+ # P444: private real Pi/tmux controlled-model event, replay and process-death acceptance.
3
+ set -uo pipefail
4
+ HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+ SKILL="$(cd -P "$HERE/.." && pwd)"
6
+ # shellcheck source=lib/main-team-fingerprint.sh
7
+ . "$HERE/lib/main-team-fingerprint.sh"
8
+ # shellcheck source=remind-tool-real.sh
9
+ . "$HERE/remind-tool-real.sh"
10
+
11
+ remind_tool_real_prepare || exit $?
12
+ REAL_MAIN="$(main_team_project_root "$SKILL")"
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
+ RC=$?
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
22
+ if [ -n "$VIOL" ]; then
23
+ printf 'remind-adversarial-real: 主项目 .pi/team 出现非白名单变化:%s\n' "$VIOL" >&2
24
+ RC=1
25
+ elif [ "$RC" -eq 0 ]; then
26
+ printf 'remind-adversarial-real: isolation=ok evidence=%s\n' "$remind_evidence"
27
+ fi
28
+ exit "$RC"
@@ -36,7 +36,7 @@ for arg in "$@"; do
36
36
  case "$arg" in
37
37
  --flip=*)
38
38
  case "${arg#--flip=}" in
39
- view-stored|no-prune|highwater-lax|past-time|key-conflict-gone) FLIPS+=("${arg#--flip=}") ;;
39
+ view-stored|no-prune|highwater-lax|past-time|key-conflict-gone|key-not-released|no-key-dedup|json-refusal) FLIPS+=("${arg#--flip=}") ;;
40
40
  *) printf 'remind-cli:不认识的 --flip 值 [%s]\n' "${arg#--flip=}" >&2; exit 2 ;;
41
41
  esac ;;
42
42
  -h|--help) sed -n '2,26p' "$0"; exit 0 ;;
@@ -187,6 +187,11 @@ printf 'first line — 中文 100%%\nsecond line\n\n' > "$ROOT/msg/full.txt"
187
187
  FULL_BYTES="$(wc -c < "$ROOT/msg/full.txt" | tr -d ' ')"
188
188
  printf 'line one\nline two\n' > "$ROOT/msg/two.txt"
189
189
  printf 'probe text\n' > "$ROOT/msg/x.txt"
190
+ python3 - "$ROOT/msg/large.txt" <<'PY'
191
+ import sys
192
+ with open(sys.argv[1], 'wb') as f:
193
+ f.write(b'x' * (64 * 1024) + b'\n')
194
+ PY
190
195
  : > "$ROOT/msg/empty.txt"
191
196
  : > "$ROOT/msg/none"
192
197
  printf 'a\000b' > "$ROOT/msg/nul.bin"
@@ -252,6 +257,42 @@ assert_has "A list:取消后计数跟着变(cancelled=1,只剩 2099 那条
252
257
  "视图 scheduled=1 derived-due=0 queued=0 intent=0 observed=0 unknown=0 cancelled=1 resolved=0"
253
258
  assert_has "A list:取消的那条仍在保留的终结历史里" "$(cat "$ROOT/out/a7.txt")" "另有 1 条已终结"
254
259
 
260
+ # 无额度:100 条活跃记录 + 最近一分钟 20 次创建之后,1 秒延迟与 64 KiB 全文仍然合法。
261
+ Q="$(new_repo Q)" || { bad "夹具建不出仓库 Q"; result; exit 1; }
262
+ run_team "$Q" "$ROOT/msg/none" "$ROOT/out/q0.txt" remind add --after 2h --message seed
263
+ [ "$RC" = "0" ] || bad "Q 夹具:种子提醒没建成($(head -1 "$ROOT/out/q0.txt"))"
264
+ cat > "$ROOT/script/q-fill.mjs" <<'JS'
265
+ snap.reminders = Array.from({ length: 100 }, (_, index) => ({
266
+ id: 'rem-' + snap.project.id + '-' + (index + 1), seq: index + 1, owner: 'pm', source: 'cli', task: null, key: null,
267
+ phase: 'scheduled', createdAt: new Date().toISOString(), request: { form: 'after', value: '2h' },
268
+ dueAt: new Date(Date.now() + 7200000).toISOString(), message: 'active ' + (index + 1), endedAt: null,
269
+ }));
270
+ snap.sequences.reminder = 101;
271
+ snap.audit = Array.from({ length: 20 }, () => ({ at: new Date().toISOString(), op: 'remind-add', ids: ['recent'], source: 'cli' }));
272
+ JS
273
+ edit_snapshot "$Q" "$ROOT/script/q-fill.mjs"
274
+ run_team "$Q" "$ROOT/msg/large.txt" "$ROOT/out/q1.txt" remind add --after 1s --message-file "$ROOT/msg/large.txt"
275
+ assert_eq "Q 100 条活跃 + 20 次近期创建后,1s/64KiB 请求仍建成" "$RC" "0"
276
+ Q_ID="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/q1.txt")"
277
+ assert_has "Q 新记录使用第 101 个单调 ID" "$Q_ID" '-101'
278
+ run_team "$Q" "$ROOT/msg/none" "$ROOT/out/q2.txt" remind show "$Q_ID" --json
279
+ if jdump "$ROOT/out/q2.txt" reminder.message "$ROOT/out/q-show-message.txt" \
280
+ && cmp -s "$ROOT/msg/large.txt" "$ROOT/out/q-show-message.txt"; then
281
+ ok "Q show 保留 64 KiB + 末尾换行(65537 字节)"
282
+ else
283
+ bad "Q show 的正文被截断或改写字节"
284
+ fi
285
+ run_team "$Q" "$ROOT/msg/none" "$ROOT/out/q3.txt" remind list --json
286
+ "$RUNNER" -e '
287
+ import fs from "node:fs";
288
+ const result = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
289
+ const record = result.active.find(item => item.id === process.argv[2]);
290
+ if (!record) process.exit(3);
291
+ fs.writeFileSync(process.argv[3], record.message);
292
+ ' "$ROOT/out/q3.txt" "$Q_ID" "$ROOT/out/q-list-message.txt"
293
+ cmp -s "$ROOT/msg/large.txt" "$ROOT/out/q-list-message.txt" \
294
+ && ok "Q list 保留同一份全文与末尾换行" || bad "Q list 的正文与原文不同"
295
+
255
296
  # ---------------------------------------------------------------- B. refusals (each names its reason, writes nothing)
256
297
  B="$(new_repo B)" || { bad "夹具建不出仓库 B"; result; exit 1; }
257
298
  run_team "$B" "$ROOT/msg/none" "$ROOT/out/b0.txt" remind add --after 2h --message seed
@@ -283,6 +324,15 @@ refuse "NUL 正文" "NUL byte" --after 2h --message-file "$ROOT/msg/nul.bin"
283
324
  refuse "非 UTF-8 正文" "not valid UTF-8" --after 2h --message-file "$ROOT/msg/bad.bin"
284
325
  refuse "key 用了非 ASCII" "outside printable ASCII" --after 2h --message-file "$ROOT/msg/x.txt" --key 有中文
285
326
 
327
+ # V150:机器调用方带 --json 时,stdin 解码/NUL 拒绝也必须是结构化结果,不能退回人读行。
328
+ for kind in nul bad; do
329
+ run_team "$B" "$ROOT/msg/none" "$ROOT/out/b-json-$kind.txt" remind add --after 2h --message-file "$ROOT/msg/$kind.bin" --json
330
+ assert_eq "B $kind 的 --json 拒绝:rc=1" "$RC" "1"
331
+ assert_eq "B $kind 的 --json 拒绝:refusal 字段" "$(jfield "$ROOT/out/b-json-$kind.txt" refusal)" "bad-message"
332
+ "$RUNNER" -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$ROOT/out/b-json-$kind.txt" \
333
+ && ok "B $kind 的 --json 拒绝:stdout 是可解析 JSON" || bad "B $kind 的 --json 拒绝混入了人读行"
334
+ done
335
+
286
336
  run_team "$B" "$ROOT/msg/none" "$ROOT/out/b-flag.txt" remind add --after 2h --message x --frobnicate
287
337
  assert_eq "B 未知参数:rc(用法错误)" "$RC" "2"
288
338
  assert_has "B 未知参数:点名该参数" "$(cat "$ROOT/out/b-flag.txt")" "--frobnicate"
@@ -320,6 +370,30 @@ else
320
370
  bad "C 终结后复用 key:没有新建(拿到 [$C_NEW])"
321
371
  fi
322
372
 
373
+ run_team "$C" "$ROOT/msg/none" "$ROOT/out/c6.txt" remind add --after 2h --message "identical without key"
374
+ C_NK1="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/c6.txt")"
375
+ run_team "$C" "$ROOT/msg/none" "$ROOT/out/c7.txt" remind add --after 2h --message "identical without key"
376
+ C_NK2="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/c7.txt")"
377
+ if [ -n "$C_NK1" ] && [ -n "$C_NK2" ] && [ "$C_NK1" != "$C_NK2" ]; then
378
+ ok "C 无 key 的相同正文与时长是两个独立 ID($C_NK1 / $C_NK2)"
379
+ else
380
+ bad "C 无 key 相同请求被错误去重([$C_NK1] / [$C_NK2])"
381
+ fi
382
+
383
+ # observed 也释放 key:下一次同 key 请求是新的单调一次性提醒,而不是全局幂等。
384
+ R="$(new_repo R)" || { bad "夹具建不出仓库 R"; result; exit 1; }
385
+ run_team "$R" "$ROOT/msg/none" "$ROOT/out/r1.txt" remind add --after 2h --message "cycle text" --key cycle
386
+ R_ID="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/r1.txt")"
387
+ printf "const r = snap.reminders.find(item => item.id === '%s'); r.phase = 'observed'; r.endedAt = new Date().toISOString();\n" "$R_ID" > "$ROOT/script/r-observed.mjs"
388
+ edit_snapshot "$R" "$ROOT/script/r-observed.mjs"
389
+ run_team "$R" "$ROOT/msg/none" "$ROOT/out/r2.txt" remind add --after 2h --message "cycle text" --key cycle
390
+ R_NEW="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/r2.txt")"
391
+ if [ -n "$R_NEW" ] && [ "$R_NEW" != "$R_ID" ]; then
392
+ ok "C observed 后同 key 新建:新单调 ID($R_ID → $R_NEW)"
393
+ else
394
+ bad "C observed 后同 key 没有新建([$R_ID] / [$R_NEW])"
395
+ fi
396
+
323
397
  # ---------------------------------------------------------------- D. views are derived, never stored
324
398
  V="$(new_repo V)" || { bad "夹具建不出仓库 V"; result; exit 1; }
325
399
  run_team "$V" "$ROOT/msg/none" "$ROOT/out/d1.txt" remind add --after 2h --message "queued one"
@@ -478,13 +552,18 @@ flip_prepare() { # <id> <helper>
478
552
  mutate "$store" " if (parsed.seq >= highWater) bad(" " if (false) bad(" ;;
479
553
  past-time) mutate "$store" " if (dueMs <= nowMs) {" " if (false) {" ;;
480
554
  key-conflict-gone) mutate "$store" " if (!sameRequest(active, candidate)) {" " if (false) {" ;;
555
+ key-not-released) mutate "$store" "const KEY_HOLDING = new Set(['scheduled', 'queued', 'intent', 'unknown']);" \
556
+ "const KEY_HOLDING = new Set(['scheduled', 'queued', 'intent', 'unknown', 'observed']);" ;;
557
+ no-key-dedup) mutate "$store" " if (key.key) {" " if (true) {" ;;
558
+ json-refusal) mutate "$2" "process.stdout.write(json ? JSON.stringify(refusal, null, 2) + '\\n' : renderRemind(requestData.op, refusal));" \
559
+ "process.stdout.write(renderRemind(requestData.op, refusal));" ;;
481
560
  *) return 1 ;;
482
561
  esac
483
562
  }
484
563
  flip_probe() { # <id> <helper>
485
564
  local id="$1" helper="$2" repo rid out
486
565
  case "$id" in
487
- view-stored|no-prune|highwater-lax|past-time|key-conflict-gone) repo="$(new_repo "flip-$id")" ;;
566
+ view-stored|no-prune|highwater-lax|past-time|key-conflict-gone|key-not-released|no-key-dedup|json-refusal) repo="$(new_repo "flip-$id")" ;;
488
567
  *) return 1 ;;
489
568
  esac
490
569
  case "$id" in
@@ -545,10 +624,36 @@ JS
545
624
  else
546
625
  bad "flip(活跃 key 的不同请求照旧返回):仍然拒绝了(rc=$RC),这条红侧是橡皮章"
547
626
  fi ;;
627
+ key-not-released)
628
+ run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --after 2h --key cycle
629
+ rid="$(sed -n 's/^已创建 \(rem-[^ ]*\) · .*/\1/p' "$ROOT/out/p.txt")"
630
+ printf "const r = snap.reminders.find(item => item.id === '%s'); r.phase = 'observed'; r.endedAt = new Date().toISOString();\n" "$rid" > "$ROOT/script/p-cycle.mjs"
631
+ edit_snapshot "$repo" "$ROOT/script/p-cycle.mjs"
632
+ run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p2.txt" remind-add --after 2h --key cycle --json
633
+ if [ "$(jfield "$ROOT/out/p2.txt" 'reminder.id')" = "$rid" ]; then
634
+ ok "flip(observed 不释放 key):同 key 续建返回旧 ID —— C 的「观察后新 ID」会红"
635
+ else
636
+ bad "flip(observed 不释放 key):仍分配了新 ID,这条红侧是橡皮章"
637
+ fi ;;
638
+ no-key-dedup)
639
+ run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p.txt" remind-add --after 2h
640
+ run_helper "$helper" "$repo" "$ROOT/msg/x.txt" "$ROOT/out/p2.txt" remind-add --after 2h --json
641
+ if [ "$(jfield "$ROOT/out/p2.txt" 'duplicate')" = "true" ]; then
642
+ ok "flip(无 key 也去重):相同正文被合并 —— C 的「两个独立 ID」会红"
643
+ else
644
+ bad "flip(无 key 也去重):仍分配了两个 ID,这条红侧是橡皮章"
645
+ fi ;;
646
+ json-refusal)
647
+ run_helper "$helper" "$repo" "$ROOT/msg/nul.bin" "$ROOT/out/p.txt" remind-add --after 2h --json
648
+ if ! "$RUNNER" -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$ROOT/out/p.txt" 2>/dev/null; then
649
+ ok "flip(--json 拒绝退回人读行):JSON.parse 失败 —— B 的结构化拒绝断言会红"
650
+ else
651
+ bad "flip(--json 拒绝退回人读行):输出仍是 JSON,这条红侧是橡皮章"
652
+ fi ;;
548
653
  esac
549
654
  }
550
655
 
551
- for flip_id in view-stored no-prune highwater-lax past-time key-conflict-gone; do
656
+ for flip_id in view-stored no-prune highwater-lax past-time key-conflict-gone key-not-released no-key-dedup json-refusal; do
552
657
  arm_selected "$flip_id" || continue
553
658
  FLIPS_RUN="${FLIPS_RUN:+$FLIPS_RUN,}$flip_id"
554
659
  if ! helper="$(helper_copy "$flip_id")"; then