@oyasmi/pipiclaw 0.9.0-beta.8 → 0.9.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.
Files changed (80) hide show
  1. package/dist/agent/channel-runner.d.ts +8 -0
  2. package/dist/agent/channel-runner.js +73 -10
  3. package/dist/agent/commands.d.ts +1 -1
  4. package/dist/agent/commands.js +9 -0
  5. package/dist/agent/index.d.ts +1 -1
  6. package/dist/agent/index.js +1 -1
  7. package/dist/agent/job-manager.d.ts +23 -3
  8. package/dist/agent/job-manager.js +14 -1
  9. package/dist/agent/runner-factory.d.ts +16 -4
  10. package/dist/agent/runner-factory.js +9 -23
  11. package/dist/agent/turn-recovery.d.ts +72 -0
  12. package/dist/agent/turn-recovery.js +193 -0
  13. package/dist/agent/types.d.ts +9 -1
  14. package/dist/agent/types.js +3 -16
  15. package/dist/playbooks/agent-delegation.md +3 -3
  16. package/dist/playbooks/runtime-orientation.md +5 -0
  17. package/dist/runtime/active-session-store.d.ts +42 -0
  18. package/dist/runtime/active-session-store.js +100 -0
  19. package/dist/runtime/bootstrap.d.ts +10 -2
  20. package/dist/runtime/bootstrap.js +122 -53
  21. package/dist/runtime/channel-event.d.ts +41 -0
  22. package/dist/runtime/channel-event.js +1 -0
  23. package/dist/runtime/delivery.d.ts +3 -2
  24. package/dist/runtime/dingtalk.d.ts +9 -31
  25. package/dist/runtime/dingtalk.js +2 -1
  26. package/dist/runtime/durable-dispatch.d.ts +3 -2
  27. package/dist/runtime/events.d.ts +3 -2
  28. package/dist/runtime/events.js +2 -3
  29. package/dist/runtime/project-commands.d.ts +16 -0
  30. package/dist/runtime/project-commands.js +112 -0
  31. package/dist/runtime/project-scope-store.d.ts +31 -0
  32. package/dist/runtime/project-scope-store.js +102 -0
  33. package/dist/runtime/task-commands.js +2 -2
  34. package/dist/runtime/task-driver.d.ts +7 -7
  35. package/dist/runtime/task-driver.js +1 -4
  36. package/dist/runtime/task-migration.js +1 -1
  37. package/dist/runtime/task-wake.d.ts +4 -4
  38. package/dist/security/config.js +10 -0
  39. package/dist/security/path-guard.js +34 -9
  40. package/dist/security/project-scope.d.ts +45 -0
  41. package/dist/security/project-scope.js +107 -0
  42. package/dist/security/types.d.ts +20 -2
  43. package/dist/settings.d.ts +0 -106
  44. package/dist/settings.js +0 -224
  45. package/dist/shared/types.d.ts +1 -0
  46. package/dist/shared/types.js +10 -1
  47. package/dist/subagents/external/run.js +2 -8
  48. package/dist/subagents/runs.d.ts +3 -3
  49. package/dist/subagents/runs.js +2 -12
  50. package/dist/subagents/tool.d.ts +13 -4
  51. package/dist/subagents/tool.js +9 -15
  52. package/dist/tasks/ledger.js +1 -1
  53. package/dist/{shared → tasks}/task-schedule.js +1 -1
  54. package/dist/tools/bash.js +4 -4
  55. package/dist/tools/edit.js +3 -3
  56. package/dist/tools/event-manage.js +1 -4
  57. package/dist/tools/grep.js +5 -6
  58. package/dist/tools/index.d.ts +3 -0
  59. package/dist/tools/index.js +7 -2
  60. package/dist/tools/job.js +5 -5
  61. package/dist/tools/memory-manage.js +3 -6
  62. package/dist/tools/read.js +3 -3
  63. package/dist/tools/registry.js +1 -1
  64. package/dist/tools/send-media.js +2 -2
  65. package/dist/tools/session-search.js +0 -1
  66. package/dist/tools/skill-manage.js +3 -3
  67. package/dist/tools/subagent-manage.js +3 -3
  68. package/dist/tools/task-manage/shared.js +2 -2
  69. package/dist/tools/task-manage.js +1 -4
  70. package/dist/tools/web-fetch.js +0 -1
  71. package/dist/tools/write-content.js +3 -3
  72. package/dist/tui/app.js +50 -4
  73. package/dist/tui/commands.d.ts +1 -0
  74. package/dist/tui/commands.js +2 -0
  75. package/dist/tui/turn-controller.d.ts +1 -0
  76. package/dist/tui/turn-controller.js +1 -0
  77. package/package.json +1 -1
  78. /package/dist/{shared → tasks}/task-events.d.ts +0 -0
  79. /package/dist/{shared → tasks}/task-events.js +0 -0
  80. /package/dist/{shared → tasks}/task-schedule.d.ts +0 -0
