@maheidem/pi-delegate 0.3.2 → 0.6.1

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/commands.ts CHANGED
@@ -18,6 +18,7 @@ export type DelegateIntent =
18
18
  | { kind: "doctor" }
19
19
  | { kind: "help" }
20
20
  | { kind: "cancel"; runId?: string }
21
+ | { kind: "answer"; runId: string; text: string }
21
22
  | { kind: "inspect"; runId?: string }
22
23
  | { kind: "resume"; runId?: string; task: string; timeoutMs?: number }
23
24
  | { kind: "peek"; runId?: string }
@@ -51,6 +52,7 @@ export const RESERVED_FIRST_TOKENS = new Set([
51
52
  "doctor",
52
53
  "help",
53
54
  "cancel",
55
+ "answer",
54
56
  "inspect",
55
57
  "resume",
56
58
  "peek",
@@ -93,6 +95,15 @@ export function parseDelegateCommand(input: string, options: ParseOptions = {}):
93
95
  const rest = trimmed.slice("cancel".length).trim();
94
96
  return { kind: "cancel", runId: rest || undefined };
95
97
  }
98
+ case "answer": {
99
+ // R19: /delegate answer <run-id> <answer text...>
100
+ const rest = trimmed.slice("answer".length).trim();
101
+ const space = rest.indexOf(" ");
102
+ if (space <= 0 || !rest.slice(space + 1).trim()) {
103
+ return { kind: "invalid", token: "answer", usage: "/delegate answer <run-id> <answer text…>" };
104
+ }
105
+ return { kind: "answer", runId: rest.slice(0, space), text: rest.slice(space + 1).trim() };
106
+ }
96
107
  case "inspect": {
97
108
  const rest = trimmed.slice("inspect".length).trim();
98
109
  return { kind: "inspect", runId: rest || undefined };
@@ -143,7 +154,7 @@ function invalid(token: string): DelegateIntent {
143
154
  export function delegateCompletions(prefix: string, recentRunIds: string[] = []): string[] {
144
155
  const words = (prefix ?? "").trimStart();
145
156
  const tokens = words.split(/\s+/);
146
- const base: string[] = ["on", "off", "status", "paths", "doctor", "help", "cancel ", "inspect ", "resume ", "peek ", "run ", "research "];
157
+ const base: string[] = ["on", "off", "status", "paths", "doctor", "help", "cancel ", "answer ", "inspect ", "resume ", "peek ", "run ", "research "];
147
158
 
148
159
  const matches: string[] = [];
149
160
  if (tokens.length <= 1) {
package/config.ts CHANGED
@@ -27,6 +27,14 @@ export interface DelegateConfigV1 {
27
27
  maxRuns: number;
28
28
  maxRunAgeDays: number;
29
29
  updateThrottleMs: number;
30
+ /** R9: concurrent background children (default 3, clamp 1–8). */
31
+ maxBackgroundRuns: number;
32
+ /** R17/R18: ask_parent channel (background children). */
33
+ askParent: {
34
+ enabled: boolean;
35
+ timeoutMs: number;
36
+ maxPerRun: number;
37
+ };
30
38
  }
31
39
 
32
40
  export const DEFAULT_DELEGATE_CONFIG: DelegateConfigV1 = {
@@ -44,6 +52,12 @@ export const DEFAULT_DELEGATE_CONFIG: DelegateConfigV1 = {
44
52
  maxRuns: 50,
45
53
  maxRunAgeDays: 30,
46
54
  updateThrottleMs: 100,
55
+ maxBackgroundRuns: 3,
56
+ askParent: {
57
+ enabled: true,
58
+ timeoutMs: 600_000,
59
+ maxPerRun: 5,
60
+ },
47
61
  };
48
62
 
49
63
  const MIN_VALUES: Partial<Record<keyof DelegateConfigV1, number>> = {
@@ -59,6 +73,7 @@ const MIN_VALUES: Partial<Record<keyof DelegateConfigV1, number>> = {
59
73
  maxRuns: 1,
60
74
  maxRunAgeDays: 1,
61
75
  updateThrottleMs: 0,
76
+ maxBackgroundRuns: 1,
62
77
  };
63
78
 
64
79
  const MAX_VALUES: Partial<Record<keyof DelegateConfigV1, number>> = {
@@ -74,6 +89,7 @@ const MAX_VALUES: Partial<Record<keyof DelegateConfigV1, number>> = {
74
89
  maxRuns: 10_000,
75
90
  maxRunAgeDays: 3650,
76
91
  updateThrottleMs: 5_000,
92
+ maxBackgroundRuns: 8,
77
93
  };
78
94
 
79
95
  /**
@@ -125,6 +141,19 @@ function applyKnownField(config: DelegateConfigV1, key: string, value: unknown):
125
141
  }
126
142
  return;
127
143
  }
144
+ // R17: nested askParent block — merge field-by-field with clamps.
145
+ if (key === "askParent") {
146
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
147
+ const raw = value as Record<string, unknown>;
148
+ if (typeof raw.enabled === "boolean") config.askParent.enabled = raw.enabled;
149
+ if (Number.isFinite(Number(raw.timeoutMs))) {
150
+ config.askParent.timeoutMs = Math.min(3_600_000, Math.max(5_000, Number(raw.timeoutMs)));
151
+ }
152
+ if (Number.isFinite(Number(raw.maxPerRun))) {
153
+ config.askParent.maxPerRun = Math.min(20, Math.max(1, Math.trunc(Number(raw.maxPerRun))));
154
+ }
155
+ return;
156
+ }
128
157
  const numeric = typeof value === "number" ? value : Number(value);
129
158
  if (!Number.isFinite(numeric)) return;
130
159
  const min = MIN_VALUES[key as keyof DelegateConfigV1];