@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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { holdSocket, isHeartbeat } from "./sessionEvents.js";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
// src/sessionsFeed.ts
|
|
4
|
+
/** Where the platform sends the sessions listing as it changes. */
|
|
5
|
+
var SESSIONS_FEED_PATH = `/ws/code/sessions?heartbeat=10`;
|
|
6
|
+
function listingFrame(data) {
|
|
7
|
+
try {
|
|
8
|
+
const frame = JSON.parse(String(data));
|
|
9
|
+
return frame.type === "sessions" ? frame.listing : void 0;
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The sessions listing as the platform sends it over a socket: at once, and
|
|
15
|
+
* again each time it changes. A listing that is polled for shows a change up
|
|
16
|
+
* to a poll late, and when a connection that went silent returns it waits
|
|
17
|
+
* most of a minute on the request it had out, which a fetch cannot take to
|
|
18
|
+
* another connection as a socket can. One socket serves every hook that reads
|
|
19
|
+
* the listing, open while any does and the app is in sight: out of sight the
|
|
20
|
+
* listing is not polled for either. */
|
|
21
|
+
function sessionsFeed({ openSocket, hidden }, onListing) {
|
|
22
|
+
const readers = /* @__PURE__ */ new Set();
|
|
23
|
+
const watchers = /* @__PURE__ */ new Set();
|
|
24
|
+
let fed = false;
|
|
25
|
+
let sent = false;
|
|
26
|
+
let stop;
|
|
27
|
+
let tryNow;
|
|
28
|
+
let writing = 0;
|
|
29
|
+
function setFed(next) {
|
|
30
|
+
if (fed !== next) {
|
|
31
|
+
fed = next;
|
|
32
|
+
for (const notify of [...watchers]) notify();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const socket = { current: {
|
|
36
|
+
open: openSocket,
|
|
37
|
+
path: () => SESSIONS_FEED_PATH,
|
|
38
|
+
onOpen: (revived) => {
|
|
39
|
+
sent &&= revived;
|
|
40
|
+
setFed(sent);
|
|
41
|
+
},
|
|
42
|
+
onClose: () => setFed(false),
|
|
43
|
+
onMessage: (data) => {
|
|
44
|
+
const listing = listingFrame(data);
|
|
45
|
+
if (!listing) return;
|
|
46
|
+
sent = true;
|
|
47
|
+
setFed(true);
|
|
48
|
+
onListing(listing);
|
|
49
|
+
for (const read of [...readers]) read(listing);
|
|
50
|
+
},
|
|
51
|
+
whenReachable: (now) => {
|
|
52
|
+
tryNow = now;
|
|
53
|
+
return () => {
|
|
54
|
+
tryNow = void 0;
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
heartbeat: (data) => {
|
|
58
|
+
if (hidden?.()) queueMicrotask(() => {
|
|
59
|
+
if (hidden()) leave();
|
|
60
|
+
});
|
|
61
|
+
return isHeartbeat(data);
|
|
62
|
+
}
|
|
63
|
+
} };
|
|
64
|
+
function open() {
|
|
65
|
+
if (!stop && openSocket && readers.size > 0 && writing === 0 && !hidden?.()) stop = holdSocket(socket, () => {});
|
|
66
|
+
}
|
|
67
|
+
function leave() {
|
|
68
|
+
if (stop) {
|
|
69
|
+
stop();
|
|
70
|
+
stop = void 0;
|
|
71
|
+
sent = false;
|
|
72
|
+
setFed(false);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Hands `reader` each listing until the returned call. */
|
|
76
|
+
function read(reader) {
|
|
77
|
+
readers.add(reader);
|
|
78
|
+
open();
|
|
79
|
+
return () => {
|
|
80
|
+
readers.delete(reader);
|
|
81
|
+
queueMicrotask(() => {
|
|
82
|
+
if (readers.size === 0) leave();
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Leaves the socket until the returned call, while the page itself writes
|
|
87
|
+
* the listing or reads it again. A listing the platform sent before that
|
|
88
|
+
* would put back what it changed; another socket's first listing is asked
|
|
89
|
+
* for after it opened. The listing is polled for meanwhile. */
|
|
90
|
+
function pause() {
|
|
91
|
+
writing += 1;
|
|
92
|
+
leave();
|
|
93
|
+
let landed = false;
|
|
94
|
+
return () => {
|
|
95
|
+
if (!landed) {
|
|
96
|
+
landed = true;
|
|
97
|
+
writing -= 1;
|
|
98
|
+
open();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function watch(notify) {
|
|
103
|
+
watchers.add(notify);
|
|
104
|
+
return () => {
|
|
105
|
+
watchers.delete(notify);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Whether the listing comes over the socket, so that nothing need poll for it. */
|
|
109
|
+
function useFed() {
|
|
110
|
+
return useSyncExternalStore(watch, () => fed, () => false);
|
|
111
|
+
}
|
|
112
|
+
/** The platform answered, so a socket waiting to try again tries at once,
|
|
113
|
+
* and one left while the app was out of sight opens again. */
|
|
114
|
+
function reachable() {
|
|
115
|
+
open();
|
|
116
|
+
tryNow?.();
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
read,
|
|
120
|
+
pause,
|
|
121
|
+
useFed,
|
|
122
|
+
reachable
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export { SESSIONS_FEED_PATH, sessionsFeed };
|
package/dist/settingsApi.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export interface PwCodeSessionSettingsOptions {
|
|
|
8
8
|
effort?: string | undefined;
|
|
9
9
|
allocation: string | undefined;
|
|
10
10
|
claudeAccount?: string | undefined;
|
|
11
|
-
/** Billed by a switch to a model the platform bills, while the session has
|
|
11
|
+
/** Billed by a switch to a model the platform bills, while the session has
|
|
12
|
+
* had no allocation of its own: the host's selected one, such as its
|
|
13
|
+
* chat's, or `usePlatformDefaults`'s. */
|
|
12
14
|
nativeAllocation?: string | null | undefined;
|
|
13
15
|
locked: boolean;
|
|
14
16
|
live: boolean;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ApprovalAnswerValue, ApprovalPart } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import { type PwCodeHandoffChat } from './chatHandoff.js';
|
|
3
|
+
import { type PwCodePalette, type PwCodeSlashCommand } from './command.js';
|
|
4
|
+
import type { PwCodeApi } from './createPwCodeApi.js';
|
|
5
|
+
import { type PwCodeMachine } from './machine.js';
|
|
6
|
+
import type { PwCodeTranslator } from './messages.js';
|
|
7
|
+
import { runsClaude } from './models.js';
|
|
8
|
+
import { type PwCodeSession } from './session.js';
|
|
9
|
+
import type { PwCodeStartLocation, PwCodeStartMachine } from './startSession.js';
|
|
10
|
+
import { type TranscriptWords } from './transcript.js';
|
|
11
|
+
import type { PwCodeApprovalRequest } from './types.js';
|
|
12
|
+
import { sessionStateText } from './wording.js';
|
|
13
|
+
type Translate = PwCodeTranslator<'agents'>;
|
|
14
|
+
/** As many sessions as a new chat offers starters, so the page fits. */
|
|
15
|
+
export declare const START_SHORTLIST = 4;
|
|
16
|
+
/** The sessions a start page offers to pick back up: the live ones, then the
|
|
17
|
+
* idle ones, each newest first as `triageSessions` orders them. */
|
|
18
|
+
export declare function startShortlist<S>(triage: {
|
|
19
|
+
active: readonly S[];
|
|
20
|
+
idle: readonly S[];
|
|
21
|
+
}, size?: number): S[];
|
|
22
|
+
/** A shortlisted session that is live shows a mark named by its state, which
|
|
23
|
+
* nothing else on its row spells out; one at rest shows none. */
|
|
24
|
+
export declare function shortlistMark(session: Parameters<typeof sessionStateText>[0], machine: Pick<PwCodeMachine, 'status'> | undefined, t: Translate): {
|
|
25
|
+
label: string;
|
|
26
|
+
} | null;
|
|
27
|
+
/** When a session began waiting on the reader: its first pending question,
|
|
28
|
+
* else its last change. */
|
|
29
|
+
export declare function waitingSince(s: Pick<PwCodeSession, 'updatedAt'> & {
|
|
30
|
+
approvals?: readonly Pick<PwCodeApprovalRequest, 'createdAt'>[] | null;
|
|
31
|
+
}): string | undefined;
|
|
32
|
+
/** What a session waiting on the reader asks, answerable where it is listed,
|
|
33
|
+
* or, when the listing carries none of its questions, `inSession`: a line
|
|
34
|
+
* sending the reader into the session to answer. */
|
|
35
|
+
export declare function waitingQuestions(s: {
|
|
36
|
+
approvals?: readonly PwCodeApprovalRequest[] | null;
|
|
37
|
+
}, words: Pick<TranscriptWords, 'allowDirectory'>, t: Translate): {
|
|
38
|
+
questions: ApprovalPart[];
|
|
39
|
+
inSession: string | null;
|
|
40
|
+
};
|
|
41
|
+
/** A start page around its composer, from the listing `api.useSessions` reads. */
|
|
42
|
+
export interface PwCodeStartScreen {
|
|
43
|
+
/** The listing has yet to answer. */
|
|
44
|
+
loading: boolean;
|
|
45
|
+
/** Shown in place of the page while the listing never loaded, since an
|
|
46
|
+
* empty one would read as having no sessions: why, or undefined for the
|
|
47
|
+
* host's own line. */
|
|
48
|
+
failed: {
|
|
49
|
+
message: string | undefined;
|
|
50
|
+
} | null;
|
|
51
|
+
/** Otherwise no machine lets a session start here, and the host says so.
|
|
52
|
+
* A machine not answering keeps it: such a machine reports starting off,
|
|
53
|
+
* so the menu says why rather than sending the reader to that setting. */
|
|
54
|
+
showComposer: boolean;
|
|
55
|
+
/** Nothing is listed, so the host explains how sessions appear (`howSessionsAppear`). */
|
|
56
|
+
explainEmpty: boolean;
|
|
57
|
+
/** Answers a listed session's question, then reads the listing again;
|
|
58
|
+
* resolves to the refusal in `describeError`'s words, or null. */
|
|
59
|
+
answer: (session: Pick<PwCodeSession, 'machineId' | 'id'>, approvalId: string, value: ApprovalAnswerValue) => Promise<string | null>;
|
|
60
|
+
}
|
|
61
|
+
export declare function useStartScreen(api: Pick<PwCodeApi, 'useSessions' | 'answerApproval'>, { location, describeError, }: {
|
|
62
|
+
location: {
|
|
63
|
+
startable: readonly unknown[];
|
|
64
|
+
down: readonly unknown[];
|
|
65
|
+
};
|
|
66
|
+
/** Words a refusal or failure for the reader. */
|
|
67
|
+
describeError: (error: unknown) => string;
|
|
68
|
+
}): PwCodeStartScreen;
|
|
69
|
+
/** What a start page's address asks for: a session to open, named by the
|
|
70
|
+
* link pw code's /rc prints, or a chat to hand to a new session. */
|
|
71
|
+
export interface PwCodeStartSearch {
|
|
72
|
+
session?: string | undefined;
|
|
73
|
+
fromChat?: string | undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The start page's parameters from its parsed query; any that is not a
|
|
76
|
+
* single string is left out. */
|
|
77
|
+
export declare function startSearch(search: Record<string, unknown>): PwCodeStartSearch;
|
|
78
|
+
/** How a link to a session stands: still being looked for, or missing from
|
|
79
|
+
* the listing; null without one. */
|
|
80
|
+
export type PwCodeSessionLinkState = 'resolving' | 'missing' | null;
|
|
81
|
+
/** Follows a link that names only a session, since the machine listed with
|
|
82
|
+
* it is not known where the link was printed: once the listing names the
|
|
83
|
+
* session, `open` takes it to the session. */
|
|
84
|
+
export declare function useSessionLink<S extends Pick<PwCodeSession, 'id'>>(session: string | undefined, listing: {
|
|
85
|
+
sessions: readonly S[];
|
|
86
|
+
loading: boolean;
|
|
87
|
+
}, open: (found: S) => void): PwCodeSessionLinkState;
|
|
88
|
+
/** The card over the composer while a link to a session is followed: news
|
|
89
|
+
* while it is looked for, a warning once the listing lacks it. Null without
|
|
90
|
+
* a link. */
|
|
91
|
+
export declare function sessionLinkNotice(state: PwCodeSessionLinkState, session: string | undefined, t: Translate): {
|
|
92
|
+
text: string;
|
|
93
|
+
tone: 'neutral' | 'warning';
|
|
94
|
+
} | null;
|
|
95
|
+
/** The commands a new session's composer offers: the directory's palette,
|
|
96
|
+
* led by the Claude Code account choice on a machine where Claude Code
|
|
97
|
+
* runs. Archiving needs a session, so it is not offered. */
|
|
98
|
+
export declare function startCommands(palette: PwCodePalette | null, machine: Parameters<typeof runsClaude>[0], t: Translate): PwCodeSlashCommand[];
|
|
99
|
+
/** A machine as the start page's menu offers it. */
|
|
100
|
+
export interface PwCodeMachineChoice {
|
|
101
|
+
id: string;
|
|
102
|
+
label: string;
|
|
103
|
+
/** A computer or a resource, or for one not answering, why. */
|
|
104
|
+
description: string | undefined;
|
|
105
|
+
checked: boolean;
|
|
106
|
+
disabled: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** The machines a session can start on, then the ones not answering, each
|
|
109
|
+
* saying why, so a missing machine can be traced. With both, the ones not
|
|
110
|
+
* answering go under `downLabel`; with one kind only, it stands alone. */
|
|
111
|
+
export interface PwCodeMachineMenu {
|
|
112
|
+
startable: PwCodeMachineChoice[];
|
|
113
|
+
down: PwCodeMachineChoice[];
|
|
114
|
+
downLabel: string | undefined;
|
|
115
|
+
/** Picks a machine; the one picked already stays as it is. */
|
|
116
|
+
pick: (id: string) => void;
|
|
117
|
+
}
|
|
118
|
+
export declare function machineMenu<M extends PwCodeStartMachine>(location: Pick<PwCodeStartLocation<M>, 'startable' | 'down' | 'machine' | 'pickMachine'>, t: Translate): PwCodeMachineMenu;
|
|
119
|
+
/** The chip naming the machine a session starts on, which opens the
|
|
120
|
+
* `machineMenu`: the machine's name after a dot in the `success` tone, since
|
|
121
|
+
* only a machine that answers can be chosen, or, until one is, a call to
|
|
122
|
+
* choose one and no dot. While the machines are still being listed
|
|
123
|
+
* (`finding`), it says so and opens nothing. `label` names the chip's action. */
|
|
124
|
+
export declare function machineChip(machine: Pick<PwCodeStartMachine, 'name'> | undefined, t: Translate, finding?: boolean): {
|
|
125
|
+
text: string;
|
|
126
|
+
label: string;
|
|
127
|
+
dot: 'success' | null;
|
|
128
|
+
};
|
|
129
|
+
/** A chat handed to a new session, while it loads or once it failed to. */
|
|
130
|
+
export interface PwCodeStartHandoff {
|
|
131
|
+
conversation: PwCodeHandoffChat | undefined;
|
|
132
|
+
error: unknown;
|
|
133
|
+
}
|
|
134
|
+
/** How a start carries a chat handed to it: it waits until the chat has
|
|
135
|
+
* arrived, since starting sooner would quietly leave it behind, then sends
|
|
136
|
+
* the chat after what was typed. A chat that failed to load holds nothing
|
|
137
|
+
* back. */
|
|
138
|
+
export declare function chatHandoffStart(handoff: PwCodeStartHandoff | undefined, t: Translate,
|
|
139
|
+
/** Words a failure for the reader. */
|
|
140
|
+
describeError: (error: unknown) => string): {
|
|
141
|
+
waiting: boolean;
|
|
142
|
+
firstPrompt: ((typed: string) => string) | undefined;
|
|
143
|
+
/** The composer's placeholder; once the chat has arrived, it asks what to do with it. */
|
|
144
|
+
placeholder: string;
|
|
145
|
+
/** The card above the composer naming the chat, or saying it is loading
|
|
146
|
+
* or why it failed to, which is a warning; null without a chat. */
|
|
147
|
+
notice: {
|
|
148
|
+
text: string;
|
|
149
|
+
failed: boolean;
|
|
150
|
+
tone: 'neutral' | 'warning';
|
|
151
|
+
} | null;
|
|
152
|
+
};
|
|
153
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { chatHandoffPrompt } from "./chatHandoff.js";
|
|
2
|
+
import { paletteOptions } from "./command.js";
|
|
3
|
+
import { loadErrorMessage } from "./loadError.js";
|
|
4
|
+
import { isComputer } from "./machine.js";
|
|
5
|
+
import { runsClaude } from "./models.js";
|
|
6
|
+
import { isActiveSession } from "./session.js";
|
|
7
|
+
import { approvalToPart } from "./transcript.js";
|
|
8
|
+
import { machineHint, sessionStateText } from "./wording.js";
|
|
9
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
10
|
+
// src/startPage.ts
|
|
11
|
+
/** As many sessions as a new chat offers starters, so the page fits. */
|
|
12
|
+
var START_SHORTLIST = 4;
|
|
13
|
+
/** The sessions a start page offers to pick back up: the live ones, then the
|
|
14
|
+
* idle ones, each newest first as `triageSessions` orders them. */
|
|
15
|
+
function startShortlist(triage, size = 4) {
|
|
16
|
+
return [...triage.active, ...triage.idle].slice(0, size);
|
|
17
|
+
}
|
|
18
|
+
/** A shortlisted session that is live shows a mark named by its state, which
|
|
19
|
+
* nothing else on its row spells out; one at rest shows none. */
|
|
20
|
+
function shortlistMark(session, machine, t) {
|
|
21
|
+
return isActiveSession(session) ? { label: sessionStateText(session, machine, t) } : null;
|
|
22
|
+
}
|
|
23
|
+
/** When a session began waiting on the reader: its first pending question,
|
|
24
|
+
* else its last change. */
|
|
25
|
+
function waitingSince(s) {
|
|
26
|
+
return s.approvals?.[0]?.createdAt ?? s.updatedAt;
|
|
27
|
+
}
|
|
28
|
+
/** What a session waiting on the reader asks, answerable where it is listed,
|
|
29
|
+
* or, when the listing carries none of its questions, `inSession`: a line
|
|
30
|
+
* sending the reader into the session to answer. */
|
|
31
|
+
function waitingQuestions(s, words, t) {
|
|
32
|
+
const questions = (s.approvals ?? []).map((req) => approvalToPart(req, words));
|
|
33
|
+
return {
|
|
34
|
+
questions,
|
|
35
|
+
inSession: questions.length > 0 ? null : t("dash.answerInSession")
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function useStartScreen(api, { location, describeError }) {
|
|
39
|
+
const { data, error, mutate } = api.useSessions();
|
|
40
|
+
const answer = useCallback(async (session, approvalId, value) => {
|
|
41
|
+
const refusal = await api.answerApproval(session.machineId, session.id, approvalId, value);
|
|
42
|
+
if (refusal) return describeError(refusal);
|
|
43
|
+
mutate();
|
|
44
|
+
return null;
|
|
45
|
+
}, [
|
|
46
|
+
api,
|
|
47
|
+
describeError,
|
|
48
|
+
mutate
|
|
49
|
+
]);
|
|
50
|
+
const loading = data === void 0;
|
|
51
|
+
return {
|
|
52
|
+
loading,
|
|
53
|
+
failed: error && !data ? { message: loadErrorMessage(error, describeError) } : null,
|
|
54
|
+
showComposer: loading || location.startable.length > 0 || location.down.length > 0,
|
|
55
|
+
explainEmpty: !loading && (data.sessions ?? []).length === 0,
|
|
56
|
+
answer
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The start page's parameters from its parsed query; any that is not a
|
|
60
|
+
* single string is left out. */
|
|
61
|
+
function startSearch(search) {
|
|
62
|
+
const text = (value) => typeof value === "string" ? value : void 0;
|
|
63
|
+
return {
|
|
64
|
+
session: text(search["session"]),
|
|
65
|
+
fromChat: text(search["fromChat"])
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Follows a link that names only a session, since the machine listed with
|
|
69
|
+
* it is not known where the link was printed: once the listing names the
|
|
70
|
+
* session, `open` takes it to the session. */
|
|
71
|
+
function useSessionLink(session, listing, open) {
|
|
72
|
+
const found = session ? listing.sessions.find((s) => s.id === session) : void 0;
|
|
73
|
+
const latest = useRef(open);
|
|
74
|
+
latest.current = open;
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (found) latest.current(found);
|
|
77
|
+
}, [found]);
|
|
78
|
+
if (!session) return null;
|
|
79
|
+
return found || listing.loading ? "resolving" : "missing";
|
|
80
|
+
}
|
|
81
|
+
/** The card over the composer while a link to a session is followed: news
|
|
82
|
+
* while it is looked for, a warning once the listing lacks it. Null without
|
|
83
|
+
* a link. */
|
|
84
|
+
function sessionLinkNotice(state, session, t) {
|
|
85
|
+
if (state === null) return null;
|
|
86
|
+
const missing = state === "missing";
|
|
87
|
+
const values = { id: session ?? "" };
|
|
88
|
+
return {
|
|
89
|
+
text: missing ? t("start.linkMissing", values) : t("start.linkResolving", values),
|
|
90
|
+
tone: missing ? "warning" : "neutral"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The commands a new session's composer offers: the directory's palette,
|
|
94
|
+
* led by the Claude Code account choice on a machine where Claude Code
|
|
95
|
+
* runs. Archiving needs a session, so it is not offered. */
|
|
96
|
+
function startCommands(palette, machine, t) {
|
|
97
|
+
return paletteOptions(palette, runsClaude(machine) ? t("claude.choose") : void 0);
|
|
98
|
+
}
|
|
99
|
+
function machineMenu(location, t) {
|
|
100
|
+
const picked = location.machine?.id;
|
|
101
|
+
const startable = location.startable.map((m) => ({
|
|
102
|
+
id: m.id,
|
|
103
|
+
label: m.name,
|
|
104
|
+
description: isComputer(m) ? t("machine.computer") : t("machine.resource"),
|
|
105
|
+
checked: m.id === picked,
|
|
106
|
+
disabled: false
|
|
107
|
+
}));
|
|
108
|
+
const down = location.down.map((m) => ({
|
|
109
|
+
id: m.id,
|
|
110
|
+
label: m.name,
|
|
111
|
+
description: machineHint(m, t)?.text,
|
|
112
|
+
checked: false,
|
|
113
|
+
disabled: true
|
|
114
|
+
}));
|
|
115
|
+
return {
|
|
116
|
+
startable,
|
|
117
|
+
down,
|
|
118
|
+
downLabel: startable.length > 0 && down.length > 0 ? t("start.notAnswering", { count: down.length }) : void 0,
|
|
119
|
+
pick: (id) => {
|
|
120
|
+
if (id !== picked) location.pickMachine(id);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** The chip naming the machine a session starts on, which opens the
|
|
125
|
+
* `machineMenu`: the machine's name after a dot in the `success` tone, since
|
|
126
|
+
* only a machine that answers can be chosen, or, until one is, a call to
|
|
127
|
+
* choose one and no dot. While the machines are still being listed
|
|
128
|
+
* (`finding`), it says so and opens nothing. `label` names the chip's action. */
|
|
129
|
+
function machineChip(machine, t, finding = false) {
|
|
130
|
+
if (finding) {
|
|
131
|
+
const text = t("start.findingMachines");
|
|
132
|
+
return {
|
|
133
|
+
text,
|
|
134
|
+
label: text,
|
|
135
|
+
dot: null
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const choose = t("start.chooseMachine");
|
|
139
|
+
return machine ? {
|
|
140
|
+
text: machine.name,
|
|
141
|
+
label: choose,
|
|
142
|
+
dot: "success"
|
|
143
|
+
} : {
|
|
144
|
+
text: choose,
|
|
145
|
+
label: choose,
|
|
146
|
+
dot: null
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** How a start carries a chat handed to it: it waits until the chat has
|
|
150
|
+
* arrived, since starting sooner would quietly leave it behind, then sends
|
|
151
|
+
* the chat after what was typed. A chat that failed to load holds nothing
|
|
152
|
+
* back. */
|
|
153
|
+
function chatHandoffStart(handoff, t, describeError) {
|
|
154
|
+
const conversation = handoff?.conversation;
|
|
155
|
+
return {
|
|
156
|
+
waiting: !!handoff && !conversation && !handoff.error,
|
|
157
|
+
firstPrompt: conversation ? (typed) => chatHandoffPrompt(conversation, typed, t) : void 0,
|
|
158
|
+
placeholder: conversation ? t("start.handoffPlaceholder") : t("start.composerPlaceholder"),
|
|
159
|
+
notice: handoff ? handoffNotice(handoff, t, describeError) : null
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function handoffNotice({ conversation, error }, t, describeError) {
|
|
163
|
+
if (error) return {
|
|
164
|
+
text: describeError(error),
|
|
165
|
+
failed: true,
|
|
166
|
+
tone: "warning"
|
|
167
|
+
};
|
|
168
|
+
return {
|
|
169
|
+
text: conversation ? t("start.handoffCard", { title: conversation.title || t("start.handoffUntitled") }) : t("start.handoffLoading"),
|
|
170
|
+
failed: false,
|
|
171
|
+
tone: "neutral"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export { START_SHORTLIST, chatHandoffStart, machineChip, machineMenu, sessionLinkNotice, shortlistMark, startCommands, startSearch, startShortlist, useSessionLink, useStartScreen, waitingQuestions, waitingSince };
|
package/dist/startSession.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface PwCodeStartLocation<M> {
|
|
|
29
29
|
startable: M[];
|
|
30
30
|
/** The machines listed but not answering, computers first, so a missing one can be traced. */
|
|
31
31
|
down: M[];
|
|
32
|
-
/** The machine picked, or the only one a session can start on. */
|
|
32
|
+
/** The machine picked, else the one picked last time, or the only one a session can start on. */
|
|
33
33
|
machine: M | undefined;
|
|
34
34
|
pickMachine: (id: string) => void;
|
|
35
35
|
/** The directories the machine's sessions worked in, newest first. */
|
|
@@ -43,17 +43,49 @@ export interface PwCodeStartLocation<M> {
|
|
|
43
43
|
/** Turns to typing a directory, keeping what was typed so far. */
|
|
44
44
|
typeOtherDirectory: () => void;
|
|
45
45
|
}
|
|
46
|
-
export declare function useStartLocation<M extends PwCodeStartMachine>(machines: readonly M[], sessions: readonly Pick<PwCodeSession, 'machineId' | 'workspace' | 'updatedAt'>[]
|
|
46
|
+
export declare function useStartLocation<M extends PwCodeStartMachine>(machines: readonly M[], sessions: readonly Pick<PwCodeSession, 'machineId' | 'workspace' | 'updatedAt'>[],
|
|
47
|
+
/** The machine the host saved the last pick of. */
|
|
48
|
+
preference?: {
|
|
49
|
+
saved: string | undefined;
|
|
50
|
+
remember: (id: string) => void;
|
|
51
|
+
}): PwCodeStartLocation<M>;
|
|
52
|
+
export interface PwCodeStartPermission {
|
|
53
|
+
mode: PermissionMode;
|
|
54
|
+
pick: (mode: PermissionMode) => void;
|
|
55
|
+
/** The widest mode the machine lets a picker offer, for `permissionModesUpTo`. */
|
|
56
|
+
ceiling: string | undefined;
|
|
57
|
+
/** The modes the machine's pw code takes, for `permissionModesUpTo`. */
|
|
58
|
+
accepted: readonly string[] | undefined;
|
|
59
|
+
}
|
|
47
60
|
/** The mode a session starts in: the one saved, or one picked on this visit,
|
|
48
61
|
* within what the machine allows. A pick holds until the visit ends, so one
|
|
49
62
|
* the host declines to save, such as bypass, still applies to this start. */
|
|
50
63
|
export declare function useStartPermissionMode(preference: {
|
|
51
64
|
saved: PermissionMode;
|
|
52
65
|
remember: (mode: PermissionMode) => void;
|
|
53
|
-
}, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined):
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
}, machine: Pick<PwCodeStartMachine, 'remoteMaxPermissionMode' | 'permissionModes'> | undefined): PwCodeStartPermission;
|
|
67
|
+
/** Which of a start's controls can change, each disabled while true. */
|
|
68
|
+
export interface PwCodeStartControls {
|
|
69
|
+
disabled: {
|
|
70
|
+
model: boolean;
|
|
71
|
+
effort: boolean;
|
|
72
|
+
allocation: boolean;
|
|
73
|
+
/** The account, as its panel and the model picker change it. */
|
|
74
|
+
account: boolean;
|
|
75
|
+
/** The chip naming the account, which opens its panel. */
|
|
76
|
+
accountChip: boolean;
|
|
77
|
+
/** Removing an image waiting to go with the first prompt. */
|
|
78
|
+
images: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** A session can start on the machine, so the model picker reads its Claude
|
|
81
|
+
* models before it opens. */
|
|
82
|
+
canStart: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** The model, effort, allocation, account and images hold while a session
|
|
85
|
+
* starts. The permission mode, machine and directory are not held, and a pick
|
|
86
|
+
* there reaches only the next start. Until a machine is chosen, its model,
|
|
87
|
+
* effort and account chip wait for one too. */
|
|
88
|
+
export declare function startControls(machine: Pick<PwCodeStartMachine, 'status' | 'remoteStart'> | undefined, starting: boolean): PwCodeStartControls;
|
|
57
89
|
type ClaudeMachine = Pick<PwCodeStartMachine, 'id' | 'claudeInstalled' | 'claudeCodeAllowed'>;
|
|
58
90
|
type StartApi = Pick<PwCodeApi, 'useClaudeModels' | 'useClaudeAccountNames' | 'createSession' | 'sendMessage' | 'useSessions'>;
|
|
59
91
|
/** A model last picked for a session, and the allocation that billed it. */
|
|
@@ -79,12 +111,14 @@ export interface PwCodeStartModel {
|
|
|
79
111
|
* machine where the machine still lists it. */
|
|
80
112
|
export declare function useStartModel(api: Pick<StartApi, 'useClaudeModels' | 'useClaudeAccountNames'>, { machine, platform, last, account: accountPreference, handedOff, }: {
|
|
81
113
|
machine: ClaudeMachine | undefined;
|
|
114
|
+
/** The platform's models and the host's selected model and allocation,
|
|
115
|
+
* such as its chat's; `usePlatformDefaults` gives all three to a host
|
|
116
|
+
* without one. */
|
|
82
117
|
platform: {
|
|
83
118
|
/** The platform's models: undefined while they load, or when they failed to. */
|
|
84
119
|
models: readonly {
|
|
85
120
|
id: string;
|
|
86
121
|
}[] | undefined;
|
|
87
|
-
/** The host's selected model and allocation. */
|
|
88
122
|
model: string | null | undefined;
|
|
89
123
|
allocation: string | null | undefined;
|
|
90
124
|
};
|
package/dist/startSession.js
CHANGED
|
@@ -25,10 +25,11 @@ function startingMode(mode, machine) {
|
|
|
25
25
|
const accepted = machine?.permissionModes ?? void 0;
|
|
26
26
|
return clampPermissionMode(clampPermissionMode(mode, mode, accepted), machine?.remoteMaxPermissionMode, accepted);
|
|
27
27
|
}
|
|
28
|
-
function useStartLocation(machines, sessions) {
|
|
28
|
+
function useStartLocation(machines, sessions, preference) {
|
|
29
29
|
const { startable, down } = useMemo(() => startMachines(machines), [machines]);
|
|
30
30
|
const [machineId, setMachineId] = useState("");
|
|
31
|
-
const
|
|
31
|
+
const wanted = machineId || preference?.saved;
|
|
32
|
+
const machine = startable.find((m) => m.id === wanted) ?? (startable.length === 1 ? startable[0] : void 0);
|
|
32
33
|
const directories = useMemo(() => recentDirectories(sessions, machine?.id), [sessions, machine]);
|
|
33
34
|
const [dir, setDir] = useState("");
|
|
34
35
|
const [typing, setTyping] = useState(false);
|
|
@@ -50,6 +51,7 @@ function useStartLocation(machines, sessions) {
|
|
|
50
51
|
machine,
|
|
51
52
|
pickMachine: (id) => {
|
|
52
53
|
setMachineId(id);
|
|
54
|
+
preference?.remember(id);
|
|
53
55
|
setDir("");
|
|
54
56
|
setTyping(false);
|
|
55
57
|
},
|
|
@@ -74,7 +76,27 @@ function useStartPermissionMode(preference, machine) {
|
|
|
74
76
|
pick: (mode) => {
|
|
75
77
|
setPicked(mode);
|
|
76
78
|
preference.remember(mode);
|
|
77
|
-
}
|
|
79
|
+
},
|
|
80
|
+
ceiling: machine?.remoteMaxPermissionMode,
|
|
81
|
+
accepted: machine?.permissionModes ?? void 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** The model, effort, allocation, account and images hold while a session
|
|
85
|
+
* starts. The permission mode, machine and directory are not held, and a pick
|
|
86
|
+
* there reaches only the next start. Until a machine is chosen, its model,
|
|
87
|
+
* effort and account chip wait for one too. */
|
|
88
|
+
function startControls(machine, starting) {
|
|
89
|
+
const none = !machine;
|
|
90
|
+
return {
|
|
91
|
+
disabled: {
|
|
92
|
+
model: starting || none,
|
|
93
|
+
effort: starting || none,
|
|
94
|
+
allocation: starting,
|
|
95
|
+
account: starting,
|
|
96
|
+
accountChip: none,
|
|
97
|
+
images: starting
|
|
98
|
+
},
|
|
99
|
+
canStart: !!machine && canStartHere(machine)
|
|
78
100
|
};
|
|
79
101
|
}
|
|
80
102
|
function useRememberedAccount(api, machine, saved) {
|
|
@@ -231,4 +253,4 @@ function useStartSession(api, options) {
|
|
|
231
253
|
start
|
|
232
254
|
};
|
|
233
255
|
}
|
|
234
|
-
export { startMachines, startingMode, useStartLocation, useStartModel, useStartPermissionMode, useStartSession };
|
|
256
|
+
export { startControls, startMachines, startingMode, useStartLocation, useStartModel, useStartPermissionMode, useStartSession };
|
package/dist/todos.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TodoItem } from '@parallelworks/ui/ai/headless';
|
|
2
|
+
import type { PwCodeHistoryItem } from './types.js';
|
|
3
|
+
/** TodoWrite's whole list, which its arguments carry; null when they hold none. */
|
|
4
|
+
export declare function todosFromArgs(argsJSON: string): TodoItem[] | null;
|
|
5
|
+
/** The list a TodoWrite call pins above the composer: empty once every task
|
|
6
|
+
* is done, as the terminal drops it, and null for arguments that hold no
|
|
7
|
+
* list, which leave the pinned one as it was. */
|
|
8
|
+
export declare function pinnedTodos(argsJSON: string): TodoItem[] | null;
|
|
9
|
+
/** The list a conversation's history leaves pinned: its last TodoWrite's. */
|
|
10
|
+
export declare function todosFromHistory(history: PwCodeHistoryItem[]): TodoItem[];
|
|
11
|
+
/** What a task reads as: what it is doing while it runs, otherwise what it is. */
|
|
12
|
+
export declare function todoLabel(todo: TodoItem): string;
|
|
13
|
+
/** At most `limit` tasks, from the one before the running one, and how many
|
|
14
|
+
* are left out by whether they are done, since the tail can hide pending ones. */
|
|
15
|
+
export declare function todoWindow(todos: TodoItem[], limit: number): {
|
|
16
|
+
visible: TodoItem[];
|
|
17
|
+
hiddenDone: number;
|
|
18
|
+
hiddenOther: number;
|
|
19
|
+
};
|
|
20
|
+
export interface PwCodeTodoRow {
|
|
21
|
+
todo: TodoItem;
|
|
22
|
+
label: string;
|
|
23
|
+
/** Its status in words, for a screen reader beside the status mark. */
|
|
24
|
+
statusWord: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PwCodeTodoPanel {
|
|
27
|
+
title: string;
|
|
28
|
+
/** How far along the list is, such as "2 of 5 done". */
|
|
29
|
+
progress: string;
|
|
30
|
+
/** What the running task is doing, which a folded panel names. */
|
|
31
|
+
running: string | null;
|
|
32
|
+
rows: PwCodeTodoRow[];
|
|
33
|
+
/** The control that shows every task, or fewer again; null when every task fits. */
|
|
34
|
+
more: {
|
|
35
|
+
label: string;
|
|
36
|
+
all: boolean;
|
|
37
|
+
toggle: () => void;
|
|
38
|
+
} | null;
|
|
39
|
+
}
|
|
40
|
+
/** The pinned task list as the terminal's panel shows it: a few rows from the
|
|
41
|
+
* one before the running task, and a control for the rest. */
|
|
42
|
+
export declare function useTodoPanel(todos: TodoItem[]): PwCodeTodoPanel;
|