@@ -0,0 +1,107 @@
1
+ import { realpathSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { isAbsolute, resolve } from "node:path";
4
+ const DIAGNOSTIC_SOURCE = "security";
5
+ function expandHome(path) {
6
+ if (path === "~")
7
+ return homedir();
8
+ if (path.startsWith("~/"))
9
+ return resolve(homedir(), path.slice(2));
10
+ return path;
11
+ }
12
+ /** Absolute, existing, real directory — or `undefined` if any of that doesn't hold. */
13
+ function canonicalizeRoot(raw) {
14
+ const expanded = expandHome(raw);
15
+ if (!isAbsolute(expanded))
16
+ return undefined;
17
+ try {
18
+ const real = realpathSync(expanded);
19
+ return statSync(real).isDirectory() ? real : undefined;
20
+ }
21
+ catch {
22
+ return undefined;
23
+ }
24
+ }
25
+ function realpathOrResolve(path) {
26
+ try {
27
+ return realpathSync(path);
28
+ }
29
+ catch {
30
+ return resolve(path);
31
+ }
32
+ }
33
+ /**
34
+ * Resolves the app's project-access policy for a fresh runner generation. `startupCwd` is only
35
+ * used as the implicit default when `projectAccess` is configured but omits `defaultRoot` (D3.2
36
+ * row 3) — the unconfigured-compat row (row 1) also uses it, but never persists it as a "chosen"
37
+ * default the way a configured policy's `defaultRoot` is.
38
+ */
39
+ export function resolveProjectAccessPolicy(config, startupCwd) {
40
+ const diagnostics = [];
41
+ const raw = config.projectAccess;
42
+ const fallbackRoot = realpathOrResolve(startupCwd);
43
+ if (!raw) {
44
+ return {
45
+ policy: { defaultRoot: fallbackRoot, allowedRoots: [fallbackRoot] },
46
+ mutable: false,
47
+ configured: false,
48
+ diagnostics,
49
+ };
50
+ }
51
+ const defaultRootRaw = raw.defaultRoot ?? startupCwd;
52
+ const defaultRoot = canonicalizeRoot(defaultRootRaw);
53
+ if (!defaultRoot) {
54
+ diagnostics.push({
55
+ source: DIAGNOSTIC_SOURCE,
56
+ path: "projectAccess.defaultRoot",
57
+ severity: "error",
58
+ message: `${JSON.stringify(defaultRootRaw)} is not an absolute, existing directory; project scope changes are disabled until this is fixed`,
59
+ });
60
+ return {
61
+ policy: { defaultRoot: fallbackRoot, allowedRoots: [fallbackRoot] },
62
+ mutable: false,
63
+ configured: true,
64
+ diagnostics,
65
+ };
66
+ }
67
+ const rawAllowed = raw.allowedRoots && raw.allowedRoots.length > 0 ? raw.allowedRoots : [defaultRootRaw];
68
+ const allowedRoots = new Set([defaultRoot]);
69
+ for (const entry of rawAllowed) {
70
+ const canonical = canonicalizeRoot(entry);
71
+ if (!canonical) {
72
+ diagnostics.push({
73
+ source: DIAGNOSTIC_SOURCE,
74
+ path: "projectAccess.allowedRoots",
75
+ severity: "warning",
76
+ message: `entry ${JSON.stringify(entry)} is not an absolute, existing directory; ignored`,
77
+ });
78
+ continue;
79
+ }
80
+ allowedRoots.add(canonical);
81
+ }
82
+ return {
83
+ policy: { defaultRoot, allowedRoots: [...allowedRoots] },
84
+ mutable: true,
85
+ configured: true,
86
+ diagnostics,
87
+ };
88
+ }
89
+ function withTrailingSlash(path) {
90
+ return path.endsWith("/") ? path : `${path}/`;
91
+ }
92
+ /** Prefix match with a path-separator boundary, so `/repo-ab` is not treated as within `/repo-a`. */
93
+ export function isWithinAllowedRoots(root, policy) {
94
+ return policy.allowedRoots.some((allowed) => root === allowed || root.startsWith(withTrailingSlash(allowed)));
95
+ }
96
+ /** True until a host sandbox injection point exists (D6.3, D9 risk #2) — see `ProjectSandboxStatus`. */
97
+ export function currentProjectSandboxStatus() {
98
+ return {
99
+ level: "application",
100
+ provider: "pipiclaw-path-guard",
101
+ summary: "文件工具被约束在项目目录内;shell 仅设置了 cwd,未受系统沙箱隔离,可通过 cd/绝对路径/子进程逃逸。",
102
+ };
103
+ }
104
+ /** True if `raw` resolves (after `~`-expansion) to an existing directory — used by `/project set` validation. */
105
+ export function resolveExistingDirectory(raw) {
106
+ return canonicalizeRoot(raw);
107
+ }
@@ -24,10 +24,28 @@ export interface SecurityConfig {
24
24
  logBlocked: boolean;
25
25
  logFile?: string;
26
26
  };
27
+ /**
28
+ * Absent (no `projectAccess` key in `security.json` at all) is a distinct, meaningful state
29
+ * from present-with-omitted-fields: absent is the upgrade-compat path (`ProjectScope.boundary`
30
+ * stays `"unbounded"`, `/project set` is disabled); present means the operator has opted into
31
+ * project boundaries (spec 043, D3.2). See `src/security/project-scope.ts` for the resolved,
32
+ * canonicalized policy this raw section feeds into.
33
+ */
34
+ projectAccess?: {
35
+ defaultRoot?: string;
36
+ allowedRoots?: string[];
37
+ };
27
38
  }
