@oyasmi/pipiclaw 0.9.0-beta.8 → 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.
Files changed (51) hide show
  1. package/dist/agent/channel-runner.d.ts +1 -0
  2. package/dist/agent/channel-runner.js +21 -2
  3. package/dist/agent/index.d.ts +1 -1
  4. package/dist/agent/index.js +1 -1
  5. package/dist/agent/job-manager.d.ts +3 -3
  6. package/dist/agent/job-manager.js +0 -1
  7. package/dist/agent/runner-factory.d.ts +16 -4
  8. package/dist/agent/runner-factory.js +9 -23
  9. package/dist/agent/types.d.ts +9 -1
  10. package/dist/agent/types.js +3 -16
  11. package/dist/runtime/bootstrap.d.ts +10 -2
  12. package/dist/runtime/bootstrap.js +74 -50
  13. package/dist/runtime/channel-event.d.ts +41 -0
  14. package/dist/runtime/channel-event.js +1 -0
  15. package/dist/runtime/delivery.d.ts +3 -2
  16. package/dist/runtime/dingtalk.d.ts +9 -31
  17. package/dist/runtime/durable-dispatch.d.ts +3 -2
  18. package/dist/runtime/events.d.ts +3 -2
  19. package/dist/runtime/events.js +2 -3
  20. package/dist/runtime/task-commands.js +2 -2
  21. package/dist/runtime/task-driver.d.ts +7 -7
  22. package/dist/runtime/task-driver.js +1 -4
  23. package/dist/runtime/task-migration.js +1 -1
  24. package/dist/runtime/task-wake.d.ts +4 -4
  25. package/dist/settings.d.ts +0 -106
  26. package/dist/settings.js +0 -224
  27. package/dist/shared/types.d.ts +1 -0
  28. package/dist/shared/types.js +10 -1
  29. package/dist/subagents/external/run.js +2 -8
  30. package/dist/subagents/runs.d.ts +3 -3
  31. package/dist/subagents/runs.js +2 -12
  32. package/dist/subagents/tool.d.ts +11 -4
  33. package/dist/subagents/tool.js +1 -13
  34. package/dist/tasks/ledger.js +1 -1
  35. package/dist/{shared → tasks}/task-schedule.js +1 -1
  36. package/dist/tools/bash.js +1 -1
  37. package/dist/tools/event-manage.js +1 -4
  38. package/dist/tools/grep.js +2 -3
  39. package/dist/tools/job.js +5 -5
  40. package/dist/tools/memory-manage.js +3 -6
  41. package/dist/tools/session-search.js +0 -1
  42. package/dist/tools/skill-manage.js +3 -3
  43. package/dist/tools/subagent-manage.js +3 -3
  44. package/dist/tools/task-manage/shared.js +2 -2
  45. package/dist/tools/task-manage.js +1 -4
  46. package/dist/tools/web-fetch.js +0 -1
  47. package/dist/tui/app.js +4 -4
  48. package/package.json +1 -1
  49. /package/dist/{shared → tasks}/task-events.d.ts +0 -0
  50. /package/dist/{shared → tasks}/task-events.js +0 -0
  51. /package/dist/{shared → tasks}/task-schedule.d.ts +0 -0
@@ -1,13 +1,13 @@
1
1
  import type { PipiclawTaskDriverSettings } from "../settings.js";
2
2
  import { type TaskLedgerEntry } from "../tasks/ledger.js";
3
- import type { DingTalkEvent } from "./dingtalk.js";
3
+ import type { ChannelEvent } from "./channel-event.js";
4
4
  export interface TaskDriverOptions {
5
5
  workspaceDir: string;
6
6
  getKnownChannelIds?: () => Iterable<string>;
7
7
  isChannelActive: (channelId: string) => boolean;
8
- dispatch: (event: DingTalkEvent) => boolean | Promise<boolean>;
8
+ dispatch: (event: ChannelEvent) => boolean | Promise<boolean>;
9
9
  /** Optional observability hook. It runs after every production dispatch attempt. */
10
- onDispatch?: (event: DingTalkEvent, accepted: boolean) => void;
10
+ onDispatch?: (event: ChannelEvent, accepted: boolean) => void;
11
11
  getSettings: () => PipiclawTaskDriverSettings;
12
12
  /**
13
13
  * Externally visible effects produced by this task's own turns so far (spec 031, D7).
@@ -19,13 +19,13 @@ export interface TaskDriverOptions {
19
19
  /** Test-only override for the idle-sleep cap; production uses `settings.maxSleepMinutes`. */
20
20
  intervalMs?: number;
21
21
  /** Direct, non-LLM receipt for deterministic governor stops. */
22
- notify?: (event: DingTalkEvent) => boolean | Promise<boolean>;
22
+ notify?: (event: ChannelEvent) => boolean | Promise<boolean>;
23
23
  }
24
24
  export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
25
- export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number, attemptGeneration?: number): DingTalkEvent;
25
+ export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number, attemptGeneration?: number): ChannelEvent;
26
26
  /** Durable checker wake created by request-verification; it is a normal main-agent turn. */
