@parallelworks/code 0.5.0 → 0.6.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 (69) hide show
  1. package/README.md +53 -12
  2. package/dist/api.d.ts +67 -5
  3. package/dist/chatStrings.d.ts +3 -0
  4. package/dist/chatStrings.js +4 -1
  5. package/dist/command.d.ts +2 -0
  6. package/dist/command.js +5 -1
  7. package/dist/commandsApi.d.ts +8 -3
  8. package/dist/commandsApi.js +25 -4
  9. package/dist/createPwCodeApi.d.ts +26 -61
  10. package/dist/index.d.ts +6 -5
  11. package/dist/index.js +3 -2
  12. package/dist/locales/en/agentTranscript.js +5 -2
  13. package/dist/locales/en/agents.js +35 -4
  14. package/dist/locales/en.d.ts +33 -0
  15. package/dist/locales/es/agentTranscript.js +5 -2
  16. package/dist/locales/es/agents.js +35 -4
  17. package/dist/locales/ja/agentTranscript.js +5 -2
  18. package/dist/locales/ja/agents.js +30 -4
  19. package/dist/locales/ko/agentTranscript.js +5 -2
  20. package/dist/locales/ko/agents.js +35 -4
  21. package/dist/locales/zh/agentTranscript.js +5 -2
  22. package/dist/locales/zh/agents.js +35 -4
  23. package/dist/machine.d.ts +27 -2
  24. package/dist/machine.js +23 -2
  25. package/dist/notices.js +9 -1
  26. package/dist/pwUpdate.d.ts +52 -0
  27. package/dist/pwUpdate.js +115 -0
  28. package/dist/session.d.ts +1 -1
  29. package/dist/session.js +1 -1
  30. package/dist/sessionActions.js +5 -2
  31. package/dist/sessionEvents.d.ts +10 -3
  32. package/dist/sessionEvents.js +27 -11
  33. package/dist/sessionScreen.d.ts +3 -2
  34. package/dist/sessionScreen.js +8 -2
  35. package/dist/sessionsApi.d.ts +8 -2
  36. package/dist/sessionsApi.js +28 -5
  37. package/dist/startPage.d.ts +6 -3
  38. package/dist/startPage.js +34 -12
  39. package/dist/startSession.d.ts +31 -11
  40. package/dist/startSession.js +126 -44
  41. package/dist/terminalHandoffPanel.js +8 -1
  42. package/dist/transcript.d.ts +26 -3
  43. package/dist/transcript.js +87 -12
  44. package/dist/transcriptRead.d.ts +1 -0
  45. package/dist/transcriptRead.js +2 -1
  46. package/dist/types.d.ts +13 -1
  47. package/dist/useComposer.d.ts +22 -10
  48. package/dist/useComposer.js +75 -25
  49. package/dist/useComposerImages.d.ts +38 -1
  50. package/dist/useComposerImages.js +59 -4
  51. package/dist/useConversation.d.ts +10 -0
  52. package/dist/useConversation.js +14 -11
  53. package/dist/useSubagent.d.ts +20 -5
  54. package/dist/useSubagent.js +39 -17
  55. package/dist/useTranscript.d.ts +27 -1
  56. package/dist/useTranscript.js +217 -45
  57. package/dist/wording.d.ts +1 -1
  58. package/dist/wording.js +14 -2
  59. package/locales/en/agentTranscript.json +5 -2
  60. package/locales/en/agents.json +32 -2
  61. package/locales/es/agentTranscript.json +5 -2
  62. package/locales/es/agents.json +32 -2
  63. package/locales/ja/agentTranscript.json +5 -2
  64. package/locales/ja/agents.json +32 -2
  65. package/locales/ko/agentTranscript.json +5 -2
  66. package/locales/ko/agents.json +32 -2
  67. package/locales/zh/agentTranscript.json +5 -2
  68. package/locales/zh/agents.json +32 -2
  69. package/package.json +3 -3
package/README.md CHANGED
@@ -15,7 +15,7 @@ reader's language, with its own components.
15
15
  pnpm add @parallelworks/code @parallelworks/ui @parallelworks/problem react openapi-fetch swr use-intl