28
39
  export interface SecurityRuntimeContext {
29
- workspaceDir: string;
30
- cwd?: string;
40
+ agentWorkspaceDir: string;
41
+ projectRoot?: string;
42
+ /**
43
+ * `"project"`: generic file tools are bounded to `projectRoot`; `security.json`'s configured
44
+ * `readAllow`/`writeAllow` can narrow within it but never widen past it (spec 043, D6.2).
45
+ * `"unbounded"` (the default when omitted, for backward compat): today's global pathGuard
46
+ * defaults — `agentWorkspaceDir` + temp + `homeDir`.
47
+ */
48
+ boundary?: "project" | "unbounded";
31
49
  homeDir?: string;
32
50
  }
33
51
  export interface PathGuardContext extends SecurityRuntimeContext {
@@ -7,44 +7,13 @@
7
7
  * This module currently provides only PipiclawSettingsManager.
8
8
  */
9
9
  import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
10
- import type { Transport } from "@earendil-works/pi-ai";
11
10
  import { type MemoryMaintenanceTuning } from "./memory/maintenance-tuning.js";
12
11
  import type { ResponseMode } from "./runtime/dingtalk.js";
13
12
  import type { ConfigDiagnostic } from "./shared/config-diagnostic.js";
14
- type PackageSource = string | {
15
- source: string;
16
- extensions?: string[];
17
- skills?: string[];
18
- prompts?: string[];
19
- themes?: string[];
20
- };
21
- type ThinkingBudgetsSettings = {
22
- minimal?: number;
23
- low?: number;
24
- medium?: number;
25
- high?: number;
26
- };
27
- type Settings = {
28
- defaultProvider?: string;
29
- defaultModel?: string;
30
- defaultThinkingLevel?: ThinkingLevel;
31
- compaction?: {
32
- enabled?: boolean;
33
- reserveTokens?: number;
34
- keepRecentTokens?: number;
35
- };
36
- retry?: {
37
- enabled?: boolean;
38
- maxRetries?: number;
39
- baseDelayMs?: number;
40
- maxDelayMs?: number;
41
- };
42
- };
43
13
  type SettingsError = {
44
14
  scope: "global" | "project";
45
15
  error: Error;
46
16
  };
47
- type TransportSetting = Transport;
48
17
  export interface PipiclawCompactionSettings {
49
18
  enabled: boolean;
50
19
  reserveTokens: number;
@@ -216,80 +185,5 @@ export declare class PipiclawSettingsManager {
216
185
  setDefaultModelAndProvider(provider: string, modelId: string): void;
217
186
  getDefaultThinkingLevel(): ThinkingLevel | undefined;
218
187
  setDefaultThinkingLevel(level: ThinkingLevel): void;
219
- getSteeringMode(): "all" | "one-at-a-time";
220
- setSteeringMode(_mode: "all" | "one-at-a-time"): void;
221
- getFollowUpMode(): "all" | "one-at-a-time";
222
- setFollowUpMode(_mode: "all" | "one-at-a-time"): void;
223
- getHookPaths(): string[];
224
- getHookTimeout(): number;
225
- getImageAutoResize(): boolean;
226
- setImageAutoResize(_enabled: boolean): void;
227
- getBlockImages(): boolean;
228
- setBlockImages(_blocked: boolean): void;
229
- getShowImages(): boolean;
230
- setShowImages(_show: boolean): void;
231
- getBranchSummarySettings(): {
232
- reserveTokens: number;
233
- };
234
- getBranchSummarySkipPrompt(): boolean;
235
- getHideThinkingBlock(): boolean;
236
- setHideThinkingBlock(_hide: boolean): void;
237
- getThinkingBudgets(): ThinkingBudgetsSettings | undefined;
238
- getShellPath(): string | undefined;
239
- setShellPath(_path: string | undefined): void;
240
- getShellCommandPrefix(): string | undefined;
241
- setShellCommandPrefix(_prefix: string | undefined): void;
242
- getQuietStartup(): boolean;
243
- setQuietStartup(_quiet: boolean): void;
244
- getCollapseChangelog(): boolean;
245
- setCollapseChangelog(_collapse: boolean): void;
246
- getTransport(): TransportSetting;
247
- setTransport(_transport: TransportSetting): void;
248
- getTheme(): string | undefined;
249
- setTheme(_theme: string): void;
250
- getPackages(): PackageSource[];
251
- setPackages(_packages: PackageSource[]): void;
252
- setProjectPackages(_packages: PackageSource[]): void;
253
- getExtensionPaths(): string[];
254
- setExtensionPaths(_paths: string[]): void;
255
- setProjectExtensionPaths(_paths: string[]): void;
256
- getSkillPaths(): string[];
257
- setSkillPaths(_paths: string[]): void;
258
- setProjectSkillPaths(_paths: string[]): void;
259
- getPromptTemplatePaths(): string[];
260
- setPromptTemplatePaths(_paths: string[]): void;
261
- setProjectPromptTemplatePaths(_paths: string[]): void;
262
- getThemePaths(): string[];
263
- setThemePaths(_paths: string[]): void;
264
- setProjectThemePaths(_paths: string[]): void;
265
- getEnableSkillCommands(): boolean;
266
- setEnableSkillCommands(_enabled: boolean): void;
267
- getEnabledModels(): string[] | undefined;
268
- setEnabledModels(_patterns: string[] | undefined): void;
269
- getDoubleEscapeAction(): "none";
270
- setDoubleEscapeAction(_action: "fork" | "tree" | "none"): void;
271
- getTreeFilterMode(): "default" | "no-tools" | "user-only" | "labeled-only" | "all";
272
- setTreeFilterMode(_mode: "default" | "no-tools" | "user-only" | "labeled-only" | "all"): void;
273
- getShowHardwareCursor(): boolean;
274
- setShowHardwareCursor(_enabled: boolean): void;
275
- getClearOnShrink(): boolean;
276
- setClearOnShrink(_enabled: boolean): void;
277
- getEditorPaddingX(): number;
278
- setEditorPaddingX(_padding: number): void;
279
- getAutocompleteMaxVisible(): number;
280
- setAutocompleteMaxVisible(_maxVisible: number): void;
281
- getCodeBlockIndent(): string;
282
- getLastChangelogVersion(): string | undefined;
283
- setLastChangelogVersion(_version: string): void;
284
- setDefaultProvider(_provider: string): void;
285
- setDefaultModel(_modelId: string): void;
286
- getSessionDir(): string | undefined;
287
- getNpmCommand(): string[] | undefined;
288
- setNpmCommand(_command: string[] | undefined): void;
289
- getGlobalSettings(): Settings;
290
- getProjectSettings(): Settings;
291
- isProjectTrusted(): boolean;
292
- setProjectTrusted(_trusted: boolean): void;
293
- flush(): Promise<void>;
294
188
  }
295
189
  export {};
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
  }
@@ -12,3 +12,4 @@ export interface UsageTotals {
12
12
  total: number;
13
13
  };
14
14
  }