27
- export declare function createTaskVerificationEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
28
- export declare function taskGovernorReceipt(channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number): DingTalkEvent;
27
+ export declare function createTaskVerificationEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): ChannelEvent;
28
+ export declare function taskGovernorReceipt(channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number): ChannelEvent;
29
29
  /**
30
30
  * Native, token-gated driver for the persistent task ledger.
31
31
  *
@@ -3,11 +3,11 @@ import { join } from "node:path";
3
3
  import * as log from "../log.js";
4
4
  import { PLAYBOOKS_DIR } from "../paths.js";
5
5
  import { parseLocalTime } from "../shared/local-time.js";
6
- import { nextTaskWake } from "../shared/task-schedule.js";
7
6
  import { errorMessage } from "../shared/text-utils.js";
8
7
  import { taskBudgetViolation } from "../tasks/control.js";
9
8
  import { normalizeTaskFields, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
10
9
  import { activateWaitingTask, claimTaskAttempt, escalateTask, openRecurringTaskCycle, releaseTaskAttemptClaim, updateStoredTask, } from "../tasks/store.js";
10
+ import { nextTaskWake } from "../tasks/task-schedule.js";
11
11
  import { discoverWorkspaceChannelIds } from "./channel-index.js";
12
12
  import { isChannelId } from "./channel-paths.js";
13
13
  /** Short debounce so a burst of nudges collapses into a single rescan. */
