@parallelworks/code 0.1.0 → 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 (118) hide show
  1. package/README.md +171 -24
  2. package/dist/ago.d.ts +8 -0
  3. package/dist/ago.js +26 -0
  4. package/dist/api.d.ts +3547 -0
  5. package/dist/apiClient.d.ts +26 -0
  6. package/dist/apiClient.js +5 -0
  7. package/dist/base64.d.ts +3 -0
  8. package/dist/base64.js +15 -0
  9. package/dist/chatHandoff.d.ts +12 -0
  10. package/dist/chatHandoff.js +27 -0
  11. package/dist/claudeAccounts.d.ts +112 -0
  12. package/dist/claudeAccounts.js +234 -0
  13. package/dist/claudeApi.d.ts +27 -0
  14. package/dist/claudeApi.js +250 -0
  15. package/dist/claudeSignIn.d.ts +62 -0
  16. package/dist/claudeSignIn.js +239 -0
  17. package/dist/command.d.ts +47 -0
  18. package/dist/command.js +64 -0
  19. package/dist/commandsApi.d.ts +64 -0
  20. package/dist/commandsApi.js +267 -0
  21. package/dist/contextRow.d.ts +25 -0
  22. package/dist/contextRow.js +16 -0
  23. package/dist/createPwCodeApi.d.ts +696 -0
  24. package/dist/createPwCodeApi.js +33 -0
  25. package/dist/howSessionsAppear.d.ts +12 -0
  26. package/dist/howSessionsAppear.js +24 -0
  27. package/dist/index.d.ts +39 -3
  28. package/dist/index.js +38 -3
  29. package/dist/locales/en/agentTranscript.js +162 -0
  30. package/dist/locales/en/agents.js +380 -0
  31. package/dist/locales/en.d.ts +523 -0
  32. package/dist/locales/en.js +8 -0
  33. package/dist/locales/es/agentTranscript.js +162 -0
  34. package/dist/locales/es/agents.js +380 -0
  35. package/dist/locales/es.d.ts +3 -0
  36. package/dist/locales/es.js +8 -0
  37. package/dist/locales/ja/agentTranscript.js +162 -0
  38. package/dist/locales/ja/agents.js +380 -0
  39. package/dist/locales/ja.d.ts +3 -0
  40. package/dist/locales/ja.js +8 -0
  41. package/dist/locales/ko/agentTranscript.js +162 -0
  42. package/dist/locales/ko/agents.js +380 -0
  43. package/dist/locales/ko.d.ts +3 -0
  44. package/dist/locales/ko.js +8 -0
  45. package/dist/locales/zh/agentTranscript.js +162 -0
  46. package/dist/locales/zh/agents.js +380 -0
  47. package/dist/locales/zh.d.ts +3 -0
  48. package/dist/locales/zh.js +8 -0
  49. package/dist/machine.d.ts +51 -0
  50. package/dist/machine.js +60 -0
  51. package/dist/messages.d.ts +17 -0
  52. package/dist/messages.js +31 -0
  53. package/dist/models.d.ts +47 -0
  54. package/dist/models.js +49 -0
  55. package/dist/notices.d.ts +12 -0
  56. package/dist/notices.js +120 -0
  57. package/dist/pullRequest.d.ts +8 -0
  58. package/dist/pullRequest.js +29 -0
  59. package/dist/pullRequestList.d.ts +52 -0
  60. package/dist/pullRequestList.js +106 -0
  61. package/dist/query.d.ts +28 -0
  62. package/dist/query.js +25 -0
  63. package/dist/session.d.ts +75 -1
  64. package/dist/session.js +101 -1
  65. package/dist/sessionActions.d.ts +105 -0
  66. package/dist/sessionActions.js +178 -0
  67. package/dist/sessionEvents.d.ts +27 -0
  68. package/dist/sessionEvents.js +212 -0
  69. package/dist/sessionGroups.d.ts +49 -0
  70. package/dist/sessionGroups.js +72 -0
  71. package/dist/sessionHeader.d.ts +14 -0
  72. package/dist/sessionHeader.js +16 -0
  73. package/dist/sessionList.d.ts +134 -0
  74. package/dist/sessionList.js +271 -0
  75. package/dist/sessionsApi.d.ts +105 -0
  76. package/dist/sessionsApi.js +511 -0
  77. package/dist/settingsApi.d.ts +36 -0
  78. package/dist/settingsApi.js +151 -0
  79. package/dist/startSession.d.ts +138 -0
  80. package/dist/startSession.js +234 -0
  81. package/dist/terminalHandoffPanel.d.ts +30 -0
  82. package/dist/terminalHandoffPanel.js +33 -0
  83. package/dist/toolStrings.d.ts +4 -0
  84. package/dist/toolStrings.js +95 -0
  85. package/dist/transcript.d.ts +14 -1
  86. package/dist/transcript.js +55 -14
  87. package/dist/types.d.ts +20 -1
  88. package/dist/usageLimit.d.ts +8 -0
  89. package/dist/usageLimit.js +13 -0
  90. package/dist/useAwayRecap.d.ts +30 -0
  91. package/dist/useAwayRecap.js +75 -0
  92. package/dist/useComposer.d.ts +121 -0
  93. package/dist/useComposer.js +244 -0
  94. package/dist/useComposerImages.d.ts +66 -0
  95. package/dist/useComposerImages.js +195 -0
  96. package/dist/useConversation.d.ts +190 -0
  97. package/dist/useConversation.js +287 -0
  98. package/dist/useSubagent.d.ts +58 -0
  99. package/dist/useSubagent.js +149 -0
  100. package/dist/useTranscript.d.ts +4 -1
  101. package/dist/useTranscript.js +54 -11
  102. package/dist/wording.d.ts +43 -0
  103. package/dist/wording.js +101 -0
  104. package/dist/workingDirectories.d.ts +32 -0
  105. package/dist/workingDirectories.js +71 -0
  106. package/dist/worktreeChoice.d.ts +31 -0
  107. package/dist/worktreeChoice.js +38 -0
  108. package/locales/en/agentTranscript.json +154 -0
  109. package/locales/en/agents.json +366 -0
  110. package/locales/es/agentTranscript.json +154 -0
  111. package/locales/es/agents.json +366 -0
  112. package/locales/ja/agentTranscript.json +154 -0
  113. package/locales/ja/agents.json +366 -0
  114. package/locales/ko/agentTranscript.json +154 -0
  115. package/locales/ko/agents.json +366 -0
  116. package/locales/zh/agentTranscript.json +154 -0
  117. package/locales/zh/agents.json +366 -0
  118. package/package.json +24 -9