15
+ export declare function createEmptyUsageTotals(): UsageTotals;
@@ -1 +1,10 @@
1
- export {};
1
+ export function createEmptyUsageTotals() {
2
+ return {
3
+ input: 0,
4
+ output: 0,
5
+ cacheRead: 0,
6
+ cacheWrite: 0,
7
+ total: 0,
8
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
9
+ };
10
+ }
@@ -7,6 +7,7 @@ import { logSecurityEvent } from "../../security/logger.js";
7
7
  import { killProcessGroup, probeCliVersion, readProcessStartTime, reapProcessGroup, } from "../../shared/host-process.js";
8
8
  import { splitShellWords } from "../../shared/shell-words.js";
9
9
  import { errorMessage } from "../../shared/text-utils.js";
10
+ import { createEmptyUsageTotals } from "../../shared/types.js";
10
11
  import { workspaceSubjectHash } from "../../tasks/artifact-subject.js";
11
12
  import { getSubAgentRunManager } from "../runs.js";
12
13
  import { getExternalHarness } from "./registry.js";
@@ -273,14 +274,7 @@ export async function launchExternalRun(input) {
273
274
  return {
274
275
  status: "failed",
275
276
  failureReason: reason,
276
- usage: {
277
- input: 0,
278
- output: 0,
279
- cacheRead: 0,
280
- cacheWrite: 0,
281
- total: 0,
282
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
283
- },
277
+ usage: createEmptyUsageTotals(),
284
278
  usageKnown: false,
285
279
  costKnown: false,
286
280
  turns: 0,
@@ -1,6 +1,6 @@
1
- import type { DingTalkEvent } from "../runtime/dingtalk.js";
1
+ import type { ChannelEvent } from "../runtime/channel-event.js";
2
2
  import type { ChannelStore } from "../runtime/store.js";
3
- import type { UsageTotals } from "../shared/types.js";
3
+ import { type UsageTotals } from "../shared/types.js";
4
4
  import type { UsageLedger } from "../usage/ledger.js";
5
5
  /**
6
6
  * The run: one abstraction level for delegation, whether it executes as an in-process sub-agent
@@ -171,7 +171,7 @@ export interface SettleInput {
171
171
  export interface RunManagerOptions {
172
172
  /** Root of the per-channel record directories (`<stateDir>/<channelId>/`). Omit to skip persistence. */
173
173
  stateDir?: string;
174
- dispatch?: (event: DingTalkEvent) => boolean | Promise<boolean>;
174
+ dispatch?: (event: ChannelEvent) => boolean | Promise<boolean>;
175
175
  ledger?: UsageLedger;
176
176
  store?: ChannelStore;
177
177
  }
@@ -7,6 +7,7 @@ import { RecoverableToolError } from "../shared/recoverable-error.js";
7
7
  import { createSerialQueue } from "../shared/serial-queue.js";
8
8
  import { errorMessage } from "../shared/text-utils.js";
9
9
  import { isRecord } from "../shared/type-guards.js";
10
+ import { createEmptyUsageTotals } from "../shared/types.js";
10
11
  import { beginWakeClaim, finishWakeClaim } from "../shared/wake-claim.js";
11
12
  import { finalizeExternalRun } from "./external/settlement.js";
12
13
  import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease } from "./workspace-lease.js";
