@oyasmi/pipiclaw 0.9.0-beta.7 → 0.9.0-beta.9
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/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +21 -2
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/job-manager.d.ts +3 -3
- package/dist/agent/job-manager.js +0 -1
- package/dist/agent/runner-factory.d.ts +16 -4
- package/dist/agent/runner-factory.js +9 -23
- package/dist/agent/types.d.ts +9 -1
- package/dist/agent/types.js +3 -16
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/scheduler.d.ts +1 -0
- package/dist/memory/scheduler.js +64 -6
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/bootstrap.d.ts +10 -2
- package/dist/runtime/bootstrap.js +83 -55
- package/dist/runtime/channel-event.d.ts +41 -0
- package/dist/runtime/channel-event.js +1 -0
- package/dist/runtime/delivery.d.ts +3 -2
- package/dist/runtime/dingtalk.d.ts +9 -31
- package/dist/runtime/durable-dispatch.d.ts +4 -2
- package/dist/runtime/durable-dispatch.js +36 -25
- package/dist/runtime/events.d.ts +3 -2
- package/dist/runtime/events.js +2 -3
- package/dist/runtime/subagent-commands.js +48 -10
- package/dist/runtime/task-commands.js +2 -2
- package/dist/runtime/task-driver.d.ts +7 -7
- package/dist/runtime/task-driver.js +1 -4
- package/dist/runtime/task-migration.js +1 -1
- package/dist/runtime/task-wake.d.ts +4 -4
- package/dist/settings.d.ts +0 -106
- package/dist/settings.js +0 -224
- package/dist/shared/host-process.d.ts +25 -9
- package/dist/shared/host-process.js +59 -10
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.js +10 -1
- package/dist/subagents/discovery.d.ts +24 -0
- package/dist/subagents/discovery.js +103 -17
- package/dist/subagents/external/claude-code.js +10 -3
- package/dist/subagents/external/codex-cli.js +9 -3
- package/dist/subagents/external/exec.js +1 -0
- package/dist/subagents/external/harness.d.ts +22 -0
- package/dist/subagents/external/harness.js +22 -4
- package/dist/subagents/external/run.d.ts +23 -3
- package/dist/subagents/external/run.js +112 -131
- package/dist/subagents/external/settlement.d.ts +50 -0
- package/dist/subagents/external/settlement.js +123 -0
- package/dist/subagents/format.d.ts +4 -0
- package/dist/subagents/format.js +7 -0
- package/dist/subagents/runs.d.ts +73 -16
- package/dist/subagents/runs.js +197 -120
- package/dist/subagents/tool.d.ts +38 -6
- package/dist/subagents/tool.js +93 -61
- package/dist/subagents/verification-outcome.d.ts +26 -0
- package/dist/subagents/verification-outcome.js +16 -0
- package/dist/subagents/workspace-lease.d.ts +10 -1
- package/dist/subagents/workspace-lease.js +15 -2
- package/dist/tasks/ledger.js +1 -1
- package/dist/{shared → tasks}/task-schedule.js +1 -1
- package/dist/tools/bash.js +1 -1
- package/dist/tools/event-manage.js +1 -4
- package/dist/tools/grep.js +2 -3
- package/dist/tools/index.js +6 -0
- package/dist/tools/job.js +5 -5
- package/dist/tools/memory-manage.js +3 -6
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-manage.js +3 -3
- package/dist/tools/subagent-manage.d.ts +20 -6
- package/dist/tools/subagent-manage.js +88 -18
- package/dist/tools/task-manage/shared.js +2 -2
- package/dist/tools/task-manage.js +1 -4
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tui/app.js +4 -4
- package/package.json +1 -1
- /package/dist/{shared → tasks}/task-events.d.ts +0 -0
- /package/dist/{shared → tasks}/task-events.js +0 -0
- /package/dist/{shared → tasks}/task-schedule.d.ts +0 -0
package/dist/settings.js
CHANGED
|
@@ -332,228 +332,4 @@ export class PipiclawSettingsManager {
|
|
|
332
332
|
this.settings.defaultThinkingLevel = level;
|
|
333
333
|
this.save();
|
|
334
334
|
}
|
|
335
|
-
// Compatibility methods for AgentSession
|
|
336
|
-
getSteeringMode() {
|
|
337
|
-
return "one-at-a-time";
|
|
338
|
-
}
|
|
339
|
-
setSteeringMode(_mode) {
|
|
340
|
-
// No-op
|
|
341
|
-
}
|
|
342
|
-
getFollowUpMode() {
|
|
343
|
-
return "one-at-a-time";
|
|
344
|
-
}
|
|
345
|
-
setFollowUpMode(_mode) {
|
|
346
|
-
// No-op
|
|
347
|
-
}
|
|
348
|
-
getHookPaths() {
|
|
349
|
-
return [];
|
|
350
|
-
}
|
|
351
|
-
getHookTimeout() {
|
|
352
|
-
return 30000;
|
|
353
|
-
}
|
|
354
|
-
// Image settings
|
|
355
|
-
getImageAutoResize() {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
setImageAutoResize(_enabled) {
|
|
359
|
-
// No-op
|
|
360
|
-
}
|
|
361
|
-
getBlockImages() {
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
setBlockImages(_blocked) {
|
|
365
|
-
// No-op
|
|
366
|
-
}
|
|
367
|
-
getShowImages() {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
setShowImages(_show) {
|
|
371
|
-
// No-op
|
|
372
|
-
}
|
|
373
|
-
getBranchSummarySettings() {
|
|
374
|
-
return { reserveTokens: this.getCompactionSettings().reserveTokens };
|
|
375
|
-
}
|
|
376
|
-
getBranchSummarySkipPrompt() {
|
|
377
|
-
return false;
|
|
378
|
-
}
|
|
379
|
-
// Thinking
|
|
380
|
-
getHideThinkingBlock() {
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
setHideThinkingBlock(_hide) {
|
|
384
|
-
// No-op
|
|
385
|
-
}
|
|
386
|
-
getThinkingBudgets() {
|
|
387
|
-
return undefined;
|
|
388
|
-
}
|
|
389
|
-
// Shell
|
|
390
|
-
getShellPath() {
|
|
391
|
-
return undefined;
|
|
392
|
-
}
|
|
393
|
-
setShellPath(_path) {
|
|
394
|
-
// No-op
|
|
395
|
-
}
|
|
396
|
-
getShellCommandPrefix() {
|
|
397
|
-
return undefined;
|
|
398
|
-
}
|
|
399
|
-
setShellCommandPrefix(_prefix) {
|
|
400
|
-
// No-op
|
|
401
|
-
}
|
|
402
|
-
// Misc settings stubs
|
|
403
|
-
getQuietStartup() {
|
|
404
|
-
return true;
|
|
405
|
-
}
|
|
406
|
-
setQuietStartup(_quiet) {
|
|
407
|
-
// No-op
|
|
408
|
-
}
|
|
409
|
-
getCollapseChangelog() {
|
|
410
|
-
return true;
|
|
411
|
-
}
|
|
412
|
-
setCollapseChangelog(_collapse) {
|
|
413
|
-
// No-op
|
|
414
|
-
}
|
|
415
|
-
getTransport() {
|
|
416
|
-
return "auto";
|
|
417
|
-
}
|
|
418
|
-
setTransport(_transport) {
|
|
419
|
-
// No-op
|
|
420
|
-
}
|
|
421
|
-
getTheme() {
|
|
422
|
-
return undefined;
|
|
423
|
-
}
|
|
424
|
-
setTheme(_theme) {
|
|
425
|
-
// No-op
|
|
426
|
-
}
|
|
427
|
-
getPackages() {
|
|
428
|
-
return [];
|
|
429
|
-
}
|
|
430
|
-
setPackages(_packages) {
|
|
431
|
-
// No-op
|
|
432
|
-
}
|
|
433
|
-
setProjectPackages(_packages) {
|
|
434
|
-
// No-op
|
|
435
|
-
}
|
|
436
|
-
getExtensionPaths() {
|
|
437
|
-
return [];
|
|
438
|
-
}
|
|
439
|
-
setExtensionPaths(_paths) {
|
|
440
|
-
// No-op
|
|
441
|
-
}
|
|
442
|
-
setProjectExtensionPaths(_paths) {
|
|
443
|
-
// No-op
|
|
444
|
-
}
|
|
445
|
-
getSkillPaths() {
|
|
446
|
-
return [];
|
|
447
|
-
}
|
|
448
|
-
setSkillPaths(_paths) {
|
|
449
|
-
// No-op
|
|
450
|
-
}
|
|
451
|
-
setProjectSkillPaths(_paths) {
|
|
452
|
-
// No-op
|
|
453
|
-
}
|
|
454
|
-
getPromptTemplatePaths() {
|
|
455
|
-
return [];
|
|
456
|
-
}
|
|
457
|
-
setPromptTemplatePaths(_paths) {
|
|
458
|
-
// No-op
|
|
459
|
-
}
|
|
460
|
-
setProjectPromptTemplatePaths(_paths) {
|
|
461
|
-
// No-op
|
|
462
|
-
}
|
|
463
|
-
getThemePaths() {
|
|
464
|
-
return [];
|
|
465
|
-
}
|
|
466
|
-
setThemePaths(_paths) {
|
|
467
|
-
// No-op
|
|
468
|
-
}
|
|
469
|
-
setProjectThemePaths(_paths) {
|
|
470
|
-
// No-op
|
|
471
|
-
}
|
|
472
|
-
getEnableSkillCommands() {
|
|
473
|
-
return false;
|
|
474
|
-
}
|
|
475
|
-
setEnableSkillCommands(_enabled) {
|
|
476
|
-
// No-op
|
|
477
|
-
}
|
|
478
|
-
getEnabledModels() {
|
|
479
|
-
return undefined;
|
|
480
|
-
}
|
|
481
|
-
setEnabledModels(_patterns) {
|
|
482
|
-
// No-op
|
|
483
|
-
}
|
|
484
|
-
getDoubleEscapeAction() {
|
|
485
|
-
return "none";
|
|
486
|
-
}
|
|
487
|
-
setDoubleEscapeAction(_action) {
|
|
488
|
-
// No-op
|
|
489
|
-
}
|
|
490
|
-
getTreeFilterMode() {
|
|
491
|
-
return "default";
|
|
492
|
-
}
|
|
493
|
-
setTreeFilterMode(_mode) {
|
|
494
|
-
// No-op
|
|
495
|
-
}
|
|
496
|
-
getShowHardwareCursor() {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
setShowHardwareCursor(_enabled) {
|
|
500
|
-
// No-op
|
|
501
|
-
}
|
|
502
|
-
getClearOnShrink() {
|
|
503
|
-
return false;
|
|
504
|
-
}
|
|
505
|
-
setClearOnShrink(_enabled) {
|
|
506
|
-
// No-op
|
|
507
|
-
}
|
|
508
|
-
getEditorPaddingX() {
|
|
509
|
-
return 0;
|
|
510
|
-
}
|
|
511
|
-
setEditorPaddingX(_padding) {
|
|
512
|
-
// No-op
|
|
513
|
-
}
|
|
514
|
-
getAutocompleteMaxVisible() {
|
|
515
|
-
return 10;
|
|
516
|
-
}
|
|
517
|
-
setAutocompleteMaxVisible(_maxVisible) {
|
|
518
|
-
// No-op
|
|
519
|
-
}
|
|
520
|
-
getCodeBlockIndent() {
|
|
521
|
-
return " ";
|
|
522
|
-
}
|
|
523
|
-
getLastChangelogVersion() {
|
|
524
|
-
return undefined;
|
|
525
|
-
}
|
|
526
|
-
setLastChangelogVersion(_version) {
|
|
527
|
-
// No-op
|
|
528
|
-
}
|
|
529
|
-
setDefaultProvider(_provider) {
|
|
530
|
-
// No-op
|
|
531
|
-
}
|
|
532
|
-
setDefaultModel(_modelId) {
|
|
533
|
-
// No-op
|
|
534
|
-
}
|
|
535
|
-
getSessionDir() {
|
|
536
|
-
return undefined;
|
|
537
|
-
}
|
|
538
|
-
getNpmCommand() {
|
|
539
|
-
return undefined;
|
|
540
|
-
}
|
|
541
|
-
setNpmCommand(_command) {
|
|
542
|
-
// No-op
|
|
543
|
-
}
|
|
544
|
-
getGlobalSettings() {
|
|
545
|
-
return {};
|
|
546
|
-
}
|
|
547
|
-
getProjectSettings() {
|
|
548
|
-
return {};
|
|
549
|
-
}
|
|
550
|
-
isProjectTrusted() {
|
|
551
|
-
return true;
|
|
552
|
-
}
|
|
553
|
-
setProjectTrusted(_trusted) {
|
|
554
|
-
// Pipiclaw handles workspace authorization at the DingTalk/runtime boundary.
|
|
555
|
-
}
|
|
556
|
-
flush() {
|
|
557
|
-
return Promise.resolve();
|
|
558
|
-
}
|
|
559
335
|
}
|
|
@@ -5,17 +5,33 @@
|
|
|
5
5
|
* never as proof either way.
|
|
6
6
|
*/
|
|
7
7
|
export declare function readProcessStartTime(pid: number): Promise<string | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Best-effort `<executable> --version`, so a run persists which build of the target CLI it ran
|
|
10
|
+
* against (spec 042 D12) — the other half of `parserVersion`'s "adapter drift vs. agent failure"
|
|
11
|
+
* diagnosis. `undefined` on any failure or timeout; this must never block or fail a dispatch over
|
|
12
|
+
* a CLI that does not support `--version`, is slow to start, or fails outright.
|
|
13
|
+
*/
|
|
14
|
+
export declare function probeCliVersion(executable: string): Promise<string | undefined>;
|
|
8
15
|
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
9
16
|
export declare function isProcessAlive(pid: number): boolean;
|
|
17
|
+
/** True if any process in `pid`'s process group is still alive — probes the *group* (`-pid`), not
|
|
18
|
+
* just the leader, so a leader that already exited while a lingering descendant (e.g. a shell
|
|
19
|
+
* that forked and returned) is still running is correctly reported as "still something there". */
|
|
20
|
+
export declare function isProcessGroupAlive(pid: number): boolean;
|
|
10
21
|
/**
|
|
11
|
-
* SIGTERM the process group, then unconditionally SIGKILL it after
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* lingering descendant (e.g. a shell that forked and returned) would make `isProcessAlive(pid)`
|
|
17
|
-
* report false while the descendant is still alive and still holding the workspace, so probing
|
|
18
|
-
* only the leader and skipping the SIGKILL on that basis is exactly the wrong direction to err in.
|
|
19
|
-
* A dead group simply makes the SIGKILL a harmless ESRCH, caught below.
|
|
22
|
+
* SIGTERM the process group, then unconditionally SIGKILL it after `graceMs`. `detached: true` at
|
|
23
|
+
* spawn time makes the child its own process-group leader, so `-pid` reaches it and everything it
|
|
24
|
+
* spawned. The SIGKILL is not gated on a liveness probe first: a dead group simply makes it a
|
|
25
|
+
* harmless ESRCH, caught below — probing first would only add a syscall on the already-rare path
|
|
26
|
+
* where this function is used to actually terminate something (cancel/timeout, not a normal exit).
|
|
20
27
|
*/
|
|
21
28
|
export declare function killProcessGroup(pid: number, graceMs?: number): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Spec 042 D8: cleanup after a *normal* exit, as opposed to `killProcessGroup`'s explicit
|
|
31
|
+
* cancel/timeout termination. The common case — nothing left in the group — returns immediately
|
|
32
|
+
* with no signal and no wait, so a normal settlement no longer pays `killProcessGroup`'s grace
|
|
33
|
+
* period on every single run. The rare case — a descendant outlived its already-exited leader —
|
|
34
|
+
* still needs terminating, so it falls through to the same TERM-then-KILL sequence, just off the
|
|
35
|
+
* hot path and with a short grace since a genuinely finished CLI has nothing left to flush.
|
|
36
|
+
*/
|
|
37
|
+
export declare function reapProcessGroup(pid: number): Promise<void>;
|
|
@@ -24,6 +24,24 @@ export async function readProcessStartTime(pid) {
|
|
|
24
24
|
return undefined;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
const CLI_VERSION_PROBE_TIMEOUT_MS = 1_000;
|
|
28
|
+
const CLI_VERSION_MAX_CHARS = 200;
|
|
29
|
+
/**
|
|
30
|
+
* Best-effort `<executable> --version`, so a run persists which build of the target CLI it ran
|
|
31
|
+
* against (spec 042 D12) — the other half of `parserVersion`'s "adapter drift vs. agent failure"
|
|
32
|
+
* diagnosis. `undefined` on any failure or timeout; this must never block or fail a dispatch over
|
|
33
|
+
* a CLI that does not support `--version`, is slow to start, or fails outright.
|
|
34
|
+
*/
|
|
35
|
+
export async function probeCliVersion(executable) {
|
|
36
|
+
try {
|
|
37
|
+
const { stdout } = await execFileAsync(executable, ["--version"], { timeout: CLI_VERSION_PROBE_TIMEOUT_MS });
|
|
38
|
+
const value = stdout.trim().split("\n")[0]?.slice(0, CLI_VERSION_MAX_CHARS);
|
|
39
|
+
return value || undefined;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
27
45
|
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
28
46
|
export function isProcessAlive(pid) {
|
|
29
47
|
try {
|
|
@@ -35,18 +53,36 @@ export function isProcessAlive(pid) {
|
|
|
35
53
|
return error.code === "EPERM";
|
|
36
54
|
}
|
|
37
55
|
}
|
|
56
|
+
/** True if any process in `pid`'s process group is still alive — probes the *group* (`-pid`), not
|
|
57
|
+
* just the leader, so a leader that already exited while a lingering descendant (e.g. a shell
|
|
58
|
+
* that forked and returned) is still running is correctly reported as "still something there". */
|
|
59
|
+
export function isProcessGroupAlive(pid) {
|
|
60
|
+
try {
|
|
61
|
+
process.kill(-pid, 0);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return error.code === "EPERM";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
38
68
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* The SIGKILL is not gated on a liveness probe of the leader pid: a leader that exits before a
|
|
44
|
-
* lingering descendant (e.g. a shell that forked and returned) would make `isProcessAlive(pid)`
|
|
45
|
-
* report false while the descendant is still alive and still holding the workspace, so probing
|
|
46
|
-
* only the leader and skipping the SIGKILL on that basis is exactly the wrong direction to err in.
|
|
47
|
-
* A dead group simply makes the SIGKILL a harmless ESRCH, caught below.
|
|
69
|
+
* Spec 042 D8: cancel/timeout grace before SIGKILL — long enough for a coding agent CLI to flush
|
|
70
|
+
* its protocol terminal event and buffered output before being force-killed (300ms was rarely
|
|
71
|
+
* enough for that, which is why D1's "keep parsed output on cancel/timeout" fix had little to
|
|
72
|
+
* actually keep). Not used on the normal-exit path below, so it costs nothing on the common case.
|
|
48
73
|
*/
|
|
49
|
-
|
|
74
|
+
const KILL_GRACE_MS = 5_000;
|
|
75
|
+
/** Grace for `reapProcessGroup`'s rare non-empty branch — a lingering descendant outliving its
|
|
76
|
+
* already-exited leader is not the hot path a normal exit takes, so this stays short. */
|
|
77
|
+
const REAP_GRACE_MS = 300;
|
|
78
|
+
/**
|
|
79
|
+
* SIGTERM the process group, then unconditionally SIGKILL it after `graceMs`. `detached: true` at
|
|
80
|
+
* spawn time makes the child its own process-group leader, so `-pid` reaches it and everything it
|
|
81
|
+
* spawned. The SIGKILL is not gated on a liveness probe first: a dead group simply makes it a
|
|
82
|
+
* harmless ESRCH, caught below — probing first would only add a syscall on the already-rare path
|
|
83
|
+
* where this function is used to actually terminate something (cancel/timeout, not a normal exit).
|
|
84
|
+
*/
|
|
85
|
+
export async function killProcessGroup(pid, graceMs = KILL_GRACE_MS) {
|
|
50
86
|
try {
|
|
51
87
|
process.kill(-pid, "SIGTERM");
|
|
52
88
|
}
|
|
@@ -61,3 +97,16 @@ export async function killProcessGroup(pid, graceMs = 300) {
|
|
|
61
97
|
// Already gone.
|
|
62
98
|
}
|
|
63
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Spec 042 D8: cleanup after a *normal* exit, as opposed to `killProcessGroup`'s explicit
|
|
102
|
+
* cancel/timeout termination. The common case — nothing left in the group — returns immediately
|
|
103
|
+
* with no signal and no wait, so a normal settlement no longer pays `killProcessGroup`'s grace
|
|
104
|
+
* period on every single run. The rare case — a descendant outlived its already-exited leader —
|
|
105
|
+
* still needs terminating, so it falls through to the same TERM-then-KILL sequence, just off the
|
|
106
|
+
* hot path and with a short grace since a genuinely finished CLI has nothing left to flush.
|
|
107
|
+
*/
|
|
108
|
+
export async function reapProcessGroup(pid) {
|
|
109
|
+
if (!isProcessGroupAlive(pid))
|
|
110
|
+
return;
|
|
111
|
+
await killProcessGroup(pid, REAP_GRACE_MS);
|
|
112
|
+
}
|
package/dist/shared/types.d.ts
CHANGED
package/dist/shared/types.js
CHANGED
|
@@ -142,6 +142,17 @@ export declare function validateToolNames(values: string[] | undefined): {
|
|
|
142
142
|
tools: SubAgentToolName[];
|
|
143
143
|
error?: string;
|
|
144
144
|
};
|
|
145
|
+
type FieldSupport = "supported" | "rejected";
|
|
146
|
+
/**
|
|
147
|
+
* Which role-file fields mean something under which runtime (spec 040 D5's "对某种 runtime 无意义
|
|
148
|
+
* 的字段一律驳回", made into data per spec 042 D3/F3). A field present under a runtime marked
|
|
149
|
+
* `"rejected"` here is rejected outright, not silently ignored — silently ignoring one is a
|
|
150
|
+
* defect, not a leniency (the review that produced spec 042 found `shell`/`env` on an internal
|
|
151
|
+
* role doing exactly that before this table existed). `cwd` is deliberately absent: it is rejected
|
|
152
|
+
* for *both* runtimes with a different message ("not a role field at all"), handled separately in
|
|
153
|
+
* `loadAgentsFromDir` rather than as a per-runtime mismatch.
|
|
154
|
+
*/
|
|
155
|
+
export declare const ROLE_FIELD_MATRIX: Record<string, Record<SubAgentRuntime, FieldSupport>>;
|
|
145
156
|
export declare function discoverSubAgents(workspaceDir: string, availableModels: Model<Api>[]): SubAgentDiscoveryResult;
|
|
146
157
|
export declare function resolveSubAgentConfig(availableModels: Model<Api>[], currentModel: Model<Api>, predefinedAgents: SubAgentConfig[], overrides: SubAgentInvocationOverrides,
|
|
147
158
|
/**
|
|
@@ -154,4 +165,17 @@ subagentDefaultModelRef?: string): {
|
|
|
154
165
|
error?: string;
|
|
155
166
|
};
|
|
156
167
|
export declare function formatSubAgentList(agents: SubAgentConfig[], maxItems?: number): string;
|
|
168
|
+
/**
|
|
169
|
+
* Spec 042 D7: a fingerprint of the parts of an external role that decide *how a launched process
|
|
170
|
+
* is built* — `command`, `externalModelRef`, `shell`. Persisted on a run at launch and compared
|
|
171
|
+
* against the role's current config on `follow_up`: a mismatch means the role was hot-edited in a
|
|
172
|
+
* way that would resume under a harness or executable it never actually wrote, so `follow_up`
|
|
173
|
+
* refuses rather than silently reinterpreting the old session with the new config.
|
|
174
|
+
*
|
|
175
|
+
* Deliberately narrow — `systemPrompt` and `maxWallTimeSec` are excluded on purpose. A resumed
|
|
176
|
+
* session already carries its own context, and folding prompt edits in would mean "fix a typo in
|
|
177
|
+
* the role" breaks every in-flight follow-up; a full invocation snapshot was considered and
|
|
178
|
+
* rejected for the same reason (spec 042 design doc, "已驳回的方案").
|
|
179
|
+
*/
|
|
180
|
+
export declare function externalRoleFingerprint(role: Pick<SubAgentConfig, "command" | "externalModelRef" | "shell">): string;
|
|
157
181
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { existsSync as existsSyncFs } from "node:fs";
|
|
2
3
|
import { join as joinPath, delimiter as pathDelimiter } from "node:path";
|
|
3
4
|
import { parseFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
@@ -204,16 +205,23 @@ function parseContextChoice(raw) {
|
|
|
204
205
|
}
|
|
205
206
|
return { value: { contextMode: "contextual", memory: normalized } };
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
+
/**
|
|
209
|
+
* `defaultValue` is computed per call site rather than derived from `contextMode` inside this
|
|
210
|
+
* function (spec 042 D4): internal keeps following `contextMode` (`contextual` → `relevant`),
|
|
211
|
+
* but an external role's default is always `none` regardless of `contextMode` — a role that
|
|
212
|
+
* merely wants `paths` injected (via `contextMode: contextual`) should not also silently start
|
|
213
|
+
* sending session/memory content to a third-party process.
|
|
214
|
+
*/
|
|
215
|
+
function parseMemoryMode(raw, defaultValue) {
|
|
208
216
|
const normalized = readOptionalTrimmedString(raw);
|
|
209
217
|
if (!normalized) {
|
|
210
|
-
return { value:
|
|
218
|
+
return { value: defaultValue };
|
|
211
219
|
}
|
|
212
220
|
if (ALLOWED_MEMORY_MODES.includes(normalized)) {
|
|
213
221
|
return { value: normalized };
|
|
214
222
|
}
|
|
215
223
|
return {
|
|
216
|
-
value:
|
|
224
|
+
value: defaultValue,
|
|
217
225
|
error: `Unknown memory "${normalized}". Allowed values: ${ALLOWED_MEMORY_MODES.join(", ")}`,
|
|
218
226
|
};
|
|
219
227
|
}
|
|
@@ -348,18 +356,33 @@ function isExecutableAvailable(token) {
|
|
|
348
356
|
const pathEnv = process.env.PATH ?? "";
|
|
349
357
|
return pathEnv.split(pathDelimiter).some((dir) => dir && existsSyncFs(joinPath(dir, token)));
|
|
350
358
|
}
|
|
351
|
-
/**
|
|
352
|
-
*
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
359
|
+
/**
|
|
360
|
+
* Which role-file fields mean something under which runtime (spec 040 D5's "对某种 runtime 无意义
|
|
361
|
+
* 的字段一律驳回", made into data per spec 042 D3/F3). A field present under a runtime marked
|
|
362
|
+
* `"rejected"` here is rejected outright, not silently ignored — silently ignoring one is a
|
|
363
|
+
* defect, not a leniency (the review that produced spec 042 found `shell`/`env` on an internal
|
|
364
|
+
* role doing exactly that before this table existed). `cwd` is deliberately absent: it is rejected
|
|
365
|
+
* for *both* runtimes with a different message ("not a role field at all"), handled separately in
|
|
366
|
+
* `loadAgentsFromDir` rather than as a per-runtime mismatch.
|
|
367
|
+
*/
|
|
368
|
+
export const ROLE_FIELD_MATRIX = {
|
|
369
|
+
harness: { internal: "rejected", external: "supported" },
|
|
370
|
+
command: { internal: "rejected", external: "supported" },
|
|
371
|
+
shell: { internal: "rejected", external: "supported" },
|
|
372
|
+
env: { internal: "rejected", external: "supported" },
|
|
373
|
+
tools: { internal: "supported", external: "rejected" },
|
|
374
|
+
maxTurns: { internal: "supported", external: "rejected" },
|
|
375
|
+
maxToolCalls: { internal: "supported", external: "rejected" },
|
|
376
|
+
bashTimeoutSec: { internal: "supported", external: "rejected" },
|
|
377
|
+
};
|
|
378
|
+
function rejectedFieldNames(frontmatter, runtime) {
|
|
379
|
+
return Object.keys(ROLE_FIELD_MATRIX).filter((field) => frontmatter[field] !== undefined && ROLE_FIELD_MATRIX[field][runtime] === "rejected");
|
|
357
380
|
}
|
|
358
381
|
function inferMutatesFromTools(tools) {
|
|
359
382
|
return tools.includes("write") || tools.includes("edit") ? "write" : "read";
|
|
360
383
|
}
|
|
361
384
|
function parseInternalAgent(entryName, filePath, frontmatter, body, name, description, availableModels) {
|
|
362
|
-
const rejected = rejectedFieldNames(frontmatter,
|
|
385
|
+
const rejected = rejectedFieldNames(frontmatter, "internal");
|
|
363
386
|
if (rejected.length > 0) {
|
|
364
387
|
return { warning: `${entryName}: field(s) ${rejected.join(", ")} are only valid for runtime: external` };
|
|
365
388
|
}
|
|
@@ -369,7 +392,7 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
369
392
|
const contextMode = parseContextMode(frontmatter.contextMode);
|
|
370
393
|
if (contextMode.error)
|
|
371
394
|
return { warning: `${entryName}: ${contextMode.error}` };
|
|
372
|
-
const memoryMode = parseMemoryMode(frontmatter.memory, contextMode.value);
|
|
395
|
+
const memoryMode = parseMemoryMode(frontmatter.memory, contextMode.value === "contextual" ? "relevant" : "none");
|
|
373
396
|
if (memoryMode.error)
|
|
374
397
|
return { warning: `${entryName}: ${memoryMode.error}` };
|
|
375
398
|
const parsedPaths = parseStringList(frontmatter.paths, "paths");
|
|
@@ -405,8 +428,16 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
405
428
|
const promptLengthError = validateSubAgentSystemPrompt(trimmedBody, "Sub-agent system prompt");
|
|
406
429
|
if (promptLengthError)
|
|
407
430
|
return { warning: `${entryName}: ${promptLengthError}` };
|
|
431
|
+
// Spec 042 D6: `bash` can write regardless of what `tools` otherwise implies, and the default
|
|
432
|
+
// tool set (`read,bash`) is inferred "read" — a role that actually writes through bash and never
|
|
433
|
+
// says so does not take the workspace write lease. Not rejected (`bash` is normal and common for
|
|
434
|
+
// read-only inspection too) — just surfaced so the declaration is a conscious choice.
|
|
435
|
+
const bashWithoutMutatesWarning = toolParse.tools.includes("bash") && mutates.value === undefined
|
|
436
|
+
? 'tools include bash but "mutates" is not declared; if this role writes to the workspace, declare mutates: write so it participates in the workspace write lease'
|
|
437
|
+
: undefined;
|
|
438
|
+
const combinedWarningBody = [numericWarning, bashWithoutMutatesWarning].filter(Boolean).join("; ");
|
|
408
439
|
return {
|
|
409
|
-
warning:
|
|
440
|
+
warning: combinedWarningBody ? `${entryName}: ${combinedWarningBody}` : undefined,
|
|
410
441
|
agent: {
|
|
411
442
|
name,
|
|
412
443
|
description,
|
|
@@ -431,7 +462,7 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
431
462
|
};
|
|
432
463
|
}
|
|
433
464
|
function parseExternalAgent(entryName, filePath, frontmatter, body, name, description) {
|
|
434
|
-
const rejected = rejectedFieldNames(frontmatter,
|
|
465
|
+
const rejected = rejectedFieldNames(frontmatter, "external");
|
|
435
466
|
if (rejected.length > 0) {
|
|
436
467
|
return { warning: `${entryName}: field(s) ${rejected.join(", ")} are not valid for runtime: external` };
|
|
437
468
|
}
|
|
@@ -471,9 +502,16 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
471
502
|
const contextMode = parseContextMode(frontmatter.contextMode);
|
|
472
503
|
if (contextMode.error)
|
|
473
504
|
return { warning: `${entryName}: ${contextMode.error}` };
|
|
474
|
-
|
|
505
|
+
// Spec 042 D4: external default is always "none", never following contextMode the way internal
|
|
506
|
+
// does — a role that only wants `paths` injected (contextMode: contextual) should not also
|
|
507
|
+
// silently start sending session/memory content to a third-party process. Explicitly declaring
|
|
508
|
+
// `memory: session|relevant` is a real, informed choice; it gets a disclosure warning below.
|
|
509
|
+
const memoryMode = parseMemoryMode(frontmatter.memory, "none");
|
|
475
510
|
if (memoryMode.error)
|
|
476
511
|
return { warning: `${entryName}: ${memoryMode.error}` };
|
|
512
|
+
const memoryDisclosureWarning = memoryMode.value !== "none"
|
|
513
|
+
? `${entryName}: memory: ${memoryMode.value} sends channel session state / recalled memory content to this external process`
|
|
514
|
+
: undefined;
|
|
477
515
|
const maxWallTimeSec = parsePositiveInteger(frontmatter.maxWallTimeSec, DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC);
|
|
478
516
|
const trimmedBody = body.trim();
|
|
479
517
|
if (!trimmedBody)
|
|
@@ -488,14 +526,28 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
488
526
|
const unavailable = executable && !isExecutableAvailable(executable)
|
|
489
527
|
? `executable "${executable}" was not found on PATH; install it or fix "command" in ${filePath}`
|
|
490
528
|
: undefined;
|
|
529
|
+
const externalModelRef = readOptionalTrimmedString(frontmatter.model);
|
|
530
|
+
// Spec 042 D10: a role's `model:` can only ever come from its own frontmatter (external `model`
|
|
531
|
+
// is never taken from the invocation) — so if `command` references `$MODEL` and none is
|
|
532
|
+
// configured here, every dispatch of this role will silently drop that argv token. Surface it
|
|
533
|
+
// at discovery time, where the fix (add `model:`) is obvious, instead of only as a per-run
|
|
534
|
+
// warning after the fact. `$EFFORT` gets no equivalent check: `thinkingLevel` can be supplied
|
|
535
|
+
// per invocation, so an unset frontmatter value does not mean "no value ever".
|
|
536
|
+
const modelPlaceholderWarning = command.includes("$MODEL") && !externalModelRef
|
|
537
|
+
? `${entryName}: command references $MODEL but no "model" is configured; that argv token will be dropped on every dispatch`
|
|
538
|
+
: undefined;
|
|
539
|
+
// Both are non-fatal (the role still loads); joined rather than picking one so an unlucky
|
|
540
|
+
// combination never silently loses one of them.
|
|
541
|
+
const combinedWarning = [memoryDisclosureWarning, modelPlaceholderWarning].filter(Boolean).join("; ") || undefined;
|
|
491
542
|
return {
|
|
543
|
+
warning: combinedWarning,
|
|
492
544
|
agent: {
|
|
493
545
|
name,
|
|
494
546
|
description,
|
|
495
547
|
systemPrompt: trimmedBody,
|
|
496
548
|
tools: [],
|
|
497
549
|
modelRef: undefined,
|
|
498
|
-
externalModelRef
|
|
550
|
+
externalModelRef,
|
|
499
551
|
maxTurns: DEFAULT_MAX_TURNS,
|
|
500
552
|
maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
|
|
501
553
|
maxWallTimeSec: maxWallTimeSec.value,
|
|
@@ -606,6 +658,24 @@ subagentDefaultModelRef) {
|
|
|
606
658
|
if (!baseConfig && (!overrides.systemPrompt || !overrides.systemPrompt.trim())) {
|
|
607
659
|
return { error: 'Provide either "agent" or "systemPrompt" to define the sub-agent.' };
|
|
608
660
|
}
|
|
661
|
+
const effectiveRuntime = baseConfig?.runtime ?? "internal";
|
|
662
|
+
// Spec 042 D3: the invocation-side counterpart to the role-file field matrix (`ROLE_FIELD_MATRIX`
|
|
663
|
+
// above) — a field only meaningful for one runtime is rejected outright when the resolved role
|
|
664
|
+
// is the other, not silently ignored. `tools` and `model` were previously accepted and either
|
|
665
|
+
// dropped on the floor or — for `model` — resolved against `models.json` and made to fail a
|
|
666
|
+
// dispatch for a reason that has nothing to do with the external role actually named.
|
|
667
|
+
if (effectiveRuntime === "external" && overrides.tools !== undefined) {
|
|
668
|
+
return {
|
|
669
|
+
error: `Sub-agent "${baseConfig?.name}" is external; its tool boundary comes from its own ` +
|
|
670
|
+
'command (e.g. "--sandbox read-only"), not the "tools" invocation parameter, which has no effect on external roles.',
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
if (effectiveRuntime === "external" && overrides.model?.trim()) {
|
|
674
|
+
return {
|
|
675
|
+
error: `Sub-agent "${baseConfig?.name}" is external; its model can only be set in the role file's ` +
|
|
676
|
+
'"model" frontmatter. The "model" invocation parameter has no effect on external roles and is never resolved against models.json.',
|
|
677
|
+
};
|
|
678
|
+
}
|
|
609
679
|
const tools = overrides.tools
|
|
610
680
|
? validateToolNames(overrides.tools)
|
|
611
681
|
: { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
|
|
@@ -614,7 +684,7 @@ subagentDefaultModelRef) {
|
|
|
614
684
|
}
|
|
615
685
|
let model = baseConfig?.model;
|
|
616
686
|
let modelRef = baseConfig?.modelRef;
|
|
617
|
-
if (overrides.model?.trim()) {
|
|
687
|
+
if (effectiveRuntime !== "external" && overrides.model?.trim()) {
|
|
618
688
|
const resolved = resolveModelReference(overrides.model.trim(), availableModels);
|
|
619
689
|
if (!resolved.model) {
|
|
620
690
|
return { error: resolved.error };
|
|
@@ -634,7 +704,6 @@ subagentDefaultModelRef) {
|
|
|
634
704
|
if (effortOverride.error) {
|
|
635
705
|
return { error: effortOverride.error };
|
|
636
706
|
}
|
|
637
|
-
const effectiveRuntime = baseConfig?.runtime ?? "internal";
|
|
638
707
|
// An explicit `effort` replaces the whole budget tuple rather than merging field by
|
|
639
708
|
// field, so a preset never produces a combination no preset describes. External is a
|
|
640
709
|
// separate branch (P1-3): it has no turn/tool-call budget, and effort's wall-time numbers
|
|
@@ -725,3 +794,20 @@ export function formatSubAgentList(agents, maxItems = 12) {
|
|
|
725
794
|
}
|
|
726
795
|
return `${listed.join("\n")}\n- ... and ${agents.length - maxItems} more`;
|
|
727
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* Spec 042 D7: a fingerprint of the parts of an external role that decide *how a launched process
|
|
799
|
+
* is built* — `command`, `externalModelRef`, `shell`. Persisted on a run at launch and compared
|
|
800
|
+
* against the role's current config on `follow_up`: a mismatch means the role was hot-edited in a
|
|
801
|
+
* way that would resume under a harness or executable it never actually wrote, so `follow_up`
|
|
802
|
+
* refuses rather than silently reinterpreting the old session with the new config.
|
|
803
|
+
*
|
|
804
|
+
* Deliberately narrow — `systemPrompt` and `maxWallTimeSec` are excluded on purpose. A resumed
|
|
805
|
+
* session already carries its own context, and folding prompt edits in would mean "fix a typo in
|
|
806
|
+
* the role" breaks every in-flight follow-up; a full invocation snapshot was considered and
|
|
807
|
+
* rejected for the same reason (spec 042 design doc, "已驳回的方案").
|
|
808
|
+
*/
|
|
809
|
+
export function externalRoleFingerprint(role) {
|
|
810
|
+
return createHash("sha256")
|
|
811
|
+
.update(JSON.stringify([role.command ?? "", role.externalModelRef ?? "", Boolean(role.shell)]))
|
|
812
|
+
.digest("hex");
|
|
813
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { detectExistingFlags, expandPlaceholders, } from "./harness.js";
|
|
2
|
+
import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
|
|
3
3
|
/**
|
|
4
4
|
* `claude-code` harness (spec 040, D3/D4). Same one-prompt-one-process model as codex-cli; the
|
|
5
5
|
* differences are argv shape and stdout schema.
|
|
@@ -31,6 +31,7 @@ function toClaudeEffort(level) {
|
|
|
31
31
|
}
|
|
32
32
|
export const claudeCodeHarness = {
|
|
33
33
|
id: "claude-code",
|
|
34
|
+
parserVersion: 1,
|
|
34
35
|
buildInvocation(input) {
|
|
35
36
|
if (input.argv.length === 0) {
|
|
36
37
|
throw new Error("claude-code: command produced no argv tokens");
|
|
@@ -38,7 +39,7 @@ export const claudeCodeHarness = {
|
|
|
38
39
|
const [executable, ...rest] = input.argv;
|
|
39
40
|
const existing = detectExistingFlags(rest);
|
|
40
41
|
const effort = toClaudeEffort(input.thinkingLevel);
|
|
41
|
-
const { argv: expandedRest, used } = expandPlaceholders(rest, {
|
|
42
|
+
const { argv: expandedRest, used, dropped, } = expandPlaceholders(rest, {
|
|
42
43
|
$MODEL: input.model,
|
|
43
44
|
$EFFORT: effort,
|
|
44
45
|
$PROMPT_FILE: input.promptFile,
|
|
@@ -62,7 +63,13 @@ export const claudeCodeHarness = {
|
|
|
62
63
|
presetSessionId = randomUUID();
|
|
63
64
|
args.push("--session-id", presetSessionId);
|
|
64
65
|
}
|
|
65
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
executable,
|
|
68
|
+
args,
|
|
69
|
+
resumable: true,
|
|
70
|
+
presetSessionId,
|
|
71
|
+
warnings: dropped.length > 0 ? formatDroppedPlaceholderWarnings(dropped) : undefined,
|
|
72
|
+
};
|
|
66
73
|
},
|
|
67
74
|
parseOutcome(input) {
|
|
68
75
|
let finalText = "";
|