@parallelworks/code 0.3.0 → 0.5.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.
- package/README.md +625 -113
- package/dist/accountApi.d.ts +31 -0
- package/dist/accountApi.js +182 -0
- package/dist/agentSwitcher.d.ts +120 -0
- package/dist/agentSwitcher.js +187 -0
- package/dist/ago.d.ts +1 -3
- package/dist/ago.js +8 -10
- package/dist/allocations.d.ts +41 -0
- package/dist/allocations.js +76 -0
- package/dist/api.d.ts +1319 -50
- package/dist/chatStrings.d.ts +189 -0
- package/dist/chatStrings.js +218 -0
- package/dist/claudeAccounts.d.ts +57 -2
- package/dist/claudeAccounts.js +144 -6
- package/dist/claudeApi.d.ts +2 -1
- package/dist/claudeApi.js +50 -4
- package/dist/claudeSignIn.d.ts +19 -1
- package/dist/claudeSignIn.js +12 -2
- package/dist/command.d.ts +5 -1
- package/dist/command.js +6 -1
- package/dist/commandsApi.d.ts +11 -1
- package/dist/commandsApi.js +24 -5
- package/dist/createPwCodeApi.d.ts +114 -6
- package/dist/createPwCodeApi.js +21 -3
- package/dist/directories.d.ts +161 -0
- package/dist/directories.js +301 -0
- package/dist/goal.d.ts +89 -0
- package/dist/goal.js +164 -0
- package/dist/imageFit.d.ts +23 -0
- package/dist/imageFit.js +27 -0
- package/dist/images.d.ts +28 -0
- package/dist/images.js +38 -6
- package/dist/index.d.ts +31 -15
- package/dist/index.js +29 -14
- package/dist/loadError.d.ts +8 -0
- package/dist/loadError.js +19 -0
- package/dist/locales/en/agentTranscript.js +74 -12
- package/dist/locales/en/agents.js +86 -11
- package/dist/locales/en.d.ts +137 -8
- package/dist/locales/es/agentTranscript.js +74 -12
- package/dist/locales/es/agents.js +86 -11
- package/dist/locales/ja/agentTranscript.js +77 -15
- package/dist/locales/ja/agents.js +60 -122
- package/dist/locales/ko/agentTranscript.js +74 -12
- package/dist/locales/ko/agents.js +86 -11
- package/dist/locales/zh/agentTranscript.js +72 -10
- package/dist/locales/zh/agents.js +86 -11
- package/dist/machine.d.ts +2 -0
- package/dist/modelPicker.d.ts +79 -0
- package/dist/modelPicker.js +107 -0
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +67 -32
- package/dist/platformDefaults.d.ts +22 -0
- package/dist/platformDefaults.js +30 -0
- package/dist/preferences.d.ts +78 -0
- package/dist/preferences.js +128 -0
- package/dist/pullRequestList.d.ts +10 -2
- package/dist/pullRequestList.js +41 -22
- package/dist/query.d.ts +9 -2
- package/dist/query.js +91 -10
- package/dist/session.d.ts +11 -2
- package/dist/session.js +16 -8
- package/dist/sessionActions.d.ts +11 -1
- package/dist/sessionActions.js +14 -6
- package/dist/sessionEvents.d.ts +37 -5
- package/dist/sessionEvents.js +196 -77
- package/dist/sessionGroups.d.ts +5 -4
- package/dist/sessionGroups.js +6 -5
- package/dist/sessionHeader.js +6 -2
- package/dist/sessionList.d.ts +68 -15
- package/dist/sessionList.js +91 -19
- package/dist/sessionScreen.d.ts +197 -0
- package/dist/sessionScreen.js +218 -0
- package/dist/sessionsApi.d.ts +29 -3
- package/dist/sessionsApi.js +180 -33
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/settingsApi.d.ts +3 -1
- package/dist/startPage.d.ts +153 -0
- package/dist/startPage.js +174 -0
- package/dist/startSession.d.ts +41 -7
- package/dist/startSession.js +26 -4
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +1 -2
- package/dist/transcript.js +111 -117
- package/dist/transcriptRead.d.ts +56 -0
- package/dist/transcriptRead.js +121 -0
- package/dist/types.d.ts +11 -1
- package/dist/useComposer.d.ts +39 -6
- package/dist/useComposer.js +73 -9
- package/dist/useComposerImages.d.ts +5 -0
- package/dist/useComposerImages.js +27 -5
- package/dist/useComposerPastes.d.ts +70 -0
- package/dist/useComposerPastes.js +125 -0
- package/dist/useConversation.d.ts +16 -1
- package/dist/useConversation.js +104 -10
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +51 -3
- package/dist/useSubagent.js +72 -7
- package/dist/useTranscript.d.ts +23 -3
- package/dist/useTranscript.js +76 -19
- package/dist/wording.d.ts +5 -2
- package/dist/wording.js +8 -6
- package/dist/workingDirectories.d.ts +31 -0
- package/dist/workingDirectories.js +25 -1
- package/locales/en/agentTranscript.json +68 -11
- package/locales/en/agents.json +82 -10
- package/locales/es/agentTranscript.json +68 -11
- package/locales/es/agents.json +82 -10
- package/locales/ja/agentTranscript.json +71 -14
- package/locales/ja/agents.json +82 -10
- package/locales/ko/agentTranscript.json +68 -11
- package/locales/ko/agents.json +82 -10
- package/locales/zh/agentTranscript.json +66 -9
- package/locales/zh/agents.json +82 -10
- package/package.json +6 -3
package/dist/claudeAccounts.js
CHANGED
|
@@ -1,24 +1,111 @@
|
|
|
1
1
|
import { usePwCodeTranslations } from "./messages.js";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { DateTime } from "luxon";
|
|
4
3
|
import { useFormatter } from "use-intl";
|
|
4
|
+
import { DateTime } from "luxon";
|
|
5
5
|
// src/claudeAccounts.ts
|
|
6
6
|
var signInRequiredCode = "agents_claude_sign_in_required";
|
|
7
7
|
/** The refusal of a read that needs the account signed in first. */
|
|
8
8
|
function claudeSignInRequired(error) {
|
|
9
9
|
return error?.code === signInRequiredCode;
|
|
10
10
|
}
|
|
11
|
+
var ACCOUNT_NAME_MAX = 64;
|
|
11
12
|
/** The account name `input` gives once trimmed, or null when Claude Code
|
|
12
13
|
* can't take it. */
|
|
13
14
|
function claudeAccountName(input) {
|
|
14
15
|
const name = input.trim();
|
|
15
|
-
if (!/^[a-zA-Z0-9_.@-]
|
|
16
|
+
if (!/^[a-zA-Z0-9_.@-]+$/.test(name) || name.length > ACCOUNT_NAME_MAX || name === "." || name === ".." || name.endsWith(".lock")) return null;
|
|
16
17
|
return name;
|
|
17
18
|
}
|
|
19
|
+
function unavailableNotice(allowed, installed, t) {
|
|
20
|
+
if (!allowed) return t("claude.disabled");
|
|
21
|
+
return installed ? null : t("claude.notInstalled");
|
|
22
|
+
}
|
|
23
|
+
function viewWords(view, host, hint, handoff, t) {
|
|
24
|
+
switch (view.kind) {
|
|
25
|
+
case "signIn": return {
|
|
26
|
+
title: t("claude.signInTitle"),
|
|
27
|
+
description: t("claude.profileOnHost", {
|
|
28
|
+
account: view.account,
|
|
29
|
+
host
|
|
30
|
+
}),
|
|
31
|
+
signInNote: null,
|
|
32
|
+
removeBody: null
|
|
33
|
+
};
|
|
34
|
+
case "remove": return {
|
|
35
|
+
title: t("claude.removeAccount"),
|
|
36
|
+
description: t("claude.profileOnHost", {
|
|
37
|
+
account: view.account,
|
|
38
|
+
host
|
|
39
|
+
}),
|
|
40
|
+
signInNote: null,
|
|
41
|
+
removeBody: t("claude.removeBody", {
|
|
42
|
+
account: view.account,
|
|
43
|
+
host
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
case "add": return {
|
|
47
|
+
title: t("claude.addAccount"),
|
|
48
|
+
description: t("claude.hostAccounts", { host }),
|
|
49
|
+
signInNote: null,
|
|
50
|
+
removeBody: null
|
|
51
|
+
};
|
|
52
|
+
default: return {
|
|
53
|
+
title: handoff ? t("claude.continueOnAnother") : t("claude.accounts"),
|
|
54
|
+
description: t("claude.hostAccounts", { host }),
|
|
55
|
+
signInNote: hint ?? t("claude.loginStaysOnHost", { host }),
|
|
56
|
+
removeBody: null
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function listControls(view, available, canAdd) {
|
|
61
|
+
const showRefresh = available && view.kind === "list";
|
|
62
|
+
return {
|
|
63
|
+
showAdd: showRefresh && canAdd,
|
|
64
|
+
showRefresh
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function startRows(accounts, selected, claudeLogin) {
|
|
68
|
+
const selectedIndex = accounts.findIndex((a) => a.name === selected);
|
|
69
|
+
const firstEnabledIndex = accounts.findIndex((a) => claudeLogin || !a.signInRequired);
|
|
70
|
+
return {
|
|
71
|
+
startIndex: startIndexOf(selectedIndex, firstEnabledIndex),
|
|
72
|
+
selectedIndex,
|
|
73
|
+
firstEnabledIndex
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function startIndexOf(selectedIndex, firstEnabledIndex) {
|
|
77
|
+
return selectedIndex < 0 ? firstEnabledIndex : selectedIndex;
|
|
78
|
+
}
|
|
79
|
+
/** Moves a host's highlight to the list's start row, then back to it each
|
|
80
|
+
* time the selected or first enabled row changes, such as when the
|
|
81
|
+
* accounts' sign-in states arrive. */
|
|
82
|
+
function useClaudeAccountStartRow(panel, setActive) {
|
|
83
|
+
const { selectedIndex, firstEnabledIndex } = panel;
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setActive(startIndexOf(selectedIndex, firstEnabledIndex));
|
|
86
|
+
}, [
|
|
87
|
+
selectedIndex,
|
|
88
|
+
firstEnabledIndex,
|
|
89
|
+
setActive
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
function signInHint(claudeLogin, t) {
|
|
93
|
+
return claudeLogin ? null : t("claude.loginOnHost");
|
|
94
|
+
}
|
|
95
|
+
function accountDetail(account, hint) {
|
|
96
|
+
if (account.signInRequired && hint !== null) return {
|
|
97
|
+
kind: "signInHint",
|
|
98
|
+
text: hint
|
|
99
|
+
};
|
|
100
|
+
return account.email ? {
|
|
101
|
+
kind: "email",
|
|
102
|
+
text: account.email
|
|
103
|
+
} : null;
|
|
104
|
+
}
|
|
18
105
|
/** The Claude Code accounts on a machine, and the steps a panel listing them
|
|
19
106
|
* takes: adding, signing in, removing after a confirmation the host shows,
|
|
20
107
|
* and choosing one for the `account` setting. */
|
|
21
|
-
function useClaudeAccountPanel(calls, { machine, sessionId, claudeInstalled, claudeAllowed, claudeLogin = false, claudeAccountRemove = false, account, onClose }) {
|
|
108
|
+
function useClaudeAccountPanel(calls, { machine, machineName, sessionId, claudeInstalled, claudeAllowed, claudeLogin = false, claudeAccountRemove = false, waitingAtLimit, account, onClose, onMovedOthers, onMoveError }) {
|
|
22
109
|
const t = usePwCodeTranslations("agents");
|
|
23
110
|
const [adding, setAdding] = useState(false);
|
|
24
111
|
const [signIn, setSignIn] = useState(null);
|
|
@@ -26,10 +113,19 @@ function useClaudeAccountPanel(calls, { machine, sessionId, claudeInstalled, cla
|
|
|
26
113
|
const [refreshError, setRefreshError] = useState(null);
|
|
27
114
|
const [refreshingModels, setRefreshingModels] = useState(false);
|
|
28
115
|
const available = claudeAllowed && claudeInstalled;
|
|
29
|
-
const catalog = calls.useClaudeAccounts(machine, sessionId, available);
|
|
116
|
+
const catalog = calls.useClaudeAccounts(machine, sessionId, available, waitingAtLimit);
|
|
30
117
|
const refreshModels = calls.useRefreshClaudeModels(machine, sessionId);
|
|
31
118
|
const deleteAccount = calls.useRemoveClaudeAccount(machine, sessionId);
|
|
32
119
|
const selected = account.value || void 0;
|
|
120
|
+
const takeAlong = useTakeAlong(calls, {
|
|
121
|
+
machine,
|
|
122
|
+
sessionId,
|
|
123
|
+
waitingAtLimit,
|
|
124
|
+
selected,
|
|
125
|
+
accounts: catalog.accounts,
|
|
126
|
+
onMovedOthers,
|
|
127
|
+
onMoveError
|
|
128
|
+
});
|
|
33
129
|
const disabled = useRef(account.disabled);
|
|
34
130
|
disabled.current = account.disabled;
|
|
35
131
|
useEffect(() => {
|
|
@@ -61,6 +157,7 @@ function useClaudeAccountPanel(calls, { machine, sessionId, claudeInstalled, cla
|
|
|
61
157
|
};
|
|
62
158
|
const select = (name) => {
|
|
63
159
|
account.onChange(name);
|
|
160
|
+
takeAlong.to(name);
|
|
64
161
|
onClose();
|
|
65
162
|
};
|
|
66
163
|
const unlessDisabled = (run) => () => {
|
|
@@ -96,17 +193,26 @@ function useClaudeAccountPanel(calls, { machine, sessionId, claudeInstalled, cla
|
|
|
96
193
|
kind: "remove",
|
|
97
194
|
account: removing
|
|
98
195
|
} : { kind: "list" };
|
|
196
|
+
const hint = signInHint(claudeLogin, t);
|
|
197
|
+
const canAdd = claudeLogin && !account.disabled;
|
|
198
|
+
const controls = listControls(view, available, canAdd);
|
|
99
199
|
return {
|
|
100
200
|
available,
|
|
201
|
+
notice: unavailableNotice(claudeAllowed, claudeInstalled, t),
|
|
101
202
|
view,
|
|
203
|
+
...viewWords(view, machineName, hint, takeAlong.handoff, t),
|
|
204
|
+
emptyHint: hint,
|
|
102
205
|
accounts: catalog.accounts,
|
|
103
206
|
loading: catalog.loading,
|
|
104
207
|
loadedUsage: catalog.loadedUsage,
|
|
105
208
|
error: catalog.error || refreshError,
|
|
106
209
|
empty: !catalog.loading && !catalog.error && catalog.accounts.length === 0,
|
|
107
210
|
refreshing: catalog.refreshing || refreshingModels,
|
|
108
|
-
canAdd
|
|
211
|
+
canAdd,
|
|
212
|
+
...controls,
|
|
213
|
+
...startRows(catalog.accounts, account.value, claudeLogin),
|
|
109
214
|
isDisabled: (a) => !!account.disabled || !!a.signInRequired && !claudeLogin,
|
|
215
|
+
detail: (a) => accountDetail(a, hint),
|
|
110
216
|
choose: (a) => {
|
|
111
217
|
if (a.signInRequired && claudeLogin) {
|
|
112
218
|
setSignIn(a.name);
|
|
@@ -137,6 +243,37 @@ function useClaudeAccountPanel(calls, { machine, sessionId, claudeInstalled, cla
|
|
|
137
243
|
await deleteAccount(name);
|
|
138
244
|
if (account.value === name && !account.disabled) account.onChange("default");
|
|
139
245
|
setRemoving(null);
|
|
246
|
+
},
|
|
247
|
+
handoff: takeAlong.handoff,
|
|
248
|
+
others: takeAlong.others,
|
|
249
|
+
moveOthersLabel: controls.showRefresh && takeAlong.others > 0 && !account.disabled ? t("claude.moveOthers", {
|
|
250
|
+
count: takeAlong.others,
|
|
251
|
+
account: takeAlong.from
|
|
252
|
+
}) : null,
|
|
253
|
+
moveOthers: takeAlong.moveOthers,
|
|
254
|
+
setMoveOthers: takeAlong.setMoveOthers
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/** The other sessions on the account a session leaves, which share its limit,
|
|
258
|
+
* and their move along with it while the reader leaves them ticked. */
|
|
259
|
+
function useTakeAlong(calls, { machine, sessionId, waitingAtLimit, selected, accounts, onMovedOthers, onMoveError }) {
|
|
260
|
+
const t = usePwCodeTranslations("agents");
|
|
261
|
+
const [moveOthers, setMoveOthers] = useState(true);
|
|
262
|
+
const moveSessions = calls.useMoveClaudeAccountSessions(machine, sessionId);
|
|
263
|
+
const handoff = !!sessionId && waitingAtLimit === true;
|
|
264
|
+
const from = selected ?? "default";
|
|
265
|
+
const others = handoff ? accounts.find((a) => a.name === from)?.sessions?.filter((id) => id !== sessionId).length ?? 0 : 0;
|
|
266
|
+
return {
|
|
267
|
+
handoff,
|
|
268
|
+
from,
|
|
269
|
+
others,
|
|
270
|
+
moveOthers,
|
|
271
|
+
setMoveOthers,
|
|
272
|
+
to: (name) => {
|
|
273
|
+
if (moveOthers && others > 0 && name !== from) moveSessions(from, name).then((moved) => onMovedOthers?.(t("claude.movedOthers", {
|
|
274
|
+
count: moved.length,
|
|
275
|
+
account: name
|
|
276
|
+
}), moved.length, name), (cause) => onMoveError?.(cause));
|
|
140
277
|
}
|
|
141
278
|
};
|
|
142
279
|
}
|
|
@@ -169,6 +306,7 @@ function useClaudeAccountName(onContinue) {
|
|
|
169
306
|
return {
|
|
170
307
|
name,
|
|
171
308
|
invalid,
|
|
309
|
+
maxLength: ACCOUNT_NAME_MAX,
|
|
172
310
|
change: (value) => {
|
|
173
311
|
setName(value);
|
|
174
312
|
setInvalid(false);
|
|
@@ -231,4 +369,4 @@ function useClaudeAccountUsage(account, loaded) {
|
|
|
231
369
|
}]
|
|
232
370
|
};
|
|
233
371
|
}
|
|
234
|
-
export { claudeAccountName, claudeSignInRequired, useClaudeAccountName, useClaudeAccountPanel, useClaudeAccountRemoval, useClaudeAccountUsage };
|
|
372
|
+
export { claudeAccountName, claudeSignInRequired, useClaudeAccountName, useClaudeAccountPanel, useClaudeAccountRemoval, useClaudeAccountStartRow, useClaudeAccountUsage };
|
package/dist/claudeApi.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare function claudeApi(client: PwCodeClient): {
|
|
|
10
10
|
useClaudeModels: (machine: string, sessionId: string | undefined, account: string | undefined, enabled: boolean, refresh?: boolean) => PwCodeQuery<ClaudeModels>;
|
|
11
11
|
useRefreshClaudeModels: (machine: string, sessionId: string | undefined) => (account: string | undefined) => Promise<void>;
|
|
12
12
|
useClaudeAccountNames: (machine: string, enabled: boolean) => PwCodeQuery<ClaudeAccounts>;
|
|
13
|
-
useClaudeAccounts: (machine: string, sessionId: string | undefined, enabled: boolean) => {
|
|
13
|
+
useClaudeAccounts: (machine: string, sessionId: string | undefined, enabled: boolean, fresh?: boolean) => {
|
|
14
14
|
accounts: ClaudeAccount[];
|
|
15
15
|
loadedUsage: boolean;
|
|
16
16
|
loading: boolean;
|
|
@@ -19,6 +19,7 @@ export declare function claudeApi(client: PwCodeClient): {
|
|
|
19
19
|
refresh: () => Promise<void>;
|
|
20
20
|
};
|
|
21
21
|
useRemoveClaudeAccount: (machine: string, sessionId: string | undefined) => (name: string) => Promise<void>;
|
|
22
|
+
useMoveClaudeAccountSessions: (machine: string, sessionId: string | undefined) => (from: string, to: string) => Promise<string[]>;
|
|
22
23
|
startClaudeLogin: (machine: string, account: string, sessionId: string | undefined, columns: number, rows: number) => Promise<ClaudeLoginEvent>;
|
|
23
24
|
writeClaudeLogin: (machine: string, loginId: string, input: ClaudeLoginInput) => Promise<void>;
|
|
24
25
|
cancelClaudeLogin: (machine: string, loginId: string) => Promise<void>;
|
package/dist/claudeApi.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./apiClient.js";
|
|
2
2
|
import { createQuery } from "./query.js";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useSWRConfig } from "swr";
|
|
5
5
|
// src/claudeApi.ts
|
|
6
6
|
var cache = {
|
|
@@ -55,11 +55,20 @@ function sessionAccountOptions(machine, id, namesOnly, refresh = false) {
|
|
|
55
55
|
}
|
|
56
56
|
} };
|
|
57
57
|
}
|
|
58
|
+
/** An account's usage with the sessions its names read gave, as that read is repeated more often. */
|
|
59
|
+
function withNamedSessions(named, usage) {
|
|
60
|
+
if (!usage) return named;
|
|
61
|
+
const { sessions: _stale, ...rest } = usage;
|
|
62
|
+
return named.sessions ? {
|
|
63
|
+
...rest,
|
|
64
|
+
sessions: named.sessions
|
|
65
|
+
} : rest;
|
|
66
|
+
}
|
|
58
67
|
function claudeLoginFinished(status) {
|
|
59
68
|
return status !== "running" && status !== "checking";
|
|
60
69
|
}
|
|
61
70
|
/** Aborts after `ms`, or with `signal`. Built by hand where AbortSignal has no
|
|
62
|
-
* `timeout` or `any`, as React Native's
|
|
71
|
+
* `timeout` or `any`, as React Native's before 0.87 had neither. */
|
|
63
72
|
function deadline(ms, signal) {
|
|
64
73
|
if (typeof AbortSignal.timeout === "function" && (!signal || typeof AbortSignal.any === "function")) {
|
|
65
74
|
const timeout = AbortSignal.timeout(ms);
|
|
@@ -107,12 +116,19 @@ function claudeApi(client) {
|
|
|
107
116
|
function useClaudeAccountNames(machine, enabled) {
|
|
108
117
|
return useQuery(hostAccountsPath, enabled && machine ? hostAccountOptions(machine, true) : null, cache);
|
|
109
118
|
}
|
|
110
|
-
|
|
119
|
+
/** With `fresh`, the names, which say what sessions each account runs, are read again on mount. */
|
|
120
|
+
function useClaudeAccounts(machine, sessionId, enabled, fresh) {
|
|
111
121
|
const { mutate } = useSWRConfig();
|
|
112
122
|
const [refreshing, setRefreshing] = useState(false);
|
|
113
123
|
const hostNames = useClaudeAccountNames(machine, enabled && !sessionId);
|
|
114
124
|
const sessionNames = useQuery(sessionAccountsPath, enabled && machine && sessionId ? sessionAccountOptions(machine, sessionId, true) : null, cache);
|
|
115
125
|
const names = sessionId ? sessionNames : hostNames;
|
|
126
|
+
const reloadNames = names.mutate;
|
|
127
|
+
const cachedNames = useRef(false);
|
|
128
|
+
cachedNames.current = names.data !== void 0;
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (fresh && cachedNames.current) reloadNames();
|
|
131
|
+
}, [fresh, reloadNames]);
|
|
116
132
|
const hostUsage = useQuery(hostAccountsPath, enabled && machine && !sessionId && names.data ? hostAccountOptions(machine, false) : null, cache);
|
|
117
133
|
const sessionUsage = useQuery(sessionAccountsPath, enabled && machine && sessionId && names.data ? sessionAccountOptions(machine, sessionId, false) : null, cache);
|
|
118
134
|
const usage = sessionId ? sessionUsage : hostUsage;
|
|
@@ -135,7 +151,7 @@ function claudeApi(client) {
|
|
|
135
151
|
}
|
|
136
152
|
};
|
|
137
153
|
return {
|
|
138
|
-
accounts: (names.data ?? []).map((a) => metadata.get(a.name)
|
|
154
|
+
accounts: (names.data ?? []).map((a) => withNamedSessions(a, metadata.get(a.name))),
|
|
139
155
|
loadedUsage: !!usage.data,
|
|
140
156
|
loading: names.isLoading,
|
|
141
157
|
error: names.error ?? usage.error,
|
|
@@ -167,6 +183,35 @@ function claudeApi(client) {
|
|
|
167
183
|
], drop, { revalidate: namesOnly })] : []]));
|
|
168
184
|
};
|
|
169
185
|
}
|
|
186
|
+
/** Moves the live sessions on one account but this one to another,
|
|
187
|
+
* answering with those moved; the account lists read again. */
|
|
188
|
+
function useMoveClaudeAccountSessions(machine, sessionId) {
|
|
189
|
+
const { mutate } = useSWRConfig();
|
|
190
|
+
return async (from, to) => {
|
|
191
|
+
const { data, error } = await client.POST("/api/code/machines/{machine}/claude-code/accounts/{name}/move", {
|
|
192
|
+
params: { path: {
|
|
193
|
+
machine,
|
|
194
|
+
name: from
|
|
195
|
+
} },
|
|
196
|
+
body: {
|
|
197
|
+
to,
|
|
198
|
+
...sessionId ? { except: sessionId } : {}
|
|
199
|
+
},
|
|
200
|
+
signal: deadline(6e4)
|
|
201
|
+
});
|
|
202
|
+
if (error) throw error;
|
|
203
|
+
await Promise.all([mutate([
|
|
204
|
+
"api",
|
|
205
|
+
hostAccountsPath,
|
|
206
|
+
hostAccountOptions(machine, true)
|
|
207
|
+
]), sessionId && mutate([
|
|
208
|
+
"api",
|
|
209
|
+
sessionAccountsPath,
|
|
210
|
+
sessionAccountOptions(machine, sessionId, true)
|
|
211
|
+
])]);
|
|
212
|
+
return data?.moved ?? [];
|
|
213
|
+
};
|
|
214
|
+
}
|
|
170
215
|
async function startClaudeLogin(machine, account, sessionId, columns, rows) {
|
|
171
216
|
const { data, error } = await client.POST(loginsPath, {
|
|
172
217
|
params: { path: { machine } },
|
|
@@ -241,6 +286,7 @@ function claudeApi(client) {
|
|
|
241
286
|
useClaudeAccountNames,
|
|
242
287
|
useClaudeAccounts,
|
|
243
288
|
useRemoveClaudeAccount,
|
|
289
|
+
useMoveClaudeAccountSessions,
|
|
244
290
|
startClaudeLogin,
|
|
245
291
|
writeClaudeLogin,
|
|
246
292
|
cancelClaudeLogin,
|
package/dist/claudeSignIn.d.ts
CHANGED
|
@@ -30,12 +30,23 @@ export interface ClaudeSignInState {
|
|
|
30
30
|
inputTooLong: boolean;
|
|
31
31
|
/** The sign-in page's address, as Claude Code last printed it. */
|
|
32
32
|
link: string | null;
|
|
33
|
+
/** The address to offer opening the sign-in page at: `link`, while the
|
|
34
|
+
* sign-in runs. */
|
|
35
|
+
signInPage: string | null;
|
|
36
|
+
/** What to do, until the sign-in completes. */
|
|
37
|
+
instructions: string | null;
|
|
38
|
+
/** That earlier output was dropped, until the sign-in completes. */
|
|
39
|
+
truncatedNote: string | null;
|
|
40
|
+
/** Leaving the view: back once the sign-in finished, cancelling it before. */
|
|
41
|
+
closeLabel: string;
|
|
33
42
|
/** The last 8192 characters of output since the screen was last cleared. */
|
|
34
43
|
output: string;
|
|
35
44
|
acceptsInput: boolean;
|
|
36
45
|
starting: boolean;
|
|
37
46
|
signedIn: boolean;
|
|
38
47
|
finished: boolean;
|
|
48
|
+
/** `onUse`, offered only once the account is signed in. */
|
|
49
|
+
use: (() => void) | undefined;
|
|
39
50
|
/** Following broke while the sign-in still runs. */
|
|
40
51
|
canReconnect: boolean;
|
|
41
52
|
/** The sign-in never started or ended without signing in. */
|
|
@@ -50,13 +61,20 @@ export interface ClaudeSignInState {
|
|
|
50
61
|
reconnect: () => void;
|
|
51
62
|
retry: () => void;
|
|
52
63
|
}
|
|
64
|
+
/** Whether a link in the sign-in's output may be opened: web addresses only,
|
|
65
|
+
* never a script or a local file. */
|
|
66
|
+
export declare function canOpenSignInLink(uri: string): boolean;
|
|
53
67
|
/** Runs Claude Code's sign-in for `account` on a machine: starts it at the
|
|
54
68
|
* terminal's size, follows its output into the terminal, sends what is typed,
|
|
55
69
|
* and cancels it when the host leaves before it finishes. */
|
|
56
|
-
export declare function useClaudeSignIn(calls: ClaudeSignInCalls, { machine, sessionId, account, terminal, onSignedIn, }: {
|
|
70
|
+
export declare function useClaudeSignIn(calls: ClaudeSignInCalls, { machine, machineName, sessionId, account, terminal, onSignedIn, onUse, }: {
|
|
57
71
|
machine: string;
|
|
72
|
+
machineName: string;
|
|
58
73
|
sessionId: string | undefined;
|
|
59
74
|
account: string;
|
|
60
75
|
terminal: ClaudeSignInTerminal;
|
|
61
76
|
onSignedIn?: (() => void) | undefined;
|
|
77
|
+
/** Makes the account the one in use, such as `useClaudeAccountPanel`'s
|
|
78
|
+
* `selectSignedIn`; unset where it can't be. */
|
|
79
|
+
onUse?: (() => void) | undefined;
|
|
62
80
|
}): ClaudeSignInState;
|
package/dist/claudeSignIn.js
CHANGED
|
@@ -8,10 +8,15 @@ var signInUrl = /https:\/\/claude\.(?:ai|com)\/[\w\-.~:/?#[\]@!$&'()*+,;=%]+(?=[
|
|
|
8
8
|
var maxQueuedInput = 16384;
|
|
9
9
|
var inputChunk = 4096;
|
|
10
10
|
var inputBatchMs = 30;
|
|
11
|
+
/** Whether a link in the sign-in's output may be opened: web addresses only,
|
|
12
|
+
* never a script or a local file. */
|
|
13
|
+
function canOpenSignInLink(uri) {
|
|
14
|
+
return /^https?:\/\//i.test(uri);
|
|
15
|
+
}
|
|
11
16
|
/** Runs Claude Code's sign-in for `account` on a machine: starts it at the
|
|
12
17
|
* terminal's size, follows its output into the terminal, sends what is typed,
|
|
13
18
|
* and cancels it when the host leaves before it finishes. */
|
|
14
|
-
function useClaudeSignIn(calls, { machine, sessionId, account, terminal, onSignedIn }) {
|
|
19
|
+
function useClaudeSignIn(calls, { machine, machineName, sessionId, account, terminal, onSignedIn, onUse }) {
|
|
15
20
|
const t = usePwCodeTranslations("agents");
|
|
16
21
|
const [attempt, setAttempt] = useState(0);
|
|
17
22
|
const [login, setLogin] = useState(null);
|
|
@@ -222,11 +227,16 @@ function useClaudeSignIn(calls, { machine, sessionId, account, terminal, onSigne
|
|
|
222
227
|
truncated,
|
|
223
228
|
inputTooLong,
|
|
224
229
|
link,
|
|
230
|
+
signInPage: login?.status === "running" ? link : null,
|
|
231
|
+
instructions: signedIn ? null : t("claude.signInInstructions", { host: machineName }),
|
|
232
|
+
truncatedNote: truncated && !signedIn ? t("claude.terminalTruncated") : null,
|
|
233
|
+
closeLabel: finished ? t("claude.backToAccounts") : t("claude.cancelSignIn"),
|
|
225
234
|
output,
|
|
226
235
|
acceptsInput,
|
|
227
236
|
starting: !login && !error,
|
|
228
237
|
signedIn,
|
|
229
238
|
finished,
|
|
239
|
+
use: signedIn ? onUse : void 0,
|
|
230
240
|
canReconnect: Boolean(error) && !!login && !finished,
|
|
231
241
|
canRetry: Boolean(error) && !login || finished && !signedIn,
|
|
232
242
|
status: login ? t(`claude.signInStatus.${login.status}`, { email: login.email ?? account }) : null,
|
|
@@ -236,4 +246,4 @@ function useClaudeSignIn(calls, { machine, sessionId, account, terminal, onSigne
|
|
|
236
246
|
retry
|
|
237
247
|
};
|
|
238
248
|
}
|
|
239
|
-
export { useClaudeSignIn };
|
|
249
|
+
export { canOpenSignInLink, useClaudeSignIn };
|
package/dist/command.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export interface PwCodeSlashCommand {
|
|
|
4
4
|
description?: string | undefined;
|
|
5
5
|
usage?: string | undefined;
|
|
6
6
|
}
|
|
7
|
+
/** A palette entry with what it takes after its name, for the composer to show. */
|
|
8
|
+
export interface PwCodePaletteOption extends PwCodeSlashCommand {
|
|
9
|
+
argumentHint?: string | undefined;
|
|
10
|
+
}
|
|
7
11
|
/** What a session can run from a slash, as far as typed text is dispatched by
|
|
8
12
|
* it. A host that types its API from a spec asserts its type extends this. */
|
|
9
13
|
export interface PwCodePalette {
|
|
@@ -35,7 +39,7 @@ export type SlashAction = {
|
|
|
35
39
|
* custom commands, and MCP prompts expand into a turn, so they are messages;
|
|
36
40
|
* built-ins run as commands, five of them on routes of their own. */
|
|
37
41
|
export declare function slashAction(text: string, palette: PwCodePalette | null): SlashAction;
|
|
38
|
-
export declare function paletteOptions(palette: PwCodePalette | null, claudeAccountDescription?: string, archiveDescription?: string):
|
|
42
|
+
export declare function paletteOptions(palette: PwCodePalette | null, claudeAccountDescription?: string, archiveDescription?: string): PwCodePaletteOption[];
|
|
39
43
|
/** The command a `!` line runs, read as the terminal reads it: empty for a bare
|
|
40
44
|
* `!`, which runs nothing, and null for text that is not a shell escape. */
|
|
41
45
|
export declare function shellCommand(text: string): string | null;
|
package/dist/command.js
CHANGED
|
@@ -36,7 +36,8 @@ function paletteOptions(palette, claudeAccountDescription, archiveDescription) {
|
|
|
36
36
|
const commands = [...palette?.commands ?? [], ...palette?.mcpPrompts ?? []].filter((c) => c.name !== "claude-code").map((c) => ({
|
|
37
37
|
name: c.name,
|
|
38
38
|
description: c.description,
|
|
39
|
-
usage: c.usage
|
|
39
|
+
usage: c.usage,
|
|
40
|
+
argumentHint: argumentHint(c)
|
|
40
41
|
}));
|
|
41
42
|
if (archiveDescription !== void 0 && !commands.some((c) => c.name === "archive")) {
|
|
42
43
|
const at = commands.findIndex((c) => c.name > "archive");
|
|
@@ -51,6 +52,10 @@ function paletteOptions(palette, claudeAccountDescription, archiveDescription) {
|
|
|
51
52
|
description: claudeAccountDescription
|
|
52
53
|
}, ...commands];
|
|
53
54
|
}
|
|
55
|
+
function argumentHint(c) {
|
|
56
|
+
const name = `/${c.name} `;
|
|
57
|
+
return c.usage?.startsWith(name) ? c.usage.slice(name.length).trim() || void 0 : void 0;
|
|
58
|
+
}
|
|
54
59
|
/** The command a `!` line runs, read as the terminal reads it: empty for a bare
|
|
55
60
|
* `!`, which runs nothing, and null for text that is not a shell escape. */
|
|
56
61
|
function shellCommand(text) {
|
package/dist/commandsApi.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ToolCallPart } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import type { PwCodeClient, PwCodeResult, Schemas } from './apiClient.js';
|
|
2
3
|
import { type SlashAction } from './command.js';
|
|
3
4
|
type Palette = Schemas['AgentPalette'];
|
|
4
5
|
export type CommandOutcome = {
|
|
@@ -34,7 +35,16 @@ export interface SlashDeps {
|
|
|
34
35
|
onRefused: (error: unknown) => void;
|
|
35
36
|
}
|
|
36
37
|
export declare const backgroundOfferDelayMs = 2000;
|
|
38
|
+
/** The tool whose running calls the machine can move to the background. */
|
|
39
|
+
export declare const BACKGROUND_TOOL = "Bash";
|
|
40
|
+
export declare function runsInBackgroundTool(part: Pick<ToolCallPart, 'name' | 'status'>): boolean;
|
|
41
|
+
/** The offer to move a turn's commands to the background sits under each of
|
|
42
|
+
* its running `BACKGROUND_TOOL` calls, once the session makes it. */
|
|
43
|
+
export declare function offersBackground(part: Pick<ToolCallPart, 'name' | 'status'>, background: {
|
|
44
|
+
offered: boolean;
|
|
45
|
+
} | null | undefined): boolean;
|
|
37
46
|
export declare function commandsApi(client: PwCodeClient): {
|
|
47
|
+
runGoal: (machine: string, id: string, args: string) => Promise<PwCodeResult<Schemas['AgentGoalResult']>>;
|
|
38
48
|
runSlashAction: (machine: string, id: string, action: Exclude<SlashAction, {
|
|
39
49
|
kind: 'message' | 'archive';
|
|
40
50
|
}>, planOnMachine: (path: string) => string) => Promise<CommandOutcome>;
|
package/dist/commandsApi.js
CHANGED
|
@@ -3,6 +3,16 @@ import { shellCommand, slashAction } from "./command.js";
|
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
// src/commandsApi.ts
|
|
5
5
|
var backgroundOfferDelayMs = 2e3;
|
|
6
|
+
/** The tool whose running calls the machine can move to the background. */
|
|
7
|
+
var BACKGROUND_TOOL = "Bash";
|
|
8
|
+
function runsInBackgroundTool(part) {
|
|
9
|
+
return part.name === "Bash" && part.status === "running";
|
|
10
|
+
}
|
|
11
|
+
/** The offer to move a turn's commands to the background sits under each of
|
|
12
|
+
* its running `BACKGROUND_TOOL` calls, once the session makes it. */
|
|
13
|
+
function offersBackground(part, background) {
|
|
14
|
+
return !!background?.offered && runsInBackgroundTool(part);
|
|
15
|
+
}
|
|
6
16
|
function planOutcome(plan, args, planOnMachine) {
|
|
7
17
|
switch (plan.action) {
|
|
8
18
|
case "answer": return {
|
|
@@ -45,6 +55,17 @@ function settle(outcome, command, kind, deps) {
|
|
|
45
55
|
function commandsApi(client) {
|
|
46
56
|
const useQuery = createQuery(client);
|
|
47
57
|
const palettes = /* @__PURE__ */ new Map();
|
|
58
|
+
/** Runs /goal with the terminal's arguments, answering with the goal as the
|
|
59
|
+
* call left it. A bare `edit` only reads it. */
|
|
60
|
+
function runGoal(machine, id, args) {
|
|
61
|
+
return client.POST("/api/code/machines/{machine}/sessions/{id}/goal", {
|
|
62
|
+
params: { path: {
|
|
63
|
+
machine,
|
|
64
|
+
id
|
|
65
|
+
} },
|
|
66
|
+
body: { args }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
48
69
|
/** Runs a command against the session's daemon, answering with what the
|
|
49
70
|
* host owes next. /plan's actions follow the terminal's, except that opening
|
|
50
71
|
* the plan file needs the machine's own editor. */
|
|
@@ -79,10 +100,7 @@ function commandsApi(client) {
|
|
|
79
100
|
};
|
|
80
101
|
}
|
|
81
102
|
case "goal": {
|
|
82
|
-
const { data, error } = await
|
|
83
|
-
...path,
|
|
84
|
-
body: { args: action.args }
|
|
85
|
-
});
|
|
103
|
+
const { data, error } = await runGoal(machine, id, action.args);
|
|
86
104
|
return error ? {
|
|
87
105
|
kind: "refused",
|
|
88
106
|
error
|
|
@@ -256,6 +274,7 @@ function commandsApi(client) {
|
|
|
256
274
|
});
|
|
257
275
|
}
|
|
258
276
|
return {
|
|
277
|
+
runGoal,
|
|
259
278
|
runSlashAction,
|
|
260
279
|
resolveTyped,
|
|
261
280
|
usePalette,
|
|
@@ -264,4 +283,4 @@ function commandsApi(client) {
|
|
|
264
283
|
requestRecap
|
|
265
284
|
};
|
|
266
285
|
}
|
|
267
|
-
export { backgroundOfferDelayMs, commandsApi };
|
|
286
|
+
export { BACKGROUND_TOOL, backgroundOfferDelayMs, commandsApi, offersBackground, runsInBackgroundTool };
|