@@ -225,7 +226,7 @@ export class SubAgentRunManager {
225
226
  ...input,
226
227
  status: "running",
227
228
  startedAt: Date.now(),
228
- usage: emptyUsage(),
229
+ usage: createEmptyUsageTotals(),
229
230
  usageKnown: true,
230
231
  costKnown: true,
231
232
  };
@@ -479,7 +480,6 @@ export class SubAgentRunManager {
479
480
  : `No text output was produced. Run artifacts: ${record.artifactDir}\n`) +
480
481
  "Continue whatever was waiting on this delegation. If it needs no follow-up, respond with exactly [SILENT].",
481
482
  ts: String(Date.now()),
482
- conversationId: "",
483
483
  conversationType: record.channelId.startsWith("group_") ? "2" : "1",
484
484
  dispatchId: `subagent:${record.channelId}:${record.runId}:done`,
485
485
  ...(record.taskId
@@ -817,16 +817,6 @@ export class SubAgentRunManager {
817
817
  }
818
818
  }
819
819
  }
820
- function emptyUsage() {
821
- return {
822
- input: 0,
823
- output: 0,
824
- cacheRead: 0,
825
- cacheWrite: 0,
826
- total: 0,
827
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
828
- };
829
- }
830
820
  const managers = new Map();
831
821
  /** Host-wide running count for the D10.2 admission check, summed across every known channel. */
