@stigmer/client 0.1.3 → 0.3.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 (76) hide show
  1. package/README.md +10 -0
  2. package/app-handover.d.ts +186 -0
  3. package/app-handover.d.ts.map +1 -0
  4. package/app-handover.js +630 -0
  5. package/app-handover.js.map +1 -0
  6. package/gen/agent.d.ts +2 -1
  7. package/gen/agent.d.ts.map +1 -1
  8. package/gen/agent.js +2 -0
  9. package/gen/agent.js.map +1 -1
  10. package/gen/organization.d.ts +2 -0
  11. package/gen/organization.d.ts.map +1 -1
  12. package/gen/organization.js +8 -0
  13. package/gen/organization.js.map +1 -1
  14. package/gen/run.d.ts +7 -1
  15. package/gen/run.d.ts.map +1 -1
  16. package/gen/run.js +23 -1
  17. package/gen/run.js.map +1 -1
  18. package/iam-principal.d.ts +11 -0
  19. package/iam-principal.d.ts.map +1 -1
  20. package/iam-principal.js +16 -0
  21. package/iam-principal.js.map +1 -1
  22. package/index.d.ts +11 -5
  23. package/index.d.ts.map +1 -1
  24. package/index.js +10 -3
  25. package/index.js.map +1 -1
  26. package/node.d.ts.map +1 -1
  27. package/node.js +12 -0
  28. package/node.js.map +1 -1
  29. package/package.json +9 -4
  30. package/platform.d.ts +41 -3
  31. package/platform.d.ts.map +1 -1
  32. package/platform.js +56 -3
  33. package/platform.js.map +1 -1
  34. package/run/format-elapsed.d.ts +10 -0
  35. package/run/format-elapsed.d.ts.map +1 -0
  36. package/run/format-elapsed.js +25 -0
  37. package/run/format-elapsed.js.map +1 -0
  38. package/run/step-words.d.ts +78 -0
  39. package/run/step-words.d.ts.map +1 -0
  40. package/run/step-words.js +316 -0
  41. package/run/step-words.js.map +1 -0
  42. package/run/tool-view.d.ts +49 -2
  43. package/run/tool-view.d.ts.map +1 -1
  44. package/run/tool-view.js +113 -17
  45. package/run/tool-view.js.map +1 -1
  46. package/run/turn-activity.d.ts +9 -7
  47. package/run/turn-activity.d.ts.map +1 -1
  48. package/run/turn-activity.js +24 -144
  49. package/run/turn-activity.js.map +1 -1
  50. package/run/turn-ending.d.ts +59 -0
  51. package/run/turn-ending.d.ts.map +1 -0
  52. package/run/turn-ending.js +405 -0
  53. package/run/turn-ending.js.map +1 -0
  54. package/run/turn-steps.d.ts +16 -0
  55. package/run/turn-steps.d.ts.map +1 -0
  56. package/run/turn-steps.js +65 -0
  57. package/run/turn-steps.js.map +1 -0
  58. package/session-events.d.ts +3 -1
  59. package/session-events.d.ts.map +1 -1
  60. package/session-events.js +1 -0
  61. package/session-events.js.map +1 -1
  62. package/src/app-handover.ts +777 -0
  63. package/src/gen/agent.ts +4 -1
  64. package/src/gen/organization.ts +7 -0
  65. package/src/gen/run.ts +21 -1
  66. package/src/iam-principal.ts +21 -0
  67. package/src/index.ts +55 -1
  68. package/src/node.ts +12 -0
  69. package/src/platform.ts +80 -3
  70. package/src/run/format-elapsed.ts +22 -0
  71. package/src/run/step-words.ts +360 -0
  72. package/src/run/tool-view.ts +133 -19
  73. package/src/run/turn-activity.ts +27 -146
  74. package/src/run/turn-ending.ts +487 -0
  75. package/src/run/turn-steps.ts +81 -0
  76. package/src/session-events.ts +4 -1
@@ -9,7 +9,9 @@
9
9
  // harness's `Bash` read alike), the asks waiting on a person, a message or