@@ -146,7 +146,6 @@ export function createTaskDriverEvent(channelId, entry, nowMs, attemptGeneration
146
146
  "For a recurring occurrence intentionally not run because it is duplicate or already satisfied, call task_manage skip with the reason, then respond with exactly [SILENT]. " +
147
147
  "If no task state or tool action is needed and this wake produces no user-visible result, respond with exactly [SILENT].",
148
148
  ts: String(nowMs),
149
- conversationId: "",
150
149
  conversationType: channelId.startsWith("group_") ? "2" : "1",
151
150
  dispatchId: taskDispatchId(channelId, entry, nowMs),
152
151
  taskAttemptGeneration: attemptGeneration,
@@ -165,7 +164,6 @@ export function createTaskVerificationEvent(channelId, entry, nowMs) {
165
164
  `subagent with purpose=verify. Import its attestation with task_manage verify using the returned run id. ` +
166
165
  `Do not modify the workspace or task contract; if verification fails, record the failure and leave the task recoverable.`,
167
166
  ts: String(nowMs),
168
- conversationId: "",
169
167
  conversationType: channelId.startsWith("group_") ? "2" : "1",
170
168
  dispatchId: `task:${channelId}:${entry.id}:verification:${control?.cycleId ?? `t${nowMs}`}`,
171
169
  };
@@ -192,7 +190,6 @@ export function taskGovernorReceipt(channelId, entry, reason, nowMs) {
192
190
  `当前阶段:${entry.frontmatter.status ?? "active"}${entry.frontmatter.control?.cycleId ? `;周期:${entry.frontmatter.control.cycleId}` : ""}\n` +
193
191
  `继续:/tasks resume ${entry.id}\n立即执行:/tasks run ${entry.id}\n不再需要:让 Agent cancel 该任务。`,
194
192
  ts: String(nowMs),
195
- conversationId: "",
196
193
  conversationType: channelId.startsWith("group_") ? "2" : "1",
197
194
  // Keyed on the cause, not the moment: re-detecting the same violation before the user has
198
195
  // acted must not queue a second identical escalation, while a different cause still does.
@@ -2,12 +2,12 @@ import { mkdir, readdir, readFile, rename, stat, unlink } from "node:fs/promises
2
2
  import { join } from "node:path";
3
3
  import * as log from "../log.js";
4
4
  import { formatLocalTime } from "../shared/local-time.js";
5
- import { parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
6
5
  import { errorMessage } from "../shared/text-utils.js";
7
6
  import { createDefaultTaskControl } from "../tasks/control.js";
8
7
  import { appendCurrentCycleNote, parseTaskFrontmatter } from "../tasks/ledger.js";
9
8
  import { withTaskMutation } from "../tasks/mutation-lock.js";
10
9
  import { readStoredTask, updateStoredTask, writeStoredTask } from "../tasks/store.js";
10
+ import { parseTaskEventName, taskEventPrefix } from "../tasks/task-events.js";
11
11
  import { parseScheduledEventContent } from "./events.js";
12
12
  import { discoverTaskChannels } from "./task-driver.js";
13
13
  /**
@@ -8,7 +8,7 @@ import { type JobSnapshot } from "../agent/job-manager.js";
8
8
  import type { Executor } from "../executor.js";
9
9
  import { type RunRecord } from "../subagents/runs.js";
10
10
  import { type WakeTaskTransitionHooks } from "../tasks/store.js";
11
- import type { DingTalkEvent } from "./dingtalk.js";
11
+ import type { ChannelEvent } from "./channel-event.js";
12
12
  /**
13
13
  * Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
14
14
  * on this channel, has actually finished (a still-`running` job cannot have produced this wake —
@@ -28,7 +28,7 @@ export declare function isVerifiedDelegationWake(record: RunRecord | undefined,
28
28
  /** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
29
29
  * and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
30
30
  * not populate `internalWake`, so copying a real wake's text is insufficient. */
31
- export declare function isTrustedInternalWake(event: DingTalkEvent, kind: "job" | "subagent", resourceId: string, taskId: string): event is DingTalkEvent & {
31
+ export declare function isTrustedInternalWake(event: ChannelEvent, kind: "job" | "subagent", resourceId: string, taskId: string): event is ChannelEvent & {
32
32
  dispatchId: string;
33
33
  };
34
34
  export interface ClaimedDelegationWake {
@@ -41,7 +41,7 @@ export interface ClaimedDelegationWake {
41
41
  /** Claim and activate a producer-created delegation wake without consuming it yet. Keeping the
42
42
  * final marker separate lets transports such as TUI mark it consumed only after they have accepted
43
43
  * the corresponding turn; a rejected submit remains replayable in the same or next process. */
44
- export declare function claimVerifiedDelegationWake(event: DingTalkEvent, workspaceDir: string, hooks?: WakeTaskTransitionHooks): Promise<ClaimedDelegationWake | undefined>;
44
+ export declare function claimVerifiedDelegationWake(event: ChannelEvent, workspaceDir: string, hooks?: WakeTaskTransitionHooks): Promise<ClaimedDelegationWake | undefined>;
45
45
  export interface ClaimedJobWake {
46
46
  taskId: string;
47
47
  generation?: number;
@@ -51,4 +51,4 @@ export interface ClaimedJobWake {
51
51
  /** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
52
52
  * <taskId>.` completion wake. A background job has no handoff/rollback bookkeeping — its wake
53
53
  * activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
54
- export declare function claimVerifiedJobWake(event: DingTalkEvent, workspaceDir: string, executor: Executor, hooks?: WakeTaskTransitionHooks): Promise<ClaimedJobWake | undefined>;
54
+ export declare function claimVerifiedJobWake(event: ChannelEvent, workspaceDir: string, executor: Executor, hooks?: WakeTaskTransitionHooks): Promise<ClaimedJobWake | undefined>;
@@ -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,6 +58,10 @@ 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(). */
@@ -147,5 +154,5 @@ export declare function buildSubAgentTask(task: string, config: Pick<SubAgentCon
147
154
  * option surface (executor, discovery, web config, etc. that a context-block build never touches). */
148
155
  export type ContextualBlocksOptions = Pick<SubAgentToolOptions, "channelDir" | "getMemoryRecallSettings" | "runtimeContext" | "workspaceDir" | "resolveApiKey" | "memoryCandidateStore">;
149
156
  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>;
157
+ export declare function createSubAgentTool(options: SubAgentToolOptions): AgentTool<typeof subagentSchema, SubAgentToolFields>;
151
158
  export {};
@@ -15,6 +15,7 @@ import { splitH1Sections } from "../shared/markdown-sections.js";
15
15
  import { clipTextByPromptUnits, countPromptUnits } from "../shared/prompt-units.js";
16
16
  import { RecoverableToolError } from "../shared/recoverable-error.js";
17
17
  import { clipText, errorMessage, extractAssistantText, extractLabelFromArgs } from "../shared/text-utils.js";
18
+ import { createEmptyUsageTotals } from "../shared/types.js";
18
19
  import { workspaceSubjectHash } from "../tasks/artifact-subject.js";
19
20
  import { readStoredTask } from "../tasks/store.js";
20
21
  import { writeVerificationAttestation } from "../tasks/verification.js";
@@ -157,16 +158,6 @@ async function gitWorkspaceState(executor) {
157
158
  const result = await executor.exec("git status --porcelain=v1 --untracked-files=all", { timeout: 30 });
158
159
  return result.code === 0 ? result.stdout : undefined;
159
160
  }
160
- function createEmptyUsageTotals() {
161
- return {
162
- input: 0,
163
- output: 0,
164
- cacheRead: 0,
165
- cacheWrite: 0,
166
- total: 0,
167
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
168
- };
169
- }
170
161
  function isAssistantMessage(message) {
171
162
  return typeof message === "object" && message !== null && "role" in message && message.role === "assistant";
172
163
  }
@@ -428,7 +419,6 @@ function filterToolsByName(allTools, names) {
428
419
  }
429
420
  function createDetails(config, runContext, usage, turns, toolCalls, durationMs, failed, failureReason, verificationVerdict, extras) {
430
421
  return {
431
- kind: "subagent",
432
422
  agent: config.name,
433
423
  source: config.source,
434
424
  model: formatModelReference(config.model),
@@ -594,7 +584,6 @@ export function createSubAgentTool(options) {
594
584
  },
595
585
  ],
596
586
  details: {
597
- kind: "subagent",
598
587
  agent: config.name,
599
588
  source: config.source,
600
589
  model: config.externalModelRef ?? "unknown",
@@ -970,7 +959,6 @@ export function createSubAgentTool(options) {
970
959
  },
971
960
  ],
972
961
  details: {
973
- kind: "subagent",
974
962
  agent: config.name,
975
963
  source: config.source,
976
964
  model: formatModelReference(config.model),