832
822
  function totalRunningSubAgentRuns() {
@@ -5,7 +5,7 @@ import type { Executor } from "../executor.js";
5
5
  import type { MemoryCandidateStore } from "../memory/candidates.js";
6
6
  import type { SecurityConfig } from "../security/types.js";
7
7
  import type { PipiclawMemoryRecallSettings } from "../settings.js";
8
- import type { UsageTotals } from "../shared/types.js";
8
+ import { type UsageTotals } from "../shared/types.js";
9
9
  import type { PipiclawWebToolsConfig } from "../tools/config.js";
10
10
  import { type ResolvedSubAgentConfig, type SubAgentConfig, type SubAgentDiscoveryResult } from "./discovery.js";
11
11
  import { getSubAgentRunManager } from "./runs.js";
@@ -26,8 +26,11 @@ declare const subagentSchema: Type.TObject<{
26
26
  returns: Type.TOptional<Type.TUnion<[Type.TLiteral<"text">, Type.TLiteral<"artifact">]>>;
27
27
  thinkingLevel: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
28
28
  }>;
29
- export interface SubAgentToolDetails {
30
- kind: "subagent";
29
+ /**
30
+ * Fields the `subagent` tool itself constructs. `kind` is not among them: `withToolDetails`
31
+ * stamps it from the registration name when the tool set is built (see `tools/tool-details.ts`).
32
+ */
33
+ export interface SubAgentToolFields {
31
34
  agent: string;
32
35
  source: "predefined" | "inline";
33
36
  model: string;
@@ -55,10 +58,16 @@ export interface SubAgentToolDetails {
55
58
  */
56
59
  dispatched?: boolean;
57
60
  }
61
+ /** The shape consumers read post-wrap, once `withToolDetails` has stamped `kind`. */
62
+ export type SubAgentToolDetails = SubAgentToolFields & {
63
+ kind: "subagent";
64
+ };
58
65
  export interface SubAgentToolOptions {
59
66
  executor: Executor;
60
67
  /** Host checkout used as the sub-agent's cwd. Defaults to process.cwd(). */
61
68
  workingDirectory?: string;
69
+ /** Mirrors the parent channel's ProjectScope.boundary onto the sub-agent's own tool set (spec 043, D6.2). */
70
+ projectBoundary?: "project" | "unbounded";
62
71
  getCurrentModel: () => Model<Api>;
63
72
  getAvailableModels: () => Model<Api>[];
64
73
  resolveApiKey: (model: Model<Api>) => Promise<string>;
@@ -147,5 +156,5 @@ export declare function buildSubAgentTask(task: string, config: Pick<SubAgentCon
147
156
  * option surface (executor, discovery, web config, etc. that a context-block build never touches). */
148
157
  export type ContextualBlocksOptions = Pick<SubAgentToolOptions, "channelDir" | "getMemoryRecallSettings" | "runtimeContext" | "workspaceDir" | "resolveApiKey" | "memoryCandidateStore">;
149
158
  export declare function buildContextualBlocks(task: string, config: Pick<SubAgentConfig, "contextMode" | "paths" | "memory" | "description">, options: ContextualBlocksOptions, currentModel: Model<Api>): Promise<string[]>;
150
- export declare function createSubAgentTool(options: SubAgentToolOptions): AgentTool<typeof subagentSchema, SubAgentToolDetails>;
159
+ export declare function createSubAgentTool(options: SubAgentToolOptions): AgentTool<typeof subagentSchema, SubAgentToolFields>;
151
160
  export {};