10
10
  // thinking still streaming, and the to-do list.
11
11
  // It returns structure, never prose; `activityPhrase` beside it gives the
12
- // present-tense words, so a surface may lay the parts out as it likes.
12
+ // present-tense words, so a surface may lay the parts out as it likes. The
13
+ // words come from one table of every kind's tenses (step-words.ts), which
14
+ // each step's own line reads too.
13
15
  //
14
16
  // Trade-offs:
15
17
  // - "How far" is a fraction only when the agent keeps a to-do list. Without
@@ -17,6 +19,11 @@
17
19
  // - The newest open call on the primary thread is "now": it is the one the
18
20
  // agent started last, and a subagent's own calls belong to its card. A
19
21
  // turn with nothing open and nothing streaming is waiting on its model.
22
+ // - A turn that has not started and whose liveness carries the server's
23
+ // wait for a sandbox (`TurnLiveness.awaitingSandboxMs`) is waiting for a
24
+ // sandbox with room. The wait is the server's, measured when it sent the
25
+ // liveness: a surface that shows it ticking counts on from the liveness's
26
+ // arrival, never from its own clock against the server's.
20
27
  // - Time is the caller's clock (`nowMs`) against the turn's own start, the
21
28
  // person's message as the log stamped it, so a page that reloads mid-turn
22
29
  // reads the same elapsed time.
@@ -25,6 +32,7 @@
25
32
  // summary and `stigmer status` all say "1h 3m", never "63m 0s".
26
33
 
27
34
  import type { ToolUse, Turn } from "@stigmer/session-log";
35
+ import { KIND_WORDS, phraseOf, targetOf } from "./step-words.js";
28
36
  import { resolveToolKind, type ToolKind } from "./tool-view.js";
29
37
 
30
38
  /** What a working turn is doing now. */
@@ -38,7 +46,12 @@ export type TurnActivity =
38
46
  /** The agent is thinking (its thinking is streaming). */
39
47
  | { readonly kind: "thinking" }
40
48
  /** Nothing is open: the turn waits on its model's next step. */
41
- | { readonly kind: "waiting_on_model" };
49
+ | { readonly kind: "waiting_on_model" }
50
+ /** The turn has not started: every sandbox is busy. `waitedMs` is the server's measure when it last said so (module header). */
51
+ | { readonly kind: "waiting_for_sandbox"; readonly waitedMs: number };
52
+
53
+ /** The words for a turn waiting for a sandbox with room. */
54
+ export const SANDBOX_WAIT_PHRASE = "Waiting for a sandbox";
42
55
 
43
56
  /** How far a turn's to-do list has got. */
