@namzu/cli 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/__tests__/resume.test.d.ts +15 -0
- package/dist/commands/__tests__/resume.test.d.ts.map +1 -0
- package/dist/commands/__tests__/resume.test.js +116 -0
- package/dist/commands/__tests__/resume.test.js.map +1 -0
- package/dist/commands/__tests__/run-flags.test.d.ts +11 -0
- package/dist/commands/__tests__/run-flags.test.d.ts.map +1 -0
- package/dist/commands/__tests__/run-flags.test.js +190 -0
- package/dist/commands/__tests__/run-flags.test.js.map +1 -0
- package/dist/commands/__tests__/run-stream-flags.test.js +161 -11
- package/dist/commands/__tests__/run-stream-flags.test.js.map +1 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/resume.d.ts +60 -0
- package/dist/commands/resume.d.ts.map +1 -0
- package/dist/commands/resume.js +107 -0
- package/dist/commands/resume.js.map +1 -0
- package/dist/commands/run-flags.d.ts +76 -0
- package/dist/commands/run-flags.d.ts.map +1 -0
- package/dist/commands/run-flags.js +163 -0
- package/dist/commands/run-flags.js.map +1 -0
- package/dist/commands/run-stream.d.ts +0 -36
- package/dist/commands/run-stream.d.ts.map +1 -1
- package/dist/commands/run-stream.js +71 -98
- package/dist/commands/run-stream.js.map +1 -1
- package/dist/commands/run.d.ts +25 -0
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +185 -16
- package/dist/commands/run.js.map +1 -1
- package/dist/config/schema.d.ts +9 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/permissions/__tests__/mode.test.d.ts +10 -0
- package/dist/permissions/__tests__/mode.test.d.ts.map +1 -0
- package/dist/permissions/__tests__/mode.test.js +115 -0
- package/dist/permissions/__tests__/mode.test.js.map +1 -0
- package/dist/permissions/__tests__/rules.test.d.ts +10 -0
- package/dist/permissions/__tests__/rules.test.d.ts.map +1 -0
- package/dist/permissions/__tests__/rules.test.js +196 -0
- package/dist/permissions/__tests__/rules.test.js.map +1 -0
- package/dist/permissions/mode.d.ts +64 -0
- package/dist/permissions/mode.d.ts.map +1 -0
- package/dist/permissions/mode.js +32 -0
- package/dist/permissions/mode.js.map +1 -0
- package/dist/permissions/rules.d.ts +105 -0
- package/dist/permissions/rules.d.ts.map +1 -0
- package/dist/permissions/rules.js +163 -0
- package/dist/permissions/rules.js.map +1 -0
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +8 -4
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/__tests__/working-directory.test.d.ts +13 -0
- package/dist/tui/__tests__/working-directory.test.d.ts.map +1 -0
- package/dist/tui/__tests__/working-directory.test.js +115 -0
- package/dist/tui/__tests__/working-directory.test.js.map +1 -0
- package/dist/tui/agent.d.ts +30 -3
- package/dist/tui/agent.d.ts.map +1 -1
- package/dist/tui/agent.js +58 -14
- package/dist/tui/agent.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resuming a conversation, and — mostly — refusing to.
|
|
3
|
+
*
|
|
4
|
+
* The rule under test: when the named conversation cannot be resumed, this
|
|
5
|
+
* REFUSES and names the cause. It never falls back to a fresh session, and it
|
|
6
|
+
* never resumes with a partial history.
|
|
7
|
+
*
|
|
8
|
+
* Both fallbacks would be invisible from outside. The user asked for a specific
|
|
9
|
+
* conversation, would get something that looks like one, and would find out
|
|
10
|
+
* several turns later having already acted on it. A half-context is the worse
|
|
11
|
+
* of the two: it is not a degraded context, it is a different context that lies
|
|
12
|
+
* about being complete.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=resume.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.test.d.ts","sourceRoot":"","sources":["../../../src/commands/__tests__/resume.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resuming a conversation, and — mostly — refusing to.
|
|
3
|
+
*
|
|
4
|
+
* The rule under test: when the named conversation cannot be resumed, this
|
|
5
|
+
* REFUSES and names the cause. It never falls back to a fresh session, and it
|
|
6
|
+
* never resumes with a partial history.
|
|
7
|
+
*
|
|
8
|
+
* Both fallbacks would be invisible from outside. The user asked for a specific
|
|
9
|
+
* conversation, would get something that looks like one, and would find out
|
|
10
|
+
* several turns later having already acted on it. A half-context is the worse
|
|
11
|
+
* of the two: it is not a degraded context, it is a different context that lies
|
|
12
|
+
* about being complete.
|
|
13
|
+
*/
|
|
14
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
15
|
+
import { listRecent, loadConversation } from '../../integrations/sessions/store.js';
|
|
16
|
+
import { resolveResume } from '../resume.js';
|
|
17
|
+
vi.mock('../../integrations/sessions/store.js', () => ({
|
|
18
|
+
listRecent: vi.fn(),
|
|
19
|
+
loadConversation: vi.fn(),
|
|
20
|
+
}));
|
|
21
|
+
const sessions = {};
|
|
22
|
+
const CWD = '/projects/foo';
|
|
23
|
+
function recent(...ids) {
|
|
24
|
+
vi.mocked(listRecent).mockResolvedValue(ids.map((id, i) => ({
|
|
25
|
+
id: id,
|
|
26
|
+
title: id,
|
|
27
|
+
updatedAt: `2026-08-0${i + 1}T00:00:00Z`,
|
|
28
|
+
count: 2,
|
|
29
|
+
})));
|
|
30
|
+
}
|
|
31
|
+
describe('asking for nothing', () => {
|
|
32
|
+
it('is a fresh run, not an error', async () => {
|
|
33
|
+
const out = await resolveResume(sessions, { continueLast: false, sessionId: null }, CWD);
|
|
34
|
+
expect(out.kind).toBe('fresh');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('--continue', () => {
|
|
38
|
+
it('takes the most recent conversation', async () => {
|
|
39
|
+
recent('ses_new', 'ses_old');
|
|
40
|
+
vi.mocked(loadConversation).mockResolvedValue([
|
|
41
|
+
{ role: 'user', content: 'hi', timestamp: 0 },
|
|
42
|
+
]);
|
|
43
|
+
const out = await resolveResume(sessions, { continueLast: true, sessionId: null }, CWD);
|
|
44
|
+
expect(out).toMatchObject({ kind: 'resumed', sessionId: 'ses_new' });
|
|
45
|
+
});
|
|
46
|
+
it('refuses with its OWN sentence when there is nothing here', async () => {
|
|
47
|
+
// Not "cannot resume" — the cause is different and so is the fix. Someone
|
|
48
|
+
// with no conversation here is usually standing in the wrong directory,
|
|
49
|
+
// so the message has to point at --cwd rather than at a broken store.
|
|
50
|
+
recent();
|
|
51
|
+
const out = await resolveResume(sessions, { continueLast: true, sessionId: null }, CWD);
|
|
52
|
+
expect(out.kind).toBe('error');
|
|
53
|
+
expect(out).toMatchObject({ message: expect.stringContaining('no previous conversation') });
|
|
54
|
+
expect(out).toMatchObject({ message: expect.stringContaining(CWD) });
|
|
55
|
+
expect(out).toMatchObject({ message: expect.stringContaining('--cwd') });
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('--resume <id>', () => {
|
|
59
|
+
it('takes the conversation it was given, not the most recent', async () => {
|
|
60
|
+
recent('ses_new', 'ses_wanted');
|
|
61
|
+
vi.mocked(loadConversation).mockResolvedValue([
|
|
62
|
+
{ role: 'user', content: 'hi', timestamp: 0 },
|
|
63
|
+
]);
|
|
64
|
+
const out = await resolveResume(sessions, { continueLast: false, sessionId: 'ses_wanted' }, CWD);
|
|
65
|
+
expect(out).toMatchObject({ kind: 'resumed', sessionId: 'ses_wanted' });
|
|
66
|
+
});
|
|
67
|
+
it('refuses an id that is not here, and says how many are', async () => {
|
|
68
|
+
// THE case. Starting fresh would hand back something indistinguishable
|
|
69
|
+
// from what was asked for.
|
|
70
|
+
recent('ses_a', 'ses_b');
|
|
71
|
+
const out = await resolveResume(sessions, { continueLast: false, sessionId: 'ses_gone' }, CWD);
|
|
72
|
+
expect(out.kind).toBe('error');
|
|
73
|
+
expect(out).toMatchObject({ message: expect.stringContaining('ses_gone') });
|
|
74
|
+
expect(out).toMatchObject({ message: expect.stringContaining('2 others') });
|
|
75
|
+
});
|
|
76
|
+
it('points at --cwd when the directory has nothing at all', async () => {
|
|
77
|
+
recent();
|
|
78
|
+
const out = await resolveResume(sessions, { continueLast: false, sessionId: 'ses_gone' }, CWD);
|
|
79
|
+
expect(out).toMatchObject({ message: expect.stringContaining('--cwd') });
|
|
80
|
+
});
|
|
81
|
+
it('refuses rather than resuming with a partial history', async () => {
|
|
82
|
+
// The half-context case. Carrying on with an empty transcript would look
|
|
83
|
+
// exactly like a resumed session to the user and to the model.
|
|
84
|
+
recent('ses_a');
|
|
85
|
+
vi.mocked(loadConversation).mockRejectedValue(new Error('transcript is corrupt'));
|
|
86
|
+
const out = await resolveResume(sessions, { continueLast: false, sessionId: 'ses_a' }, CWD);
|
|
87
|
+
expect(out.kind).toBe('error');
|
|
88
|
+
expect(out).toMatchObject({ message: expect.stringContaining('transcript is corrupt') });
|
|
89
|
+
});
|
|
90
|
+
it('refuses an empty transcript rather than calling it resumed', async () => {
|
|
91
|
+
recent('ses_a');
|
|
92
|
+
vi.mocked(loadConversation).mockResolvedValue([]);
|
|
93
|
+
const out = await resolveResume(sessions, { continueLast: false, sessionId: 'ses_a' }, CWD);
|
|
94
|
+
expect(out.kind).toBe('error');
|
|
95
|
+
expect(out).toMatchObject({ message: expect.stringContaining('no messages') });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe('the two flags together', () => {
|
|
99
|
+
it('refuses, because they name different conversations', async () => {
|
|
100
|
+
const out = await resolveResume(sessions, { continueLast: true, sessionId: 'ses_a' }, CWD);
|
|
101
|
+
expect(out.kind).toBe('error');
|
|
102
|
+
expect(out).toMatchObject({ message: expect.stringContaining('Pass one') });
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('no store at all', () => {
|
|
106
|
+
it('refuses instead of quietly starting fresh', async () => {
|
|
107
|
+
const out = await resolveResume(null, { continueLast: true, sessionId: null }, CWD);
|
|
108
|
+
expect(out.kind).toBe('error');
|
|
109
|
+
expect(out).toMatchObject({ message: expect.stringContaining('nothing to resume') });
|
|
110
|
+
});
|
|
111
|
+
it('still runs fresh when nothing was asked for', async () => {
|
|
112
|
+
const out = await resolveResume(null, { continueLast: false, sessionId: null }, CWD);
|
|
113
|
+
expect(out.kind).toBe('fresh');
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=resume.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.test.js","sourceRoot":"","sources":["../../../src/commands/__tests__/resume.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAGjD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C,EAAE,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE,CAAC,CAAC;IACtD,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE;IACnB,gBAAgB,EAAE,EAAE,CAAC,EAAE,EAAE;CACzB,CAAC,CAAC,CAAA;AAEH,MAAM,QAAQ,GAAG,EAAiB,CAAA;AAClC,MAAM,GAAG,GAAG,eAAe,CAAA;AAE3B,SAAS,MAAM,CAAC,GAAG,GAAa;IAC/B,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,iBAAiB,CACtC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACnB,EAAE,EAAE,EAAW;QACf,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,YAAY,CAAC,GAAG,CAAC,YAAY;QACxC,KAAK,EAAE,CAAC;KACR,CAAC,CAAC,CACH,CAAA;AACF,CAAC;AAED,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,8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AAG,MAAM,aAAa,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,CAAA;QAEnF,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAA;IACrF,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,CAAA;QAEpF,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `namzu run` accepts what `namzu run-stream` accepts.
|
|
3
|
+
*
|
|
4
|
+
* The two are the same headless one-shot and differ only in how they print, so
|
|
5
|
+
* an option one takes and the other reads aloud to the model is a defect, not a
|
|
6
|
+
* design. `run` joined every argument into the prompt, which is the exact shape
|
|
7
|
+
* already fixed once in the streaming sibling — `--cwd` was documented there,
|
|
8
|
+
* unparsed, and silently ran in the process's own directory.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=run-flags.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-flags.test.d.ts","sourceRoot":"","sources":["../../../src/commands/__tests__/run-flags.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `namzu run` accepts what `namzu run-stream` accepts.
|
|
3
|
+
*
|
|
4
|
+
* The two are the same headless one-shot and differ only in how they print, so
|
|
5
|
+
* an option one takes and the other reads aloud to the model is a defect, not a
|
|
6
|
+
* design. `run` joined every argument into the prompt, which is the exact shape
|
|
7
|
+
* already fixed once in the streaming sibling — `--cwd` was documented there,
|
|
8
|
+
* unparsed, and silently ran in the process's own directory.
|
|
9
|
+
*/
|
|
10
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { Readable } from 'node:stream';
|
|
14
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
15
|
+
import { EXIT_USAGE } from '../../exit-codes.js';
|
|
16
|
+
import { composePrompt, runCommand } from '../run.js';
|
|
17
|
+
const seen = { prompt: null, cwd: undefined, provider: undefined, model: undefined };
|
|
18
|
+
vi.mock('../../tui/agent.js', () => ({
|
|
19
|
+
probeAgentSession: vi.fn(async () => ({
|
|
20
|
+
preferences: { version: 2, provider: 'mock', subagents: { active: [] } },
|
|
21
|
+
needsRepickReason: null,
|
|
22
|
+
detected: [],
|
|
23
|
+
})),
|
|
24
|
+
createAgentSession: vi.fn(async (prefs, _detected, opts) => {
|
|
25
|
+
seen.cwd = opts?.cwd;
|
|
26
|
+
seen.provider = prefs.provider;
|
|
27
|
+
seen.model = prefs.model;
|
|
28
|
+
return {
|
|
29
|
+
hasProvider: true,
|
|
30
|
+
providerSummary: 'mock',
|
|
31
|
+
modelSummary: 'mock-model',
|
|
32
|
+
toolNames: [],
|
|
33
|
+
deferredToolCount: 0,
|
|
34
|
+
errorHint: null,
|
|
35
|
+
send: (messages) => {
|
|
36
|
+
seen.prompt = messages[0]?.content ?? null;
|
|
37
|
+
return (async function* () {
|
|
38
|
+
yield { kind: 'done', stopReason: 'end_turn' };
|
|
39
|
+
})();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
}));
|
|
44
|
+
function context() {
|
|
45
|
+
const printed = [];
|
|
46
|
+
const errors = [];
|
|
47
|
+
const ctx = {
|
|
48
|
+
formatter: {
|
|
49
|
+
name: 'text',
|
|
50
|
+
print: (d) => printed.push(String(d?.text ?? d)),
|
|
51
|
+
info: () => { },
|
|
52
|
+
error: (e) => errors.push(String(e?.message ?? e)),
|
|
53
|
+
},
|
|
54
|
+
config: {},
|
|
55
|
+
};
|
|
56
|
+
return { ctx, printed, errors };
|
|
57
|
+
}
|
|
58
|
+
async function run(rawArgs) {
|
|
59
|
+
seen.prompt = null;
|
|
60
|
+
seen.cwd = undefined;
|
|
61
|
+
seen.provider = undefined;
|
|
62
|
+
seen.model = undefined;
|
|
63
|
+
const { ctx, errors } = context();
|
|
64
|
+
const code = (await runCommand.handler({ rawArgs, ctx }));
|
|
65
|
+
return { code, errors };
|
|
66
|
+
}
|
|
67
|
+
describe('namzu run reads its options instead of reciting them', () => {
|
|
68
|
+
it('works in --cwd and keeps it out of the prompt', async () => {
|
|
69
|
+
const elsewhere = mkdtempSync(join(tmpdir(), 'namzu-run-cwd-'));
|
|
70
|
+
try {
|
|
71
|
+
const { code } = await run(['--cwd', elsewhere, 'fix', 'the', 'test']);
|
|
72
|
+
expect(code).toBe(0);
|
|
73
|
+
expect(seen.cwd).toBe(elsewhere);
|
|
74
|
+
// The whole point: the flag was previously the first two words the
|
|
75
|
+
// model was asked to act on.
|
|
76
|
+
expect(seen.prompt).toBe('fix the test');
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
rmSync(elsewhere, { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
it('takes --provider and --model over the stored preference', async () => {
|
|
83
|
+
const { code } = await run(['--provider', 'openai', '--model', 'some-model', 'hello']);
|
|
84
|
+
expect(code).toBe(0);
|
|
85
|
+
expect(seen.provider).toBe('openai');
|
|
86
|
+
expect(seen.model).toBe('some-model');
|
|
87
|
+
expect(seen.prompt).toBe('hello');
|
|
88
|
+
});
|
|
89
|
+
it('refuses an option it does not know, with a usage exit code', async () => {
|
|
90
|
+
// A shell caller reads `$?`; saying "--temperature 0.5" to the model and
|
|
91
|
+
// exiting 0 is the failure this replaces.
|
|
92
|
+
const { code, errors } = await run(['--temperature', '0.5', 'hello']);
|
|
93
|
+
expect(code).toBe(EXIT_USAGE);
|
|
94
|
+
expect(errors.join('')).toContain('--temperature');
|
|
95
|
+
expect(seen.prompt).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
it('refuses a --cwd that is not there rather than running in this one', async () => {
|
|
98
|
+
const { code, errors } = await run(['--cwd', join(tmpdir(), 'namzu-run-no-such'), 'hello']);
|
|
99
|
+
expect(code).toBe(EXIT_USAGE);
|
|
100
|
+
expect(errors.join('')).toContain('--cwd does not exist');
|
|
101
|
+
expect(seen.prompt).toBeNull();
|
|
102
|
+
});
|
|
103
|
+
it('lets `--` carry a prompt that begins with a dash', async () => {
|
|
104
|
+
const { code } = await run(['--', '--force', 'is', 'part', 'of', 'the', 'question']);
|
|
105
|
+
expect(code).toBe(0);
|
|
106
|
+
expect(seen.prompt).toBe('--force is part of the question');
|
|
107
|
+
});
|
|
108
|
+
it('accepts --yolo and does not put it in the prompt', async () => {
|
|
109
|
+
// Headless turns never prompt for approval, so there is nothing to skip.
|
|
110
|
+
// Accepting it silently is what keeps `namzu --yolo run …` working.
|
|
111
|
+
const { code } = await run(['--yolo', 'hello']);
|
|
112
|
+
expect(code).toBe(0);
|
|
113
|
+
expect(seen.prompt).toBe('hello');
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('a pipe and a question are both the prompt', () => {
|
|
117
|
+
// `cat notes.txt | namzu run "summarise this"` read the three words and
|
|
118
|
+
// silently dropped the file: piped input was consulted only when there was
|
|
119
|
+
// no argument prompt. The run succeeded and answered about nothing.
|
|
120
|
+
it('keeps piped material alongside the question', () => {
|
|
121
|
+
const prompt = composePrompt('summarise this', 'line one\nline two\n');
|
|
122
|
+
expect(prompt).toContain('summarise this');
|
|
123
|
+
expect(prompt).toContain('line one');
|
|
124
|
+
expect(prompt).toContain('line two');
|
|
125
|
+
});
|
|
126
|
+
it('fences the piped material so it cannot read as part of the question', () => {
|
|
127
|
+
// Without a boundary the last line of a long paste runs into the
|
|
128
|
+
// instruction, and the model cannot tell the request from the material.
|
|
129
|
+
const prompt = composePrompt('what is wrong here?', 'const x = 1');
|
|
130
|
+
expect(prompt).toBe('what is wrong here?\n\n<stdin>\nconst x = 1\n</stdin>');
|
|
131
|
+
});
|
|
132
|
+
it('is just the pipe when no question was given', () => {
|
|
133
|
+
expect(composePrompt('', 'do the thing')).toBe('do the thing');
|
|
134
|
+
});
|
|
135
|
+
it('is just the question when nothing was piped', () => {
|
|
136
|
+
expect(composePrompt('do the thing', '')).toBe('do the thing');
|
|
137
|
+
// No empty tag block either — a model shown `<stdin></stdin>` is being
|
|
138
|
+
// told something was attached when nothing was.
|
|
139
|
+
expect(composePrompt('do the thing', ' \n ')).toBe('do the thing');
|
|
140
|
+
});
|
|
141
|
+
it('is empty when neither was given, so the caller can report it', () => {
|
|
142
|
+
expect(composePrompt('', '')).toBe('');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe('the pipe reaches the model, not just the composer', () => {
|
|
146
|
+
// composePrompt is pure and proves the shape. This proves the plumbing:
|
|
147
|
+
// that piped bytes are actually READ when a prompt argument is present.
|
|
148
|
+
// They were not — stdin was consulted only when the argument was absent —
|
|
149
|
+
// and a unit test of the composer alone would pass with that defect intact.
|
|
150
|
+
function withStdin(text, fn) {
|
|
151
|
+
const real = Object.getOwnPropertyDescriptor(process, 'stdin');
|
|
152
|
+
const fake = text === null ? Readable.from([]) : Readable.from([Buffer.from(text)]);
|
|
153
|
+
Object.defineProperty(process, 'stdin', {
|
|
154
|
+
configurable: true,
|
|
155
|
+
get: () => Object.assign(fake, { isTTY: text === null }),
|
|
156
|
+
});
|
|
157
|
+
return fn().finally(() => {
|
|
158
|
+
if (real)
|
|
159
|
+
Object.defineProperty(process, 'stdin', real);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
it('sends the piped file alongside the question', async () => {
|
|
163
|
+
await withStdin('the contents of notes.txt', async () => {
|
|
164
|
+
const { code } = await run(['summarise this']);
|
|
165
|
+
expect(code).toBe(0);
|
|
166
|
+
expect(seen.prompt).toContain('summarise this');
|
|
167
|
+
expect(seen.prompt).toContain('the contents of notes.txt');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
it('reads the pipe as the whole prompt for the `-` sentinel', async () => {
|
|
171
|
+
await withStdin('the question is in here', async () => {
|
|
172
|
+
const { code } = await run(['-']);
|
|
173
|
+
expect(code).toBe(0);
|
|
174
|
+
expect(seen.prompt).toBe('the question is in here');
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('a flag that was never read is refused, not swallowed', () => {
|
|
179
|
+
// `--instance` was parsed into a field nothing anywhere in the repo read.
|
|
180
|
+
// A host passing it got the persona selection it asked for exactly never,
|
|
181
|
+
// and was told exactly nothing — which is worse than an absent flag,
|
|
182
|
+
// because an absent flag says so immediately.
|
|
183
|
+
it('refuses --instance now that it means nothing', async () => {
|
|
184
|
+
const { code, errors } = await run(['--instance', 'namzu-2', 'hello']);
|
|
185
|
+
expect(code).toBe(EXIT_USAGE);
|
|
186
|
+
expect(errors.join('')).toContain('--instance');
|
|
187
|
+
expect(seen.prompt).toBeNull();
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
//# sourceMappingURL=run-flags.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-flags.test.js","sourceRoot":"","sources":["../../../src/commands/__tests__/run-flags.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAA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AAI,EAAE;QAC7D,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAA;QAEtE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;QAC/C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC/B,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
1
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
5
|
import { openSessions } from '../../integrations/sessions/store.js';
|
|
3
|
-
import {
|
|
6
|
+
import { parseRunFlags } from '../run-flags.js';
|
|
7
|
+
import { historyCommand, runStreamCommand, skillsJSONCommand } from '../run-stream.js';
|
|
4
8
|
// Mocked so the directory the store is opened at is observable. Nothing here
|
|
5
9
|
// touches a real `.namzu` store; `resolveConversation` returning null is the
|
|
6
10
|
// "no such session" path, which is what makes the handler terminate.
|
|
@@ -10,6 +14,29 @@ vi.mock('../../integrations/sessions/store.js', () => ({
|
|
|
10
14
|
loadConversation: vi.fn(async () => []),
|
|
11
15
|
appendMessages: vi.fn(async () => undefined),
|
|
12
16
|
}));
|
|
17
|
+
// Stubbed so a turn can be driven to completion without a credential, and so
|
|
18
|
+
// the directory the SESSION is created in is observable. What the session then
|
|
19
|
+
// does with that directory is asserted in `src/tui/__tests__/`.
|
|
20
|
+
const sessionOptions = [];
|
|
21
|
+
vi.mock('../../tui/agent.js', () => ({
|
|
22
|
+
probeAgentSession: vi.fn(async () => ({
|
|
23
|
+
preferences: { version: 2, provider: 'anthropic', subagents: { active: [] } },
|
|
24
|
+
needsRepickReason: null,
|
|
25
|
+
detected: [],
|
|
26
|
+
})),
|
|
27
|
+
createAgentSession: vi.fn(async (_prefs, _detected, opts) => {
|
|
28
|
+
sessionOptions.push(opts);
|
|
29
|
+
return {
|
|
30
|
+
hasProvider: true,
|
|
31
|
+
providerSummary: 'stub',
|
|
32
|
+
modelSummary: 'stub',
|
|
33
|
+
toolNames: [],
|
|
34
|
+
deferredToolCount: 0,
|
|
35
|
+
errorHint: null,
|
|
36
|
+
send: async function* () { },
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
}));
|
|
13
40
|
/**
|
|
14
41
|
* `run-stream` folded every argument it did not recognise into `rest`, and
|
|
15
42
|
* `rest.join(' ')` is the PROMPT. `--cwd <path>` was in this command's own help
|
|
@@ -22,7 +49,7 @@ vi.mock('../../integrations/sessions/store.js', () => ({
|
|
|
22
49
|
* to stop treating an option as content; the fix here is the same, plus
|
|
23
50
|
* actually honouring the flag that was advertised.
|
|
24
51
|
*/
|
|
25
|
-
const ctx = {};
|
|
52
|
+
const ctx = { config: {} };
|
|
26
53
|
function capture() {
|
|
27
54
|
const lines = [];
|
|
28
55
|
const spy = vi.spyOn(process.stdout, 'write').mockImplementation((chunk) => {
|
|
@@ -33,6 +60,7 @@ function capture() {
|
|
|
33
60
|
}
|
|
34
61
|
beforeEach(() => {
|
|
35
62
|
vi.mocked(openSessions).mockClear();
|
|
63
|
+
sessionOptions.length = 0;
|
|
36
64
|
});
|
|
37
65
|
afterEach(() => {
|
|
38
66
|
vi.restoreAllMocks();
|
|
@@ -71,51 +99,122 @@ describe('run-stream does not turn options into prompt text', () => {
|
|
|
71
99
|
expect(lines.join('')).toContain('"kind":"done"');
|
|
72
100
|
});
|
|
73
101
|
});
|
|
102
|
+
describe('run-stream works in the directory it was pointed at', () => {
|
|
103
|
+
it('hands --cwd to the agent session, not only to the session store', async () => {
|
|
104
|
+
// `--session` keeps the turn off stdin: without a session key the command
|
|
105
|
+
// reads prior history from a pipe, and in a test runner that pipe never
|
|
106
|
+
// closes.
|
|
107
|
+
const elsewhere = mkdtempSync(join(tmpdir(), 'namzu-run-stream-'));
|
|
108
|
+
try {
|
|
109
|
+
await run(['--cwd', elsewhere, '--session', 'k', 'read', 'notes.txt']);
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
rmSync(elsewhere, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
expect(sessionOptions[0]?.cwd).toBe(elsewhere);
|
|
115
|
+
});
|
|
116
|
+
it('refuses a --cwd that is not there instead of quietly using this one', async () => {
|
|
117
|
+
// The silent fallback is the whole defect: the run proceeds, searches the
|
|
118
|
+
// wrong tree, finds nothing, and reports that the file does not exist.
|
|
119
|
+
const lines = await run(['--cwd', join(tmpdir(), 'namzu-no-such-dir'), 'hello']);
|
|
120
|
+
const joined = lines.join('');
|
|
121
|
+
expect(joined).toContain('--cwd does not exist');
|
|
122
|
+
expect(joined).toContain('"kind":"done"');
|
|
123
|
+
expect(sessionOptions).toEqual([]);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
74
126
|
describe('the flag parser itself', () => {
|
|
75
127
|
// Asserted here rather than through the handler: a valid prompt sends the
|
|
76
128
|
// handler on to stdin and a provider probe, so the first version of this
|
|
77
129
|
// case hung for five seconds and failed on a timeout rather than on the
|
|
78
130
|
// behaviour. A pure function deserves to be called.
|
|
79
131
|
it('lets `--` carry a prompt that begins with a dash', () => {
|
|
80
|
-
const flags =
|
|
132
|
+
const flags = parseRunFlags(['--', '--this-is-the-prompt']);
|
|
81
133
|
expect(flags.rest).toEqual(['--this-is-the-prompt']);
|
|
82
134
|
expect(flags.unknown).toEqual([]);
|
|
83
135
|
});
|
|
84
136
|
it('stops interpreting options after `--`', () => {
|
|
85
|
-
const flags =
|
|
137
|
+
const flags = parseRunFlags(['--session', 'abc', '--', '--model', 'not-a-flag']);
|
|
86
138
|
expect(flags.session).toBe('abc');
|
|
87
139
|
expect(flags.model).toBeNull();
|
|
88
140
|
expect(flags.rest).toEqual(['--model', 'not-a-flag']);
|
|
89
141
|
});
|
|
90
142
|
it('reads --cwd in both spellings', () => {
|
|
91
|
-
expect(
|
|
92
|
-
expect(
|
|
93
|
-
expect(
|
|
143
|
+
expect(parseRunFlags(['--cwd', '/a', 'hi']).cwd).toBe('/a');
|
|
144
|
+
expect(parseRunFlags(['--cwd=/b', 'hi']).cwd).toBe('/b');
|
|
145
|
+
expect(parseRunFlags(['--cwd', '/a', 'hi']).rest).toEqual(['hi']);
|
|
94
146
|
});
|
|
95
147
|
it('leaves a lone dash alone, since that is not an option', () => {
|
|
96
|
-
expect(
|
|
97
|
-
expect(
|
|
148
|
+
expect(parseRunFlags(['-', 'hi']).unknown).toEqual([]);
|
|
149
|
+
expect(parseRunFlags(['-', 'hi']).rest).toEqual(['-', 'hi']);
|
|
98
150
|
});
|
|
99
151
|
});
|
|
152
|
+
describe('skills-json lists the directory it was pointed at', () => {
|
|
153
|
+
// A host that lists skills for one checkout and then runs a turn in that
|
|
154
|
+
// same checkout has to be told about the same skills both times. It was
|
|
155
|
+
// not: this command read the process directory whatever `--cwd` said, so
|
|
156
|
+
// it could offer a skill that `run-stream --cwd <there>` then could not
|
|
157
|
+
// find, and hide one that was actually available.
|
|
158
|
+
function skillIn(root, name) {
|
|
159
|
+
mkdirSync(join(root, 'skills', name), { recursive: true });
|
|
160
|
+
writeFileSync(join(root, 'skills', name, 'SKILL.md'), `---\nname: ${name}\ndescription: only in this checkout\n---\n\nbody\n`);
|
|
161
|
+
}
|
|
162
|
+
it('discovers the project skills under --cwd', async () => {
|
|
163
|
+
const elsewhere = mkdtempSync(join(tmpdir(), 'namzu-skills-'));
|
|
164
|
+
skillIn(elsewhere, 'only-over-there');
|
|
165
|
+
const { lines, restore } = capture();
|
|
166
|
+
try {
|
|
167
|
+
await skillsJSONCommand.handler({ rawArgs: ['--cwd', elsewhere], ctx });
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
restore();
|
|
171
|
+
rmSync(elsewhere, { recursive: true, force: true });
|
|
172
|
+
}
|
|
173
|
+
const names = JSON.parse(lines.join('').trim()).map((s) => s.name);
|
|
174
|
+
expect(names).toContain('only-over-there');
|
|
175
|
+
});
|
|
176
|
+
// There is deliberately no paired "and not from anywhere else" case: with
|
|
177
|
+
// the flag ignored the command read `packages/cli`, which has no skills
|
|
178
|
+
// directory, so a negative assertion passes with the defect still in place
|
|
179
|
+
// and would only look like coverage.
|
|
180
|
+
});
|
|
100
181
|
describe('history reads the directory it was pointed at', () => {
|
|
101
182
|
it('opens the store at --cwd, not at the process directory', async () => {
|
|
102
183
|
// Parsing the flag is not the fix; USING it is. An assertion that the
|
|
103
184
|
// command merely survives `--cwd` would pass with the wiring reverted —
|
|
104
185
|
// `[]` is printed either way — which would leave the flag parsed and
|
|
105
186
|
// still undriven, the exact shape being repaired here.
|
|
187
|
+
//
|
|
188
|
+
// A real directory, because `--cwd` is now resolved and checked before
|
|
189
|
+
// the store is opened: a path that is not there cannot be told apart
|
|
190
|
+
// from a session with no messages, so it never reaches the store.
|
|
191
|
+
const elsewhere = mkdtempSync(join(tmpdir(), 'namzu-history-'));
|
|
106
192
|
const { lines, restore } = capture();
|
|
107
193
|
try {
|
|
108
194
|
await historyCommand.handler({
|
|
109
|
-
rawArgs: ['--cwd',
|
|
195
|
+
rawArgs: ['--cwd', elsewhere, '--session', 'some-key'],
|
|
110
196
|
ctx,
|
|
111
197
|
});
|
|
112
198
|
}
|
|
113
199
|
finally {
|
|
114
200
|
restore();
|
|
201
|
+
rmSync(elsewhere, { recursive: true, force: true });
|
|
115
202
|
}
|
|
116
|
-
expect(openSessions).toHaveBeenCalledWith(
|
|
203
|
+
expect(openSessions).toHaveBeenCalledWith(elsewhere);
|
|
117
204
|
expect(lines.join('').trim()).toBe('[]');
|
|
118
205
|
});
|
|
206
|
+
it('resolves a relative --cwd against the process directory', async () => {
|
|
207
|
+
// A host that passes `.` or `../sibling` gets the directory it meant,
|
|
208
|
+
// and the agent downstream gets an absolute path it cannot misread.
|
|
209
|
+
const { restore } = capture();
|
|
210
|
+
try {
|
|
211
|
+
await historyCommand.handler({ rawArgs: ['--cwd', '.', '--session', 'k'], ctx });
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
restore();
|
|
215
|
+
}
|
|
216
|
+
expect(openSessions).toHaveBeenCalledWith(resolve(process.cwd(), '.'));
|
|
217
|
+
});
|
|
119
218
|
it('falls back to the process directory when --cwd is absent', async () => {
|
|
120
219
|
const { restore } = capture();
|
|
121
220
|
try {
|
|
@@ -127,4 +226,55 @@ describe('history reads the directory it was pointed at', () => {
|
|
|
127
226
|
expect(openSessions).toHaveBeenCalledWith(process.cwd());
|
|
128
227
|
});
|
|
129
228
|
});
|
|
229
|
+
describe('run-stream honours the permission surface, not just parses it', () => {
|
|
230
|
+
// It accepted `--permission-mode` and never used it, and it never compiled
|
|
231
|
+
// the `[permissions]` table at all — so an operator who wrote rules, or who
|
|
232
|
+
// typed `--permission-mode strict` precisely because they did not trust the
|
|
233
|
+
// run, got an unrestricted one that looked like it had obeyed. A safety
|
|
234
|
+
// control that parses and does nothing is worse than one that is missing,
|
|
235
|
+
// because the absence is visible and the silence is not.
|
|
236
|
+
const withConfig = {
|
|
237
|
+
config: { permissions: { bash: 'deny' } },
|
|
238
|
+
};
|
|
239
|
+
async function runWith(rawArgs, context = withConfig) {
|
|
240
|
+
const { lines, restore } = capture();
|
|
241
|
+
try {
|
|
242
|
+
await runStreamCommand.handler({ rawArgs, ctx: context });
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
restore();
|
|
246
|
+
}
|
|
247
|
+
return lines;
|
|
248
|
+
}
|
|
249
|
+
it('compiles the operator table into the session', async () => {
|
|
250
|
+
await runWith(['--session', 'k', 'hello']);
|
|
251
|
+
expect(sessionOptions[0]?.rules).toEqual([{ type: 'deny_by_name', toolNames: ['bash'] }]);
|
|
252
|
+
});
|
|
253
|
+
it('passes --permission-mode through instead of ignoring it', async () => {
|
|
254
|
+
await runWith(['--session', 'k', '--permission-mode', 'strict', 'hello']);
|
|
255
|
+
expect(sessionOptions[0]?.permissionMode).toBe('strict');
|
|
256
|
+
});
|
|
257
|
+
it('refuses a mode it does not know rather than running unrestricted', async () => {
|
|
258
|
+
const lines = await runWith(['--session', 'k', '--permission-mode', 'yolo', 'hello']);
|
|
259
|
+
expect(lines.join('')).toContain('--permission-mode must be one of');
|
|
260
|
+
expect(sessionOptions).toEqual([]);
|
|
261
|
+
});
|
|
262
|
+
it('defaults to auto when nothing was asked for, and says so by acting on it', async () => {
|
|
263
|
+
await runWith(['--session', 'k', 'hello']);
|
|
264
|
+
expect(sessionOptions[0]?.permissionMode).toBe('auto');
|
|
265
|
+
});
|
|
266
|
+
it('reports an unreadable rule in band, where a host can see it', async () => {
|
|
267
|
+
const bad = {
|
|
268
|
+
config: { permissions: { bash: { 'git push*': 'maybe' } } },
|
|
269
|
+
};
|
|
270
|
+
const lines = await runWith(['--session', 'k', 'hello'], bad);
|
|
271
|
+
// Parsed, not substring-matched: the line is JSON, so the quotes around
|
|
272
|
+
// the pattern are escaped in the raw text and a naive contains() would
|
|
273
|
+
// pass or fail for reasons unrelated to what the host actually reads.
|
|
274
|
+
const messages = lines
|
|
275
|
+
.map((l) => JSON.parse(l))
|
|
276
|
+
.map((e) => e.message ?? '');
|
|
277
|
+
expect(messages.some((m) => m.includes('permissions.bash."git push*"'))).toBe(true);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
130
280
|
//# sourceMappingURL=run-stream-flags.test.js.map
|