@@ -0,0 +1,64 @@
1
+ import { type PwCodeClient, type PwCodeResult, type Schemas } from './apiClient.js';
2
+ import { type SlashAction } from './command.js';
3
+ type Palette = Schemas['AgentPalette'];
4
+ export type CommandOutcome = {
5
+ kind: 'output';
6
+ text: string;
7
+ } | {
8
+ kind: 'compacted';
9
+ } | {
10
+ kind: 'cleared';
11
+ newId: string;
12
+ } | {
13
+ kind: 'send';
14
+ text: string;
15
+ } | {
16
+ kind: 'refused';
17
+ error: unknown;
18
+ } | {
19
+ kind: 'none';
20
+ };
21
+ export interface SlashDeps {
22
+ machine: string;
23
+ sessionId: string;
24
+ palette: Palette | null;
25
+ loadPalette: () => Promise<Palette | null>;
26
+ planOnMachine: (path: string) => string;
27
+ onOutput: (command: string, text: string) => void;
28
+ /** stop is why the owner's hook asked that the model not react to the run. */
29
+ onShellRun: (command: string, output: string, stop: string | undefined) => Promise<void> | void;
30
+ onCompacted: () => void;
31
+ onCleared: (newId: string) => void;
32
+ /** Archives the open session the way the host's own archive action does, keeping its lists in step. */
33
+ onArchive: () => Promise<void> | void;
34
+ onRefused: (error: unknown) => void;
35
+ }
36
+ export declare const backgroundOfferDelayMs = 2000;
37
+ export declare function commandsApi(client: PwCodeClient): {
38
+ runSlashAction: (machine: string, id: string, action: Exclude<SlashAction, {
39
+ kind: 'message' | 'archive';
40
+ }>, planOnMachine: (path: string) => string) => Promise<CommandOutcome>;
41
+ resolveTyped: (text: string, deps: SlashDeps) => Promise<string | null>;
42
+ usePalette: (machine: string, sessionId: string) => {
43
+ palette: Palette | null;
44
+ loading: boolean;
45
+ load: () => Promise<Palette | null>;
46
+ };
47
+ useWorkspacePalette: (machine: string | undefined, workspace: string, model: string | null | undefined) => {
48
+ palette: Palette | null;
49
+ loading: boolean;
50
+ load: () => void;
51
+ };
52
+ useBackgroundCommands: ({ machine, sessionId, running, onError, }: {
53
+ machine: string;
54
+ sessionId: string;
55
+ running: boolean;
56
+ onError: (error: unknown) => void;
57
+ }) => {
58
+ offered: boolean;
59
+ moving: boolean;
60
+ move: () => Promise<void>;
61
+ };
62
+ requestRecap: (machine: string, id: string, signal?: AbortSignal) => Promise<PwCodeResult<undefined>>;
63
+ };
64
+ export {};
@@ -0,0 +1,267 @@
1
+ import { createQuery } from "./query.js";
2
+ import { shellCommand, slashAction } from "./command.js";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ // src/commandsApi.ts
5
+ var backgroundOfferDelayMs = 2e3;
6
+ function planOutcome(plan, args, planOnMachine) {
7
+ switch (plan.action) {
8
+ case "answer": return {
9
+ kind: "output",
10
+ text: plan.output ?? ""
11
+ };
12
+ case "show": return {
13
+ kind: "output",
14
+ text: plan.planBody ?? ""
15
+ };
16
+ case "turn": return {
17
+ kind: "send",
18
+ text: args
19
+ };
20
+ case "open": return {
21
+ kind: "output",
22
+ text: planOnMachine(plan.planPath ?? "")
23
+ };
24
+ default: return { kind: "none" };
25
+ }
26
+ }
27
+ function settle(outcome, command, kind, deps) {
28
+ switch (outcome.kind) {
29
+ case "send": return outcome.text;
30
+ case "output":
31
+ if (outcome.text && kind !== "goal") deps.onOutput(command, outcome.text);
32
+ return null;
33
+ case "compacted":
34
+ deps.onCompacted();
35
+ return null;
36
+ case "cleared":
37
+ deps.onCleared(outcome.newId);
38
+ return null;
39
+ case "refused":
40
+ deps.onRefused(outcome.error);
41
+ return null;
42
+ default: return null;
43
+ }
44
+ }
45
+ function commandsApi(client) {
46
+ const useQuery = createQuery(client);
47
+ const palettes = /* @__PURE__ */ new Map();
48
+ /** Runs a command against the session's daemon, answering with what the
49
+ * host owes next. /plan's actions follow the terminal's, except that opening
50
+ * the plan file needs the machine's own editor. */
51
+ async function runSlashAction(machine, id, action, planOnMachine) {
52
+ const path = { params: { path: {
53
+ machine,
54
+ id
55
+ } } };
56
+ switch (action.kind) {
57
+ case "clear": {
58
+ const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/clear", path);
59
+ return error ? {
60
+ kind: "refused",
61
+ error
62
+ } : {
63
+ kind: "cleared",
64
+ newId: data.id
65
+ };
66
+ }
67
+ case "compact": {
68
+ const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/compact", {
69
+ ...path,
70
+ body: { focus: action.focus }
71
+ });
72
+ if (error) return {
73
+ kind: "refused",
74
+ error
75
+ };
76
+ return data.compacted ? { kind: "compacted" } : {
77
+ kind: "output",
78
+ text: data.output
79
+ };
80
+ }
81
+ case "goal": {
82
+ const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/goal", {
83
+ ...path,
84
+ body: { args: action.args }
85
+ });
86
+ return error ? {
87
+ kind: "refused",
88
+ error
89
+ } : {
90
+ kind: "output",
91
+ text: data.output
92
+ };
93
+ }
94
+ case "plan": {
95
+ const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/plan", {
96
+ ...path,
97
+ body: { args: action.args }
98
+ });
99
+ return error ? {
100
+ kind: "refused",
101
+ error
102
+ } : planOutcome(data, action.args, planOnMachine);
103
+ }
104
+ case "command": {
105
+ const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/commands", {
106
+ ...path,
107
+ body: {
108
+ name: action.name,
109
+ args: action.args
110
+ }
111
+ });
112
+ return error ? {
113
+ kind: "refused",
114
+ error
115
+ } : {
116
+ kind: "output",
117
+ text: [data.output, data.note].filter(Boolean).join("\n\n")
118
+ };
119
+ }
120
+ }
121
+ }
122
+ async function runShell(command, deps) {
123
+ const { data, error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/shell", {
124
+ params: { path: {
125
+ machine: deps.machine,
126
+ id: deps.sessionId
127
+ } },
128
+ body: { command }
129
+ });
130
+ if (error) {
131
+ deps.onRefused(error);
132
+ return;
133
+ }
134
+ await deps.onShellRun(command, data.output, data.stop);
135
+ }
136
+ /** Runs typed text that is a command or a `!` shell escape, answering with
137
+ * what still goes to the session as a message, or null once it was taken. */
138
+ async function resolveTyped(text, deps) {
139
+ const command = shellCommand(text);
140
+ if (command !== null) {
141
+ if (command) await runShell(command, deps);
142
+ return null;
143
+ }
144
+ if (!text.trimStart().startsWith("/")) return text;
145
+ const action = slashAction(text, deps.palette ?? await deps.loadPalette());
146
+ if (action.kind === "message") return text;
147
+ if (action.kind === "archive") {
148
+ await deps.onArchive();
149
+ return null;
150
+ }
151
+ return settle(await runSlashAction(deps.machine, deps.sessionId, action, deps.planOnMachine), text.trim(), action.kind, deps);
152
+ }
153
+ /** The session's palette, loaded the first time the composer reads as a
154
+ * command: loading attaches a saved session, which viewing must not do. */
155
+ function usePalette(machine, sessionId) {
156
+ const key = `${machine}/${sessionId}`;
157
+ const [palette, setPalette] = useState(() => palettes.get(key) ?? null);
158
+ const [fetching, setFetching] = useState(false);
159
+ const loading = useRef(null);
160
+ useEffect(() => {
161
+ setPalette(palettes.get(key) ?? null);
162
+ setFetching(false);
163
+ loading.current = null;
164
+ }, [key]);
165
+ const load = useCallback(() => {
166
+ if (!loading.current) {
167
+ setFetching(true);
168
+ const request = client.GET("/api/code/machines/{machine}/sessions/{id}/palette", { params: { path: {
169
+ machine,
170
+ id: sessionId
171
+ } } }).then(({ data }) => {
172
+ if (data) palettes.set(key, data);
173
+ if (loading.current === request) {
174
+ setFetching(false);
175
+ if (data) setPalette(data);
176
+ else loading.current = null;
177
+ }
178
+ return data ?? null;
179
+ }, (error) => {
180
+ if (loading.current === request) {
181
+ setFetching(false);
182
+ loading.current = null;
183
+ }
184
+ throw error;
185
+ });
186
+ loading.current = request;
187
+ }
188
+ return loading.current;
189
+ }, [
190
+ key,
191
+ machine,
192
+ sessionId
193
+ ]);
194
+ return {
195
+ palette,
196
+ loading: fetching && !palette,
197
+ load
198
+ };
199
+ }
200
+ /** What a session started in workspace could run first, loaded once the composer reads as a command. */
201
+ function useWorkspacePalette(machine, workspace, model) {
202
+ const [wanted, setWanted] = useState(false);
203
+ const load = useCallback(() => setWanted(true), []);
204
+ const { data, isLoading } = useQuery("/api/code/machines/{machine}/palette", wanted && machine && workspace.startsWith("/") ? { params: {
205
+ path: { machine },
206
+ query: {
207
+ workspace,
208
+ ...model ? { model } : {}
209
+ }
210
+ } } : null, { shouldRetryOnError: false });
211
+ return {
212
+ palette: data ?? null,
213
+ loading: isLoading,
214
+ load
215
+ };
216
+ }
217
+ /** Offers to move the Bash commands a turn waits on to the background, as
218
+ * ctrl+b does in the terminal. */
219
+ function useBackgroundCommands({ machine, sessionId, running, onError }) {
220
+ const [offered, setOffered] = useState(false);
221
+ const [moving, setMoving] = useState(false);
222
+ useEffect(() => {
223
+ setOffered(false);
224
+ if (!running) return;
225
+ const timer = setTimeout(() => setOffered(true), backgroundOfferDelayMs);
226
+ return () => clearTimeout(timer);
227
+ }, [running]);
228
+ const move = useCallback(async () => {
229
+ setMoving(true);
230
+ const { error } = await client.POST("/api/code/machines/{machine}/sessions/{id}/background", { params: { path: {
231
+ machine,
232
+ id: sessionId
233
+ } } });
234
+ setMoving(false);
235
+ if (error) onError(error);
236
+ }, [
237
+ machine,
238
+ onError,
239
+ sessionId
240
+ ]);
241
+ return {
242
+ offered: running && offered,
243
+ moving,
244
+ move
245
+ };
246
+ }
247
+ /** Asks the session for a recap of where it stands, which arrives on its
248
+ * event feed. The machine declines while its recaps are off. */
249
+ function requestRecap(machine, id, signal) {
250
+ return client.POST("/api/code/machines/{machine}/sessions/{id}/recap", {
251
+ params: { path: {
252
+ machine,
253
+ id
254
+ } },
255
+ ...signal ? { signal } : {}
256
+ });
257
+ }
258
+ return {
259
+ runSlashAction,
260
+ resolveTyped,
261
+ usePalette,
262
+ useWorkspacePalette,
263
+ useBackgroundCommands,
264
+ requestRecap
265
+ };
266
+ }
267
+ export { backgroundOfferDelayMs, commandsApi };
@@ -0,0 +1,25 @@
1
+ import { type LabeledPullRequest, type PullRequestStateOf } from './pullRequestList.js';
2
+ import type { PwCodeAddedDirectory, PwCodeAllowedDirectory } from './types.js';
3
+ /** What a session's context shows besides its working directory and goal. */
4
+ export interface PwCodeContextRow {
5
+ /** The directories added to the session. */
6
+ added: PwCodeAddedDirectory[];
7
+ /** The directories approvals opened for the session. */
8
+ allowed: PwCodeAllowedDirectory[];
9
+ /** In `orderPullRequests` order. */
10
+ pullRequests: LabeledPullRequest[];
11
+ stateOf: PullRequestStateOf;
12
+ /** For each of `pullRequests`, whether it folds into the merged-or-closed count. */
13
+ foldGroups: boolean[];
14
+ }
15
+ /** A session's context from its detail and the states read for its pull
16
+ * requests, which come from the URLs `labeledPullRequests` keeps. */
17
+ export declare function sessionContextRow({ added, allowed, pullRequests, states, }: {
18
+ added: PwCodeAddedDirectory[] | null | undefined;
19
+ allowed: PwCodeAllowedDirectory[] | null | undefined;
20
+ pullRequests: readonly string[] | null | undefined;
21
+ states: readonly {
22
+ url: string;
23
+ state?: string | undefined;
24
+ }[] | undefined;
25
+ }): PwCodeContextRow;
@@ -0,0 +1,16 @@
1
+ import { labeledPullRequests, orderPullRequests, pullRequestFoldGroups, pullRequestStateOf } from "./pullRequestList.js";
2
+ // src/contextRow.ts
3
+ /** A session's context from its detail and the states read for its pull
4
+ * requests, which come from the URLs `labeledPullRequests` keeps. */
5
+ function sessionContextRow({ added, allowed, pullRequests, states }) {
6
+ const stateOf = pullRequestStateOf(states);
7
+ const ordered = orderPullRequests(labeledPullRequests(pullRequests), stateOf);
8
+ return {
9
+ added: added ?? [],
10
+ allowed: allowed ?? [],
11
+ pullRequests: ordered,
12
+ stateOf,
13
+ foldGroups: pullRequestFoldGroups(ordered, stateOf)
14
+ };
15
+ }
16
+ export { sessionContextRow };