@picassohq/cli 0.0.0-stage → 1.0.1
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/agents/browser_agent.yaml +53 -0
- package/agents/code_reviewer.yaml +49 -0
- package/agents/codebase_investigator.yaml +70 -0
- package/agents/design_auditor.yaml +50 -0
- package/agents/devex_auditor.yaml +50 -0
- package/agents/doc_writer.yaml +54 -0
- package/agents/engineering_architect.yaml +51 -0
- package/agents/generalist.yaml +55 -0
- package/agents/migration_planner.yaml +51 -0
- package/agents/product_reviewer.yaml +48 -0
- package/agents/qa_operator.yaml +52 -0
- package/agents/release_engineer.yaml +50 -0
- package/agents/security_auditor.yaml +62 -0
- package/agents/test_writer.yaml +52 -0
- package/assets/first-light-lockup.png +0 -0
- package/assets/first-light-tagline.png +0 -0
- package/assets/house/README.md +26 -0
- package/assets/house/auraone-banner.png +0 -0
- package/assets/house/auraone-logo.png +0 -0
- package/assets/house/kiro-prism-banner.png +0 -0
- package/assets/house/kiro-prism-logo.png +0 -0
- package/assets/house/picasso-banner.png +0 -0
- package/assets/house/picasso-logo.png +0 -0
- package/assets/wordmark-app.png +0 -0
- package/assets/wordmark-tight.png +0 -0
- package/assets/wordmark.png +0 -0
- package/design/styles.css +1042 -0
- package/dist/build-info.json +37 -0
- package/dist/index.js +3028 -0
- package/goals/cli-hardening.yaml +40 -0
- package/goals/repo-maintenance.yaml +40 -0
- package/package.json +49 -4
- package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
- package/runtime/dsh/picasso-ecosystem.community.json +185 -0
- package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
- package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
- package/runtime/dsh/picasso-isolation.patch.yml +25 -0
- package/runtime/dsh/picasso-providers.patch.yml +373 -0
- package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
- package/runtime/dsh/picasso-sdk.patch.yml +204 -0
- package/runtime/engine-manifest.json +214 -0
- package/runtime/package.json +6 -0
- package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
- package/runtime/packages/picasso-cache-probe/index.js +477 -0
- package/runtime/packages/picasso-cache-probe/package.json +38 -0
- package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-commands/fresh-review.js +573 -0
- package/runtime/packages/picasso-commands/index.js +497 -0
- package/runtime/packages/picasso-commands/package.json +28 -0
- package/runtime/packages/picasso-instructions/conflicts.js +115 -0
- package/runtime/packages/picasso-instructions/formats.js +145 -0
- package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
- package/runtime/packages/picasso-instructions/glob.js +114 -0
- package/runtime/packages/picasso-instructions/globals.js +90 -0
- package/runtime/packages/picasso-instructions/imports.js +123 -0
- package/runtime/packages/picasso-instructions/index.js +326 -0
- package/runtime/packages/picasso-instructions/modes.js +64 -0
- package/runtime/packages/picasso-instructions/package.json +30 -0
- package/runtime/packages/picasso-instructions/parse.js +134 -0
- package/runtime/packages/picasso-instructions/report.js +161 -0
- package/runtime/packages/picasso-instructions/resolve.js +939 -0
- package/runtime/packages/picasso-instructions/scan.js +181 -0
- package/runtime/packages/picasso-instructions/settings.js +150 -0
- package/runtime/packages/picasso-instructions/skills.js +345 -0
- package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
- package/runtime/packages/picasso-lean-context/index.js +6049 -0
- package/runtime/packages/picasso-lean-context/package.json +26 -0
- package/runtime/packages/picasso-lean-context/timeline.js +417 -0
- package/runtime/packages/picasso-librarian/classify.js +146 -0
- package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-librarian/index.js +878 -0
- package/runtime/packages/picasso-librarian/notes.js +159 -0
- package/runtime/packages/picasso-librarian/package.json +34 -0
- package/runtime/packages/picasso-librarian/state.js +478 -0
- package/runtime/packages/picasso-memory/index.js +1184 -0
- package/runtime/packages/picasso-memory/package.json +21 -0
- package/runtime/packages/picasso-model-router/connections.js +895 -0
- package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
- package/runtime/packages/picasso-model-router/index.js +1081 -0
- package/runtime/packages/picasso-model-router/package.json +30 -0
- package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-options/index.js +263 -0
- package/runtime/packages/picasso-options/package.json +28 -0
- package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-progress-reports/index.js +267 -0
- package/runtime/packages/picasso-progress-reports/package.json +30 -0
- package/runtime/packages/picasso-progress-reports/report.js +235 -0
- package/runtime/packages/picasso-sdk-server/aside.js +128 -0
- package/runtime/packages/picasso-sdk-server/connections.js +38 -0
- package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
- package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
- package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
- package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
- package/runtime/packages/picasso-sdk-server/goal.js +131 -0
- package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
- package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
- package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
- package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
- package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
- package/runtime/packages/picasso-sdk-server/index.js +886 -0
- package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
- package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
- package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
- package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
- package/runtime/packages/picasso-sdk-server/package.json +50 -0
- package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
- package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
- package/runtime/packages/picasso-sdk-server/queue.js +322 -0
- package/runtime/packages/picasso-sdk-server/requester.js +43 -0
- package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
- package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
- package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
- package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
- package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
- package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
- package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
- package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
- package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
- package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
- package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
- package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
- package/runtime/packages/picasso-web-search/backends.js +350 -0
- package/runtime/packages/picasso-web-search/config.js +121 -0
- package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
- package/runtime/packages/picasso-web-search/failure.js +111 -0
- package/runtime/packages/picasso-web-search/format.js +35 -0
- package/runtime/packages/picasso-web-search/index.js +66 -0
- package/runtime/packages/picasso-web-search/package.json +38 -0
- package/runtime/packages/picasso-web-search/router.js +155 -0
- package/runtime/packages/picasso-x-reader/circle.js +324 -0
- package/runtime/packages/picasso-x-reader/command.js +169 -0
- package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
- package/runtime/packages/picasso-x-reader/index.js +170 -0
- package/runtime/packages/picasso-x-reader/package.json +39 -0
- package/runtime/packages/picasso-x-reader/read.js +370 -0
- package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
- package/runtime/packages/picasso-x-reader/settings.js +131 -0
- package/runtime/packages/picasso-x-reader/urls.js +154 -0
- package/runtime/packages/picasso-x-reader/xmd.js +512 -0
- package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
- package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
- package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
- package/runtime/plugins/picasso-auto-approve/package.json +28 -0
- package/runtime/plugins/picasso-browser/index.js +424 -0
- package/runtime/plugins/picasso-browser/package.json +28 -0
- package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
- package/runtime/plugins/picasso-checkpoints/index.js +885 -0
- package/runtime/plugins/picasso-checkpoints/package.json +29 -0
- package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
- package/runtime/plugins/picasso-commands/index.js +497 -0
- package/runtime/plugins/picasso-commands/package.json +28 -0
- package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
- package/runtime/plugins/picasso-instructions/formats.js +145 -0
- package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
- package/runtime/plugins/picasso-instructions/glob.js +114 -0
- package/runtime/plugins/picasso-instructions/globals.js +90 -0
- package/runtime/plugins/picasso-instructions/imports.js +123 -0
- package/runtime/plugins/picasso-instructions/index.js +326 -0
- package/runtime/plugins/picasso-instructions/modes.js +64 -0
- package/runtime/plugins/picasso-instructions/package.json +30 -0
- package/runtime/plugins/picasso-instructions/parse.js +134 -0
- package/runtime/plugins/picasso-instructions/report.js +161 -0
- package/runtime/plugins/picasso-instructions/resolve.js +939 -0
- package/runtime/plugins/picasso-instructions/scan.js +181 -0
- package/runtime/plugins/picasso-instructions/settings.js +150 -0
- package/runtime/plugins/picasso-instructions/skills.js +345 -0
- package/runtime/plugins/picasso-lean-context/index.js +6049 -0
- package/runtime/plugins/picasso-lean-context/package.json +26 -0
- package/runtime/plugins/picasso-lean-context/timeline.js +417 -0
- package/runtime/plugins/picasso-librarian/classify.js +146 -0
- package/runtime/plugins/picasso-librarian/index.js +878 -0
- package/runtime/plugins/picasso-librarian/notes.js +159 -0
- package/runtime/plugins/picasso-librarian/package.json +34 -0
- package/runtime/plugins/picasso-librarian/state.js +478 -0
- package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
- package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
- package/runtime/plugins/picasso-mail/inbox.js +207 -0
- package/runtime/plugins/picasso-mail/index.js +293 -0
- package/runtime/plugins/picasso-mail/package.json +22 -0
- package/runtime/plugins/picasso-memory/index.js +1184 -0
- package/runtime/plugins/picasso-memory/package.json +21 -0
- package/runtime/plugins/picasso-model-router/connections.js +895 -0
- package/runtime/plugins/picasso-model-router/index.js +1081 -0
- package/runtime/plugins/picasso-model-router/package.json +30 -0
- package/runtime/plugins/picasso-options/index.js +263 -0
- package/runtime/plugins/picasso-options/package.json +28 -0
- package/runtime/plugins/picasso-progress-reports/index.js +267 -0
- package/runtime/plugins/picasso-progress-reports/package.json +30 -0
- package/runtime/plugins/picasso-progress-reports/report.js +235 -0
- package/runtime/plugins/picasso-provider-models/index.js +436 -0
- package/runtime/plugins/picasso-provider-models/package.json +28 -0
- package/runtime/plugins/picasso-repo-index/index.js +1850 -0
- package/runtime/plugins/picasso-repo-index/package.json +28 -0
- package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
- package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
- package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
- package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
- package/runtime/plugins/picasso-trackers/index.js +895 -0
- package/runtime/plugins/picasso-trackers/package.json +28 -0
- package/runtime/plugins/picasso-web-search/backends.js +350 -0
- package/runtime/plugins/picasso-web-search/config.js +121 -0
- package/runtime/plugins/picasso-web-search/failure.js +111 -0
- package/runtime/plugins/picasso-web-search/format.js +35 -0
- package/runtime/plugins/picasso-web-search/index.js +66 -0
- package/runtime/plugins/picasso-web-search/package.json +38 -0
- package/runtime/plugins/picasso-web-search/router.js +155 -0
- package/runtime/plugins/picasso-x-reader/circle.js +324 -0
- package/runtime/plugins/picasso-x-reader/command.js +169 -0
- package/runtime/plugins/picasso-x-reader/index.js +170 -0
- package/runtime/plugins/picasso-x-reader/package.json +39 -0
- package/runtime/plugins/picasso-x-reader/read.js +370 -0
- package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
- package/runtime/plugins/picasso-x-reader/settings.js +131 -0
- package/runtime/plugins/picasso-x-reader/urls.js +154 -0
- package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
- package/runtime/relay/attachment-text.mjs +737 -0
- package/runtime/relay/companion/companion.css +126 -0
- package/runtime/relay/companion/companion.js +648 -0
- package/runtime/relay/companion/icon.svg +5 -0
- package/runtime/relay/companion/index.html +25 -0
- package/runtime/relay/companion/manifest.json +13 -0
- package/runtime/relay/companion/sw.js +41 -0
- package/runtime/relay/main.mjs +37252 -0
- package/runtime/relay/model-listing.mjs +614 -0
- package/runtime/relay/versions-routes.mjs +1198 -0
- package/runtime/verify-plugins.mjs +205 -0
- package/runtime-lock/package-lock.json +10779 -0
- package/runtime-lock/package.json +7 -0
- package/scripts/install-runtime.mjs +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Progress-report detection and parsing — the one contract every surface follows.
|
|
2
|
+
//
|
|
3
|
+
// A progress report is real assistant text (C1: parsed and condensed, never invented) that has
|
|
4
|
+
// 1. a heading: a line whose first 100 characters (markdown stripped) say "progress" or "status"
|
|
5
|
+
// (`**Progress report** · 45%`, `## Status update`, `10-Minute Progress Status Update 1. …`), and
|
|
6
|
+
// 2. at least MIN_FIELDS distinct known field labels after it, each followed by `:` (or ` - `/` — `).
|
|
7
|
+
//
|
|
8
|
+
// The labels cover both Picasso's compact format (Goal / Done / In progress / Next / Blockers) and the
|
|
9
|
+
// ten-field policy format (Original task / goal, Total work packages, Fully completed, Partially completed
|
|
10
|
+
// (in-progress), Not started, Blocked, Overall completion %, Work completed in the last 10 minutes,
|
|
11
|
+
// Current work, Next steps). Labels are found anywhere in the body, so a report squeezed onto one line
|
|
12
|
+
// (`… 1. Original Task / Goal: X 2. Total work packages: 7 …`) parses the same as a multi-line one.
|
|
13
|
+
//
|
|
14
|
+
// Mirrors: packages/tui/src/progress-report.ts (TS) and
|
|
15
|
+
// apps/mac/Picasso/Features/Thread/ProgressReport.swift (Swift). All three run
|
|
16
|
+
// test/fixtures/reports.json, so they agree on every fixture.
|
|
17
|
+
|
|
18
|
+
export const MIN_FIELDS = 3;
|
|
19
|
+
export const ONE_LINE_PART_MAX = 72;
|
|
20
|
+
|
|
21
|
+
/** Field key → label alternation (longest first inside each; the scan takes the earliest match position). */
|
|
22
|
+
export const FIELD_LABELS = Object.freeze([
|
|
23
|
+
['recent', String.raw`(?:work\s+)?(?:done|completed|finished)\s+(?:in\s+)?(?:the\s+)?(?:last|past)\s+10\s*-?\s*m(?:in(?:ute)?s?)?|(?:in\s+)?(?:the\s+)?(?:last|past)\s+10\s*-?\s*m(?:in(?:ute)?s?)?|since\s+(?:the\s+)?last\s+(?:update|report)`],
|
|
24
|
+
['goal', String.raw`original\s+(?:task|goal|request)(?:\s*\/\s*goal)?|task\s*\/\s*goal|goal|objective`],
|
|
25
|
+
['total', String.raw`total(?:\s+number\s+of)?\s+work[\s-]*packages|total\s+(?:steps|tasks)|work[\s-]*packages`],
|
|
26
|
+
['inProgress', String.raw`partially\s+completed|in[\s-]+progress`],
|
|
27
|
+
['notStarted', String.raw`not[\s-]+(?:yet\s+)?started|remaining`],
|
|
28
|
+
['done', String.raw`fully\s+completed|completed|done|finished`],
|
|
29
|
+
['blocked', String.raw`blocked(?:\s+work\s+packages)?|blockers?`],
|
|
30
|
+
['percent', String.raw`overall(?:\s+(?:completion|progress))?(?:\s*%)?|completion(?:\s*%)?|percent(?:age)?(?:\s+complete)?`],
|
|
31
|
+
['current', String.raw`current(?:ly)?(?:\s+work)?|working\s+on|now`],
|
|
32
|
+
['next', String.raw`next(?:\s+steps?)?|up\s+next`],
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const LABEL_SOURCE = FIELD_LABELS.map(([key, source]) => `(?<${key}>${source})`).join('|');
|
|
36
|
+
// A label starts a line, follows a list marker / number / separator, and ends at `:` (or a spaced dash),
|
|
37
|
+
// optionally after `**`, a parenthetical, or `%`.
|
|
38
|
+
const LABEL_RE = new RegExp(
|
|
39
|
+
String.raw`(?:^|(?<=[\s>*_#•·|(]|\d[.)]))(?:${LABEL_SOURCE})(?:\*\*|__)?\s*(?:\([^)\n]{0,40}\))?\s*(?:\*\*|__)?\s*(?::|\s[-–—]\s)`,
|
|
40
|
+
'gimu',
|
|
41
|
+
);
|
|
42
|
+
const HEADING_RE = /\b(?:progress|status)\b/iu;
|
|
43
|
+
const PERCENT_RE = /(\d{1,3}(?:\.\d+)?)\s*%/u;
|
|
44
|
+
|
|
45
|
+
/** Markdown emphasis/heading marks removed, so labels and headings match plain text. */
|
|
46
|
+
export function stripMarkdown(text) {
|
|
47
|
+
return String(text ?? '')
|
|
48
|
+
.replace(/\r\n?/gu, '\n')
|
|
49
|
+
.replace(/^\s{0,3}#{1,6}\s+/gmu, '')
|
|
50
|
+
.replace(/\*\*|__|`/gu, '')
|
|
51
|
+
.replace(/^\s{0,3}>\s?/gmu, '');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const collapse = (value) => value.replace(/\s+/gu, ' ').trim();
|
|
55
|
+
|
|
56
|
+
/** One field value: whitespace collapsed, a trailing list number (`… 3.`) and separators removed. */
|
|
57
|
+
function cleanValue(raw) {
|
|
58
|
+
let value = collapse(raw);
|
|
59
|
+
value = value.replace(/(?:^|\s)(?:\d{1,2}[.)]|[-*•·|])\s*$/u, '').trim();
|
|
60
|
+
value = value.replace(/^[-*•·|]\s*/u, '').trim();
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The first sentence-ish clause of a value, capped for one line. */
|
|
65
|
+
export function clip(value, max = ONE_LINE_PART_MAX) {
|
|
66
|
+
const line = collapse(String(value ?? ''));
|
|
67
|
+
if (line.length <= max) return line;
|
|
68
|
+
const cut = line.slice(0, max - 1);
|
|
69
|
+
const space = cut.lastIndexOf(' ');
|
|
70
|
+
return `${(space > max * 0.6 ? cut.slice(0, space) : cut).replace(/[\s,;:.]+$/u, '')}…`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The heading line's index in `lines`, or -1. */
|
|
74
|
+
function headingIndex(lines) {
|
|
75
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
76
|
+
const line = lines[index].trim();
|
|
77
|
+
if (line.length === 0) continue;
|
|
78
|
+
if (HEADING_RE.test(line.slice(0, 100))) return index;
|
|
79
|
+
}
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Parse `text` as a progress report. Returns `undefined` when it is not one; otherwise
|
|
85
|
+
* `{heading, title, percent?, method?, fields: {key: value}, fieldCount, oneLine}` built only from the text.
|
|
86
|
+
*/
|
|
87
|
+
export function parseProgressReport(text) {
|
|
88
|
+
if (typeof text !== 'string' || text.length === 0) return undefined;
|
|
89
|
+
const plain = stripMarkdown(text);
|
|
90
|
+
const lines = plain.split('\n');
|
|
91
|
+
const at = headingIndex(lines);
|
|
92
|
+
if (at < 0) return undefined;
|
|
93
|
+
const body = lines.slice(at).join('\n');
|
|
94
|
+
const matches = [];
|
|
95
|
+
LABEL_RE.lastIndex = 0;
|
|
96
|
+
for (let match = LABEL_RE.exec(body); match !== null; match = LABEL_RE.exec(body)) {
|
|
97
|
+
const key = Object.entries(match.groups ?? {}).find(([, value]) => value !== undefined)?.[0];
|
|
98
|
+
if (key !== undefined) matches.push({ key, start: match.index, end: match.index + match[0].length });
|
|
99
|
+
if (match[0].length === 0) LABEL_RE.lastIndex += 1;
|
|
100
|
+
}
|
|
101
|
+
const fields = {};
|
|
102
|
+
for (let index = 0; index < matches.length; index += 1) {
|
|
103
|
+
const { key, end } = matches[index];
|
|
104
|
+
if (fields[key] !== undefined) continue;
|
|
105
|
+
const stop = index + 1 < matches.length ? matches[index + 1].start : body.length;
|
|
106
|
+
const value = cleanValue(body.slice(end, stop));
|
|
107
|
+
if (value.length > 0) fields[key] = value;
|
|
108
|
+
}
|
|
109
|
+
const fieldCount = Object.keys(fields).length;
|
|
110
|
+
if (fieldCount < MIN_FIELDS) return undefined;
|
|
111
|
+
const headingLine = lines[at].trim();
|
|
112
|
+
// A one-line report runs its fields into the heading line: the heading is the text before the first label,
|
|
113
|
+
// without the list number (`… Update 1.`) that introduced it.
|
|
114
|
+
const inline = matches.length > 0 && matches[0].start < headingLine.length;
|
|
115
|
+
const heading = inline
|
|
116
|
+
? collapse(headingLine.slice(0, matches[0].start)).replace(/(?:\s*(?:\d{1,2}[.)]|[-*•·|]))+\s*$/u, '').trim()
|
|
117
|
+
: collapse(headingLine);
|
|
118
|
+
let percent;
|
|
119
|
+
let method;
|
|
120
|
+
for (const source of [fields.percent, heading, body]) {
|
|
121
|
+
if (typeof source !== 'string') continue;
|
|
122
|
+
const found = PERCENT_RE.exec(source);
|
|
123
|
+
if (found === null) continue;
|
|
124
|
+
const value = Number(found[1]);
|
|
125
|
+
if (!Number.isFinite(value) || value < 0 || value > 100) continue;
|
|
126
|
+
percent = Math.round(value);
|
|
127
|
+
const rest = source.slice(found.index + found[0].length).replace(/^[\s·:,-]+/u, '');
|
|
128
|
+
const paren = /^\(([^)]{1,120})\)/u.exec(rest);
|
|
129
|
+
if (source !== body && (paren || rest.length > 0)) method = clip(paren ? paren[1] : rest.split(/\s[·|]\s/u)[0], 80);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
const now = fields.current ?? fields.inProgress;
|
|
133
|
+
const parts = [];
|
|
134
|
+
if (percent !== undefined) parts.push(`${percent}%`);
|
|
135
|
+
if (now) parts.push(`Now: ${clip(now)}`);
|
|
136
|
+
if (fields.next) parts.push(`Next: ${clip(fields.next)}`);
|
|
137
|
+
if (parts.length < 2 && fields.done) parts.push(`Done: ${clip(fields.done)}`);
|
|
138
|
+
// The card title: the heading without its inline percent/method tail (`Progress report · 45% (…)` → `Progress report`).
|
|
139
|
+
const title = (heading.split(/\s[·|–—-]\s|\s\d{1,3}(?:\.\d+)?\s*%/u)[0] ?? '').replace(/[\s:·|–—-]+$/u, '').trim();
|
|
140
|
+
return {
|
|
141
|
+
heading: heading || 'Progress report',
|
|
142
|
+
title: title || 'Progress report',
|
|
143
|
+
...(percent === undefined ? {} : { percent }),
|
|
144
|
+
...(method ? { method } : {}),
|
|
145
|
+
fields,
|
|
146
|
+
fieldCount,
|
|
147
|
+
oneLine: parts.join(' · '),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Whether `text` is a progress report (see `parseProgressReport`). */
|
|
152
|
+
export function isProgressReport(text) {
|
|
153
|
+
return parseProgressReport(text) !== undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ── The full report as markdown ───────────────────────────────────────────────────────────────────────────────
|
|
157
|
+
//
|
|
158
|
+
// The model often writes a report as plain `Label: text` lines, which every surface drew as run-on prose. The
|
|
159
|
+
// expanded card renders `formatReportMarkdown(text)` instead: the heading line goes (the card already shows the title
|
|
160
|
+
// and percent), each `Label: value` line gets a bold label, and a value of several `;`-separated items (outside
|
|
161
|
+
// parentheses, brackets and code) becomes a bullet list under its label. Words are never changed (C1). A one-line
|
|
162
|
+
// report (fields on the heading line) is returned as written.
|
|
163
|
+
|
|
164
|
+
/** A line that starts with a short label and `:` — optional list marker, optional `**`/`__` around the label. */
|
|
165
|
+
const LABEL_LINE_RE = /^(\s*)((?:[-*•]|\d{1,2}[.)])\s+)?(?:\*\*|__)?([A-Za-z][A-Za-z0-9 /%()'&-]{0,48}?)(?:\*\*|__)?\s*:(?:\*\*|__)?\s+(\S.*)$/u;
|
|
166
|
+
const MAX_LABEL_WORDS = 8;
|
|
167
|
+
|
|
168
|
+
/** `value` split at `;` outside (), [], {} and backticks; parts trimmed, empties dropped. */
|
|
169
|
+
export function splitReportItems(value) {
|
|
170
|
+
const parts = [];
|
|
171
|
+
let depth = 0;
|
|
172
|
+
let code = false;
|
|
173
|
+
let start = 0;
|
|
174
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
175
|
+
const char = value[index];
|
|
176
|
+
if (char === '`') code = !code;
|
|
177
|
+
else if (code) continue;
|
|
178
|
+
else if (char === '(' || char === '[' || char === '{') depth += 1;
|
|
179
|
+
else if ((char === ')' || char === ']' || char === '}') && depth > 0) depth -= 1;
|
|
180
|
+
else if (char === ';' && depth === 0) {
|
|
181
|
+
parts.push(value.slice(start, index));
|
|
182
|
+
start = index + 1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
parts.push(value.slice(start));
|
|
186
|
+
return parts.map((part) => part.trim()).filter((part) => part.length > 0);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The report text as markdown with bold labels and per-item bullets (see above). */
|
|
190
|
+
export function formatReportMarkdown(text) {
|
|
191
|
+
const source = String(text ?? '').replace(/\r\n?/gu, '\n');
|
|
192
|
+
const lines = source.split('\n');
|
|
193
|
+
const plain = stripMarkdown(source).split('\n');
|
|
194
|
+
let heading = -1;
|
|
195
|
+
for (let index = 0; index < plain.length; index += 1) {
|
|
196
|
+
const line = plain[index].trim();
|
|
197
|
+
if (line === '') continue;
|
|
198
|
+
if (HEADING_RE.test(line.slice(0, 100))) heading = index;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
if (heading >= 0) {
|
|
202
|
+
LABEL_RE.lastIndex = 0;
|
|
203
|
+
if (LABEL_RE.test(plain[heading])) return source.trim();
|
|
204
|
+
LABEL_RE.lastIndex = 0;
|
|
205
|
+
}
|
|
206
|
+
const out = [];
|
|
207
|
+
const blank = () => { if (out.length > 0 && out[out.length - 1] !== '') out.push(''); };
|
|
208
|
+
let fence = false;
|
|
209
|
+
lines.forEach((line, index) => {
|
|
210
|
+
if (index === heading) return;
|
|
211
|
+
if (/^\s*(```|~~~)/u.test(line)) fence = !fence;
|
|
212
|
+
const match = fence ? null : LABEL_LINE_RE.exec(line);
|
|
213
|
+
const label = match?.[3]?.trim() ?? '';
|
|
214
|
+
if (match === null || label.split(/\s+/u).length > MAX_LABEL_WORDS) {
|
|
215
|
+
out.push(line);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const [, indent, marker, , value] = match;
|
|
219
|
+
// A list item (`3. Done: …`) keeps its list tight: bold label only, no blank lines, no nested bullets.
|
|
220
|
+
if (marker !== undefined || indent !== '') {
|
|
221
|
+
out.push(`${indent}${marker ?? ''}**${label}:** ${value.trim()}`);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const items = splitReportItems(value);
|
|
225
|
+
blank();
|
|
226
|
+
if (items.length >= 2) {
|
|
227
|
+
out.push(`**${label}:**`);
|
|
228
|
+
for (const item of items) out.push(`- ${item}`);
|
|
229
|
+
} else {
|
|
230
|
+
out.push(`**${label}:** ${value.trim()}`);
|
|
231
|
+
}
|
|
232
|
+
out.push('');
|
|
233
|
+
});
|
|
234
|
+
return out.join('\n').replace(/\n{3,}/gu, '\n\n').trim();
|
|
235
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Side questions (`/btw`): a throwaway session seeded from the live one.
|
|
2
|
+
//
|
|
3
|
+
// session/aside/open { sessionId, newSessionId? }
|
|
4
|
+
// -> { sessionId, boundary, seeded }
|
|
5
|
+
// Forks the source through its newest event while a turn is running (the
|
|
6
|
+
// engine closes the copied open turn), else at its latest completed turn, so
|
|
7
|
+
// a side question sees the work in progress; then opens
|
|
8
|
+
// the fork in this process (dsh `session/resume`), carries over the
|
|
9
|
+
// source's live model selection and switches the fork to a read-only
|
|
10
|
+
// sandbox. A source with no completed turn yet gets an empty session.
|
|
11
|
+
// The source session is never written. Prompt the aside with the stock
|
|
12
|
+
// `session/prompt` + `session/wait`; its notifications carry its own id.
|
|
13
|
+
// session/aside/close { sessionId }
|
|
14
|
+
// -> { closed: true, removed }
|
|
15
|
+
// Cancels a running aside, disposes its agent and deletes its session log
|
|
16
|
+
// and workspace archive, so it never appears among saved sessions.
|
|
17
|
+
//
|
|
18
|
+
// Approvals asked inside an aside are rejected without reaching the client:
|
|
19
|
+
// a side question answers from context, it does not act.
|
|
20
|
+
|
|
21
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
22
|
+
import { rm } from 'node:fs/promises';
|
|
23
|
+
import { homedir } from 'node:os';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
export const ASIDE_METHODS = Object.freeze(['session/aside/open', 'session/aside/close']);
|
|
27
|
+
|
|
28
|
+
/** Session ids that are safe as one path segment (an aside's log directory is deleted by id). */
|
|
29
|
+
const SESSION_DIR_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
30
|
+
|
|
31
|
+
/** Delete every `$DSH_HOME/sessions/<project>/<sessionId>` directory; returns the removed paths. */
|
|
32
|
+
export async function removeSessionLogs(sessionId, dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')) {
|
|
33
|
+
if (typeof sessionId !== 'string' || !SESSION_DIR_ID.test(sessionId)) throw new TypeError(`refusing to delete a session log for id ${JSON.stringify(sessionId)}`);
|
|
34
|
+
const root = join(dshHome, 'sessions');
|
|
35
|
+
let projects = [];
|
|
36
|
+
try {
|
|
37
|
+
projects = readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory());
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
const removed = [];
|
|
42
|
+
for (const project of projects) {
|
|
43
|
+
const dir = join(root, project.name, sessionId);
|
|
44
|
+
if (!existsSync(dir)) continue;
|
|
45
|
+
await rm(dir, { recursive: true, force: true });
|
|
46
|
+
removed.push(dir);
|
|
47
|
+
}
|
|
48
|
+
return removed;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {object} deps
|
|
53
|
+
* @param {(sessionId: string) => any} deps.agentFor - the live agent (undefined when not attached).
|
|
54
|
+
* @param {(params: { sessionId: string, newSessionId: string }) => Promise<{ sessionId: string, boundary: number }>} deps.fork
|
|
55
|
+
* @param {(sessionId: string) => Promise<void>} deps.resume - open a persisted session in this process.
|
|
56
|
+
* @param {(sessionId: string) => Promise<void>} deps.create - open a new empty session in this process.
|
|
57
|
+
* @param {(source: any, aside: any, asideId: string) => Promise<void>} deps.inherit - carry the source's model selection.
|
|
58
|
+
* @param {(session: any) => void} deps.readOnly - switch a session's sandbox to read-only.
|
|
59
|
+
* @param {(sessionId: string) => Promise<readonly string[]>} deps.discard - dispose and delete one session.
|
|
60
|
+
* @param {(sessionId: string) => string} [deps.newId]
|
|
61
|
+
*/
|
|
62
|
+
export function createAside({ agentFor, fork, resume, create, inherit, readOnly, discard, newId }) {
|
|
63
|
+
const mintId = newId ?? ((sessionId) => `${sessionId}-btw-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`);
|
|
64
|
+
/** Open asides, by id, to their source session id. */
|
|
65
|
+
const asides = new Map();
|
|
66
|
+
|
|
67
|
+
const methods = {
|
|
68
|
+
async 'session/aside/open'(params) {
|
|
69
|
+
if (typeof params?.sessionId !== 'string' || params.sessionId.length === 0) throw new TypeError('a non-empty sessionId is required');
|
|
70
|
+
const sourceId = params.sessionId;
|
|
71
|
+
if (asides.has(sourceId)) throw new Error('an aside cannot open another aside');
|
|
72
|
+
const asideId = typeof params.newSessionId === 'string' && params.newSessionId.length > 0 ? params.newSessionId : mintId(sourceId);
|
|
73
|
+
if (asides.has(asideId) || agentFor(asideId) !== undefined) throw new Error(`session already open: ${asideId}`);
|
|
74
|
+
let boundary = -1;
|
|
75
|
+
let seeded = false;
|
|
76
|
+
try {
|
|
77
|
+
const forked = await fork({ sessionId: sourceId, newSessionId: asideId, liveHead: true });
|
|
78
|
+
boundary = forked.boundary;
|
|
79
|
+
seeded = true;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
// No completed turn (or no log yet): the question still deserves an answer, from an empty session.
|
|
82
|
+
if (!/no completed turn|not found|ENOENT|unknown session|no such/iu.test(error instanceof Error ? error.message : String(error))) throw error;
|
|
83
|
+
}
|
|
84
|
+
asides.set(asideId, sourceId);
|
|
85
|
+
try {
|
|
86
|
+
if (seeded) await resume(asideId);
|
|
87
|
+
else await create(asideId);
|
|
88
|
+
const aside = agentFor(asideId);
|
|
89
|
+
if (aside === undefined) throw new Error(`aside session did not open: ${asideId}`);
|
|
90
|
+
const source = agentFor(sourceId);
|
|
91
|
+
if (source !== undefined) await inherit(source, aside, asideId);
|
|
92
|
+
readOnly(aside.session);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
asides.delete(asideId);
|
|
95
|
+
await discard(asideId).catch(() => undefined);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return { sessionId: asideId, boundary, seeded };
|
|
99
|
+
},
|
|
100
|
+
async 'session/aside/close'(params) {
|
|
101
|
+
if (typeof params?.sessionId !== 'string' || params.sessionId.length === 0) throw new TypeError('a non-empty sessionId is required');
|
|
102
|
+
if (!asides.has(params.sessionId)) throw new Error(`not an open aside: ${params.sessionId}`);
|
|
103
|
+
const agent = agentFor(params.sessionId);
|
|
104
|
+
if (agent !== undefined && agent.status !== 'idle') {
|
|
105
|
+
try {
|
|
106
|
+
agent.cancel({ kind: 'user' }, { keepInbox: false });
|
|
107
|
+
} catch {
|
|
108
|
+
// disposal below stops it either way
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return { closed: true, removed: [...await discard(params.sessionId)] };
|
|
113
|
+
} finally {
|
|
114
|
+
asides.delete(params.sessionId);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
methods,
|
|
121
|
+
/** Whether a session is an open aside (approvals there are rejected). */
|
|
122
|
+
isAside: (sessionId) => asides.has(sessionId),
|
|
123
|
+
/** Close every open aside (server shutdown). */
|
|
124
|
+
async closeAll() {
|
|
125
|
+
await Promise.allSettled([...asides.keys()].map((sessionId) => methods['session/aside/close']({ sessionId })));
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Ordered model connections over the SDK JSON-RPC transport (CLI/TUI): thin faces over @picasso/model-router's
|
|
2
|
+
// `modelRouter` service (`connections`, `setConnections`, `checkAccess`), which the CLI runtime mounts.
|
|
3
|
+
//
|
|
4
|
+
// connections/list {} -> { policy, connections: [{ id, label, kind, models, status, reason?, since? }] }
|
|
5
|
+
// connections/set { policy?, order?, equivalents? } -> same shape, persisted to the shared settings file
|
|
6
|
+
// connections/check { id, model? } -> { id, model?, ok, reason?, kind?, code?, status?, latencyMs }
|
|
7
|
+
//
|
|
8
|
+
// A runtime without the router answers `connections/unavailable`; nothing is synthesized (C1).
|
|
9
|
+
|
|
10
|
+
export const CONNECTION_METHODS = Object.freeze(['connections/list', 'connections/set', 'connections/check']);
|
|
11
|
+
|
|
12
|
+
export class ConnectionsUnavailableError extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super('connections/unavailable: model connections are not mounted in this runtime');
|
|
15
|
+
this.name = 'ConnectionsUnavailableError';
|
|
16
|
+
this.code = 'connections/unavailable';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @param {() => any} router - the live `modelRouter` service (undefined when not mounted). */
|
|
21
|
+
export function connectionMethods(router) {
|
|
22
|
+
const service = () => {
|
|
23
|
+
const found = router();
|
|
24
|
+
if (found === undefined || found === null || typeof found.connections !== 'function') throw new ConnectionsUnavailableError();
|
|
25
|
+
return found;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
async 'connections/list'() {
|
|
29
|
+
return service().connections();
|
|
30
|
+
},
|
|
31
|
+
async 'connections/set'(params) {
|
|
32
|
+
return service().setConnections(params ?? {});
|
|
33
|
+
},
|
|
34
|
+
async 'connections/check'(params) {
|
|
35
|
+
return service().checkAccess(params ?? {});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// `session/context/timeline { sessionId }` -> the session's context timeline (`@picasso/lean-context`'s
|
|
2
|
+
// `contextTimeline` service): per turn what entered the context, compaction, per-step cache hit and miss, and a lane
|
|
3
|
+
// per subagent. The TUI's `/context timeline` reads it; the Mac reads the same service through Host Remote
|
|
4
|
+
// (`contextTimeline/get`). Read-only: the service folds durable session events, it never prompts a model.
|
|
5
|
+
|
|
6
|
+
export const CONTEXT_TIMELINE_METHOD = 'session/context/timeline';
|
|
7
|
+
export const CONTEXT_TIMELINE_METHODS = Object.freeze([CONTEXT_TIMELINE_METHOD]);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {{ timeline: () => { get(sessionId: string): Promise<unknown> } | undefined }} deps
|
|
11
|
+
*/
|
|
12
|
+
export function createContextTimeline({ timeline }) {
|
|
13
|
+
return {
|
|
14
|
+
methods: {
|
|
15
|
+
async [CONTEXT_TIMELINE_METHOD](params) {
|
|
16
|
+
const sessionId = params?.sessionId;
|
|
17
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) throw new TypeError('a non-empty sessionId is required');
|
|
18
|
+
const service = timeline();
|
|
19
|
+
// C1: without the lean-context plugin there is no timeline to show, so say so rather than return an empty one.
|
|
20
|
+
if (service === undefined || service === null || typeof service.get !== 'function') {
|
|
21
|
+
throw new Error('the context timeline is not available (lean-context plugin not loaded)');
|
|
22
|
+
}
|
|
23
|
+
return service.get(sessionId);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|