@memnexus-ai/mx-agent-cli 0.1.219 → 0.1.221
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/__tests__/claude-sync.test.js +138 -16
- package/dist/__tests__/claude-sync.test.js.map +1 -1
- package/dist/__tests__/coordination-command.test.js +58 -0
- package/dist/__tests__/coordination-command.test.js.map +1 -1
- package/dist/__tests__/gh-remote.test.js +7 -7
- package/dist/__tests__/gh-remote.test.js.map +1 -1
- package/dist/__tests__/memory-autocreate.test.d.ts +10 -0
- package/dist/__tests__/memory-autocreate.test.d.ts.map +1 -0
- package/dist/__tests__/memory-autocreate.test.js +143 -0
- package/dist/__tests__/memory-autocreate.test.js.map +1 -0
- package/dist/__tests__/team-memory-commands.test.d.ts +11 -0
- package/dist/__tests__/team-memory-commands.test.d.ts.map +1 -0
- package/dist/__tests__/team-memory-commands.test.js +117 -0
- package/dist/__tests__/team-memory-commands.test.js.map +1 -0
- package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +2 -0
- package/dist/agent-config/hooks/coordination-midsession-drain.sh +120 -0
- package/dist/agent-config/settings.json +4 -0
- package/dist/commands/coordination.d.ts +18 -1
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +43 -2
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +14 -5
- package/dist/commands/create.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +113 -28
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/gh-remote.d.ts.map +1 -1
- package/dist/lib/gh-remote.js +4 -2
- package/dist/lib/gh-remote.js.map +1 -1
- package/dist/lib/memory.d.ts +40 -0
- package/dist/lib/memory.d.ts.map +1 -1
- package/dist/lib/memory.js +118 -24
- package/dist/lib/memory.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the auto-create codeContext path (#4445 Part 5).
|
|
3
|
+
*
|
|
4
|
+
* bootstrapTeamMemories / createNamedMemory must pass `--code-context` with the
|
|
5
|
+
* SAME values the manual-command printer uses (from teamMemorySpecs), and must
|
|
6
|
+
* degrade gracefully on an older mx CLI that rejects the flag: retry once without
|
|
7
|
+
* it and warn (fail toward creating the memory unscoped).
|
|
8
|
+
*/
|
|
9
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
10
|
+
// Mock child_process before importing the module under test.
|
|
11
|
+
vi.mock('child_process', () => ({ spawnSync: vi.fn(), execSync: vi.fn() }));
|
|
12
|
+
import { spawnSync } from 'child_process';
|
|
13
|
+
import { createNamedMemory, bootstrapTeamMemories } from '../lib/memory.js';
|
|
14
|
+
const mockSpawnSync = spawnSync;
|
|
15
|
+
function ok(stdout = 'created mem_123') {
|
|
16
|
+
return { status: 0, stdout, stderr: '', error: undefined };
|
|
17
|
+
}
|
|
18
|
+
function fail(stderr = 'error') {
|
|
19
|
+
return { status: 1, stdout: '', stderr, error: undefined };
|
|
20
|
+
}
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
describe('createNamedMemory — codeContext', () => {
|
|
25
|
+
it('passes --code-context with the JSON when codeContext is provided', () => {
|
|
26
|
+
mockSpawnSync.mockReturnValueOnce(ok());
|
|
27
|
+
const ctx = { product: 'memnexus', team: 'retrieval', role: 'team-lead' };
|
|
28
|
+
const r = createNamedMemory({ name: 'memnexus-retrieval-leader-state', content: 'c', codeContext: ctx });
|
|
29
|
+
expect(r.ok).toBe(true);
|
|
30
|
+
expect(mockSpawnSync).toHaveBeenCalledTimes(1);
|
|
31
|
+
const [cmd, args] = mockSpawnSync.mock.calls[0];
|
|
32
|
+
expect(cmd).toBe('mx');
|
|
33
|
+
const i = args.indexOf('--code-context');
|
|
34
|
+
expect(i).toBeGreaterThan(-1);
|
|
35
|
+
expect(args[i + 1]).toBe(JSON.stringify(ctx));
|
|
36
|
+
});
|
|
37
|
+
it('omits undefined codeContext keys (role absent for non-role memories)', () => {
|
|
38
|
+
mockSpawnSync.mockReturnValueOnce(ok());
|
|
39
|
+
createNamedMemory({
|
|
40
|
+
name: 'memnexus-retrieval-iteration-log',
|
|
41
|
+
content: 'c',
|
|
42
|
+
codeContext: { product: 'memnexus', team: 'retrieval', role: undefined },
|
|
43
|
+
});
|
|
44
|
+
const [, args] = mockSpawnSync.mock.calls[0];
|
|
45
|
+
const i = args.indexOf('--code-context');
|
|
46
|
+
expect(JSON.parse(args[i + 1])).toEqual({ product: 'memnexus', team: 'retrieval' });
|
|
47
|
+
});
|
|
48
|
+
it('does not pass --code-context when none is given', () => {
|
|
49
|
+
mockSpawnSync.mockReturnValueOnce(ok());
|
|
50
|
+
createNamedMemory({ name: 'x-leader-state', content: 'c' });
|
|
51
|
+
const [, args] = mockSpawnSync.mock.calls[0];
|
|
52
|
+
expect(args).not.toContain('--code-context');
|
|
53
|
+
});
|
|
54
|
+
it('drops empty-string values (unscoped project) — product key absent, not product:""', () => {
|
|
55
|
+
mockSpawnSync.mockReturnValueOnce(ok());
|
|
56
|
+
createNamedMemory({
|
|
57
|
+
name: 'retrieval-leader-state',
|
|
58
|
+
content: 'c',
|
|
59
|
+
codeContext: { product: '', team: 'retrieval', role: 'team-lead' },
|
|
60
|
+
});
|
|
61
|
+
const [, args] = mockSpawnSync.mock.calls[0];
|
|
62
|
+
const i = args.indexOf('--code-context');
|
|
63
|
+
expect(i).toBeGreaterThan(-1);
|
|
64
|
+
expect(JSON.parse(args[i + 1])).toEqual({ team: 'retrieval', role: 'team-lead' });
|
|
65
|
+
expect(args[i + 1]).not.toContain('product');
|
|
66
|
+
});
|
|
67
|
+
it('older mx CLI rejects --code-context — retries once WITHOUT it and warns', () => {
|
|
68
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
69
|
+
try {
|
|
70
|
+
mockSpawnSync
|
|
71
|
+
.mockReturnValueOnce(fail("error: unknown option '--code-context'")) // first attempt with ctx
|
|
72
|
+
.mockReturnValueOnce(ok()); // retry without ctx succeeds
|
|
73
|
+
const r = createNamedMemory({
|
|
74
|
+
name: 'memnexus-retrieval-leader-state',
|
|
75
|
+
content: 'c',
|
|
76
|
+
codeContext: { product: 'memnexus', team: 'retrieval', role: 'team-lead' },
|
|
77
|
+
});
|
|
78
|
+
expect(r.ok).toBe(true);
|
|
79
|
+
expect(mockSpawnSync).toHaveBeenCalledTimes(2);
|
|
80
|
+
const firstArgs = mockSpawnSync.mock.calls[0][1];
|
|
81
|
+
const secondArgs = mockSpawnSync.mock.calls[1][1];
|
|
82
|
+
expect(firstArgs).toContain('--code-context');
|
|
83
|
+
expect(secondArgs).not.toContain('--code-context');
|
|
84
|
+
// Soft warning printed.
|
|
85
|
+
const printed = logSpy.mock.calls.map((c) => String(c[0])).join('\n');
|
|
86
|
+
expect(printed).toContain('does not support --code-context');
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
logSpy.mockRestore();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
it('does NOT downgrade when the unknown-option text is only on STDOUT (CWE-20: stderr-only match)', () => {
|
|
93
|
+
// Attacker-controlled content echoed back on stdout must not trigger the
|
|
94
|
+
// scope-stripping retry. stderr is clean, so no downgrade.
|
|
95
|
+
mockSpawnSync
|
|
96
|
+
.mockReturnValueOnce({ status: 1, stdout: "unknown option '--code-context'", stderr: '', error: undefined }) // echoed on stdout
|
|
97
|
+
.mockReturnValueOnce(ok()); // mx memories get verify → exists
|
|
98
|
+
const r = createNamedMemory({
|
|
99
|
+
name: 'memnexus-retrieval-leader-state',
|
|
100
|
+
content: 'c',
|
|
101
|
+
codeContext: { product: 'memnexus', team: 'retrieval', role: 'team-lead' },
|
|
102
|
+
});
|
|
103
|
+
// Second call is the existence verify, NOT a scope-stripped re-create.
|
|
104
|
+
expect(mockSpawnSync).toHaveBeenCalledTimes(2);
|
|
105
|
+
const secondArgs = mockSpawnSync.mock.calls[1][1];
|
|
106
|
+
expect(secondArgs.slice(0, 2)).toEqual(['memories', 'get']);
|
|
107
|
+
expect(secondArgs).not.toContain('--code-context');
|
|
108
|
+
expect(r.ok).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
it('does NOT downgrade on a real (non-unknown-option) failure — keeps codeContext, falls to verify', () => {
|
|
111
|
+
mockSpawnSync
|
|
112
|
+
.mockReturnValueOnce(fail('server 500: internal error')) // create fails, but not an unknown-option error
|
|
113
|
+
.mockReturnValueOnce(ok()); // mx memories get verify → exists
|
|
114
|
+
const r = createNamedMemory({
|
|
115
|
+
name: 'memnexus-retrieval-leader-state',
|
|
116
|
+
content: 'c',
|
|
117
|
+
codeContext: { product: 'memnexus', team: 'retrieval', role: 'team-lead' },
|
|
118
|
+
});
|
|
119
|
+
// No retry-without-ctx; second call is the existence verify, not a re-create.
|
|
120
|
+
expect(mockSpawnSync).toHaveBeenCalledTimes(2);
|
|
121
|
+
const secondArgs = mockSpawnSync.mock.calls[1][1];
|
|
122
|
+
expect(secondArgs.slice(0, 2)).toEqual(['memories', 'get']);
|
|
123
|
+
expect(r.ok).toBe(true); // verify confirmed existence
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('bootstrapTeamMemories — per-key codeContext', () => {
|
|
127
|
+
it('passes leader-state with role team-lead and log/issues without role', () => {
|
|
128
|
+
mockSpawnSync.mockReturnValue(ok());
|
|
129
|
+
bootstrapTeamMemories('retrieval', 'Retrieval', 'rg.md', 'memnexus');
|
|
130
|
+
const createCalls = mockSpawnSync.mock.calls
|
|
131
|
+
.filter(([, args]) => args[0] === 'memories' && args[1] === 'create');
|
|
132
|
+
expect(createCalls).toHaveLength(3);
|
|
133
|
+
const ctxFor = (nameFragment) => {
|
|
134
|
+
const call = createCalls.find(([, args]) => args.some((a) => a.includes(nameFragment)));
|
|
135
|
+
const i = call[1].indexOf('--code-context');
|
|
136
|
+
return JSON.parse(call[1][i + 1]);
|
|
137
|
+
};
|
|
138
|
+
expect(ctxFor('leader-state')).toEqual({ product: 'memnexus', team: 'retrieval', role: 'team-lead' });
|
|
139
|
+
expect(ctxFor('iteration-log')).toEqual({ product: 'memnexus', team: 'retrieval' });
|
|
140
|
+
expect(ctxFor('known-issues')).toEqual({ product: 'memnexus', team: 'retrieval' });
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=memory-autocreate.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-autocreate.test.js","sourceRoot":"","sources":["../../src/__tests__/memory-autocreate.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE9D,6DAA6D;AAC7D,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,aAAa,GAAG,SAAgD,CAAC;AAEvE,SAAS,EAAE,CAAC,MAAM,GAAG,iBAAiB;IACpC,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC7D,CAAC;AACD,SAAS,IAAI,CAAC,MAAM,GAAG,OAAO;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CA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,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;QACpF,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the team-bootstrap memory spec + manual-command fallback (#4445 Part 4).
|
|
3
|
+
*
|
|
4
|
+
* When automatic memory initialisation is skipped (mx CLI missing) or fails (mx
|
|
5
|
+
* not authenticated), the provisioning path must print ready-to-paste
|
|
6
|
+
* `mx memories create` commands — the exact content the successful path would
|
|
7
|
+
* have written, plus the team's codeContext — so "create manually — see above"
|
|
8
|
+
* in the DoD checklist actually has commands above it.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=team-memory-commands.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team-memory-commands.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/team-memory-commands.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the team-bootstrap memory spec + manual-command fallback (#4445 Part 4).
|
|
3
|
+
*
|
|
4
|
+
* When automatic memory initialisation is skipped (mx CLI missing) or fails (mx
|
|
5
|
+
* not authenticated), the provisioning path must print ready-to-paste
|
|
6
|
+
* `mx memories create` commands — the exact content the successful path would
|
|
7
|
+
* have written, plus the team's codeContext — so "create manually — see above"
|
|
8
|
+
* in the DoD checklist actually has commands above it.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
11
|
+
import { teamMemorySpecs, logManualMemoryCommands } from '../lib/memory.js';
|
|
12
|
+
describe('teamMemorySpecs', () => {
|
|
13
|
+
it('returns the three keys with content the successful path writes (no project prefix)', () => {
|
|
14
|
+
const specs = teamMemorySpecs('retrieval', 'Retrieval', 'mx-agent-system/roleguides/retrieval-leader.md');
|
|
15
|
+
expect(specs.map((s) => s.key)).toEqual(['leaderState', 'iterationLog', 'knownIssues']);
|
|
16
|
+
expect(specs.map((s) => s.name)).toEqual([
|
|
17
|
+
'retrieval-leader-state',
|
|
18
|
+
'retrieval-iteration-log',
|
|
19
|
+
'retrieval-known-issues',
|
|
20
|
+
]);
|
|
21
|
+
// Content matches the strings bootstrapTeamMemories creates.
|
|
22
|
+
expect(specs[0].content).toContain('Retrieval team leader state — initialized');
|
|
23
|
+
expect(specs[0].content).toContain('Roleguide: mx-agent-system/roleguides/retrieval-leader.md');
|
|
24
|
+
expect(specs[1].content).toBe('Retrieval iteration log — initialized. No iterations completed yet.');
|
|
25
|
+
expect(specs[2].content).toBe('Retrieval known issues — initialized. No known issues.');
|
|
26
|
+
});
|
|
27
|
+
it('scopes codeContext per key: leader-state carries role team-lead, log/issues omit role', () => {
|
|
28
|
+
const specs = teamMemorySpecs('retrieval', 'Retrieval', 'rg.md', 'memnexus');
|
|
29
|
+
expect(specs[0].codeContext).toEqual({ product: 'memnexus', team: 'retrieval', role: 'team-lead' });
|
|
30
|
+
expect(specs[1].codeContext).toEqual({ product: 'memnexus', team: 'retrieval' });
|
|
31
|
+
expect(specs[2].codeContext).toEqual({ product: 'memnexus', team: 'retrieval' });
|
|
32
|
+
});
|
|
33
|
+
it('applies the project-scoped prefix when projectSlug is set', () => {
|
|
34
|
+
const specs = teamMemorySpecs('retrieval', 'Retrieval', 'rg.md', 'memnexus');
|
|
35
|
+
expect(specs.map((s) => s.name)).toEqual([
|
|
36
|
+
'memnexus-retrieval-leader-state',
|
|
37
|
+
'memnexus-retrieval-iteration-log',
|
|
38
|
+
'memnexus-retrieval-known-issues',
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('logManualMemoryCommands', () => {
|
|
43
|
+
it('prints one runnable create command per memory, carrying each spec content + its own codeContext', () => {
|
|
44
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
45
|
+
try {
|
|
46
|
+
const specs = teamMemorySpecs('retrieval', 'Retrieval', 'rg.md', 'memnexus');
|
|
47
|
+
logManualMemoryCommands(specs);
|
|
48
|
+
const lines = logSpy.mock.calls.map((c) => String(c[0]));
|
|
49
|
+
expect(lines).toHaveLength(3);
|
|
50
|
+
// Every line is a runnable create command with the exact content AND the
|
|
51
|
+
// spec's own codeContext (same object auto-create passes — no drift).
|
|
52
|
+
for (const spec of specs) {
|
|
53
|
+
const line = lines.find((l) => l.includes(`--name ${spec.name}`));
|
|
54
|
+
expect(line, `expected a command for ${spec.name}`).toBeDefined();
|
|
55
|
+
expect(line).toContain('mx memories create');
|
|
56
|
+
expect(line).toContain('--conversation-id NEW');
|
|
57
|
+
// Content + codeContext are single-quoted (CWE-78). No apostrophes in these
|
|
58
|
+
// fixtures, so the quoted forms are the raw strings wrapped in single quotes.
|
|
59
|
+
expect(line).toContain(`--content '${spec.content}'`);
|
|
60
|
+
expect(line).toContain(`--code-context '${JSON.stringify(spec.codeContext)}'`);
|
|
61
|
+
}
|
|
62
|
+
// leader-state line carries role; log/issues lines do not.
|
|
63
|
+
const leaderLine = lines.find((l) => l.includes('memnexus-retrieval-leader-state'));
|
|
64
|
+
const iterLine = lines.find((l) => l.includes('memnexus-retrieval-iteration-log'));
|
|
65
|
+
expect(leaderLine).toContain('"role":"team-lead"');
|
|
66
|
+
expect(iterLine).not.toContain('role');
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
logSpy.mockRestore();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
it('single-quotes content so an embedded $(...)/backtick from the roleguide path is inert on paste (CWE-78)', () => {
|
|
73
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
74
|
+
try {
|
|
75
|
+
// Malicious roleguide path flows into the leader-state content.
|
|
76
|
+
const specs = teamMemorySpecs('x', 'X', 'rg.md$(touch /tmp/pwned)`id`', 'proj');
|
|
77
|
+
logManualMemoryCommands(specs);
|
|
78
|
+
const leaderLine = logSpy.mock.calls.map((c) => String(c[0])).find((l) => l.includes('proj-x-leader-state'));
|
|
79
|
+
// Content is single-quoted — the $()/backtick payload is literal, not a command.
|
|
80
|
+
expect(leaderLine).toContain("--content 'X team leader state — initialized. Roleguide: rg.md$(touch /tmp/pwned)`id`.");
|
|
81
|
+
// Never double-quoted (where $()/backticks would expand).
|
|
82
|
+
expect(leaderLine).not.toContain('--content "');
|
|
83
|
+
expect(leaderLine).not.toContain('--code-context "');
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
logSpy.mockRestore();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
it("escapes an embedded single quote in content as '\\''", () => {
|
|
90
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
91
|
+
try {
|
|
92
|
+
const specs = teamMemorySpecs('x', "O'Brien", 'rg.md', 'proj');
|
|
93
|
+
logManualMemoryCommands(specs);
|
|
94
|
+
const leaderLine = String(logSpy.mock.calls[0][0]);
|
|
95
|
+
// The apostrophe is closed-escaped-reopened, keeping the string single-quoted throughout.
|
|
96
|
+
expect(leaderLine).toContain("O'\\''Brien");
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
logSpy.mockRestore();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
it('omits the product key (not product:"") in codeContext when no projectSlug is given', () => {
|
|
103
|
+
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
104
|
+
try {
|
|
105
|
+
const specs = teamMemorySpecs('retrieval', 'Retrieval', 'rg.md');
|
|
106
|
+
logManualMemoryCommands(specs);
|
|
107
|
+
const first = String(logSpy.mock.calls[0][0]);
|
|
108
|
+
// product is dropped entirely — team + role remain, no empty-string noise.
|
|
109
|
+
expect(first).toContain(`--code-context '${JSON.stringify({ team: 'retrieval', role: 'team-lead' })}'`);
|
|
110
|
+
expect(first).not.toContain('"product"');
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
logSpy.mockRestore();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=team-memory-commands.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team-memory-commands.test.js","sourceRoot":"","sources":["../../src/__tests__/team-memory-commands.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,oFAAoF,EAAE,GAAG,EAAE;QAC5F,MAAM,KAAK,GAAG,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,gDAAgD,CAAC,CAAC;QAC1G,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;QACxF,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACvC,wBAAwB;YACxB,yBAAyB;YACzB,wBAAwB;SACzB,CAAC,CAAC;QACH,6DAA6D;QAC7D,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,2CAA2C,CAAC,CAAC;QAChF,MAAM,CAAC,KAAK,CAAC,CAAC,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ACjE,uBAAuB,CAAC,KAAK,CAAC,CAAC;YAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,2EAA2E;YAC3E,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,mBAAmB,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;YACxG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC3C,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -58,6 +58,8 @@ Audit of every `|| true` pattern in hook scripts, classifying each by failure im
|
|
|
58
58
|
| `set-terminal-appearance.sh` | 27, 31 | B | `printf ... > /dev/tty 2>/dev/null \|\| true` | Setting terminal title/color; cosmetic. |
|
|
59
59
|
| `worktree-guard.sh` | 118 | B | `tr ... \|\| true` | Stripping quotes from parsed path; empty on failure is safe. |
|
|
60
60
|
| `auto-capture-precompact.sh` | 174 | B | `>/dev/null 2>&1 \|\| true` | mx-agent create-memory call; pre-compact capture is best-effort. |
|
|
61
|
+
| `coordination-midsession-drain.sh` | 39 | B | `cat 2>/dev/null \|\| true` | Reading the Stop-hook stdin payload; empty = no stop_hook_active field, proceed. |
|
|
62
|
+
| `coordination-midsession-drain.sh` | 98 | B | `touch "$STATE_FILE" 2>/dev/null \|\| true` | Writing the throttle timestamp; loss = one extra drain next turn (harmless). |
|
|
61
63
|
|
|
62
64
|
## Summary
|
|
63
65
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# coordination-midsession-drain.sh — Stop hook (v2.66)
|
|
3
|
+
#
|
|
4
|
+
# Delivers cross-team coordination messages to a RUNNING session, not just at
|
|
5
|
+
# session start. The session-start brief (coordination-brief.sh) is the only
|
|
6
|
+
# other delivery point; between restarts, nothing surfaces queued messages. This
|
|
7
|
+
# hook closes that gap by draining the queue at turn boundaries (the Stop chain,
|
|
8
|
+
# where observability-sync already does network work), THROTTLED so it hits the
|
|
9
|
+
# network at most once every 10 minutes.
|
|
10
|
+
#
|
|
11
|
+
# Design (v2.66, Red Team-amended — see gap-assessment 2db88968):
|
|
12
|
+
# - Runs in the STOP chain, not PreToolUse: a slow drain delays the NEXT turn,
|
|
13
|
+
# it never blocks a mid-turn tool call. Fail-open, hard 10s budget.
|
|
14
|
+
# - PRIORITY RULE (fixed, not a knob): P0/P1/P2 messages are injected NOW via a
|
|
15
|
+
# Stop-block `reason`; P3 is NEVER injected mid-session — it is left queued for
|
|
16
|
+
# the session-start brief. The P3 hold is enforced SERVER-SIDE by the CLI's
|
|
17
|
+
# `--min-priority p2` floor: the service returns and confirms only {p0,p1,p2},
|
|
18
|
+
# so P3 is neither delivered nor consumed here.
|
|
19
|
+
# - Token/roster/fence machinery is REUSED, not reinvented: `mx-agent
|
|
20
|
+
# coordination drain` self-provisions the per-team KV token (marker-authoritative,
|
|
21
|
+
# roster-gated, slug-bound 0600 cache) and wraps output in the MX_COORD_UNTRUSTED
|
|
22
|
+
# provenance fence. This hook forwards that fenced block VERBATIM — it never
|
|
23
|
+
# strips or re-wraps the fence.
|
|
24
|
+
#
|
|
25
|
+
# Fail policy: fail-OPEN everywhere. Any error (no jq, old CLI, timeout, drain
|
|
26
|
+
# error, unwritable state dir) exits 0 silently — a coordination hiccup must never
|
|
27
|
+
# block a turn from completing. The throttle timestamp is updated ONLY on a
|
|
28
|
+
# successful drain, so a transient failure retries on the next turn.
|
|
29
|
+
#
|
|
30
|
+
# Output contract: to make the model SEE the messages, a Stop hook emits JSON
|
|
31
|
+
# `{"decision":"block","reason":"<content>"}` on stdout (the documented Stop-hook
|
|
32
|
+
# mechanism). We emit that JSON ONLY when the drain returned at least one message.
|
|
33
|
+
|
|
34
|
+
# Fail-open: any unhandled error → exit 0 silently.
|
|
35
|
+
trap 'exit 0' ERR
|
|
36
|
+
set -u
|
|
37
|
+
|
|
38
|
+
# ── Read the Stop-hook payload; break any hook-recursion loop. ────────────────
|
|
39
|
+
INPUT="$(cat 2>/dev/null || true)"
|
|
40
|
+
|
|
41
|
+
# jq is required BOTH to read stop_hook_active and to safely JSON-encode the block
|
|
42
|
+
# reason (so the fence content is never mangled). Without it, fail-open silently.
|
|
43
|
+
command -v jq >/dev/null 2>&1 || exit 0
|
|
44
|
+
command -v mx-agent >/dev/null 2>&1 || exit 0
|
|
45
|
+
|
|
46
|
+
STOP_HOOK_ACTIVE="$(printf '%s' "$INPUT" | jq -r '.stop_hook_active // false' 2>/dev/null || echo false)"
|
|
47
|
+
# If we already blocked once (the model is re-stopping after seeing our reason),
|
|
48
|
+
# do not block again — the throttle would also catch this, but the guard is cheap
|
|
49
|
+
# insurance against a block/stop loop.
|
|
50
|
+
[ "$STOP_HOOK_ACTIVE" = "true" ] && exit 0
|
|
51
|
+
|
|
52
|
+
# ── Opt-in gate: same flag as the session-start brief. Default OFF. ──────────
|
|
53
|
+
ENABLED="$(mx-agent config get coordination-brief-enabled 2>/dev/null || echo '')"
|
|
54
|
+
[ "$ENABLED" = "true" ] || exit 0
|
|
55
|
+
|
|
56
|
+
# ── Worktree name (same derivation as observability-sync: basename of path). ─
|
|
57
|
+
WORKTREE_PATH="${CLAUDE_WORKTREE_PATH:-${CLAUDE_PROJECT_DIR:-}}"
|
|
58
|
+
[ -z "$WORKTREE_PATH" ] && exit 0
|
|
59
|
+
WORKTREE_NAME="$(basename "$WORKTREE_PATH")"
|
|
60
|
+
# Sanitize for use as a filename (defense against a hostile path component).
|
|
61
|
+
WORKTREE_NAME="${WORKTREE_NAME//[^a-zA-Z0-9_.-]/}"
|
|
62
|
+
WORKTREE_NAME="${WORKTREE_NAME:-default}"
|
|
63
|
+
|
|
64
|
+
# ── Throttle: at most one successful drain per THROTTLE_SECS (default 10 min). ─
|
|
65
|
+
THROTTLE_SECS="${MX_COORD_DRAIN_THROTTLE_SECS:-600}"
|
|
66
|
+
STATE_DIR="${HOME:-/tmp}/.mx-agent/coordination-drain"
|
|
67
|
+
STATE_FILE="${STATE_DIR}/${WORKTREE_NAME}.last"
|
|
68
|
+
mkdir -p "$STATE_DIR" 2>/dev/null || exit 0
|
|
69
|
+
# Own the state dir tightly so a co-tenant cannot drop files into it (CWE-59).
|
|
70
|
+
chmod 700 "$STATE_DIR" 2>/dev/null || true
|
|
71
|
+
# CWE-59: NEVER follow a symlink at the state path. A co-tenant could pre-plant a
|
|
72
|
+
# symlink there to redirect our stat/touch onto an arbitrary file. If the .last
|
|
73
|
+
# path is a symlink, refuse and fail-open (hook policy) rather than following it.
|
|
74
|
+
[ -L "$STATE_FILE" ] && exit 0
|
|
75
|
+
if [ -f "$STATE_FILE" ]; then
|
|
76
|
+
LAST="$(stat -c %Y "$STATE_FILE" 2>/dev/null || stat -f %m "$STATE_FILE" 2>/dev/null || echo 0)"
|
|
77
|
+
NOW="$(date +%s 2>/dev/null || echo 0)"
|
|
78
|
+
AGE=$(( NOW - LAST ))
|
|
79
|
+
# Fresh success within the window → skip WITHOUT touching the network.
|
|
80
|
+
if [ "$LAST" -gt 0 ] && [ "$AGE" -ge 0 ] && [ "$AGE" -lt "$THROTTLE_SECS" ]; then
|
|
81
|
+
exit 0
|
|
82
|
+
fi
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
# ── Drain P0-P2 only. P3 is held server-side for the session-start brief. ────
|
|
86
|
+
# Fenced by default (MX_COORD_UNTRUSTED). stderr is suppressed: the CLI routes
|
|
87
|
+
# non-secret fall-back notices there, but a Stop hook must keep stdout clean for
|
|
88
|
+
# the JSON block. Hard-capped to stay inside the 10s budget.
|
|
89
|
+
TIMEOUT_SECS="${MX_COORD_DRAIN_TIMEOUT_SECS:-10}"
|
|
90
|
+
OUT=""
|
|
91
|
+
STATUS=0
|
|
92
|
+
OUT="$(timeout "$TIMEOUT_SECS" mx-agent coordination drain --min-priority p2 2>/dev/null)" || STATUS=$?
|
|
93
|
+
|
|
94
|
+
if [ "$STATUS" -ne 0 ]; then
|
|
95
|
+
# Timeout, drain error, or a too-old CLI (missing the `coordination` command or
|
|
96
|
+
# the `--min-priority` option → Commander exits non-zero). Fail-open and do NOT
|
|
97
|
+
# update the throttle, so the next turn retries. We deliberately do NOT retry
|
|
98
|
+
# without --min-priority: an unfiltered drain would consume P3s the brief owns.
|
|
99
|
+
exit 0
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
# Successful drain — record the timestamp so an empty queue does not re-hit the
|
|
103
|
+
# network every turn. Applies whether or not messages were returned.
|
|
104
|
+
touch "$STATE_FILE" 2>/dev/null || true
|
|
105
|
+
|
|
106
|
+
# Emit ONLY when the drain returned fenced messages. The fence marker is present
|
|
107
|
+
# iff there is at least one message; the empty-queue line has no fence.
|
|
108
|
+
case "$OUT" in
|
|
109
|
+
*MX_COORD_UNTRUSTED*)
|
|
110
|
+
# Forward the fenced block VERBATIM as the Stop-block reason. `jq -Rs`
|
|
111
|
+
# JSON-encodes the raw stdin so the fence + per-render nonce are preserved
|
|
112
|
+
# byte-for-byte — never stripped, never re-wrapped.
|
|
113
|
+
printf '%s' "$OUT" | jq -Rs '{decision:"block", reason:.}'
|
|
114
|
+
exit 0
|
|
115
|
+
;;
|
|
116
|
+
*)
|
|
117
|
+
# Empty queue (or an unfenced fall-back notice) → nothing to surface.
|
|
118
|
+
exit 0
|
|
119
|
+
;;
|
|
120
|
+
esac
|
|
@@ -109,6 +109,10 @@
|
|
|
109
109
|
{
|
|
110
110
|
"type": "command",
|
|
111
111
|
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/iteration-log-check.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"type": "command",
|
|
115
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/coordination-midsession-drain.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
112
116
|
}
|
|
113
117
|
]
|
|
114
118
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* mx-agent coordination commands (FR-7) + FR-8 degraded fallback.
|
|
3
3
|
*
|
|
4
4
|
* mx-agent escalate --to <team> --priority p0..p3 --body "..."
|
|
5
|
-
* mx-agent coordination drain [--all] [--limit N] [--no-confirm]
|
|
5
|
+
* mx-agent coordination drain [--all] [--limit N] [--no-confirm] [--min-priority pN]
|
|
6
6
|
* mx-agent coordination ack <messageId>
|
|
7
7
|
*
|
|
8
8
|
* These map 1:1 to the standalone service's enqueue / drain / ack operations.
|
|
@@ -64,6 +64,23 @@ export interface DrainOptions {
|
|
|
64
64
|
fenced?: boolean;
|
|
65
65
|
/** Operator opt-out of the provenance fence. Fields are STILL sanitized. */
|
|
66
66
|
raw?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Server-side priority floor (v2.66): drain ONLY messages at or above this
|
|
69
|
+
* urgency, e.g. `p2` → {p0,p1,p2}. Lower-urgency messages (p3 when floor=p2)
|
|
70
|
+
* are NOT returned and NOT confirmed — they remain queued for the SessionStart
|
|
71
|
+
* brief. Used by the mid-session drain hook to inject P0-P2 now while leaving
|
|
72
|
+
* P3 for session start. Invalid values exit non-zero.
|
|
73
|
+
*/
|
|
74
|
+
minPriority?: string;
|
|
75
|
+
/**
|
|
76
|
+
* SF-1 wrong-team interlock (CWE-863 parity with runBrief): the team this
|
|
77
|
+
* worktree expects to be draining (the authoritative marker slug). When set and
|
|
78
|
+
* the service reports a DIFFERENT team for the batch, the output is discarded
|
|
79
|
+
* and the batch is NOT confirmed, so the wrong team's messages redeliver instead
|
|
80
|
+
* of being consumed here. Falls back to MX_COORD_EXPECT_TEAM when unset — which
|
|
81
|
+
* prepareClient arms automatically on the self-provisioned path.
|
|
82
|
+
*/
|
|
83
|
+
expectedTeam?: string;
|
|
67
84
|
}
|
|
68
85
|
/**
|
|
69
86
|
* FR-7 drain. `--all` returns the full backlog; `--limit N` caps it. Output is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordination.d.ts","sourceRoot":"","sources":["../../src/commands/coordination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAOL,KAAK,kBAAkB,EAExB,MAAM,+BAA+B,CAAC;AASvC,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAgHvC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAAE,GAAG,kBAAkB,GAAG,IAAI,CA+C/F;AAkCD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AASD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAkDD;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyD/F;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,CAAC;IAC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,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CA8RlF"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* mx-agent coordination commands (FR-7) + FR-8 degraded fallback.
|
|
3
3
|
*
|
|
4
4
|
* mx-agent escalate --to <team> --priority p0..p3 --body "..."
|
|
5
|
-
* mx-agent coordination drain [--all] [--limit N] [--no-confirm]
|
|
5
|
+
* mx-agent coordination drain [--all] [--limit N] [--no-confirm] [--min-priority pN]
|
|
6
6
|
* mx-agent coordination ack <messageId>
|
|
7
7
|
*
|
|
8
8
|
* These map 1:1 to the standalone service's enqueue / drain / ack operations.
|
|
@@ -318,6 +318,24 @@ export async function runEscalate(opts, deps) {
|
|
|
318
318
|
process.exit(1);
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
+
/** Priority urgency order, most-urgent first. p0 > p1 > p2 > p3. */
|
|
322
|
+
const PRIORITY_ORDER = ['p0', 'p1', 'p2', 'p3'];
|
|
323
|
+
/**
|
|
324
|
+
* Expand a `--min-priority` floor into the explicit priority set at or above it.
|
|
325
|
+
* `p2` → ['p0','p1','p2']. Returns undefined for an unset floor (drain all).
|
|
326
|
+
* Exits non-zero on an invalid value so a typo cannot silently widen the drain
|
|
327
|
+
* to include P3 (which would consume P3s the SessionStart brief must surface).
|
|
328
|
+
*/
|
|
329
|
+
function priorityFloorToSet(min) {
|
|
330
|
+
if (!min)
|
|
331
|
+
return undefined;
|
|
332
|
+
const idx = PRIORITY_ORDER.indexOf(min);
|
|
333
|
+
if (idx < 0) {
|
|
334
|
+
console.error(`Error: --min-priority must be one of p0, p1, p2, p3 (got "${min}").`);
|
|
335
|
+
process.exit(1);
|
|
336
|
+
}
|
|
337
|
+
return PRIORITY_ORDER.slice(0, idx + 1);
|
|
338
|
+
}
|
|
321
339
|
/**
|
|
322
340
|
* FR-7 drain. `--all` returns the full backlog; `--limit N` caps it. Output is
|
|
323
341
|
* wrapped in the provenance fence BY DEFAULT (KI-COORDCLI-DRAIN-UNFENCED-DEFAULT);
|
|
@@ -327,6 +345,9 @@ export async function runEscalate(opts, deps) {
|
|
|
327
345
|
* it pending for re-queue. `--no-confirm` leaves the batch unconfirmed.
|
|
328
346
|
*/
|
|
329
347
|
export async function runDrain(opts, deps) {
|
|
348
|
+
// Validate the priority floor first — a typo must fail fast, before any
|
|
349
|
+
// network work, and must never silently widen the drain to include P3.
|
|
350
|
+
const priorities = priorityFloorToSet(opts.minPriority);
|
|
330
351
|
if (resolveCoordinationMode() === 'memory') {
|
|
331
352
|
memoryModeQueueOnlyNote('drain');
|
|
332
353
|
return; // exit 0 — no crash
|
|
@@ -337,7 +358,27 @@ export async function runDrain(opts, deps) {
|
|
|
337
358
|
// Flush any queued-locally entries now that the service is reachable.
|
|
338
359
|
await opportunisticFlush(client);
|
|
339
360
|
const limit = opts.all ? undefined : opts.limit ? parseInt(opts.limit, 10) : undefined;
|
|
340
|
-
|
|
361
|
+
// v2.66: the optional priority floor (validated above) filters server-side so
|
|
362
|
+
// lower-urgency messages (p3 when floor=p2) are neither returned nor confirmed
|
|
363
|
+
// — they stay queued for the SessionStart brief.
|
|
364
|
+
const res = await client.drain({ limit, priorities });
|
|
365
|
+
// SF-1 wrong-token interlock (CWE-863) — same guard runBrief applies: if we
|
|
366
|
+
// know which team this worktree should be draining, verify the service served
|
|
367
|
+
// THAT team before rendering/confirming. On mismatch the batch stays unconfirmed
|
|
368
|
+
// → the service re-queues it (TTL) so another team's messages are never consumed
|
|
369
|
+
// or leaked here. Mirrors runBrief exactly, incl. the INFO-1 rolled-back-service
|
|
370
|
+
// note (armed but the service echoed no team).
|
|
371
|
+
const expectedTeam = opts.expectedTeam ?? process.env.MX_COORD_EXPECT_TEAM;
|
|
372
|
+
if (expectedTeam && !res.team) {
|
|
373
|
+
console.error(`coordination drain: SF-1 armed (expected team "${expectedTeam}") but the service reported no team — ` +
|
|
374
|
+
'cannot verify drain ownership; proceeding unverified (update the coordination service to re-enable the interlock)');
|
|
375
|
+
}
|
|
376
|
+
if (expectedTeam && res.team && res.team !== expectedTeam) {
|
|
377
|
+
// No message bodies in the warning — only the two team slugs (non-secret).
|
|
378
|
+
console.error(`coordination drain: drained team "${res.team}" != expected "${expectedTeam}" — ` +
|
|
379
|
+
'skipping confirm and discarding output (messages will redeliver)');
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
341
382
|
if (res.messages.length === 0) {
|
|
342
383
|
console.log('no cross-team coordination pending');
|
|
343
384
|
return;
|