clawt 3.7.1 → 3.8.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/.clawt/postCreate.sh +2 -0
- package/CLAUDE.md +10 -0
- package/README.md +18 -1
- package/dist/index.js +171 -25
- package/dist/postinstall.js +30 -1
- package/docs/create.md +6 -2
- package/docs/init.md +2 -2
- package/docs/post-create-hook.md +142 -0
- package/docs/project-config.md +9 -2
- package/docs/run.md +10 -6
- package/docs/spec.md +4 -1
- package/package.json +1 -1
- package/src/commands/create.ts +5 -0
- package/src/commands/run.ts +12 -0
- package/src/constants/config.ts +1 -1
- package/src/constants/messages/index.ts +2 -0
- package/src/constants/messages/post-create.ts +29 -0
- package/src/constants/project-config.ts +4 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/post-create.ts +198 -0
- package/src/types/command.ts +4 -0
- package/src/types/index.ts +1 -0
- package/src/types/postCreateHook.ts +24 -0
- package/src/types/projectConfig.ts +2 -0
- package/src/utils/claude.ts +2 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/task-executor.ts +5 -1
- package/tests/unit/commands/create.test.ts +1 -0
- package/tests/unit/commands/run.test.ts +1 -0
- package/tests/unit/constants/messages-post-create.test.ts +112 -0
- package/tests/unit/hooks/post-create.test.ts +434 -0
- package/tests/unit/utils/claude.test.ts +76 -1
|
@@ -29,10 +29,11 @@ vi.mock('../../../src/utils/formatter.js', () => ({
|
|
|
29
29
|
|
|
30
30
|
import { spawnSync } from 'node:child_process';
|
|
31
31
|
import { existsSync, readdirSync } from 'node:fs';
|
|
32
|
-
import { launchInteractiveClaude, hasClaudeSessionHistory } from '../../../src/utils/claude.js';
|
|
32
|
+
import { launchInteractiveClaude, hasClaudeSessionHistory, buildClaudeCommand } from '../../../src/utils/claude.js';
|
|
33
33
|
import { getConfigValue } from '../../../src/utils/config.js';
|
|
34
34
|
import { printInfo, printWarning } from '../../../src/utils/formatter.js';
|
|
35
35
|
import { ClawtError } from '../../../src/errors/index.js';
|
|
36
|
+
import { APPEND_SYSTEM_PROMPT } from '../../../src/constants/config.js';
|
|
36
37
|
import { createWorktreeInfo } from '../../helpers/fixtures.js';
|
|
37
38
|
|
|
38
39
|
const mockedSpawnSync = vi.mocked(spawnSync);
|
|
@@ -283,4 +284,78 @@ describe('launchInteractiveClaude', () => {
|
|
|
283
284
|
const callArgs = mockedSpawnSync.mock.calls[0][1] as string[];
|
|
284
285
|
expect(callArgs).not.toContain('--continue');
|
|
285
286
|
});
|
|
287
|
+
|
|
288
|
+
it('固定使用 APPEND_SYSTEM_PROMPT 作为系统提示', () => {
|
|
289
|
+
mockedGetConfigValue.mockReturnValue('claude');
|
|
290
|
+
mockedExistsSync.mockReturnValue(false);
|
|
291
|
+
mockedSpawnSync.mockReturnValue({
|
|
292
|
+
status: 0,
|
|
293
|
+
error: undefined,
|
|
294
|
+
stdout: '',
|
|
295
|
+
stderr: '',
|
|
296
|
+
pid: 1234,
|
|
297
|
+
output: [],
|
|
298
|
+
signal: null,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
launchInteractiveClaude(worktree);
|
|
302
|
+
|
|
303
|
+
const callArgs = mockedSpawnSync.mock.calls[0][1] as string[];
|
|
304
|
+
const promptIndex = callArgs.indexOf('--append-system-prompt');
|
|
305
|
+
expect(callArgs[promptIndex + 1]).toBe(APPEND_SYSTEM_PROMPT);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe('buildClaudeCommand', () => {
|
|
310
|
+
const worktree = createWorktreeInfo({
|
|
311
|
+
path: '/tmp/test-worktree',
|
|
312
|
+
branch: 'feature-test',
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('生成包含 cd 和 claude 命令的字符串', () => {
|
|
316
|
+
mockedGetConfigValue.mockReturnValue('claude');
|
|
317
|
+
|
|
318
|
+
const cmd = buildClaudeCommand(worktree, false);
|
|
319
|
+
|
|
320
|
+
expect(cmd).toContain("cd '/tmp/test-worktree'");
|
|
321
|
+
expect(cmd).toContain('claude');
|
|
322
|
+
expect(cmd).toContain('--append-system-prompt');
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('hasPreviousSession 为 true 时包含 --continue', () => {
|
|
326
|
+
mockedGetConfigValue.mockReturnValue('claude');
|
|
327
|
+
|
|
328
|
+
const cmd = buildClaudeCommand(worktree, true);
|
|
329
|
+
|
|
330
|
+
expect(cmd).toContain('--continue');
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('hasPreviousSession 为 false 时不包含 --continue', () => {
|
|
334
|
+
mockedGetConfigValue.mockReturnValue('claude');
|
|
335
|
+
|
|
336
|
+
const cmd = buildClaudeCommand(worktree, false);
|
|
337
|
+
|
|
338
|
+
expect(cmd).not.toContain('--continue');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('固定使用 APPEND_SYSTEM_PROMPT 作为系统提示', () => {
|
|
342
|
+
mockedGetConfigValue.mockReturnValue('claude');
|
|
343
|
+
|
|
344
|
+
const cmd = buildClaudeCommand(worktree, false);
|
|
345
|
+
|
|
346
|
+
expect(cmd).toContain(APPEND_SYSTEM_PROMPT);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('路径中的单引号被正确转义', () => {
|
|
350
|
+
mockedGetConfigValue.mockReturnValue('claude');
|
|
351
|
+
const wtWithQuote = createWorktreeInfo({
|
|
352
|
+
path: "/tmp/test's-worktree",
|
|
353
|
+
branch: 'feat',
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
const cmd = buildClaudeCommand(wtWithQuote, false);
|
|
357
|
+
|
|
358
|
+
// 单引号应被转义为 '\''
|
|
359
|
+
expect(cmd).toContain("test'\\''s-worktree");
|
|
360
|
+
});
|
|
286
361
|
});
|