16
16
  ```
17
17
 
18
- `@parallelworks/ui` (0.136.0 or newer), `@parallelworks/problem`, `react`,
18
+ `@parallelworks/ui` (0.148.0 or newer), `@parallelworks/problem`, `react`,
19
19
  `openapi-fetch`, `swr` and `use-intl` are peer dependencies. Only the ui
20
20
  package's two entries without a DOM are imported:
21
21
  `@parallelworks/ui/ai/headless`, for the message and part types, the reducers
@@ -80,6 +80,13 @@ showing a toast, wording an error. Types are exported beside each.
80
80
  `removeQueued`), or every one the machine still holds at once, each with
81
81
  its pastes and images, and the first refusal, since one the model read
82
82
  meanwhile stays sent (`takeBackPending`, each a `PwCodeTakenBack`).
83
+ A message this window sent comes back too when its turn fails or stops
84
+ before the model reads it, which leaves it out of the conversation:
85
+ `handedBack` counts what is waiting to come back, and `takeBackPending`
86
+ returns it first. One its turn failed on stays drawn where it was sent,
87
+ as the machine records it; one a stop gave back leaves the transcript.
88
+ Another window's message a stop gave back leaves the transcript too, as
89
+ the machine keeps nothing of it, but only its own window gets it back.
83
90
  The `typed` option of its `sendMessage` keeps what was typed when a command
84
91
  resolved it to other text, so it comes back as typed.
85
92
  - `approvalToPart` and `approvalAnswerBody`, between a session's approval
@@ -105,12 +112,27 @@ showing a toast, wording an error. Types are exported beside each.
105
112
  can come back, and `take` resolves to each message's text and pastes, in
106
113
  the order they would have reached the model (to none while another `take`
107
114
  runs), having put their images back
108
- through the `images` option's `restore`. It has the shape of the `recall`
115
+ through the `images` option's `restore`. A message still drawn where it was
116
+ sent, as a failed turn leaves it, is marked `shown`, and its images wait
117
+ for `placed`, which the composer calls with the messages it put in its box
118
+ (from `@parallelworks/ui` 0.148.0): it may let that message go for what was
119
+ typed meanwhile. A host drawing its own composer calls `placed` too. It has
120
+ the shape of the `recall`
109
121
  that `@parallelworks/ui/ai`'s composer takes from 0.139.0. A host drawing
110
122
  its own composer stops a turn with `stopTurn`, as that composer's stop
111
123
  does: while anything can come back, the composer's own take-back runs
112
124
  first, then the turn stops, even when the take-back threw, which
113
- `stopTurn` resolves to. Its command
125
+ `stopTurn` resolves to. Its `handedBack` grows as a turn gives back a
126
+ message the model never read: a host takes it into the composer then, such
127
+ as with `recall()` on the session view's handle, as the terminal puts it
128
+ back in its box. While `handedBackShown` says something waiting is still
129
+ drawn where it was sent, as a failed turn leaves it, it goes back only into
130
+ an empty composer (`recall({ ifEmpty: true })`, from `@parallelworks/ui`
131
+ 0.147.0), and `dropShownHandedBack` lets it go when the composer held
132
+ something: it stays in the transcript and its history, as the terminal
133
+ refills only an empty line, and what a stop gave back then comes back as
134
+ `handedBack` drops. `recall`'s `take` marks such a message `shown`, so a
135
+ composer typed into while it comes back lets it go too. Its command
114
136
  outputs (`useCommandOutputs`) and sent prompts (`promptHistory`, per
115
137
  person) go with it.
116
138
  - `usePwCodeSessionScreen`, the screen around those two: the banner while
@@ -147,7 +169,10 @@ showing a toast, wording an error. Types are exported beside each.
147
169
  which throws `PwCodeImageTooLarge` for one it cannot fit; `fitImageWith`
148
170
  works out the sizes an image is written at to fit `IMAGE_MAX_BYTES` and
149
171
  `IMAGE_MAX_SIDE`, `IMAGE_TYPES` are the types a session takes, and
150
- `nextImageSeq` numbers an image's placeholder. `useComposerImages`'
172
+ `nextImageSeq` numbers an image's placeholder. Each image is saved under its
173
+ number, so every composer on one session's screen passes `useComposerImages`
174
+ the same `numbering` counter, and none gives a number another's unsent image
175
+ holds. `useComposerImages`'
151
176
  `restore` puts back the images of a message taken back, already saved with
152
177
  the session, and `withoutAppendedImages` takes the placeholders its send
153
178
  appended out of that message's text. `useComposerPastes` says where a
@@ -163,11 +188,14 @@ showing a toast, wording an error. Types are exported beside each.
163
188
  read's `error`), whether messages show their author (`showAuthor`), its
164
189
  activity line (`activity`), where a queued message goes
165
190
  (`queueDelivery`), taking one back (`canRemoveQueued`, `removeQueued`) or
166
- all of them into the composer (`recall`, as the main composer's), its
191
+ all of them into the composer (`recall` and `handedBack`, as the main
192
+ composer's), its
167
193
  composer's draft key (`draftKey`), the `id` its `promptHistory` takes
168
194
  (`historyId`), and the model it runs on (`model`) and
169
195
  that model's name (`modelLabel`, from the `modelNames` option, the session
170
- state's). Beside it, the switcher that lists them
196
+ state's). Its `images` option, which `useComposerImages` returns for the
197
+ subagent's own composer, sends images with what is typed, as the main
198
+ composer's does. Beside it, the switcher that lists them
171
199
  (`usePwCodeAgentSwitcher`, `switcherAgent`, `usePwCodeAgentLine`,
172
200
  `useAgentTypeLabel`), taking one that is not running off the list, which
173
201
  shows the main conversation again when it was the one in view and the
@@ -257,7 +285,8 @@ showing a toast, wording an error. Types are exported beside each.
257
285
  starts in and the machine's bounds on its picker (`useStartPermissionMode`,
258
286
  a `PwCodeStartPermission`, `startingMode`), its model, allocation and
259
287
  Claude Code account (`useStartModel`), and the start itself with its first
260
- prompt and images (`useStartSession`). The host passes in its saved
288
+ prompt and images, or a `/goal` or `/plan` typed first (`useStartSession`,
289
+ whose `blocked` says why a start was not tried). The host passes in its saved
261
290
  preferences and opens the session once it starts. `startControls`
262
291
  (`PwCodeStartControls`) says which controls are locked while it starts or
263
292
  until a machine is chosen, and whether the model picker reads the
@@ -443,7 +472,11 @@ that session, so the connection goes to the one the reader moved on to.
443
472
  Its other options:
444
473
 
445
474
  - `hidden`, when given, says the app is out of sight, where animation frames
446
- do not run, so feed frames are applied as they arrive.
475
+ do not run. There a reply streaming into a session is applied about once a
476
+ second, and every other feed frame as it arrives.
477
+ - `whenShown` calls the function it is given each time the app comes back
478
+ into sight, until the call it returns, so what streamed while the app was
479
+ hidden is drawn at once.
447
480
  - `onPreferenceError` hears a preference that failed to save; it shows its
448
481
  saved value again.
449
482
  - `previewsByRef` reads a transcript with each image's preview left to its
@@ -631,9 +664,10 @@ and navigates nowhere. The host supplies each:
631
664
  }),
632
665
  ```
