sideby 0.19.1 → 0.21.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 +7 -4
- package/ai-tasks.json +28 -0
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +22 -1
- package/dist/src/cli/commands.js +815 -21
- package/dist/src/cli/format.d.ts +4 -0
- package/dist/src/cli/format.js +42 -4
- package/dist/src/cli/json-schemas.js +334 -4
- package/dist/src/cli/main.js +159 -13
- package/dist/src/core/accounts.d.ts +6 -0
- package/dist/src/core/accounts.js +12 -0
- package/dist/src/core/autostart.d.ts +11 -0
- package/dist/src/core/autostart.js +32 -5
- package/dist/src/core/browser-profiles.d.ts +23 -2
- package/dist/src/core/browser-profiles.js +148 -37
- package/dist/src/core/claude-settings-file.d.ts +18 -0
- package/dist/src/core/claude-settings-file.js +52 -3
- package/dist/src/core/config.d.ts +5 -0
- package/dist/src/core/config.js +12 -1
- package/dist/src/core/edit-settings.d.ts +7 -0
- package/dist/src/core/edit-settings.js +10 -5
- package/dist/src/core/history-group.d.ts +28 -0
- package/dist/src/core/history-group.js +47 -0
- package/dist/src/core/history-index.d.ts +145 -0
- package/dist/src/core/history-index.js +447 -0
- package/dist/src/core/history-project.d.ts +13 -0
- package/dist/src/core/history-project.js +87 -0
- package/dist/src/core/history.d.ts +210 -0
- package/dist/src/core/history.js +952 -0
- package/dist/src/core/inbound.d.ts +62 -0
- package/dist/src/core/inbound.js +215 -0
- package/dist/src/core/launch.d.ts +9 -1
- package/dist/src/core/launch.js +58 -24
- package/dist/src/core/live-sessions-copy.d.ts +5 -0
- package/dist/src/core/live-sessions-copy.js +46 -0
- package/dist/src/core/live-sessions-procs.d.ts +89 -0
- package/dist/src/core/live-sessions-procs.js +296 -0
- package/dist/src/core/live-sessions-title.d.ts +28 -0
- package/dist/src/core/live-sessions-title.js +80 -0
- package/dist/src/core/live-sessions.d.ts +68 -0
- package/dist/src/core/live-sessions.js +163 -0
- package/dist/src/core/login-check.d.ts +15 -0
- package/dist/src/core/login-check.js +32 -0
- package/dist/src/core/messages.d.ts +83 -0
- package/dist/src/core/messages.js +433 -0
- package/dist/src/core/project-categories.d.ts +14 -0
- package/dist/src/core/project-categories.js +48 -0
- package/dist/src/core/quota-fetch.d.ts +3 -3
- package/dist/src/core/quota-fetch.js +5 -5
- package/dist/src/core/quota-levels.d.ts +5 -0
- package/dist/src/core/quota-levels.js +5 -0
- package/dist/src/core/remote-control.d.ts +2 -0
- package/dist/src/core/remote-control.js +34 -59
- package/dist/src/core/run-link.d.ts +76 -0
- package/dist/src/core/run-link.js +245 -0
- package/dist/src/core/same-login.d.ts +4 -3
- package/dist/src/core/same-login.js +10 -7
- package/dist/src/core/session-select.d.ts +31 -0
- package/dist/src/core/session-select.js +44 -0
- package/dist/src/families/browser.d.ts +7 -18
- package/dist/src/families/browser.js +19 -8
- package/dist/src/families/claude/deliver.d.ts +2 -0
- package/dist/src/families/claude/deliver.js +43 -0
- package/dist/src/families/claude/history.d.ts +2 -0
- package/dist/src/families/claude/history.js +192 -0
- package/dist/src/families/claude/live-sessions.d.ts +13 -0
- package/dist/src/families/claude/live-sessions.js +117 -0
- package/dist/src/families/claude/messaging.d.ts +69 -0
- package/dist/src/families/claude/messaging.js +165 -0
- package/dist/src/families/claude/mod.d.ts +26 -0
- package/dist/src/families/claude/mod.js +105 -0
- package/dist/src/families/claude/session-files.d.ts +21 -0
- package/dist/src/families/claude/session-files.js +54 -0
- package/dist/src/families/codex/deliver.d.ts +5 -0
- package/dist/src/families/codex/deliver.js +76 -0
- package/dist/src/families/codex/history.d.ts +7 -0
- package/dist/src/families/codex/history.js +174 -0
- package/dist/src/families/codex/index.js +2 -0
- package/dist/src/families/codex/live-sessions.d.ts +12 -0
- package/dist/src/families/codex/live-sessions.js +193 -0
- package/dist/src/families/codex/quota.d.ts +3 -0
- package/dist/src/families/codex/quota.js +123 -0
- package/dist/src/families/codex/rate-limits.js +2 -0
- package/dist/src/families/codex/rollout.js +1 -1
- package/dist/src/families/grok/browser.d.ts +3 -0
- package/dist/src/families/grok/browser.js +5 -0
- package/dist/src/families/grok/history.d.ts +2 -0
- package/dist/src/families/grok/history.js +157 -0
- package/dist/src/families/grok/live-sessions.d.ts +4 -0
- package/dist/src/families/grok/live-sessions.js +80 -0
- package/dist/src/families/grok/login-key.d.ts +14 -0
- package/dist/src/families/grok/login-key.js +37 -0
- package/dist/src/families/history.d.ts +20 -0
- package/dist/src/families/history.js +81 -0
- package/dist/src/families/live-sessions.d.ts +26 -0
- package/dist/src/families/live-sessions.js +9 -0
- package/dist/src/families/login-keys.js +5 -1
- package/dist/src/families/messaging.d.ts +27 -0
- package/dist/src/families/messaging.js +6 -0
- package/dist/src/families/pi/history.d.ts +2 -0
- package/dist/src/families/pi/history.js +124 -0
- package/dist/src/families/pi/live-sessions.d.ts +2 -0
- package/dist/src/families/pi/live-sessions.js +70 -0
- package/dist/src/families/shared/history-text.d.ts +65 -0
- package/dist/src/families/shared/history-text.js +261 -0
- package/dist/src/menubar/hotkey.d.ts +86 -0
- package/dist/src/menubar/hotkey.js +159 -0
- package/dist/src/menubar/script.d.ts +2 -0
- package/dist/src/menubar/script.js +118 -22
- package/dist/src/menubar/snapshot.d.ts +8 -4
- package/dist/src/menubar/snapshot.js +45 -13
- package/dist/src/menubar/strings.d.ts +24 -6
- package/dist/src/menubar/strings.js +24 -6
- package/dist/src/panel/handler.d.ts +69 -0
- package/dist/src/panel/handler.js +686 -15
- package/dist/src/panel/i18n.d.ts +305 -3
- package/dist/src/panel/i18n.js +622 -18
- package/dist/src/panel/orca.d.ts +48 -0
- package/dist/src/panel/orca.js +153 -0
- package/dist/src/panel/page-logic.d.ts +260 -13
- package/dist/src/panel/page-logic.js +497 -1
- package/dist/src/panel/page-script.js +2309 -204
- package/dist/src/panel/page-styles.js +398 -32
- package/dist/src/panel/page.js +1 -0
- package/dist/src/plugins/check.js +16 -4
- package/dist/src/plugins/loader.d.ts +8 -1
- package/dist/src/plugins/loader.js +72 -7
- package/dist/src/runtime.d.ts +5 -0
- package/dist/src/runtime.js +27 -5
- package/dist/src/types.d.ts +116 -1
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.js +5 -0
- package/mods/claude/.claude-plugin/plugin.json +7 -0
- package/mods/claude/hooks/hooks.json +1 -0
- package/mods/claude/hooks/register.js +261 -0
- package/package.json +5 -2
- package/schemas/autostart.json +74 -1
- package/schemas/browser-set.json +110 -0
- package/schemas/browser.json +22 -2
- package/schemas/config.json +26 -1
- package/schemas/history-index.json +209 -0
- package/schemas/history-projects.json +133 -0
- package/schemas/history-show.json +275 -0
- package/schemas/history.json +410 -0
- package/schemas/menubar-hotkey.json +139 -0
- package/schemas/menubar-snapshot.json +36 -2
- package/schemas/menubar.json +74 -1
- package/schemas/messages-inbound.json +258 -0
- package/schemas/messages.json +164 -0
- package/schemas/send.json +165 -0
- package/schemas/sessions-copy.json +113 -0
- package/schemas/sessions-open-run.json +97 -0
- package/schemas/sessions.json +237 -0
- package/skills/sideby/SKILL.md +10 -5
- package/skills/sideby/references/accounts.md +11 -0
- package/skills/sideby/references/ai-tasks.md +17 -1
- package/skills/sideby/references/panel.md +6 -4
- package/skills/sideby/references/quota.md +2 -2
- package/skills/sideby/references/sessions.md +79 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { claudeHistory } from './claude/history.js';
|
|
2
|
+
import { codexHistory } from './codex/history.js';
|
|
3
|
+
import { grokHistory } from './grok/history.js';
|
|
4
|
+
import { piHistory } from './pi/history.js';
|
|
5
|
+
import { cutText, SESSION_TEXT_MAX, TITLE_MAX, titleFromText } from './shared/history-text.js';
|
|
6
|
+
const READERS = new Map([claudeHistory, codexHistory, grokHistory, piHistory].map((r) => [r.family, r]));
|
|
7
|
+
const PLUGIN_READERS = new WeakMap();
|
|
8
|
+
async function* nothing() { }
|
|
9
|
+
const strings = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string');
|
|
10
|
+
/**
|
|
11
|
+
* A plugin reader's Session as the built-in readers give one: the wrong shape is an error naming the Family, and its
|
|
12
|
+
* text and title are cut to the same limits (a plugin cannot fill the History Index or the Panel without bound).
|
|
13
|
+
*/
|
|
14
|
+
export function checkParsed(family, p) {
|
|
15
|
+
if (p === undefined || p === null)
|
|
16
|
+
return undefined;
|
|
17
|
+
const bad = (what) => new Error(`family ${family}: history.parse returned ${what}; fix the plugin's reader or remove its history`);
|
|
18
|
+
if (typeof p !== 'object')
|
|
19
|
+
throw bad('something that is not an object');
|
|
20
|
+
if (typeof p.sessionId !== 'string' || !p.sessionId)
|
|
21
|
+
throw bad('no sessionId');
|
|
22
|
+
if (!strings(p.prompts) || !strings(p.replies))
|
|
23
|
+
throw bad('prompts or replies that are not lists of text');
|
|
24
|
+
if (typeof p.messages !== 'number' || !Number.isFinite(p.messages))
|
|
25
|
+
throw bad('a messages count that is not a number');
|
|
26
|
+
let room = SESSION_TEXT_MAX;
|
|
27
|
+
let cut = Boolean(p.cut);
|
|
28
|
+
const keep = (list) => list.flatMap((t) => {
|
|
29
|
+
if (room <= 0) {
|
|
30
|
+
cut = true;
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const kept = cutText(t, room);
|
|
34
|
+
if (kept.length < t.length)
|
|
35
|
+
cut = true;
|
|
36
|
+
room -= kept.length;
|
|
37
|
+
return [kept];
|
|
38
|
+
});
|
|
39
|
+
const text = (v) => (typeof v === 'string' && v ? v : undefined);
|
|
40
|
+
const prompts = keep(p.prompts);
|
|
41
|
+
const replies = keep(p.replies);
|
|
42
|
+
return {
|
|
43
|
+
...p,
|
|
44
|
+
cwd: text(p.cwd),
|
|
45
|
+
gitRoot: text(p.gitRoot),
|
|
46
|
+
title: text(p.title) && titleFromText(p.title).slice(0, TITLE_MAX),
|
|
47
|
+
branch: text(p.branch),
|
|
48
|
+
model: text(p.model),
|
|
49
|
+
startedAt: text(p.startedAt),
|
|
50
|
+
updatedAt: text(p.updatedAt),
|
|
51
|
+
parent: text(p.parent),
|
|
52
|
+
script: Boolean(p.script),
|
|
53
|
+
messages: Math.max(0, Math.floor(p.messages)),
|
|
54
|
+
prompts,
|
|
55
|
+
replies,
|
|
56
|
+
...(cut ? { cut: true } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The Session History reader of a Family: a built-in one's, else the `history` a plugin Family declares. */
|
|
60
|
+
export function historyReader(familyId, families) {
|
|
61
|
+
const builtin = READERS.get(familyId);
|
|
62
|
+
if (builtin)
|
|
63
|
+
return builtin;
|
|
64
|
+
const h = families?.get(familyId)?.history;
|
|
65
|
+
if (!h)
|
|
66
|
+
return undefined;
|
|
67
|
+
let r = PLUGIN_READERS.get(h);
|
|
68
|
+
if (!r) {
|
|
69
|
+
r = {
|
|
70
|
+
family: familyId,
|
|
71
|
+
list: (account, problems) => h.list(account, problems),
|
|
72
|
+
parse: async (file, account) => checkParsed(familyId, await h.parse(file, account)),
|
|
73
|
+
messages: (path) => h.messages(path),
|
|
74
|
+
toolText: (path) => (h.toolText ? h.toolText(path) : nothing()),
|
|
75
|
+
resumeArgs: (id) => h.resumeArgs(id),
|
|
76
|
+
...(h.titles ? { titles: (account) => h.titles(account) } : {}),
|
|
77
|
+
};
|
|
78
|
+
PLUGIN_READERS.set(h, r);
|
|
79
|
+
}
|
|
80
|
+
return r;
|
|
81
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LiveSessionStatus } from '../core/live-sessions.ts';
|
|
2
|
+
import type { ProcessView } from '../core/live-sessions-procs.ts';
|
|
3
|
+
import type { Account } from '../types.ts';
|
|
4
|
+
/** A Live Session as a Family reads it, before sideby adds the Account's name, the Label and the commands. */
|
|
5
|
+
export interface RawLiveSession {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
/** The Host's own title, when its files give one. */
|
|
8
|
+
title?: string;
|
|
9
|
+
status: LiveSessionStatus;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
pid?: number;
|
|
12
|
+
startedAt?: string;
|
|
13
|
+
updatedAt?: string;
|
|
14
|
+
guessed: boolean;
|
|
15
|
+
transcript?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface LiveSessionReader {
|
|
18
|
+
family: string;
|
|
19
|
+
/**
|
|
20
|
+
* The Account's Live Sessions. Reads only the Host's session files, never a credential file; throws only when
|
|
21
|
+
* the Account cannot be read at all (a malformed record is skipped and named in `problems`).
|
|
22
|
+
*/
|
|
23
|
+
read(account: Account, procs: ProcessView, problems: string[]): Promise<RawLiveSession[]>;
|
|
24
|
+
}
|
|
25
|
+
/** The Live Session reader of a built-in Family id, if it has one. */
|
|
26
|
+
export declare function liveSessionReader(familyId: string): LiveSessionReader | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { claudeLiveSessions } from './claude/live-sessions.js';
|
|
2
|
+
import { codexLiveSessions } from './codex/live-sessions.js';
|
|
3
|
+
import { grokLiveSessions } from './grok/live-sessions.js';
|
|
4
|
+
import { piLiveSessions } from './pi/live-sessions.js';
|
|
5
|
+
const READERS = new Map([claudeLiveSessions, codexLiveSessions, grokLiveSessions, piLiveSessions].map((r) => [r.family, r]));
|
|
6
|
+
/** The Live Session reader of a built-in Family id, if it has one. */
|
|
7
|
+
export function liveSessionReader(familyId) {
|
|
8
|
+
return READERS.get(familyId);
|
|
9
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { codexLoginKey } from './codex/login-key.js';
|
|
2
|
+
import { grokLoginKey } from './grok/login-key.js';
|
|
2
3
|
/**
|
|
3
4
|
* Family id → its Login Key reader. Must list exactly the Families of `LOGIN_KEY_FAMILIES` (core/same-login.ts);
|
|
4
5
|
* a test keeps the two in step.
|
|
5
6
|
*/
|
|
6
|
-
export const LOGIN_KEY_READERS = new Map([
|
|
7
|
+
export const LOGIN_KEY_READERS = new Map([
|
|
8
|
+
['codex', codexLoginKey],
|
|
9
|
+
['grok', grokLoginKey],
|
|
10
|
+
]);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LiveSession } from '../core/live-sessions.ts';
|
|
2
|
+
import type { ProcessView } from '../core/live-sessions-procs.ts';
|
|
3
|
+
import type { MessageDeps, MessageStatus } from '../core/messages.ts';
|
|
4
|
+
import type { Runtime } from '../runtime.ts';
|
|
5
|
+
import type { Account } from '../types.ts';
|
|
6
|
+
export interface DeliveryRequest {
|
|
7
|
+
rt: Runtime;
|
|
8
|
+
/** The target Session, known by its process. */
|
|
9
|
+
to: LiveSession;
|
|
10
|
+
pid: number;
|
|
11
|
+
acct: Account;
|
|
12
|
+
/** What the session receives (`deliveredText`). */
|
|
13
|
+
text: string;
|
|
14
|
+
/** The line that points at the kept Message file, for a channel that must not carry the text itself. */
|
|
15
|
+
pasteText: string;
|
|
16
|
+
/** A fresh look at the processes. */
|
|
17
|
+
procs: ProcessView;
|
|
18
|
+
deps: MessageDeps;
|
|
19
|
+
}
|
|
20
|
+
export interface Delivery {
|
|
21
|
+
status: MessageStatus;
|
|
22
|
+
/** Plain-language note: why paste is needed, or what the target must still do. */
|
|
23
|
+
note?: string;
|
|
24
|
+
/** The Host took it but shows it only after the user approves it in the target's terminal (ADR-0045). */
|
|
25
|
+
needsApproval?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const DELIVERERS: Readonly<Record<string, (req: DeliveryRequest) => Promise<Delivery>>>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// pi's Session History (spec §3.33): one `sessions/<cwd>/<time>_<id>.jsonl` per Session under the Account's agent
|
|
2
|
+
// folder (tried with pi 1.3.0 on 2026-10-20). The first line is a `session` header with `id`, `cwd` and
|
|
3
|
+
// `timestamp`; `message` records hold the conversation. pi keeps no title, so the first prompt is the Session Title.
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { blockText, dirEntries, fileLines, historyFile, isoTime, jsonText, parseRecord, SessionText, str, titleFromText, typedText, } from '../shared/history-text.js';
|
|
6
|
+
function toolNames(m) {
|
|
7
|
+
if (!Array.isArray(m.content))
|
|
8
|
+
return [];
|
|
9
|
+
return m.content
|
|
10
|
+
.filter((b) => b && typeof b === 'object' && b.type === 'toolCall')
|
|
11
|
+
.map((b) => str(b.name) ?? 'tool');
|
|
12
|
+
}
|
|
13
|
+
export const piHistory = {
|
|
14
|
+
family: 'pi',
|
|
15
|
+
async list(account) {
|
|
16
|
+
const out = [];
|
|
17
|
+
const root = join(account.dir, 'sessions');
|
|
18
|
+
for (const c of await dirEntries(root)) {
|
|
19
|
+
if (!c.isDirectory())
|
|
20
|
+
continue;
|
|
21
|
+
for (const e of await dirEntries(join(root, c.name))) {
|
|
22
|
+
if (!e.isFile() || !e.name.endsWith('.jsonl'))
|
|
23
|
+
continue;
|
|
24
|
+
const f = await historyFile(join(root, c.name, e.name));
|
|
25
|
+
if (f)
|
|
26
|
+
out.push(f);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
},
|
|
31
|
+
async parse(file) {
|
|
32
|
+
let sessionId;
|
|
33
|
+
let cwd;
|
|
34
|
+
let model;
|
|
35
|
+
let startedAt;
|
|
36
|
+
let updatedAt;
|
|
37
|
+
const text = new SessionText();
|
|
38
|
+
for await (const line of fileLines(file.path)) {
|
|
39
|
+
const rec = parseRecord(line);
|
|
40
|
+
if (!rec)
|
|
41
|
+
continue;
|
|
42
|
+
const at = isoTime(rec.timestamp);
|
|
43
|
+
if (at) {
|
|
44
|
+
startedAt ??= at;
|
|
45
|
+
updatedAt = at;
|
|
46
|
+
}
|
|
47
|
+
if (rec.type === 'session') {
|
|
48
|
+
sessionId ??= str(rec.id);
|
|
49
|
+
cwd ??= str(rec.cwd);
|
|
50
|
+
}
|
|
51
|
+
else if (rec.type === 'message') {
|
|
52
|
+
const m = (rec.message ?? {});
|
|
53
|
+
if (m.role === 'user') {
|
|
54
|
+
const t = typedText(blockText(m.content));
|
|
55
|
+
if (t)
|
|
56
|
+
text.prompt(t);
|
|
57
|
+
}
|
|
58
|
+
else if (m.role === 'assistant') {
|
|
59
|
+
model = str(m.model) ?? model;
|
|
60
|
+
const t = blockText(m.content).trim();
|
|
61
|
+
if (t)
|
|
62
|
+
text.reply(t);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!sessionId || !text.count)
|
|
67
|
+
return undefined;
|
|
68
|
+
const s = {
|
|
69
|
+
sessionId,
|
|
70
|
+
titleFrom: text.first ? 'prompt' : 'none',
|
|
71
|
+
messages: text.count,
|
|
72
|
+
script: false,
|
|
73
|
+
prompts: text.prompts,
|
|
74
|
+
replies: text.replies,
|
|
75
|
+
...(text.cut ? { cut: true } : {}),
|
|
76
|
+
};
|
|
77
|
+
if (text.first)
|
|
78
|
+
s.title = titleFromText(text.first);
|
|
79
|
+
if (cwd)
|
|
80
|
+
s.cwd = cwd;
|
|
81
|
+
if (model)
|
|
82
|
+
s.model = model;
|
|
83
|
+
if (startedAt)
|
|
84
|
+
s.startedAt = startedAt;
|
|
85
|
+
if (updatedAt)
|
|
86
|
+
s.updatedAt = updatedAt;
|
|
87
|
+
return s;
|
|
88
|
+
},
|
|
89
|
+
async *messages(path) {
|
|
90
|
+
for await (const line of fileLines(path)) {
|
|
91
|
+
if (!line.includes('"type":"message"'))
|
|
92
|
+
continue;
|
|
93
|
+
const rec = parseRecord(line);
|
|
94
|
+
const m = (rec?.message ?? {});
|
|
95
|
+
const at = isoTime(rec?.timestamp);
|
|
96
|
+
const when = at ? { at } : {};
|
|
97
|
+
if (m.role === 'user') {
|
|
98
|
+
const text = typedText(blockText(m.content));
|
|
99
|
+
if (text)
|
|
100
|
+
yield { role: 'user', text, ...when };
|
|
101
|
+
}
|
|
102
|
+
else if (m.role === 'assistant') {
|
|
103
|
+
const text = blockText(m.content).trim();
|
|
104
|
+
if (text)
|
|
105
|
+
yield { role: 'assistant', text, ...when };
|
|
106
|
+
for (const tool of toolNames(m))
|
|
107
|
+
yield { role: 'tool', text: tool, tool, ...when };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async *toolText(path) {
|
|
112
|
+
for await (const line of fileLines(path)) {
|
|
113
|
+
if (!line.includes('"type":"message"'))
|
|
114
|
+
continue;
|
|
115
|
+
const m = (parseRecord(line)?.message ?? {});
|
|
116
|
+
if (m.role === 'toolResult')
|
|
117
|
+
yield jsonText(m.content);
|
|
118
|
+
else if (m.role === 'assistant' && Array.isArray(m.content))
|
|
119
|
+
for (const b of m.content)
|
|
120
|
+
if (b?.type === 'toolCall')
|
|
121
|
+
yield jsonText(b.arguments);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
2
|
+
import { basename, join, resolve } from 'node:path';
|
|
3
|
+
import { accountProcesses, headerField, isoOf, readHead } from '../../core/live-sessions-procs.js';
|
|
4
|
+
const piDirIs = (account, dir) => dir ? resolve(dir) === resolve(account.dir) : account.isMain;
|
|
5
|
+
async function newestSession(dir, problems, ref) {
|
|
6
|
+
let entries;
|
|
7
|
+
try {
|
|
8
|
+
entries = await readdir(join(dir, 'sessions'), { recursive: true, withFileTypes: true });
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
// Only a missing directory means "no sessions yet"; another error is the Account's to report.
|
|
12
|
+
if (err.code === 'ENOENT')
|
|
13
|
+
return undefined;
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
let best;
|
|
17
|
+
for (const e of entries) {
|
|
18
|
+
if (!e.isFile() || !e.name.endsWith('.jsonl'))
|
|
19
|
+
continue;
|
|
20
|
+
const path = join(e.parentPath, e.name);
|
|
21
|
+
try {
|
|
22
|
+
const { mtimeMs } = await stat(path);
|
|
23
|
+
if (!best || mtimeMs > best.mtimeMs)
|
|
24
|
+
best = { path, mtimeMs };
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
// Removed while scanning is fine; anything else is said.
|
|
28
|
+
if (err.code !== 'ENOENT')
|
|
29
|
+
problems.push(`${ref}: could not read ${path} (${err.code}); check that the file is readable`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return best;
|
|
33
|
+
}
|
|
34
|
+
export const piLiveSessions = {
|
|
35
|
+
family: 'pi',
|
|
36
|
+
async read(account, procs, problems) {
|
|
37
|
+
const mine = await accountProcesses(procs, { bin: 'pi', envName: 'PI_CODING_AGENT_DIR', belongs: (dir) => piDirIs(account, dir) }, problems);
|
|
38
|
+
if (!mine.length)
|
|
39
|
+
return [];
|
|
40
|
+
const newest = await newestSession(account.dir, problems, account.ref);
|
|
41
|
+
if (!newest)
|
|
42
|
+
return [];
|
|
43
|
+
let head;
|
|
44
|
+
try {
|
|
45
|
+
head = await readHead(newest.path);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err.code === 'ENOENT')
|
|
49
|
+
return [];
|
|
50
|
+
problems.push(`${account.ref}: could not read ${newest.path} (${err.code}); check that the file is readable`);
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
const sessionId = headerField(head, 'id');
|
|
54
|
+
if (!sessionId)
|
|
55
|
+
return [];
|
|
56
|
+
const cwd = headerField(head, 'cwd');
|
|
57
|
+
const started = headerField(head, 'timestamp');
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
sessionId,
|
|
61
|
+
...(cwd ? { title: basename(cwd), cwd } : {}),
|
|
62
|
+
status: 'unknown',
|
|
63
|
+
...(started ? { startedAt: started } : {}),
|
|
64
|
+
...(isoOf(newest.mtimeMs) ? { updatedAt: isoOf(newest.mtimeMs) } : {}),
|
|
65
|
+
guessed: true,
|
|
66
|
+
transcript: newest.path,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type Dirent } from 'node:fs';
|
|
2
|
+
/** The longest record line read; a longer one (a huge tool output, never a typed prompt) is skipped unread. */
|
|
3
|
+
export declare const MAX_LINE_BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* Every non-empty line of a file, streamed: a huge file never sits in memory at once, a line over `MAX_LINE_BYTES`
|
|
6
|
+
* is dropped as it streams by, and stopping early closes the file.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fileLines(path: string): AsyncGenerator<string>;
|
|
9
|
+
/** A JSON object from one record line, or undefined for a line that is cut, still being written or not an object. */
|
|
10
|
+
export declare function parseRecord(line: string): Record<string, unknown> | undefined;
|
|
11
|
+
export declare const str: (v: unknown) => string | undefined;
|
|
12
|
+
/** The `text` of every `{ type: <kind>, text }` block of a message's content; a string content is its own text. */
|
|
13
|
+
export declare function blockText(content: unknown, kinds?: readonly string[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* `text` without its injected blocks. Blocks may nest (a reminder quoting a reminder), so each one ends at the close
|
|
16
|
+
* tag that balances its own open tag; a block left open runs to the end of the text, which is cut too.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stripInjected(text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* What a person typed in a "user" turn: injected blocks cut out, a slash command shown as `/name args`, a shell
|
|
21
|
+
* escape as `!cmd`. Empty when nothing typed is left.
|
|
22
|
+
*/
|
|
23
|
+
export declare function typedText(text: string): string;
|
|
24
|
+
/** The most text of one Session that is kept for search, in characters; the rest is counted but not kept. */
|
|
25
|
+
export declare const SESSION_TEXT_MAX: number;
|
|
26
|
+
/** The first `max` UTF-16 units of `t`, one fewer when the cut would leave half of a surrogate pair. */
|
|
27
|
+
export declare function cutText(t: string, max: number): string;
|
|
28
|
+
/** Collects a Session's prompts and replies while a reader parses it, keeping at most `SESSION_TEXT_MAX` of text. */
|
|
29
|
+
export declare class SessionText {
|
|
30
|
+
#private;
|
|
31
|
+
readonly prompts: string[];
|
|
32
|
+
readonly replies: string[];
|
|
33
|
+
/** Prompts plus replies, kept or not. */
|
|
34
|
+
count: number;
|
|
35
|
+
/** The first prompt, kept whole for the title. */
|
|
36
|
+
first: string | undefined;
|
|
37
|
+
/** True once some text was left out for the limit. */
|
|
38
|
+
cut: boolean;
|
|
39
|
+
constructor(max?: number);
|
|
40
|
+
prompt(t: string): void;
|
|
41
|
+
reply(t: string): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Every string, number and boolean inside a JSON value, one per line: the text of a tool's input or output, without
|
|
45
|
+
* the `type` names of content blocks.
|
|
46
|
+
*/
|
|
47
|
+
export declare function jsonText(v: unknown): string;
|
|
48
|
+
/** The longest Session Title sideby shows; the Host's own titles are cut the same way. */
|
|
49
|
+
export declare const TITLE_MAX = 120;
|
|
50
|
+
/** A one-line title from a prompt: its first non-empty line, spaces collapsed, cut at `TITLE_MAX` characters. */
|
|
51
|
+
export declare function titleFromText(text: string): string;
|
|
52
|
+
/** ISO time of a value a Host wrote as an ISO string or epoch milliseconds/seconds; undefined when it is neither. */
|
|
53
|
+
export declare function isoTime(v: unknown): string | undefined;
|
|
54
|
+
/** A record file as a `HistoryFile`, signed by size, mtime and inode; undefined when it vanished meanwhile. */
|
|
55
|
+
export declare function historyFile(path: string, extra?: {
|
|
56
|
+
parent?: string;
|
|
57
|
+
also?: string;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
path: string;
|
|
60
|
+
sig: string;
|
|
61
|
+
mtimeMs: number;
|
|
62
|
+
parent?: string;
|
|
63
|
+
} | undefined>;
|
|
64
|
+
/** The entries of a folder; empty when it does not exist, other errors thrown. */
|
|
65
|
+
export declare function dirEntries(dir: string): Promise<Dirent[]>;
|