instar 1.3.1151 → 1.3.1153
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data/standards-guard-index.json +1 -1
- package/dist/data/standards-guard-index.meta.json +2 -2
- package/dist/data/standards-registry.meta.json +1 -1
- package/package.json +1 -1
- package/scripts/lint-no-unfunneled-tmux-literal-send.js +159 -12
- package/src/data/builtin-manifest.json +2 -2
- package/src/data/standards-guard-index.json +1 -1
- package/src/data/standards-guard-index.meta.json +2 -2
- package/src/data/standards-registry.meta.json +1 -1
- package/upgrades/1.3.1152.md +54 -0
- package/upgrades/1.3.1153.md +62 -0
- package/upgrades/side-effects/atomic-writes-method-scope.md +152 -0
- package/upgrades/side-effects/tmux-send-lint-array-scope.md +122 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"generatedFrom": "source-tree",
|
|
4
4
|
"registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
|
|
5
|
-
"packageVersion": "1.3.
|
|
5
|
+
"packageVersion": "1.3.1153",
|
|
6
6
|
"guards": [
|
|
7
7
|
{
|
|
8
8
|
"ref": "docs/audits/phase-b/f10-triage.md",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sha256": "
|
|
2
|
+
"sha256": "c9fe9271930f52c79239f9b43e4d3c873717dc1dd98744525290c8ccba4f07bf",
|
|
3
3
|
"registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
|
|
4
|
-
"packageVersion": "1.3.
|
|
4
|
+
"packageVersion": "1.3.1153"
|
|
5
5
|
}
|
package/package.json
CHANGED
|
@@ -22,9 +22,33 @@
|
|
|
22
22
|
* Structure > Willpower — a comment asking authors to remember is a wish; this
|
|
23
23
|
* is the guarantee.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* SCOPE CORRECTED 2026-08-15. The previous header said only that "a wrapper that
|
|
26
|
+
* builds the argv array dynamically could still evade it". That understated the
|
|
27
|
+
* gap: the check was LINE-oriented and required `send-keys` and `'-l'` on the
|
|
28
|
+
* SAME line, so four PLAIN literal forms — none of them dynamic, none of them a
|
|
29
|
+
* wrapper — walked straight past it. Measured against the shipped check, with the
|
|
30
|
+
* one-line form as a positive control firing in the same run:
|
|
31
|
+
*
|
|
32
|
+
* ["send-keys", "-l", p] CONTROL exit 1 (caught)
|
|
33
|
+
* [\n "send-keys",\n "-l",\n p,\n] exit 0 — EVADES
|
|
34
|
+
* const F = "-l"; ["send-keys", F, p] exit 0 — EVADES
|
|
35
|
+
* const C = "send-keys"; [C, "-l", p] exit 0 — EVADES
|
|
36
|
+
* ["send-keys","-l",p] // buildLiteralSendArgs exit 0 — EVADES
|
|
37
|
+
*
|
|
38
|
+
* The first is the one that matters: a multi-line argv array is simply how any
|
|
39
|
+
* formatter writes an array over the print width. The guard could be defeated by
|
|
40
|
+
* running prettier. The last is worse in kind — merely NAMING the funnel in a
|
|
41
|
+
* COMMENT on that line suppressed the check, so `// TODO: use buildLiteralSendArgs`
|
|
42
|
+
* beside a raw send silenced the guard that the TODO was admitting was needed.
|
|
43
|
+
*
|
|
44
|
+
* Now: comments are stripped quote-aware first, string constants are resolved
|
|
45
|
+
* per file, and the unit of matching is the ARRAY LITERAL (bracket-matched,
|
|
46
|
+
* bounded) rather than the line — which is what the original rule always meant.
|
|
47
|
+
*
|
|
48
|
+
* STILL not proof, and this is the honest remainder: an argv array assembled at
|
|
49
|
+
* RUNTIME (push(), concat(), spread of a computed list, a helper that returns the
|
|
50
|
+
* array) is invisible here. That is the gap the original header named, and it is
|
|
51
|
+
* the only one left. Closing it needs dataflow, not more patterns.
|
|
28
52
|
*/
|
|
29
53
|
import fs from 'node:fs';
|
|
30
54
|
import path from 'node:path';
|
|
@@ -46,20 +70,142 @@ function walk(dir, out = []) {
|
|
|
46
70
|
return out;
|
|
47
71
|
}
|
|
48
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Strip // and block comments WITHOUT touching string contents, replacing each
|
|
75
|
+
* removed character with a space so every byte offset — and therefore every
|
|
76
|
+
* reported line number — is preserved exactly.
|
|
77
|
+
*/
|
|
78
|
+
export function stripComments(src) {
|
|
79
|
+
let out = '';
|
|
80
|
+
let i = 0;
|
|
81
|
+
let quote = null;
|
|
82
|
+
while (i < src.length) {
|
|
83
|
+
const c = src[i];
|
|
84
|
+
const n = src[i + 1];
|
|
85
|
+
if (quote) {
|
|
86
|
+
out += c;
|
|
87
|
+
if (c === '\\') { out += n ?? ''; i += 2; continue; }
|
|
88
|
+
if (c === quote) quote = null;
|
|
89
|
+
i += 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (c === '"' || c === "'" || c === '`') { quote = c; out += c; i += 1; continue; }
|
|
93
|
+
if (c === '/' && n === '/') {
|
|
94
|
+
while (i < src.length && src[i] !== '\n') { out += ' '; i += 1; }
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (c === '/' && n === '*') {
|
|
98
|
+
out += ' '; i += 2;
|
|
99
|
+
while (i < src.length && !(src[i] === '*' && src[i + 1] === '/')) {
|
|
100
|
+
out += src[i] === '\n' ? '\n' : ' ';
|
|
101
|
+
i += 1;
|
|
102
|
+
}
|
|
103
|
+
out += ' '; i += 2;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
out += c;
|
|
107
|
+
i += 1;
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Identifiers bound to a plain string literal in THIS file. An identifier bound
|
|
114
|
+
* more than once to DIFFERENT values is UNRESOLVABLE and dropped, so an ambiguous
|
|
115
|
+
* name can never be substituted into a match — ambiguity fails toward NOT flagging,
|
|
116
|
+
* because a guess that fails someone's build is the expensive direction.
|
|
117
|
+
*/
|
|
118
|
+
export function collectStringConsts(code) {
|
|
119
|
+
const seen = new Map();
|
|
120
|
+
const conflicting = new Set();
|
|
121
|
+
const DECL = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(['"`])([^'"`\n]*)\2/g;
|
|
122
|
+
let m;
|
|
123
|
+
while ((m = DECL.exec(code)) !== null) {
|
|
124
|
+
const [, name, , value] = m;
|
|
125
|
+
if (seen.has(name) && seen.get(name) !== value) conflicting.add(name);
|
|
126
|
+
else seen.set(name, value);
|
|
127
|
+
}
|
|
128
|
+
for (const name of conflicting) seen.delete(name);
|
|
129
|
+
return seen;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Every bracket-matched array literal in the source, as {text, line}. Bounded:
|
|
134
|
+
* an array longer than MAX_ARRAY_CHARS is truncated rather than scanned whole, so
|
|
135
|
+
* a pathological file cannot make this quadratic. Unbalanced brackets simply
|
|
136
|
+
* yield no region — the check fails toward NOT flagging.
|
|
137
|
+
*/
|
|
138
|
+
const MAX_ARRAY_CHARS = 4000;
|
|
139
|
+
export function arrayRegions(code) {
|
|
140
|
+
const regions = [];
|
|
141
|
+
for (let i = 0; i < code.length; i++) {
|
|
142
|
+
if (code[i] !== '[') continue;
|
|
143
|
+
let depth = 0;
|
|
144
|
+
let quote = null;
|
|
145
|
+
let j = i;
|
|
146
|
+
for (; j < code.length && j - i < MAX_ARRAY_CHARS; j++) {
|
|
147
|
+
const c = code[j];
|
|
148
|
+
if (quote) {
|
|
149
|
+
if (c === '\\') { j += 1; continue; }
|
|
150
|
+
if (c === quote) quote = null;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (c === '"' || c === "'" || c === '`') { quote = c; continue; }
|
|
154
|
+
if (c === '[') depth += 1;
|
|
155
|
+
else if (c === ']') { depth -= 1; if (depth === 0) break; }
|
|
156
|
+
}
|
|
157
|
+
if (depth !== 0) continue;
|
|
158
|
+
const text = code.slice(i, j + 1);
|
|
159
|
+
const line = code.slice(0, i).split('\n').length;
|
|
160
|
+
regions.push({ text, line });
|
|
161
|
+
}
|
|
162
|
+
return regions;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** True when the resolved region is a raw literal `send-keys -l` argv. */
|
|
166
|
+
export function regionViolates(regionText, consts) {
|
|
167
|
+
let t = regionText;
|
|
168
|
+
for (const [name, value] of consts) {
|
|
169
|
+
t = t.replace(new RegExp(`\\b${name}\\b`, 'g'), `'${value}'`);
|
|
170
|
+
}
|
|
171
|
+
if (!/['"`]send-keys['"`]/.test(t)) return false;
|
|
172
|
+
if (!/['"`]-l['"`]/.test(t)) return false;
|
|
173
|
+
// Already funnelled — checked on COMMENT-STRIPPED code, so merely naming the
|
|
174
|
+
// funnel in a comment can no longer silence the guard.
|
|
175
|
+
if (t.includes('buildLiteralSendArgs')) return false;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function scanSource(code) {
|
|
180
|
+
const stripped = stripComments(code);
|
|
181
|
+
const consts = collectStringConsts(stripped);
|
|
182
|
+
const hits = [];
|
|
183
|
+
for (const region of arrayRegions(stripped)) {
|
|
184
|
+
if (regionViolates(region.text, consts)) {
|
|
185
|
+
hits.push({ line: region.line, text: region.text.replace(/\s+/g, ' ').trim() });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return hits;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// DIRECT-INVOCATION GUARD. Without it, importing this module to unit-test the
|
|
192
|
+
// helpers above runs the whole src/ scan and calls process.exit(1) the moment the
|
|
193
|
+
// repo has a real violation — killing the importing process. Four other lints hit
|
|
194
|
+
// exactly that this week; the guard is the same fix.
|
|
195
|
+
const invokedDirectly =
|
|
196
|
+
process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
|
|
197
|
+
|
|
198
|
+
if (invokedDirectly) runLint();
|
|
199
|
+
|
|
200
|
+
function runLint() {
|
|
49
201
|
const violations = [];
|
|
50
202
|
|
|
51
203
|
for (const file of walk(SRC)) {
|
|
52
204
|
const rel = path.relative(REPO, file);
|
|
53
205
|
if (EXEMPT.has(rel)) continue;
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!line.includes('send-keys')) return;
|
|
58
|
-
if (!/['"]-l['"]/.test(line)) return;
|
|
59
|
-
// Already funnelled.
|
|
60
|
-
if (line.includes('buildLiteralSendArgs')) return;
|
|
61
|
-
violations.push({ rel, line: i + 1, text: line.trim() });
|
|
62
|
-
});
|
|
206
|
+
for (const hit of scanSource(fs.readFileSync(file, 'utf-8'))) {
|
|
207
|
+
violations.push({ rel, line: hit.line, text: hit.text });
|
|
208
|
+
}
|
|
63
209
|
}
|
|
64
210
|
|
|
65
211
|
if (violations.length > 0) {
|
|
@@ -76,3 +222,4 @@ if (violations.length > 0) {
|
|
|
76
222
|
}
|
|
77
223
|
|
|
78
224
|
console.log(`✓ tmux literal sends funnelled (scanned ${walk(SRC).length} files, 0 unfunneled)`);
|
|
225
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "./builtin-manifest.schema.json",
|
|
3
3
|
"schemaVersion": 1,
|
|
4
|
-
"generatedAt": "2026-08-
|
|
5
|
-
"instarVersion": "1.3.
|
|
4
|
+
"generatedAt": "2026-08-15T01:31:14.741Z",
|
|
5
|
+
"instarVersion": "1.3.1153",
|
|
6
6
|
"entryCount": 202,
|
|
7
7
|
"entries": {
|
|
8
8
|
"hook:session-start": {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"generatedFrom": "source-tree",
|
|
4
4
|
"registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
|
|
5
|
-
"packageVersion": "1.3.
|
|
5
|
+
"packageVersion": "1.3.1153",
|
|
6
6
|
"guards": [
|
|
7
7
|
{
|
|
8
8
|
"ref": "docs/audits/phase-b/f10-triage.md",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sha256": "
|
|
2
|
+
"sha256": "c9fe9271930f52c79239f9b43e4d3c873717dc1dd98744525290c8ccba4f07bf",
|
|
3
3
|
"registrySha256": "81b53363a440e832672618965540b3e507ae0d93adcc67ec2b93daf7933b3ab4",
|
|
4
|
-
"packageVersion": "1.3.
|
|
4
|
+
"packageVersion": "1.3.1153"
|
|
5
5
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Upgrade Guide — vNEXT
|
|
2
|
+
|
|
3
|
+
<!-- assembled-by: assemble-next-md -->
|
|
4
|
+
<!-- bump: patch -->
|
|
5
|
+
|
|
6
|
+
## What Changed
|
|
7
|
+
|
|
8
|
+
`scripts/lint-no-unfunneled-tmux-literal-send.js` now matches the bracket-matched ARGV ARRAY rather
|
|
9
|
+
than a single line.
|
|
10
|
+
|
|
11
|
+
That lint guards the `send-keys -l` argv ceiling (~16.2 KB) — the class behind the 2026-08-04 incident
|
|
12
|
+
where a ~40 KB prompt blew the ceiling, the circuit breaker misread the opaque send error as a provider
|
|
13
|
+
rate-limit and tripped 14 consecutive times, and ten LLM-backed components sat at 76-100% error rate.
|
|
14
|
+
|
|
15
|
+
It required `send-keys` and `'-l'` on the SAME line, so four PLAIN literal forms evaded it — measured
|
|
16
|
+
against the shipped check with the one-line form as a positive control firing in the same run: a
|
|
17
|
+
multi-line array (what any formatter produces), the flag lifted into a const, the verb lifted into a
|
|
18
|
+
const, and — worst in kind — merely NAMING the funnel in a comment on that line, so
|
|
19
|
+
`// TODO: use buildLiteralSendArgs` beside a raw send silenced the guard the TODO was admitting was
|
|
20
|
+
needed.
|
|
21
|
+
|
|
22
|
+
The first is the one that matters: **the guard could be defeated by running prettier.**
|
|
23
|
+
|
|
24
|
+
Added: `stripComments` (quote-aware, line-number preserving), `collectStringConsts` (per-file;
|
|
25
|
+
conflicting bindings dropped as unresolvable), `arrayRegions` (bracket-matched, string-aware, bounded),
|
|
26
|
+
`regionViolates` and `scanSource`. The rule, the exemption and the message are unchanged. Also added a
|
|
27
|
+
direct-invocation guard — importing the module previously ran the whole `src/` scan and could
|
|
28
|
+
`process.exit(1)`, which is why its internals had never been unit-tested.
|
|
29
|
+
|
|
30
|
+
## What to Tell Your User
|
|
31
|
+
|
|
32
|
+
Nothing changes for you. A build-time check that stops a known way of breaking terminal sends could be
|
|
33
|
+
walked past just by letting a code formatter split a list across lines — no intent required. It now
|
|
34
|
+
reads the whole list instead of one line. Nothing you use behaves differently; a failure mode that once
|
|
35
|
+
took down ten components for hours got harder to reintroduce by accident.
|
|
36
|
+
|
|
37
|
+
## Summary of New Capabilities
|
|
38
|
+
|
|
39
|
+
None. No new command, endpoint, setting, or runtime behaviour. A CI guard that a code formatter could
|
|
40
|
+
defeat no longer can be.
|
|
41
|
+
|
|
42
|
+
## Evidence
|
|
43
|
+
|
|
44
|
+
- `tests/unit/tmux-send-lint-array-scope.test.ts` — 18/18 green.
|
|
45
|
+
- **Negative control: 6 of 18 fail** against the shipped line-oriented behaviour; the other 12 pass both
|
|
46
|
+
ways and are the controls. Source restored byte-exact afterwards (sha match, zero markers left).
|
|
47
|
+
- Six anti-over-block controls, because this lint blocks commits: send-keys without the flag; a genuinely
|
|
48
|
+
funnelled call; two SEPARATE arrays never joined; a const bound to a different flag; an example living
|
|
49
|
+
entirely inside a comment; and an identifier with conflicting bindings left unresolvable.
|
|
50
|
+
- Real tree: `exit 0` before AND after, 1,631 files scanned.
|
|
51
|
+
- Full `npm run lint` chain green; chain membership verified explicitly rather than inferred.
|
|
52
|
+
- **Scope CORRECTED, not restated:** the old header claimed only that a dynamically-built argv could
|
|
53
|
+
evade it. None of the four measured evasions is dynamic. The header now names what was actually
|
|
54
|
+
missing, and the genuine remainder (a runtime-assembled array — push/concat/spread/helper).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Upgrade Guide — vNEXT
|
|
2
|
+
|
|
3
|
+
<!-- assembled-by: assemble-next-md -->
|
|
4
|
+
<!-- bump: patch -->
|
|
5
|
+
|
|
6
|
+
## What Changed
|
|
7
|
+
|
|
8
|
+
The atomic-writes consistency test could not detect the defect it exists to detect.
|
|
9
|
+
|
|
10
|
+
Measured rather than argued: a bare `fs.writeFileSync` of durable session state, inserted into
|
|
11
|
+
`saveSession` — a DECLARED method of a DECLARED module — passed all 21 of its assertions.
|
|
12
|
+
|
|
13
|
+
Three causes, all fixed:
|
|
14
|
+
|
|
15
|
+
1. **Scoping.** `inSaveMethod` was set when a method NAME appeared on a line and never reset, while
|
|
16
|
+
`hasWriteFile`/`hasRename` were re-zeroed at each occurrence. Only the window from the LAST name
|
|
17
|
+
mention to EOF reached the assertion — 125 of 617 lines (20%) in `StateManager.ts`, leaving three
|
|
18
|
+
of its four declared methods structurally unreachable. Bodies are now brace-matched per method.
|
|
19
|
+
2. **File-scope substring checks.** `source.includes('renameSync')` and `source.includes('.tmp')` are
|
|
20
|
+
satisfied by one occurrence anywhere in the file, comments included. Pairing is now per body.
|
|
21
|
+
3. **Silent declaration rot.** A missing file was `it.skip`ped and a missing method never set the
|
|
22
|
+
flag, so a rename dropped a module out of coverage without a sound. Both are failures now — and
|
|
23
|
+
enabling that found two immediately: `saveState` has ZERO occurrences in `StateManager.ts` and in
|
|
24
|
+
`QuotaTracker.ts`. QuotaTracker's real writer, `updateState()`, is atomic and had never been
|
|
25
|
+
verified by this test. The declared list is corrected here.
|
|
26
|
+
|
|
27
|
+
**Delegation.** `StateManager` funnels every write through a private `atomicWrite()`. A naive
|
|
28
|
+
per-method rule would have failed the best-written module in the set for being well written, so one
|
|
29
|
+
level of `this.helper()` delegation is resolved and the funnel is what gets verified — which means
|
|
30
|
+
`StateManager`'s writes are now genuinely checked, where before nothing checked them.
|
|
31
|
+
|
|
32
|
+
Added `tests/helpers/atomicWriteScope.ts` (`stripComments`, `methodBodies`, `delegateTargets`,
|
|
33
|
+
`classifyMethod`) and `tests/unit/atomic-write-scope.test.ts`.
|
|
34
|
+
|
|
35
|
+
**Declared open in the source:** the module list is curated at 7 entries and says nothing about the
|
|
36
|
+
hundreds of other files under `src/` that call `writeFileSync`; delegation resolves one level within
|
|
37
|
+
one file; only `writeFileSync`/`renameSync` are recognised.
|
|
38
|
+
|
|
39
|
+
**The production code is atomic** everywhere the check now looks. This fixes a weak instrument, not a
|
|
40
|
+
live corruption bug.
|
|
41
|
+
|
|
42
|
+
## What to Tell Your User
|
|
43
|
+
|
|
44
|
+
None — internal change (no user-facing surface).
|
|
45
|
+
|
|
46
|
+
## Summary of New Capabilities
|
|
47
|
+
|
|
48
|
+
None — internal change (no user-facing surface).
|
|
49
|
+
|
|
50
|
+
## Evidence
|
|
51
|
+
|
|
52
|
+
- `tests/unit/atomic-write-scope.test.ts` — 18/18 green (6 defect cases, 6 over-block controls, 6 primitives).
|
|
53
|
+
- `tests/unit/atomic-writes-consistency.test.ts` — 32/32 green against the real tree.
|
|
54
|
+
- **Both-directions proof in ONE worktree**, shipped check restored from git alongside the new one so
|
|
55
|
+
subject and control share a boundary: shipped → **21/21 PASSED** against the mutation; new →
|
|
56
|
+
**1 failed / 31 passed**, naming file, method, deciding body and line. `src/core/StateManager.ts`
|
|
57
|
+
restored byte-exact (sha match, zero markers, zero stray files).
|
|
58
|
+
- Six over-block controls pass under BOTH behaviours — genuine funnel delegation, in-body
|
|
59
|
+
tmp-then-rename, a method that writes nothing, a commented-out write, a call site vs a declaration,
|
|
60
|
+
and worst-verdict-wins across duplicate declarations.
|
|
61
|
+
- `tsc --noEmit` exit 0 — with the boundary stated: `tsconfig.json` excludes `tests`, so that run says
|
|
62
|
+
nothing about these files.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Side-Effects Review — atomic-writes check scopes to method bodies
|
|
2
|
+
|
|
3
|
+
**Version / slug:** `atomic-writes-method-scope`
|
|
4
|
+
**Date:** `2026-08-15`
|
|
5
|
+
**Author:** `echo`
|
|
6
|
+
**Second-pass reviewer:** `not required — Tier 1. Test-only change; no file under src/, scripts/, .husky/ or skills/ is touched, so there is no runtime path and no shipped behaviour. The change makes an existing check stricter and adds no authority.`
|
|
7
|
+
|
|
8
|
+
## Summary of the change
|
|
9
|
+
|
|
10
|
+
`tests/unit/atomic-writes-consistency.test.ts` verifies that state-writing modules use
|
|
11
|
+
write-to-tmp-then-rename, so a crash mid-write cannot leave a truncated state file. **It could not
|
|
12
|
+
detect the defect it exists to detect.**
|
|
13
|
+
|
|
14
|
+
Measured, not argued — a bare `fs.writeFileSync` of durable session state inserted into
|
|
15
|
+
`saveSession`, a DECLARED method of a DECLARED module:
|
|
16
|
+
|
|
17
|
+
| check | verdict against that mutation |
|
|
18
|
+
|---|---|
|
|
19
|
+
| shipped | **21/21 PASSED** |
|
|
20
|
+
| this change | **1 failed / 31 passed**, naming file, method, deciding body, line |
|
|
21
|
+
|
|
22
|
+
Both runs were made in the SAME worktree against the SAME mutated source, with the shipped check
|
|
23
|
+
restored from git alongside the new one — subject and control share a boundary rather than being
|
|
24
|
+
compared across two checkouts.
|
|
25
|
+
|
|
26
|
+
Three causes, all fixed:
|
|
27
|
+
|
|
28
|
+
1. **Scoping.** `inSaveMethod` was set when a method NAME appeared on a line and never reset, while
|
|
29
|
+
`hasWriteFile`/`hasRename` were re-zeroed at each occurrence. Only the window from the LAST name
|
|
30
|
+
mention to EOF survived to the assertion — measured at **125 of 617 lines (20%)** in
|
|
31
|
+
`StateManager.ts`, leaving three of its four declared methods structurally unreachable. Within
|
|
32
|
+
that window the booleans were file-scope, so a rename in one method vouched for a write in another.
|
|
33
|
+
2. **File-scope substring checks.** `source.includes('renameSync')` and `source.includes('.tmp')` are
|
|
34
|
+
satisfied by one occurrence anywhere, comments included.
|
|
35
|
+
3. **Silent declaration rot.** A missing file was `it.skip`ped; a missing method simply never set the
|
|
36
|
+
flag. Both are failures now.
|
|
37
|
+
|
|
38
|
+
## What enabling (3) immediately found
|
|
39
|
+
|
|
40
|
+
**Two of the ten declared (module, method) pairs name methods that do not exist.** `saveState` has
|
|
41
|
+
ZERO occurrences in `src/core/StateManager.ts` and ZERO in `src/monitoring/QuotaTracker.ts` — verified
|
|
42
|
+
by grep with a control (`saveSession(`, `appendEvent(`, `persistUsers(` all found). QuotaTracker's
|
|
43
|
+
real writer is `updateState()`, which is correctly atomic and had never been verified by this test.
|
|
44
|
+
The declared list is corrected in the same change.
|
|
45
|
+
|
|
46
|
+
## Decision-point inventory
|
|
47
|
+
|
|
48
|
+
- `tests/helpers/atomicWriteScope.ts` — ADD. `stripComments` (quote-aware, line-count preserving),
|
|
49
|
+
`methodBodies` (brace-matched, string-aware, declaration-vs-call aware), `delegateTargets`,
|
|
50
|
+
`classifyMethod`.
|
|
51
|
+
- `tests/unit/atomic-writes-consistency.test.ts` — REWRITTEN to per-method assertions; declared list
|
|
52
|
+
corrected; missing file/method now fail; anti-vacuity assertion added.
|
|
53
|
+
- `tests/unit/atomic-write-scope.test.ts` — ADD. 18 tests pinning the primitives and both directions.
|
|
54
|
+
- No file under `src/`, `scripts/`, `.husky/` or `skills/` is touched. No runtime decision added.
|
|
55
|
+
|
|
56
|
+
## 1. Over-block
|
|
57
|
+
|
|
58
|
+
**The dominant risk, and it nearly bit me.** The obvious fix — require a rename in each declared
|
|
59
|
+
method's own body — would have FAILED on `StateManager`, the best-written module in the set, because
|
|
60
|
+
it routes every write through a private `atomicWrite()` funnel and its save methods contain no write
|
|
61
|
+
call at all. Failing the single-funnel pattern this codebase argues for everywhere else would be a
|
|
62
|
+
false red on exemplary code.
|
|
63
|
+
|
|
64
|
+
So one level of `this.helper()` delegation is resolved and the funnel is what gets verified — which
|
|
65
|
+
also means `StateManager`'s writes are now genuinely checked, where previously nothing checked them.
|
|
66
|
+
|
|
67
|
+
Six controls, each with a test, all passing under BOTH the old and new behaviour:
|
|
68
|
+
|
|
69
|
+
- delegation to a genuine atomic funnel → `atomic-via-funnel`, not a violation;
|
|
70
|
+
- in-body tmp-then-rename → `atomic-inline`;
|
|
71
|
+
- a method that legitimately writes nothing → `no-write`, no invented violation;
|
|
72
|
+
- a commented-out write is not a write;
|
|
73
|
+
- a CALL site (`this.saveSession({...})` inside another method) is not a declaration — treating it as
|
|
74
|
+
one is precisely how the old flag conflated two methods;
|
|
75
|
+
- an unbalanced brace yields no body rather than a wrong region, so a syntax error elsewhere cannot
|
|
76
|
+
become a false verdict here.
|
|
77
|
+
|
|
78
|
+
**Verified against the real tree: 32/32 green.** The production code is atomic everywhere the check
|
|
79
|
+
now looks, including through the funnel.
|
|
80
|
+
|
|
81
|
+
**A defect in my own helper, caught by these controls before it shipped:** the first `methodBodies`
|
|
82
|
+
required a declaration at line start. That works on real source (which indents declarations) and
|
|
83
|
+
returned `found: false` for every hand-written fixture — so five tests failed loudly rather than
|
|
84
|
+
passing vacuously. The matcher now decides by the PRECEDING token (start / `{` / `}` / `;` after
|
|
85
|
+
skipping modifiers), which rejects `this.save(` and `helper(save(1))` as calls while accepting a
|
|
86
|
+
declaration that does not begin its own line.
|
|
87
|
+
|
|
88
|
+
## 2. Under-block
|
|
89
|
+
|
|
90
|
+
Stated in the source rather than implied:
|
|
91
|
+
|
|
92
|
+
- **Population.** The module list is CURATED and holds 7 entries. Hundreds of files under `src/` call
|
|
93
|
+
`writeFileSync`; this test says nothing about any of them. A heuristic sweep suggested a state-writing
|
|
94
|
+
population in the low hundreds, but that heuristic missed 2 of the 7 KNOWN-good modules, so it is not
|
|
95
|
+
a defect count and is not quoted as one. Widening the population is separate work with real
|
|
96
|
+
over-block risk and is deliberately not attempted here.
|
|
97
|
+
- **Delegation depth.** One level, one file. A helper calling another helper, or an imported writer,
|
|
98
|
+
is not resolved — that needs a symbol graph, not text.
|
|
99
|
+
- **Write vocabulary.** Only `writeFileSync`/`renameSync`. A module writing via a stream, `fs.promises`,
|
|
100
|
+
or a third-party helper is invisible.
|
|
101
|
+
|
|
102
|
+
## 3. Level-of-abstraction fit
|
|
103
|
+
|
|
104
|
+
Same layer as the existing check — source-text analysis in a unit test, no AST, no type information,
|
|
105
|
+
no new dependency. The brace matcher is the minimum needed to answer "which method is this line in?",
|
|
106
|
+
which is the question the original flag was trying and failing to answer.
|
|
107
|
+
|
|
108
|
+
## 4. Signal vs authority compliance
|
|
109
|
+
|
|
110
|
+
A test, not a runtime authority. It gates CI only. It gained teeth (it can now fail) but no new
|
|
111
|
+
decision-making power over agent behaviour.
|
|
112
|
+
|
|
113
|
+
## 5. Interactions
|
|
114
|
+
|
|
115
|
+
- Runs in the existing unit shards; no new script, no lint-chain entry, no CI wiring change.
|
|
116
|
+
- `tsc --noEmit` exit 0 — **but stated honestly: `tsconfig.json` excludes `tests`, so that run says
|
|
117
|
+
nothing about these files.** Their correctness is evidenced by the suite passing, not by the compiler.
|
|
118
|
+
- No source module, route, config key, or state file touched.
|
|
119
|
+
|
|
120
|
+
## 6. External surfaces
|
|
121
|
+
|
|
122
|
+
None. Developer tooling. The Agent Awareness Standard does not apply — no agent capability is added.
|
|
123
|
+
|
|
124
|
+
## 7. Multi-machine posture (Cross-Machine Coherence)
|
|
125
|
+
|
|
126
|
+
**Machine-local by design, and correct.** A unit test reads files in one checkout and returns an exit
|
|
127
|
+
code. No durable state, no user-facing notice, no generated URL, no runtime decision — nothing to
|
|
128
|
+
replicate, merge on read, or strand on a topic transfer. Every machine runs it over its own checkout
|
|
129
|
+
of the same tracked source and reaches the same verdict; determinism comes from the source tree, not
|
|
130
|
+
from coordination.
|
|
131
|
+
|
|
132
|
+
## 8. Rollback cost
|
|
133
|
+
|
|
134
|
+
`git revert` of three test files. No migration, no state, no deployed artifact, no runtime impact.
|
|
135
|
+
|
|
136
|
+
## Conclusion
|
|
137
|
+
|
|
138
|
+
Ship. A check that could not fail on its own subject now fails on it, two stale declarations are
|
|
139
|
+
repaired, the best-written module in the set is verified for the first time, and the limits are named
|
|
140
|
+
in the source rather than implied.
|
|
141
|
+
|
|
142
|
+
## Evidence pointers
|
|
143
|
+
|
|
144
|
+
- `tests/unit/atomic-write-scope.test.ts` — 18/18 green (6 defect cases, 6 over-block controls, 6 primitives).
|
|
145
|
+
- `tests/unit/atomic-writes-consistency.test.ts` — 32/32 green against the real tree.
|
|
146
|
+
- **Both-directions proof in ONE worktree:** shipped check vs the mutation → 21/21 PASSED; new check
|
|
147
|
+
vs the SAME mutation → 1 failed / 31 passed. `src/core/StateManager.ts` restored byte-exact
|
|
148
|
+
(sha match, zero probe markers, zero stray files).
|
|
149
|
+
- Stale declarations verified by grep with a control that fired.
|
|
150
|
+
- `tsc --noEmit` exit 0 (boundary stated above: tests are excluded from that config).
|
|
151
|
+
- Tier **1** declared: `classifyTier` reports riskFloor 1 with no safety-invariant match, and `tests/`
|
|
152
|
+
is outside `inScope()`, so the size heuristic contributes nothing either.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Side-Effects Review — tmux send-keys guard matches the array, not the line
|
|
2
|
+
|
|
3
|
+
**Version / slug:** `tmux-send-lint-array-scope`
|
|
4
|
+
**Date:** `2026-08-15`
|
|
5
|
+
**Author:** `echo`
|
|
6
|
+
**Second-pass reviewer:** `not required — Tier 1 (CI-only lint script; no runtime path). The rule is unchanged; the check now reads the unit it always meant (the argv array) instead of a single line.`
|
|
7
|
+
|
|
8
|
+
## Summary of the change
|
|
9
|
+
|
|
10
|
+
`scripts/lint-no-unfunneled-tmux-literal-send.js` guards the `send-keys -l` argv ceiling (~16.2 KB).
|
|
11
|
+
The 2026-08-04 incident it exists to prevent: a ~40 KB prompt blew the ceiling, `LlmCircuitBreaker`
|
|
12
|
+
misclassified the opaque send error as a provider rate-limit and tripped 14 consecutive times while ten
|
|
13
|
+
LLM-backed components sat at 76-100% error rate.
|
|
14
|
+
|
|
15
|
+
The check required `send-keys` AND `'-l'` on the SAME LINE. Measured against the shipped check, with the
|
|
16
|
+
one-line form as a positive control firing in the same run:
|
|
17
|
+
|
|
18
|
+
| form | shipped |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `["send-keys", "-l", p]` — POSITIVE CONTROL | exit 1 (caught) |
|
|
21
|
+
| the same array across 5 lines | **exit 0 — EVADES** |
|
|
22
|
+
| `const F = "-l"; ["send-keys", F, p]` | **exit 0 — EVADES** |
|
|
23
|
+
| `const C = "send-keys"; [C, "-l", p]` | **exit 0 — EVADES** |
|
|
24
|
+
| `["send-keys","-l",p] // buildLiteralSendArgs` | **exit 0 — EVADES** |
|
|
25
|
+
|
|
26
|
+
The unit of matching is now the bracket-matched ARRAY LITERAL, over comment-stripped, const-resolved
|
|
27
|
+
source. The rule, the exemption and the message are unchanged.
|
|
28
|
+
|
|
29
|
+
## Decision-point inventory
|
|
30
|
+
|
|
31
|
+
- `stripComments(src)` — ADD — quote-aware; replaces removed bytes with spaces so line numbers are exact.
|
|
32
|
+
- `collectStringConsts(code)` — ADD — per-file identifier → literal; conflicting bindings dropped.
|
|
33
|
+
- `arrayRegions(code)` — ADD — bracket-matched, string-aware, bounded at 4000 chars per region.
|
|
34
|
+
- `regionViolates(text, consts)` — ADD — resolves then applies the EXISTING two patterns.
|
|
35
|
+
- `scanSource(code)` — ADD — the composed scan, extracted so matching is testable.
|
|
36
|
+
- Direct-invocation guard — ADD — the scan runs only when invoked directly.
|
|
37
|
+
- The `EXEMPT` set, the two patterns, the violation message and exit codes — UNCHANGED.
|
|
38
|
+
- No runtime block/allow decision added or modified. CI-time only.
|
|
39
|
+
|
|
40
|
+
## 1. Over-block
|
|
41
|
+
|
|
42
|
+
The failure that matters: this lint blocks commits, and a check that flags correct code gets switched
|
|
43
|
+
off. Six controls, each with a test, all passing under BOTH old and new behaviour:
|
|
44
|
+
|
|
45
|
+
- `send-keys` WITHOUT `-l` is not flagged (only the literal form has the ceiling).
|
|
46
|
+
- A genuinely funnelled `buildLiteralSendArgs(...)` call is not flagged.
|
|
47
|
+
- **Two separate arrays are never joined** — an unrelated `["ls", "-l"]` cannot complete a send-keys
|
|
48
|
+
array. This is the whole reason the unit is a bracket-matched region rather than a line window.
|
|
49
|
+
- A const bound to a different flag is not flagged.
|
|
50
|
+
- An example living entirely inside a comment is not flagged — which is what makes it safe to document
|
|
51
|
+
the bad pattern, including in this file and the ELI16.
|
|
52
|
+
- An identifier bound twice to DIFFERENT values is unresolvable and never substituted.
|
|
53
|
+
|
|
54
|
+
Unbalanced brackets yield no region, so a syntax error elsewhere cannot become a false accusation.
|
|
55
|
+
|
|
56
|
+
**Verified against the real tree: exit 0 before AND after**, scanning 1,631 files. No new flags.
|
|
57
|
+
|
|
58
|
+
## 2. Under-block
|
|
59
|
+
|
|
60
|
+
Stated in the source, and it is a CORRECTION rather than a restatement. The old header claimed only
|
|
61
|
+
that "a wrapper that builds the argv array dynamically could still evade it" — true, but it understated
|
|
62
|
+
the gap, since none of the four measured evasions is dynamic or a wrapper. The header now names what was
|
|
63
|
+
actually missing and what genuinely remains:
|
|
64
|
+
|
|
65
|
+
- An argv array assembled at RUNTIME — `push()`, `concat()`, spread of a computed list, or a helper that
|
|
66
|
+
returns the array. That is the original declared gap and it is the only one left.
|
|
67
|
+
- Closing it needs dataflow, not more patterns.
|
|
68
|
+
|
|
69
|
+
## 3. Level-of-abstraction fit
|
|
70
|
+
|
|
71
|
+
Same layer as the existing check — regex over source text, no AST, no type information, no new
|
|
72
|
+
dependency. Bracket matching is the minimum needed to read an array literal as one unit; going further
|
|
73
|
+
(a parser) would be a different check at a different layer.
|
|
74
|
+
|
|
75
|
+
## 4. Signal vs authority compliance
|
|
76
|
+
|
|
77
|
+
Unchanged. A CI guard, not a runtime authority. It pushes callers toward `buildLiteralSendArgs()`; the
|
|
78
|
+
funnel itself stays exempt.
|
|
79
|
+
|
|
80
|
+
## 5. Interactions
|
|
81
|
+
|
|
82
|
+
- `npm run lint` chain — membership verified explicitly (in the `lint` chain CI runs, not merely
|
|
83
|
+
referenced by a standalone entry); full chain green.
|
|
84
|
+
- The direct-invocation guard changes import behaviour from "runs the src/ scan and may exit(1)" to
|
|
85
|
+
"exports only". Nothing imported this module before, so no caller changes.
|
|
86
|
+
- No source module, route, config key, or state file touched.
|
|
87
|
+
|
|
88
|
+
## 6. External surfaces
|
|
89
|
+
|
|
90
|
+
None. Developer tooling, not an agent capability; the Agent Awareness Standard does not apply.
|
|
91
|
+
|
|
92
|
+
## 7. Multi-machine posture (Cross-Machine Coherence)
|
|
93
|
+
|
|
94
|
+
**Machine-local BY DESIGN, and correctly so — not an unexamined assumption.** A CI-time source scan with
|
|
95
|
+
no runtime surface: it reads files in one checkout and exits. No durable state, no user-facing notice, no
|
|
96
|
+
generated URL, no runtime decision — so nothing to replicate, nothing to merge on read, nothing that can
|
|
97
|
+
strand on a topic transfer. Every machine runs it over its own checkout of the same tracked source and
|
|
98
|
+
reaches the same verdict; determinism comes from the source tree, not from coordination. Resolution is
|
|
99
|
+
explicitly per-file, so it cannot depend on the rest of the checkout, let alone another machine.
|
|
100
|
+
|
|
101
|
+
## 8. Rollback cost
|
|
102
|
+
|
|
103
|
+
`git revert` of one script plus the added test file. No migration, no state, no deployed artifact.
|
|
104
|
+
|
|
105
|
+
## Conclusion
|
|
106
|
+
|
|
107
|
+
Ship. Four evasions closed on a guard with a real production incident behind it, six anti-over-block
|
|
108
|
+
controls added, the stated scope corrected rather than restated, and the import hazard removed.
|
|
109
|
+
|
|
110
|
+
## Evidence pointers
|
|
111
|
+
|
|
112
|
+
- `tests/unit/tmux-send-lint-array-scope.test.ts` — **18/18 green**.
|
|
113
|
+
- **Negative control: 6 of 18 fail** against the shipped line-oriented behaviour. The other 12 pass both
|
|
114
|
+
ways — which is what makes them controls. Source restored byte-exact after the mutation (sha match,
|
|
115
|
+
zero markers left).
|
|
116
|
+
- Reproduced by hand FIRST with a positive control firing in the same run; the control is what makes the
|
|
117
|
+
four EVADES verdicts mean anything.
|
|
118
|
+
- Real-tree verdict: exit 0, 1,631 files scanned, before and after.
|
|
119
|
+
- Full `npm run lint` chain green.
|
|
120
|
+
- Tier **1** declared: risk floor 1, verified with a directional control (`SessionReaper.ts` → floor 2
|
|
121
|
+
with its reason named). The size heuristic suggests 2 on added LOC alone; stated openly, since the tier
|
|
122
|
+
I choose is the one that lets my own change through.
|