633
666
 
634
- - Whether the app is out of sight, as `hidden`, and whether the reader is away
635
- from a session, as `useAwayRecap`'s `presence` (`away`, and `watch`, which
636
- calls `leave` and `back` as that changes), both read from the app's state.
667
+ - Whether the app is out of sight, as `hidden` and `whenShown`, and whether
668
+ the reader is away from a session, as `useAwayRecap`'s `presence` (`away`,
669
+ and `watch`, which calls `leave` and `back` as that changes), all read from
670
+ the app's state.
637
671
  - Images: `useComposerImages`' `encode`, which writes a picked image as base64
638
672
  within `IMAGE_MAX_BYTES` and `IMAGE_MAX_SIDE` and throws
639
673
  `PwCodeImageTooLarge` for one it cannot fit (`fitImageWith` works out the
@@ -685,6 +719,11 @@ change them.
685
719
 
686
720
  ### Breaking changes since 0.3.0
687
721
 
722
+ - `useStartSession` takes `runSlashAction` and `useSessionMutations` from the
723
+ API as well, reads pw code's messages as the composer does, and returns
724
+ `blocked`, why a start was not tried, such as a `/goal` sent with images,
725
+ for the host to show where it shows `error`. A start that fails once its
726
+ session exists deletes that session, rather than keeping it for a retry.
688
727
  - `usePwCodeSubagent` takes `listed`, the subagent's switcher row
689
728
  (`switcherAgent`), and `usage`, its tokens as the session's feed last
690
729
  counted them, and no longer takes `name`: it names the subagent itself and
@@ -706,7 +745,9 @@ change them.
706
745
  `useComposerImages` returns it, so a host passing what that returns
707
746
  changes nothing; one passing its own `{ take, taking }` adds it.
708
747
  - Peer dependencies: `@parallelworks/problem` (`>=0.6.1 <1`) is new, and
709
- `@parallelworks/ui` needs 0.136.0 or newer, up from 0.132.0.
748
+ `@parallelworks/ui` needs 0.148.0 or newer, up from 0.132.0, so its
749
+ composer calls `recall.placed`. A host drawing its own composer calls
750
+ `placed` too, or a failed message it takes back comes without its images.
710
751
  - The host's API types must include eight more routes, which
711
752
  `createPwCodeApi` now calls: `/api/allocations`, `/api/openai/v1/models`,
712
753
  `/api/previews`, `/api/user/preferences`,
package/dist/api.d.ts CHANGED
@@ -631,7 +631,7 @@ export interface paths {
631
631
  * Copy a pw code session
632
632
  * @description > This is a user-centric route, so the response will always be in the context of the currently authenticated user.
633
633
  *
634
- * Copies the session and its subagent transcripts into a new one on the same machine, leaving the original untouched. Refused while the session is mid-turn, and while another host holds it live.
634
+ * Copies the session and its subagent transcripts into a new one on the same machine, leaving the original untouched. While a turn runs, the copy ends with the reply before it, and a machine whose pw predates forkMidTurn refuses it. Refused while another host holds the session live.
635
635
  */
636
636
  post: operations["fork-agent-session"];
637
637
  delete?: never;
@@ -1358,6 +1358,8 @@ export interface components {
1358
1358
  output: string;
1359
1359
  };
1360
1360
  AgentCompactBody: {
1361
+ /** @description Names this request on the session's event feed, whose command_started event carries it once the compaction begins. */
1362
+ client?: string;
1361
1363
  /** @description What the summary should keep. */
1362
1364
  focus?: string;
1363
1365
  };
@@ -1464,32 +1466,52 @@ export interface components {
1464
1466
  claudeInstalled?: boolean;
1465
1467
  /** @description The daemon supports signing in to Claude Code from the web. */
1466
1468
  claudeLogin?: boolean;
1469
+ /** @description Cloud provider of a cloud cluster or instance. */
1470
+ csp?: string;
1467
1471
  /** @description Machine id the pw code daemon reported, when it answered. A local computer with the same id as a resource is the same host and is listed only as the resource. */
1468
1472
  daemonId?: string;
1469
1473
  /** @description The daemon lists the machine's folders, for choosing where a session starts. */
1470
1474
  directories?: boolean;
1471
1475
  error?: string;
1476
+ /** @description The daemon can fork a session while a turn runs, copying it up to its last reply. */
1477
+ forkMidTurn?: boolean;
1478
+ /** @description Home directory of the daemon's user, when it answered, where a session starts on a machine with no recent directory. */
1479
+ home?: string;
1472
1480
  /** @description Hostname the daemon reported, when it answered. */
1473
1481
  hostname?: string;
1474
- /** @description Hex ObjectID of the cluster, pool, or instance document; for a local computer, the id its pw code daemon registered. */
1482
+ /** @description Hex ObjectID of the cluster, pool, or instance document; for a local computer, the id its pw code daemon registered; workspace for the caller's own workspace. */
1475
1483
  id: string;
1484
+ /** @description The icon uploaded for the resource. */
1485
+ imageUrl?: string;
1476
1486
  /**
1477
- * @description local is a computer whose pw code daemon connected itself; the others are resources reached through their pw agent.
1487
+ * @description local is a computer whose pw code daemon connected itself; workspace is the caller's own workspace, which is always listed; the others are resources reached through their pw agent.
1478
1488
  * @enum {string}
1479
1489
  */
1480
- kind: "cloud" | "existing" | "instance" | "local";
1490
+ kind: "cloud" | "existing" | "instance" | "local" | "workspace";
1481
1491
  name: string;
1492
+ /** @description Operating system as Go names it (darwin, linux, windows): the one the machine's pw code daemon reported when it answered, else the one an existing cluster's agent reported. */
1493
+ os?: string;
1482
1494
  /** @description Platform username of the resource owner. */
1483
1495
  owner: string;
1484
1496
  /** @description Modes the machine's pw code daemon accepts. Absent when the daemon predates the list, in which case it accepts read-only, accept-edits, bypass-permissions and plan. */
1485
1497
  permissionModes?: ("read-only" | "accept-edits" | "auto" | "bypass-permissions" | "plan")[] | null;
1498
+ /** @description The pw build the machine's pw code daemon runs, when it answered. Canary builds share a release, so only the build tells two of them apart. */
1499
+ pwBuild?: string;
1500
+ /** @description A newer pw than the machine's pw code daemon runs, and how far installing it got. Absent when its pw is the newest, or the daemon predates reporting one. */
1501
+ pwUpdate?: components["schemas"]["PwUpdate"];
1502
+ /** @description The daemon installs the platform's newest pw when a session on it runs /upgrade. */
1503
+ pwUpgrade?: boolean;
1504
+ /** @description The pw release the machine's pw code daemon runs, when it answered. */
1505
+ pwVersion?: string;
1486
1506
  /** @enum {string} */
1487
1507
  remoteMaxPermissionMode?: "" | "read-only" | "accept-edits" | "auto" | "bypass-permissions" | "plan";
1488
1508
  remoteStart?: boolean;
1509
+ /** @description Scheduler of an existing cluster. */
1510
+ schedulerType?: string;
1489
1511
  /** @description The daemon stores which of the reader's groups a session is in. */
1490
1512
  sessionGroups?: boolean;
1491
1513
  /** @enum {string} */
1492
- status: "connected" | "no_daemon" | "no_agent" | "unreachable" | "unsupported_agent";
1514
+ status: "connected" | "no_daemon" | "no_agent" | "unreachable" | "unsupported_agent" | "starting";
1493
1515
  /** @description Session store the pw code daemon reported, when it answered. Machines with the same store list the same sessions, which are listed once. */
1494
1516
  storeId?: string;
1495
1517
  };
@@ -1619,6 +1641,11 @@ export interface components {
1619
1641
  goal?: components["schemas"]["GoalStatus"];
1620
1642
  group?: string;
1621
1643
  history: components["schemas"]["HistoryItem"][] | null;
1644
+ /**
1645
+ * Format: int64
1646
+ * @description Where history begins in the session's whole history: on the tail of a transcript, how many items older holds. Absent when history is the whole of it.
1647
+ */
1648
+ historyStart?: number;
1622
1649
  id: string;
1623
1650
  /** Format: int64 */
1624
1651
  inputTokens?: number;
@@ -1755,6 +1782,7 @@ export interface components {
1755
1782
  result?: string;
1756
1783
  /** Format: date-time */
1757
1784
  resumeAt?: string;
1785
+ scheduled?: components["schemas"]["ScheduledRun"];
1758
1786
  /** Format: int64 */
1759
1787
  seq: number;
1760
1788
  shellProgress?: components["schemas"]["ShellProgress"];
@@ -2034,6 +2062,8 @@ export interface components {
2034
2062
  * @description Creation timestamp
2035
2063
  */
2036
2064
  createdAt: string;
2065
+ /** @description The reply still being written, when one is */
2066
+ generating?: components["schemas"]["GeneratingReply"];
2037
2067
  /** @description Conversation ID */
2038
2068
  id: string;
2039
2069
  /** @description Whether the current user owns this conversation */
@@ -2107,6 +2137,23 @@ export interface components {
2107
2137
  } & {
2108
2138
  [key: string]: unknown;
2109
2139
  };
2140
+ GeneratingReply: {
2141
+ /** @description Text written so far */
2142
+ content: string;
2143
+ /** @description ID the reply's message will have */
2144
+ messageId: string;
2145
+ /** @description Model writing the reply */
2146
+ model: string;
2147
+ /** @description Message the reply answers */
2148
+ parentId: string | null;
2149
+ /** @description Reasoning written so far */
2150
+ reasoning: string;
2151
+ /**
2152
+ * Format: date-time
2153
+ * @description When the reply started
2154
+ */
2155
+ startedAt: string;
2156
+ };
2110
2157
  GoalProgress: {
2111
2158
  condition?: string;
2112
2159
  /** Format: int64 */
@@ -2142,6 +2189,7 @@ export interface components {
2142
2189
  kind: "user" | "assistant" | "thinking" | "tool_call" | "tool_result" | "notice" | "warning" | "error" | "plan_view" | "goal_view" | "goal_progress" | "turn_end" | "recap" | "compaction";
2143
2190
  pastes?: components["schemas"]["PasteView"][] | null;
2144
2191
  planBody?: string;
2192
+ scheduled?: components["schemas"]["ScheduledRun"];
2145
2193
  /** Format: int64 */
2146
2194
  startLine?: number;
2147
2195
  text?: string;
@@ -2344,6 +2392,17 @@ export interface components {
2344
2392
  */
2345
2393
  status: "unauthorized" | "unreachable";
2346
2394
  };
2395
+ PwUpdate: {
2396
+ canary?: boolean;
2397
+ error?: string;
2398
+ host?: string;
2399
+ path?: string;
2400
+ /** Format: int64 */
2401
+ progress?: number;
2402
+ /** @enum {string} */
2403
+ state: "available" | "installing" | "installed" | "needs_admin";
2404
+ version: string;
2405
+ };
2347
2406
  RemotePolicy: {
2348
2407
  maxPermissionMode: string;
2349
2408
  newSessions: boolean;
@@ -2354,6 +2413,9 @@ export interface components {
2354
2413
  /** @enum {string} */
2355
2414
  state: "connected" | "connecting" | "off";
2356
2415
  };
2416
+ ScheduledRun: {
2417
+ taskId?: string;
2418
+ };
2357
2419
  SendMessageBody: {
2358
2420
  /** @description Images uploaded to the session with upload-agent-session-image, each named in the text by its placeholder. */
2359
2421
  images?: components["schemas"]["AgentImageRef"][] | null;
@@ -67,6 +67,7 @@ declare function chatStrings(t: PwCodeTranslator<'agentTranscript'>, tAgents: Pw
67
67
  previewOf: (label: string) => string;
68
68
  notesLabel: string;
69
69
  notesPlaceholder: string;
70
+ addNotes: string;
70
71
  notesOnly: string;
71
72
  todoPending: string;
72
73
  todoInProgress: string;
@@ -105,6 +106,8 @@ declare function chatStrings(t: PwCodeTranslator<'agentTranscript'>, tAgents: Pw
105
106
  stopGenerating: string;
106
107
  loadingCommands: string;
107
108
  emoji: string;
109
+ shellMode: string;
110
+ shellHint: string;
108
111
  };
109
112
  thread: {
110
113
  jumpToPrompt: (text: string) => string;
@@ -79,6 +79,7 @@ function chatStrings(t, tAgents, tools) {
79
79
  previewOf: (label) => t("transcript.previewOf", { label }),
80
80
  notesLabel: t("transcript.notesLabel"),
81
81
  notesPlaceholder: t("transcript.notesPlaceholder"),
82
+ addNotes: t("transcript.addNotes"),
82
83
  notesOnly: t("transcript.notesOnly"),
83
84
  todoPending: t("transcript.todoPending"),
84
85
  todoInProgress: t("transcript.todoInProgress"),
@@ -122,7 +123,9 @@ function chatStrings(t, tAgents, tools) {
122
123
  input: {
123
124
  stopGenerating: t("input.stopGenerating"),
124
125
  loadingCommands: t("input.loadingCommands"),
125
- emoji: t("input.emoji")
126
+ emoji: t("input.emoji"),
127
+ shellMode: t("input.shellMode"),
128
+ shellHint: t("input.shellHint")
126
129
  },
127
130
  thread: { jumpToPrompt: (text) => t("thread.jumpToPrompt", { text }) },
128
131
  find: {
package/dist/command.d.ts CHANGED
@@ -35,6 +35,8 @@ export type SlashAction = {
35
35
  name: string;
36
36
  args: string;
37
37
  };
38
+ /** The command typed text runs, without its slash; undefined for prose. */
39
+ export declare function invocationName(text: string): string | undefined;
38
40
  /** Where typed text goes, in the order the terminal dispatches it: skills,
39
41
  * custom commands, and MCP prompts expand into a turn, so they are messages;
40
42
  * built-ins run as commands, five of them on routes of their own. */
package/dist/command.js CHANGED
@@ -1,5 +1,9 @@
1
1
  // src/command.ts
2
2
  var INVOCATION = /^\/([A-Za-z0-9_:-]+)(?:\s+([\s\S]*))?$/;
3
+ /** The command typed text runs, without its slash; undefined for prose. */
4
+ function invocationName(text) {
5
+ return INVOCATION.exec(text.trim())?.[1];
6
+ }
3
7
  /** Where typed text goes, in the order the terminal dispatches it: skills,
4
8
  * custom commands, and MCP prompts expand into a turn, so they are messages;
5
9
  * built-ins run as commands, five of them on routes of their own. */
@@ -66,4 +70,4 @@ function shellCommand(text) {
66
70
  function steerMayHaveLanded(error) {
67
71
  return error.code === "upstream_no_answer" || !error.code && !error.type && (error.status === 502 || error.status === 504);
68
72
  }
69
- export { paletteOptions, shellCommand, slashAction, steerMayHaveLanded };
73
+ export { invocationName, paletteOptions, shellCommand, slashAction, steerMayHaveLanded };
@@ -2,6 +2,9 @@ import type { ToolCallPart } from '@parallelworks/ui/ai/headless';
2
2
  import type { PwCodeClient, PwCodeResult, Schemas } from './apiClient.js';
3
3
  import { type SlashAction } from './command.js';
4
4
  type Palette = Schemas['AgentPalette'];
5
+ type RoutedAction = Exclude<SlashAction, {
6
+ kind: 'message' | 'archive';
7
+ }>;
5
8
  export type CommandOutcome = {
6
9
  kind: 'output';
7
10
  text: string;
@@ -29,6 +32,10 @@ export interface SlashDeps {
29
32
  /** stop is why the owner's hook asked that the model not react to the run. */
30
33
  onShellRun: (command: string, output: string, stop: string | undefined) => Promise<void> | void;
31
34
  onCompacted: () => void;
35
+ /** A command starts on the machine. The call it may return ends it once the
36
+ * command settles: `filed`, the machine filed its record for the next read.
37
+ * The feed's `command_started` names the request by `requestId`. */
38
+ onRunning?: (command: string, kind: RoutedAction['kind'], requestId: string) => ((filed: boolean) => void) | undefined;
32
39
  onCleared: (newId: string) => void;
33
40
  /** Archives the open session the way the host's own archive action does, keeping its lists in step. */
34
41
  onArchive: () => Promise<void> | void;
@@ -45,9 +52,7 @@ export declare function offersBackground(part: Pick<ToolCallPart, 'name' | 'stat
45
52
  } | null | undefined): boolean;
46
53
  export declare function commandsApi(client: PwCodeClient): {
47
54
  runGoal: (machine: string, id: string, args: string) => Promise<PwCodeResult<Schemas['AgentGoalResult']>>;
48
- runSlashAction: (machine: string, id: string, action: Exclude<SlashAction, {
49
- kind: 'message' | 'archive';
50
- }>, planOnMachine: (path: string) => string) => Promise<CommandOutcome>;
55
+ runSlashAction: (machine: string, id: string, action: RoutedAction, planOnMachine: (path: string) => string, requestId?: string) => Promise<CommandOutcome>;
51
56
  resolveTyped: (text: string, deps: SlashDeps) => Promise<string | null>;
52
57
  usePalette: (machine: string, sessionId: string) => {
53
58
  palette: Palette | null;
@@ -34,11 +34,20 @@ function planOutcome(plan, args, planOnMachine) {
34
34
  default: return { kind: "none" };
35
35
  }
36
36
  }
37
+ /** Unique across windows, which may each run commands on one session. `crypto` is not on Hermes. */
38
+ function newRequestId() {
39
+ return `${Date.now()}-${Math.random()}`;
40
+ }
41
+ /** The daemon files the command into the transcript itself: /compact with its
42
+ * summary, /goal with its answer. */
43
+ function filedByMachine(outcome, kind) {
44
+ return outcome.kind === "compacted" || outcome.kind === "output" && kind === "goal";
45
+ }
37
46
  function settle(outcome, command, kind, deps) {
38
47
  switch (outcome.kind) {
39
48
  case "send": return outcome.text;
40
49
  case "output":
41
- if (outcome.text && kind !== "goal") deps.onOutput(command, outcome.text);
50
+ if (outcome.text && !filedByMachine(outcome, kind)) deps.onOutput(command, outcome.text);
42
51
  return null;
43
52
  case "compacted":
44
53
  deps.onCompacted();
@@ -69,7 +78,7 @@ function commandsApi(client) {
69
78
  /** Runs a command against the session's daemon, answering with what the
70
79
  * host owes next. /plan's actions follow the terminal's, except that opening
71
80
  * the plan file needs the machine's own editor. */
72
- async function runSlashAction(machine, id, action, planOnMachine) {
81
+ async function runSlashAction(machine, id, action, planOnMachine, requestId) {
73
82
  const path = { params: { path: {
74
83
  machine,
75
84
  id
@@ -88,7 +97,10 @@ function commandsApi(client) {
88
97
  case "compact": {
89
98
  const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/compact", {
90
99
  ...path,
91
- body: { focus: action.focus }
100
+ body: {
101
+ focus: action.focus,
102
+ ...requestId ? { client: requestId } : {}
103
+ }
92
104
  });
93
105
  if (error) return {
94
106
  kind: "refused",
@@ -166,7 +178,16 @@ function commandsApi(client) {
166
178
  await deps.onArchive();
167
179
  return null;
168
180
  }
169
- return settle(await runSlashAction(deps.machine, deps.sessionId, action, deps.planOnMachine), text.trim(), action.kind, deps);
181
+ const typed = text.trim();
182
+ const requestId = newRequestId();
183
+ const end = deps.onRunning?.(typed, action.kind, requestId);
184
+ let outcome = { kind: "none" };
185
+ try {
186
+ outcome = await runSlashAction(deps.machine, deps.sessionId, action, deps.planOnMachine, requestId);
187
+ } finally {
188
+ end?.(filedByMachine(outcome, action.kind));
189
+ }
190
+ return settle(outcome, typed, action.kind, deps);
170
191
  }
171
192
  /** The session's palette, loaded the first time the composer reads as a
172
193
  * command: loading attaches a saved session, which viewing must not do. */
@@ -65,9 +65,22 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
65
65
  cancelClaudeLogin: (machine: string, loginId: string) => Promise<void>;
66
66
  followClaudeLogin: (machine: string, login: import("./claudeApi.js").ClaudeLogin, after: number, signal: AbortSignal, receive: (event: import("./claudeApi.js").ClaudeLoginEvent) => void) => Promise<void>;
67
67
  runGoal: (machine: string, id: string, args: string) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentGoalResult']>>;
68
- runSlashAction: (machine: string, id: string, action: Exclude<import("./command.js").SlashAction, {
69
- kind: 'message' | 'archive';
70
- }>, planOnMachine: (path: string) => string) => Promise<import("./commandsApi.js").CommandOutcome>;
68
+ runSlashAction: (machine: string, id: string, action: {
69
+ kind: 'clear';
70
+ } | {
71
+ kind: 'compact';
72
+ focus: string;
73
+ } | {
74
+ kind: 'goal';
75
+ args: string;
76
+ } | {
77
+ kind: 'plan';
78
+ args: string;
79
+ } | {
80
+ kind: 'command';
81
+ name: string;
82
+ args: string;
83
+ }, planOnMachine: (path: string) => string, requestId?: string) => Promise<import("./commandsApi.js").CommandOutcome>;
71
84
  resolveTyped: (text: string, deps: import("./commandsApi.js").SlashDeps) => Promise<string | null>;
72
85
  usePalette: (machine: string, sessionId: string) => {
73
86
  palette: {
@@ -180,6 +193,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
180
193
  goal?: import("./api.js").components["schemas"]["GoalStatus"];
181
194
  group?: string;
182
195
  history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
196
+ historyStart?: number;
183
197
  id: string;
184
198
  inputTokens?: number;
185
199
  lastError?: string;
@@ -221,6 +235,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
221
235
  goal?: import("./api.js").components["schemas"]["GoalStatus"];
222
236
  group?: string;
223
237
  history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
238
+ historyStart?: number;
224
239
  id: string;
225
240
  inputTokens?: number;
226
241
  lastError?: string;
@@ -264,6 +279,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
264
279
  goal?: import("./api.js").components["schemas"]["GoalStatus"];
265
280
  group?: string;
266
281
  history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
282
+ historyStart?: number;
267
283
  id: string;
268
284
  inputTokens?: number;
269
285
  lastError?: string;
@@ -388,37 +404,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
388
404
  }>;
389
405
  useSessionMutations: () => {
390
406
  deleteSession: (s: {
391
- allocation?: string;
392
- approvals?: import("./api.js").components["schemas"]["ApprovalRequest"][] | null;
393
- archivedAt?: string;
394
- autoName?: string;
395
- branch?: string;
396
- createdAt: string;
397
- effort?: string;
398
- group?: string;
399
407
  id: string;
400
- inputTokens?: number;
401
- lastError?: string;
402
- liveHost?: string;
403
408
  machineId: string;
404
- messages: number;
405
- model: string;
406
- name?: string;
407
- outputTokens?: number;
408
- permissionMode?: string;
409
- pinnedAt?: string;
410
- preview: string;
411
- pullRequestStates?: {
412
- [key: string]: string;
413
- };
414
- pullRequests?: string[] | null;
415
- remoteControl?: boolean;
416
- status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
417
- turnStartedAt?: string;
418
- updatedAt: string;
419
- usageLimitResumeAt?: string;
420
- waitingForUsageLimit?: boolean;
421
- workspace: string;
422
409
  }, removeWorktree?: string) => Promise<unknown>;
423
410
  renameSession: (s: {
424
411
  allocation?: string;
@@ -589,37 +576,8 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
589
576
  workspace: string;
590
577
  }, pinned: boolean) => Promise<unknown>;
591
578
  groupSession: (s: {
592
- allocation?: string;
593
- approvals?: import("./api.js").components["schemas"]["ApprovalRequest"][] | null;
594
- archivedAt?: string;
595
- autoName?: string;
596
- branch?: string;
597
- createdAt: string;
598
- effort?: string;
599
- group?: string;
600
579
  id: string;
601
- inputTokens?: number;
602
- lastError?: string;
603
- liveHost?: string;
604
580
  machineId: string;
605
- messages: number;
606
- model: string;
607
- name?: string;
608
- outputTokens?: number;
609
- permissionMode?: string;
610
- pinnedAt?: string;
611
- preview: string;
612
- pullRequestStates?: {
613
- [key: string]: string;
614
- };
615
- pullRequests?: string[] | null;
616
- remoteControl?: boolean;
617
- status: "idle" | "running" | "awaiting_approval" | "live_elsewhere";
618
- turnStartedAt?: string;
619
- updatedAt: string;
620
- usageLimitResumeAt?: string;
621
- waitingForUsageLimit?: boolean;
622
- workspace: string;
623
581
  }, group: string | null) => Promise<unknown>;
624
582
  stopSession: (s: {
625
583
  allocation?: string;
@@ -705,6 +663,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
705
663
  goal?: import("./api.js").components["schemas"]["GoalStatus"];
706
664
  group?: string;
707
665
  history: import("./api.js").components["schemas"]["HistoryItem"][] | null;
666
+ historyStart?: number;
708
667
  id: string;
709
668
  inputTokens?: number;
710
669
  lastError?: string;
@@ -742,6 +701,11 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
742
701
  saveImage: (machine: string, id: string, body: Schemas['AgentImageBody']) => Promise<import("./apiClient.js").PwCodeResult<Schemas['AgentImageSaved']>>;
743
702
  answerApproval: (machine: string, sessionId: string, approvalId: string, answer: import("@parallelworks/ui/ai/headless").ApprovalAnswerValue) => Promise<unknown>;
744
703
  removeSessionDirectory: (machine: string, sessionId: string, path: string) => Promise<unknown>;
704
+ upgradePw: (machine: string, sessionId: string) => Promise<{
705
+ answer: string;
706
+ } | {
707
+ error: unknown;
708
+ }>;
745
709
  uploadPaste: (machine: string, sessionId: string, text: string, describe: (error: unknown) => string) => Promise<import("./sessionsApi.js").PwCodePasteUpload>;
746
710
  updateSessionSettings: (machine: string, id: string, body: {
747
711
  allocation?: string;
@@ -779,6 +743,7 @@ export declare function createPwCodeApi<P extends {}>(client: Client<P> & Covers
779
743
  recorded?: boolean;
780
744
  result?: string;
781
745
  resumeAt?: string;
746
+ scheduled?: import("./api.js").components["schemas"]["ScheduledRun"];
782
747
  seq: number;
783
748
  shellProgress?: import("./api.js").components["schemas"]["ShellProgress"];
784
749
  startLine?: number;