44
57
  export interface TodoProgress {
@@ -64,23 +77,9 @@ export interface TurnProgress {
64
77
  readonly todos: TodoProgress | undefined;
65
78
  }
66
79
 
67
- /** The longest target a phrase carries before it is cut. */
68
- const TARGET_MAX = 48;
69
-
70
- /**
71
- * A span of time in at most two units, the larger first: "42s", "1m 12s",
72
- * "1h 3m", "2d 5h". Seconds are floored, so a span never reads longer than it
73
- * was; a negative span reads "0s".
74
- */
75
- export function formatElapsed(ms: number): string {
76
- const seconds = Math.max(0, Math.floor(ms / 1000));
77
- if (seconds < 60) return `${seconds}s`;
78
- const minutes = Math.floor(seconds / 60);
79
- if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
80
- const hours = Math.floor(minutes / 60);
81
- if (hours < 24) return `${hours}h ${minutes % 60}m`;
82
- return `${Math.floor(hours / 24)}d ${hours % 24}h`;
83
- }
80
+ // formatElapsed lives in its own module (./format-elapsed.ts), so a surface
81
+ // that only says a duration does not load this module's step words.
82
+ export { formatElapsed } from "./format-elapsed.js";
84
83
 
85
84
  /** The activity, time and progress of `turn` at `nowMs` (module header). */
86
85
  export function describeTurnActivity(turn: Turn, nowMs: number): TurnProgress {
@@ -101,6 +100,8 @@ export function describeTurnActivity(turn: Turn, nowMs: number): TurnProgress {
101
100
  }
102
101
 
103
102
  function activityOf(turn: Turn, open: readonly ToolUse[]): TurnActivity {
103
+ const sandboxWait = turn.liveness?.awaitingSandboxMs;
104
+ if (sandboxWait !== undefined && !turn.ended) return { kind: "waiting_for_sandbox", waitedMs: sandboxWait };
104
105
  if (turn.asks.length > 0) return { kind: "waiting_for_you", count: turn.asks.length };
105
106
  const last = turn.items.at(-1);
106
107
  if (last?.kind === "message" && last.live) return { kind: "writing" };
@@ -125,75 +126,9 @@ function todoProgress(turn: Turn): TodoProgress | undefined {
125
126
  };
126
127
  }
127
128
 
128
- /** What a call acts on, in a few characters: a file's name, a search's pattern, a page's host, a subagent's task. */
129
- function targetOf(tool: ToolUse): string {
130
- const input = tool.input;
131
- const text = (key: string): string => {
132
- const value = input[key];
133
- return typeof value === "string" ? value : "";
134
- };
135
- const kind = resolveToolKind(tool);
136
- switch (kind) {
137
- case "file_read":
138
- case "file_write":
139
- case "file_edit":
140
- case "file_delete":
141
- return short(baseName(text("path") || text("file_path") || text("notebook_path")));
142
- case "search":
143
- return short(text("pattern") || text("query"));
144
- case "fetch":
145
- return short(hostOf(text("url")));
146
- case "web_search":
147
- return short(text("query"));
148
- case "subagent":
149
- return short(text("description"));
150
- case "mcp":
151
- return short(tool.name);
152
- case "skill":
153
- return short(text("skill") || text("name"));
154
- case "list":
155
- return short(baseName(text("path")));
156
- case "shell":
157
- case "think":
158
- case "todo":
159
- case "memory":
160
- case "background_stop":
161
- case "unknown":
162
- return "";
163
- /* v8 ignore next -- @preserve: the exhaustiveness guard over ToolKind; resolveToolKind answers only the arms above */
164
- default: {
165
- const never: never = kind;
166
- return never;
167
- }
168
- }
169
- }
170
-
171
- // The path is the model's, so the trailing separators are trimmed by a loop:
172
- // a regular expression like /[\\/]+$/ backtracks quadratically on a long run
173
- // of them, and the activity line reads this every second.
174
- function baseName(path: string): string {
175
- let end = path.length;
176
- while (end > 0 && (path[end - 1] === "/" || path[end - 1] === "\\")) end -= 1;
177
- const trimmed = path.slice(0, end);
178
- return trimmed.slice(Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\")) + 1);
179
- }
180
-
181
- function hostOf(url: string): string {
182
- try {
183
- return new URL(url).host;
184
- } catch {
185
- return "";
186
- }
187
- }
188
-
189
- function short(value: string): string {
190
- const flat = value.replace(/\s+/g, " ").trim();
191
- return flat.length <= TARGET_MAX ? flat : `${flat.slice(0, TARGET_MAX - 1)}…`;
192
- }
193
-
194
129
  /**
195
130
  * The activity in present-tense words: "Editing invoice.ts", "Running a
196
- * command", "Waiting for you". A kind's words name the work, whichever
131
+ * command", "Waiting for you", "Waiting for a sandbox". A kind's words name the work, whichever
197
132
  * harness ran it; a target the input did not name leaves the generic words.
198
133
  */
199
134
  export function activityPhrase(activity: TurnActivity): string {
@@ -206,6 +141,8 @@ export function activityPhrase(activity: TurnActivity): string {
206
141
  return "Thinking";
207
142
  case "waiting_on_model":
208
143
  return "Working";
144
+ case "waiting_for_sandbox":
145
+ return SANDBOX_WAIT_PHRASE;
209
146
  case "tool":
210
147
  return toolPhrase(activity.toolKind, activity.target);
211
148
  /* v8 ignore next -- @preserve: the exhaustiveness guard over TurnActivity; describeTurnActivity answers only the arms above */
@@ -216,67 +153,11 @@ export function activityPhrase(activity: TurnActivity): string {
216
153
  }
217
154
  }
218
155
 
156
+ /** A kind's present-tense words, on its target when it names one (step-words.ts). */
219
157
  function toolPhrase(kind: ToolKind, target: string): string {
220
- const on = (verb: string, fallback: string): string => (target === "" ? fallback : `${verb} ${target}`);
221
- switch (kind) {
222
- case "file_read":
223
- return on("Reading", "Reading a file");
224
- case "file_write":
225
- return on("Writing", "Writing a file");
226
- case "file_edit":
227
- return on("Editing", "Editing a file");
228
- case "file_delete":
229
- return on("Deleting", "Deleting a file");
230
- case "shell":
231
- return "Running a command";
232
- case "search":
233
- return on("Searching for", "Searching");
234
- case "list":
235
- return on("Looking in", "Looking through files");
236
- case "fetch":
237
- return on("Reading", "Reading a page");
238
- case "web_search":
239
- return on("Searching the web for", "Searching the web");
240
- case "think":
241
- return "Thinking";
242
- case "todo":
243
- return "Planning";
244
- case "subagent":
245
- return target === "" ? "A helper is working" : `A helper is working on ${target}`;
246
- case "mcp":
247
- return on("Using", "Using a tool");
248
- case "memory":
249
- return "Remembering";
250
- case "background_stop":
251
- return "Stopping a command";
252
- case "skill":
253
- return on("Using the skill", "Using a skill");
254
- case "unknown":
255
- return "Working";
256
- /* v8 ignore next -- @preserve: the exhaustiveness guard over ToolKind; resolveToolKind answers only the arms above */
257
- default: {
258
- const never: never = kind;
259
- return never;
260
- }
261
- }
158
+ return phraseOf(KIND_WORDS[kind].present, target);
262
159
  }
263
160
 
264
- /** The past-tense verb and the counted noun a settled call of each kind reads as. */
265
- const SETTLED_WORDS: Readonly<Partial<Record<ToolKind, readonly [verb: string, noun: string]>>> = {
266
- file_read: ["read", "file"],
267
- file_write: ["wrote", "file"],
268
- file_edit: ["edited", "file"],
269
- file_delete: ["deleted", "file"],
270
- shell: ["ran", "command"],
271
- search: ["searched", "pattern"],
272
- list: ["looked through", "folder"],
273
- fetch: ["read", "page"],
274
- web_search: ["searched the web", "time"],
275
- mcp: ["used", "tool"],
276
- skill: ["used", "skill"],
277
- unknown: ["used", "tool"],
278
- };
279
-
280
161
  /**
281
162
  * A stretch of settled calls in a few words, kinds in the order the agent
282
163
  * first used them: "Searched 1 pattern, read 1 file, edited invoice.ts,
@@ -288,11 +169,11 @@ export function settledStepsPhrase(tools: readonly ToolUse[]): string {
288
169
  const byKind = new Map<ToolKind, ToolUse[]>();
289
170
  for (const tool of tools) {
290
171
  const kind = resolveToolKind(tool);
291
- if (SETTLED_WORDS[kind] === undefined) continue;
172
+ if (KIND_WORDS[kind].counted === undefined) continue;
292
173
  byKind.set(kind, [...(byKind.get(kind) ?? []), tool]);
293
174
  }
294
175
  const parts = [...byKind].map(([kind, uses]) => {
295
- const [verb, noun] = SETTLED_WORDS[kind]!;
176
+ const [verb, noun] = KIND_WORDS[kind].counted!;
296
177
  const only = uses.length === 1 ? targetOf(uses[0]!) : "";
297
178
  if (kind === "file_edit" && only !== "") return `${verb} ${only}`;
298
179
  return `${verb} ${uses.length} ${noun}${uses.length === 1 ? "" : "s"}`;