@xingular/harness 1.0.0 → 1.1.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/CHANGELOG.md +33 -5
- package/README.md +70 -19
- package/dist/cli.js +10321 -5785
- package/dist/sdk/agents/builtin.d.ts +2 -0
- package/dist/sdk/agents/builtin.js +34 -0
- package/dist/sdk/agents/narrow.d.ts +13 -0
- package/dist/sdk/agents/narrow.js +29 -0
- package/dist/sdk/agents/profiles.d.ts +80 -0
- package/dist/sdk/agents/profiles.js +221 -0
- package/dist/sdk/annotations/bridge.d.ts +42 -0
- package/dist/sdk/annotations/bridge.js +264 -0
- package/dist/sdk/annotations/capture.d.ts +116 -0
- package/dist/sdk/annotations/capture.js +308 -0
- package/dist/sdk/annotations/delivery.d.ts +72 -0
- package/dist/sdk/annotations/delivery.js +130 -0
- package/dist/sdk/annotations/inspect.d.ts +10 -0
- package/dist/sdk/annotations/inspect.js +33 -0
- package/dist/sdk/annotations/isolated.d.ts +6 -0
- package/dist/sdk/annotations/isolated.js +51 -0
- package/dist/sdk/annotations/pageScript.d.ts +28 -0
- package/dist/sdk/annotations/pageScript.js +570 -0
- package/dist/sdk/annotations/part.d.ts +10 -0
- package/dist/sdk/annotations/part.js +144 -0
- package/dist/sdk/annotations/queue.d.ts +4 -0
- package/dist/sdk/annotations/queue.js +40 -0
- package/dist/sdk/annotations/serverMethods.d.ts +3 -0
- package/dist/sdk/annotations/serverMethods.js +62 -0
- package/dist/sdk/annotations/store.d.ts +160 -0
- package/dist/sdk/annotations/store.js +386 -0
- package/dist/sdk/browser/index.d.ts +14 -3
- package/dist/sdk/browser/index.js +11 -4
- package/dist/sdk/browser/serverMethods.d.ts +3 -0
- package/dist/sdk/browser/serverMethods.js +7 -0
- package/dist/sdk/browser/session.d.ts +1 -0
- package/dist/sdk/browser/session.js +45 -9
- package/dist/sdk/cli.js +19 -11
- package/dist/sdk/core/bus.js +1 -1
- package/dist/sdk/core/env.d.ts +1 -1
- package/dist/sdk/core/env.js +1 -1
- package/dist/sdk/doctor/serverMethods.d.ts +3 -0
- package/dist/sdk/doctor/serverMethods.js +8 -0
- package/dist/sdk/harness.d.ts +15 -0
- package/dist/sdk/harness.js +44 -5
- package/dist/sdk/history/recall.js +8 -8
- package/dist/sdk/history/serverMethods.d.ts +3 -0
- package/dist/sdk/history/serverMethods.js +8 -0
- package/dist/sdk/hub/cli.d.ts +1 -1
- package/dist/sdk/hub/cli.js +1 -1
- package/dist/sdk/hub/schema.d.ts +1 -1
- package/dist/sdk/hub/serverMethods.d.ts +3 -0
- package/dist/sdk/hub/serverMethods.js +11 -0
- package/dist/sdk/index.d.ts +10 -0
- package/dist/sdk/index.js +7 -0
- package/dist/sdk/mcp/connections.js +14 -7
- package/dist/sdk/mcp/serverMethods.d.ts +3 -0
- package/dist/sdk/mcp/serverMethods.js +22 -0
- package/dist/sdk/plugins/builtin.d.ts +1 -0
- package/dist/sdk/plugins/builtin.js +128 -33
- package/dist/sdk/plugins/builtinRegistry.d.ts +53 -0
- package/dist/sdk/plugins/builtinRegistry.js +49 -0
- package/dist/sdk/plugins/cli.d.ts +1 -1
- package/dist/sdk/plugins/cli.js +4 -3
- package/dist/sdk/prompt/compile.d.ts +5 -2
- package/dist/sdk/prompt/compile.js +25 -8
- package/dist/sdk/refine/cli.d.ts +1 -1
- package/dist/sdk/refine/cli.js +2 -2
- package/dist/sdk/refine/serverMethods.d.ts +3 -0
- package/dist/sdk/refine/serverMethods.js +20 -0
- package/dist/sdk/server/methods.js +9 -86
- package/dist/sdk/server/params.d.ts +4 -0
- package/dist/sdk/server/params.js +11 -0
- package/dist/sdk/sessions/contracts.d.ts +17 -0
- package/dist/sdk/sessions/contracts.js +42 -3
- package/dist/sdk/sessions/planMode.d.ts +5 -2
- package/dist/sdk/sessions/planMode.js +12 -3
- package/dist/sdk/sessions/reasoningSummaries.d.ts +2 -2
- package/dist/sdk/sessions/reasoningSummaries.js +3 -3
- package/dist/sdk/sessions/registry.d.ts +1 -0
- package/dist/sdk/sessions/registry.js +4 -1
- package/dist/sdk/sessions/runIndex.js +7 -7
- package/dist/sdk/sessions/runStore.js +3 -1
- package/dist/sdk/sessions/runner.js +2 -2
- package/dist/sdk/sessions/sessions.d.ts +17 -5
- package/dist/sdk/sessions/sessions.js +79 -12
- package/dist/sdk/sessions/sideQuestionServerMethods.d.ts +3 -0
- package/dist/sdk/sessions/sideQuestionServerMethods.js +19 -0
- package/dist/sdk/sessions/sideQuestions.d.ts +66 -0
- package/dist/sdk/sessions/sideQuestions.js +290 -0
- package/dist/sdk/sessions/subagentServerMethods.d.ts +3 -0
- package/dist/sdk/sessions/subagentServerMethods.js +41 -0
- package/dist/sdk/sessions/subagentService.d.ts +13 -2
- package/dist/sdk/sessions/subagentService.js +34 -16
- package/dist/sdk/sessions/subagents.d.ts +9 -1
- package/dist/sdk/sessions/subagents.js +19 -0
- package/dist/sdk/terminal/browser.d.ts +62 -0
- package/dist/sdk/terminal/browser.js +41 -0
- package/dist/sdk/terminal/browserControl.d.ts +29 -0
- package/dist/sdk/terminal/browserControl.js +186 -0
- package/dist/sdk/terminal/commandHelp.d.ts +17 -0
- package/dist/sdk/terminal/commandHelp.js +20 -0
- package/dist/sdk/terminal/controller.d.ts +7 -1
- package/dist/sdk/terminal/controller.js +34 -2
- package/dist/sdk/terminal/opentui/subagentsWidget.d.ts +28 -0
- package/dist/sdk/terminal/opentui/subagentsWidget.js +52 -0
- package/dist/sdk/terminal/piExtension.js +33 -48
- package/dist/sdk/terminal/socket.d.ts +6 -3
- package/dist/sdk/terminal/socket.js +40 -9
- package/dist/sdk/terminal/standalone.d.ts +2 -0
- package/dist/sdk/terminal/standalone.js +50 -10
- package/dist/sdk/terminal/subagentMonitor.d.ts +38 -0
- package/dist/sdk/terminal/subagentMonitor.js +121 -0
- package/dist/sdk/terminal/terminals.d.ts +42 -6
- package/dist/sdk/terminal/terminals.js +359 -18
- package/dist/sdk/terminal/trajectory.js +2 -2
- package/dist/sdk/terminal/tui/annotateCommand.d.ts +3 -0
- package/dist/sdk/terminal/tui/annotateCommand.js +22 -0
- package/dist/sdk/terminal/tui/commandPages.d.ts +5 -1
- package/dist/sdk/terminal/tui/commandPages.js +54 -6
- package/dist/sdk/terminal/tui/commands.d.ts +8 -4
- package/dist/sdk/terminal/tui/commands.js +181 -58
- package/dist/sdk/terminal/tui/dialogGeometry.d.ts +2 -2
- package/dist/sdk/terminal/tui/dialogGeometry.js +4 -2
- package/dist/sdk/terminal/tui/dialogs.d.ts +6 -1
- package/dist/sdk/terminal/tui/dialogs.js +9 -2
- package/dist/sdk/terminal/tui/modelPicker.js +1 -6
- package/dist/sdk/terminal/tui/page.d.ts +3 -0
- package/dist/sdk/terminal/tui/pageOverlay.js +17 -6
- package/dist/sdk/terminal/tui/pages/accountsPage.d.ts +26 -4
- package/dist/sdk/terminal/tui/pages/accountsPage.js +264 -36
- package/dist/sdk/terminal/tui/pages/agentsPage.d.ts +74 -0
- package/dist/sdk/terminal/tui/pages/agentsPage.js +190 -0
- package/dist/sdk/terminal/tui/pages/annotatePage.d.ts +94 -0
- package/dist/sdk/terminal/tui/pages/annotatePage.js +341 -0
- package/dist/sdk/terminal/tui/pages/browserPage.d.ts +87 -0
- package/dist/sdk/terminal/tui/pages/browserPage.js +738 -0
- package/dist/sdk/terminal/tui/pages/doctorPage.d.ts +2 -0
- package/dist/sdk/terminal/tui/pages/doctorPage.js +103 -15
- package/dist/sdk/terminal/tui/pages/notesPage.d.ts +75 -0
- package/dist/sdk/terminal/tui/pages/notesPage.js +201 -0
- package/dist/sdk/terminal/tui/pages/settingsPage.d.ts +8 -0
- package/dist/sdk/terminal/tui/pages/settingsPage.js +16 -1
- package/dist/sdk/terminal/tui/pages/subagentsPage.d.ts +23 -0
- package/dist/sdk/terminal/tui/pages/subagentsPage.js +70 -0
- package/dist/sdk/terminal/tui/pages/trajectoryPage.d.ts +12 -5
- package/dist/sdk/terminal/tui/pages/trajectoryPage.js +156 -83
- package/dist/sdk/terminal/tui/pages/worktreesPage.d.ts +72 -0
- package/dist/sdk/terminal/tui/pages/worktreesPage.js +203 -0
- package/dist/sdk/terminal/tui/planMode.d.ts +1 -1
- package/dist/sdk/terminal/tui/planMode.js +1 -1
- package/dist/sdk/terminal/tui/pluginCommands.d.ts +14 -0
- package/dist/sdk/terminal/tui/pluginCommands.js +27 -0
- package/dist/sdk/terminal/tui/questions.d.ts +2 -0
- package/dist/sdk/terminal/tui/runtime.js +4 -2
- package/dist/sdk/terminal/tui/settingsModel.d.ts +2 -0
- package/dist/sdk/terminal/tui/settingsModel.js +32 -2
- package/dist/sdk/terminal/tui/sideQuestion.d.ts +26 -26
- package/dist/sdk/terminal/tui/sideQuestion.js +131 -98
- package/dist/sdk/terminal/tui/ui.d.ts +2 -0
- package/dist/sdk/terminal/tui/ui.js +1 -0
- package/dist/sdk/tools/askUser.js +26 -8
- package/dist/sdk/tools/checklist.js +2 -2
- package/dist/sdk/tools/harnessTools.d.ts +2 -0
- package/dist/sdk/tools/harnessTools.js +1 -1
- package/dist/sdk/tools/spawnSubagent.js +13 -4
- package/dist/sdk/web/part.d.ts +10 -0
- package/dist/sdk/web/part.js +6 -0
- package/dist/sdk/web/serverMethods.d.ts +3 -0
- package/dist/sdk/web/serverMethods.js +7 -0
- package/dist/sdk/wiki/serverMethods.d.ts +3 -0
- package/dist/sdk/wiki/serverMethods.js +26 -0
- package/dist/sdk/worktrees/cli.d.ts +11 -0
- package/dist/sdk/worktrees/cli.js +146 -0
- package/dist/sdk/worktrees/copy.d.ts +9 -0
- package/dist/sdk/worktrees/copy.js +111 -0
- package/dist/sdk/worktrees/git.d.ts +16 -0
- package/dist/sdk/worktrees/git.js +81 -0
- package/dist/sdk/worktrees/serverMethods.d.ts +3 -0
- package/dist/sdk/worktrees/serverMethods.js +30 -0
- package/dist/sdk/worktrees/service.d.ts +73 -0
- package/dist/sdk/worktrees/service.js +483 -0
- package/dist/sdk/worktrees/setup.d.ts +23 -0
- package/dist/sdk/worktrees/setup.js +65 -0
- package/dist/sdk/worktrees/types.d.ts +91 -0
- package/dist/sdk/worktrees/types.js +1 -0
- package/dist/sdk/world/cli.d.ts +2 -2
- package/dist/sdk/world/cli.js +6 -6
- package/dist/sdk/world/world.d.ts +3 -1
- package/dist/sdk/world/world.js +8 -9
- package/dist/terminal-opentui.js +14540 -7374
- package/dist/terminal-pi.js +285 -666
- package/docs/README.md +22 -2
- package/docs/architecture/00-overview.md +28 -16
- package/docs/architecture/02-sessions-and-runs.md +72 -15
- package/docs/architecture/03-variants.md +10 -2
- package/docs/architecture/04-prompt.md +26 -6
- package/docs/architecture/06-plugins-and-capabilities.md +39 -3
- package/docs/architecture/07-tools-and-gate.md +21 -6
- package/docs/architecture/09-accounts-and-connectors.md +8 -0
- package/docs/architecture/10-server-protocol.md +111 -2
- package/docs/architecture/11-terminal.md +185 -5
- package/docs/architecture/12-storage.md +15 -1
- package/docs/architecture/13-world-tools.md +28 -6
- package/docs/architecture/14-surfaces-and-parity.md +89 -0
- package/docs/architecture/README.md +15 -4
- package/docs/architecture/proposals/PROP-0006-run-checklist.md +4 -2
- package/docs/architecture/proposals/PROP-0013-resource-browser.md +58 -0
- package/docs/architecture/proposals/PROP-0014-fullscreen-browser-tabs.md +58 -0
- package/docs/architecture/proposals/PROP-0015-one-capability-surface.md +88 -0
- package/docs/architecture/proposals/PROP-0016-managed-worktrees.md +156 -0
- package/docs/architecture/proposals/PROP-0017-page-annotations.md +127 -0
- package/docs/architecture/proposals/PROP-0018-annotation-queue-and-app-targets.md +179 -0
- package/docs/architecture/proposals/PROP-0019-contextual-side-questions.md +122 -0
- package/docs/architecture/proposals/PROP-0020-builtin-feature-plugins.md +105 -0
- package/docs/architecture/proposals/PROP-0021-command-namespaces-and-duplicates.md +99 -0
- package/docs/architecture/proposals/PROP-0022-plan-only-questions.md +102 -0
- package/docs/architecture/proposals/PROP-0023-xagent-cli-name.md +61 -0
- package/docs/architecture/proposals/PROP-0024-question-sketch-previews.md +130 -0
- package/docs/architecture/proposals/PROP-0025-contextual-question-wireframes.md +49 -0
- package/docs/architecture/proposals/PROP-0026-connected-sketch-display.md +94 -0
- package/docs/architecture/proposals/PROP-0027-xingular-agent-product-identity.md +60 -0
- package/docs/architecture/proposals/PROP-0028-normalize-question-wireframes.md +55 -0
- package/docs/architecture/proposals/PROP-0029-agent-profiles.md +124 -0
- package/docs/architecture/proposals/PROP-0030-subagent-title.md +86 -0
- package/docs/architecture/proposals/README.md +25 -0
- package/docs/decisions/ADR-0009-xharness-command.md +6 -5
- package/docs/decisions/ADR-0014-public-release-baseline.md +3 -2
- package/docs/decisions/ADR-0015-resource-browser.md +28 -0
- package/docs/decisions/ADR-0016-fullscreen-browser-tabs.md +31 -0
- package/docs/decisions/ADR-0017-one-capability-surface.md +34 -0
- package/docs/decisions/ADR-0018-builtin-feature-plugins.md +35 -0
- package/docs/decisions/ADR-0019-managed-git-worktrees.md +31 -0
- package/docs/decisions/ADR-0020-page-annotations.md +37 -0
- package/docs/decisions/ADR-0021-required-command-namespaces.md +40 -0
- package/docs/decisions/ADR-0022-plan-only-question-tools.md +34 -0
- package/docs/decisions/ADR-0023-contextual-side-question-runs.md +35 -0
- package/docs/decisions/ADR-0024-xagent-command.md +40 -0
- package/docs/decisions/ADR-0025-question-choice-sketches.md +49 -0
- package/docs/decisions/ADR-0026-contextual-question-wireframes.md +58 -0
- package/docs/decisions/ADR-0027-connected-sketch-display.md +60 -0
- package/docs/decisions/ADR-0028-xingular-agent-product-identity.md +56 -0
- package/docs/decisions/ADR-0029-normalized-question-wireframe-borders.md +33 -0
- package/docs/decisions/ADR-0030-agent-profiles.md +43 -0
- package/docs/doctor.md +10 -4
- package/docs/features/README.md +26 -0
- package/docs/features/interfaces/README.md +1 -1
- package/docs/future-work.md +48 -0
- package/docs/parity.md +78 -0
- package/docs/releases/1.0.0.md +2 -2
- package/docs/releases/4.0.0.md +46 -0
- package/docs/releases/README.md +20 -15
- package/docs/study/00-index.md +5 -0
- package/docs/study/autonomous-engineering-sources.md +277 -0
- package/docs/study/autonomy-sources.md +147 -0
- package/docs/study/proactive-autonomy.md +408 -0
- package/docs/study/tui-resource-browser.md +78 -0
- package/docs/terminal-tui.md +325 -93
- package/package.json +3 -3
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
// Page notes (PROP-0017): what a person wrote about a whole web page, a quoted passage or an element
|
|
2
|
+
// of it. One JSON file per note under `<data root>/annotations/`, changed only with the version the
|
|
3
|
+
// caller last saw. A note is private until a person shares it with a session or an agent; the
|
|
4
|
+
// model can only read notes shared with it.
|
|
5
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { HarnessError, invalid, notFound } from "../core/errors.js";
|
|
8
|
+
import { newId, now, readJson, safeId, writeJson } from "../core/fs.js";
|
|
9
|
+
export const MAX_NOTES = 10_000;
|
|
10
|
+
const MAX_HISTORY = 100;
|
|
11
|
+
const codepoints = (value) => Array.from(value).length;
|
|
12
|
+
function bounded(value, max, required, field) {
|
|
13
|
+
if (typeof value !== 'string' || codepoints(value) > max || (required && !value.trim()))
|
|
14
|
+
throw invalid(`Invalid note ${field}.`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function validateUrl(value) {
|
|
18
|
+
const text = bounded(value, 4096, true, 'URL');
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
url = new URL(text);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw invalid('Invalid note URL.');
|
|
25
|
+
}
|
|
26
|
+
const authority = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)/i.exec(text)?.[1] ?? null;
|
|
27
|
+
if (!['http:', 'https:'].includes(url.protocol) || !url.hostname || url.username || url.password || authority === null || authority.includes('@') || /[\s\p{Cc}]/u.test(text)) {
|
|
28
|
+
throw invalid('Note URLs must be HTTP(S) without credentials.');
|
|
29
|
+
}
|
|
30
|
+
return text;
|
|
31
|
+
}
|
|
32
|
+
const APP_SCHEMES = new Set(['http:', 'https:', 'file:', 'app:', 'tauri:', 'electron:', 'asset:']);
|
|
33
|
+
/** An app window's address: web addresses, plus the local schemes desktop apps load from. Never credentials. */
|
|
34
|
+
export function validateAppUrl(value) {
|
|
35
|
+
const text = bounded(value, 4096, true, 'URL');
|
|
36
|
+
let url;
|
|
37
|
+
try {
|
|
38
|
+
url = new URL(text);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw invalid('Invalid note URL.');
|
|
42
|
+
}
|
|
43
|
+
if (!APP_SCHEMES.has(url.protocol) || url.username || url.password || /[\s\p{Cc}]/u.test(text))
|
|
44
|
+
throw invalid('An app note URL must be a web, file or app address without credentials.');
|
|
45
|
+
return text;
|
|
46
|
+
}
|
|
47
|
+
function validateApp(app) {
|
|
48
|
+
if (app == null)
|
|
49
|
+
return null;
|
|
50
|
+
const value = app;
|
|
51
|
+
if (value.kind !== 'cdp' && value.kind !== 'bridge')
|
|
52
|
+
throw invalid('A note app is attached through cdp or a bridge.');
|
|
53
|
+
return { kind: value.kind, name: bounded(value.name, 200, true, 'app name') };
|
|
54
|
+
}
|
|
55
|
+
function validateSource(source) {
|
|
56
|
+
if (!source || typeof source !== 'object')
|
|
57
|
+
throw invalid('A note needs its source page.');
|
|
58
|
+
const value = source;
|
|
59
|
+
const app = validateApp(value.app);
|
|
60
|
+
return {
|
|
61
|
+
url: app ? validateAppUrl(value.url) : validateUrl(value.url),
|
|
62
|
+
...(app ? { app } : {}),
|
|
63
|
+
title: bounded(value.title ?? '', 200, false, 'title'),
|
|
64
|
+
capturedAt: typeof value.capturedAt === 'string' && value.capturedAt ? value.capturedAt : now(),
|
|
65
|
+
...(value.surface != null ? { surface: bounded(value.surface, 200, true, 'surface') } : {}),
|
|
66
|
+
...(value.representationHint != null ? { representationHint: bounded(value.representationHint, 128, true, 'representation hint') } : {})
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function validateTarget(target) {
|
|
70
|
+
if (!target || typeof target !== 'object')
|
|
71
|
+
throw invalid('A note needs a target.');
|
|
72
|
+
const value = target;
|
|
73
|
+
const keys = Object.keys(value).sort().join(',');
|
|
74
|
+
if (value.kind === 'page') {
|
|
75
|
+
if (keys !== 'kind')
|
|
76
|
+
throw invalid('Invalid page target.');
|
|
77
|
+
return { kind: 'page' };
|
|
78
|
+
}
|
|
79
|
+
if (value.kind === 'text') {
|
|
80
|
+
if (keys !== 'end,exact,kind,prefix,start,suffix')
|
|
81
|
+
throw invalid('Invalid text target.');
|
|
82
|
+
const exact = bounded(value.exact, 4000, true, 'exact text');
|
|
83
|
+
const prefix = bounded(value.prefix, 128, false, 'text prefix');
|
|
84
|
+
const suffix = bounded(value.suffix, 128, false, 'text suffix');
|
|
85
|
+
const start = value.start;
|
|
86
|
+
const end = value.end;
|
|
87
|
+
// Offsets count Unicode code points of the page's normalised text, not UTF-16 units.
|
|
88
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end <= start || end - start !== codepoints(exact)) {
|
|
89
|
+
throw invalid('Note text offsets do not match the exact text.');
|
|
90
|
+
}
|
|
91
|
+
return { kind: 'text', exact, prefix, suffix, start: start, end: end };
|
|
92
|
+
}
|
|
93
|
+
if (value.kind === 'element') {
|
|
94
|
+
if (keys !== 'context,kind,name,role,selector,tag,text')
|
|
95
|
+
throw invalid('Invalid element target.');
|
|
96
|
+
const element = {
|
|
97
|
+
kind: 'element',
|
|
98
|
+
tag: bounded(value.tag, 40, true, 'element tag'),
|
|
99
|
+
role: bounded(value.role, 80, false, 'element role'),
|
|
100
|
+
name: bounded(value.name, 200, false, 'element name'),
|
|
101
|
+
text: bounded(value.text, 500, false, 'element text'),
|
|
102
|
+
context: bounded(value.context, 200, false, 'element context'),
|
|
103
|
+
selector: bounded(value.selector, 500, false, 'element selector')
|
|
104
|
+
};
|
|
105
|
+
if (!element.name.trim() && !element.text.trim())
|
|
106
|
+
throw invalid('An element note needs a meaningful name or text.');
|
|
107
|
+
return element;
|
|
108
|
+
}
|
|
109
|
+
throw invalid('A note target is a page, text or an element.');
|
|
110
|
+
}
|
|
111
|
+
function normalizeBody(body) {
|
|
112
|
+
return bounded(typeof body === 'string' ? body.trim() : body, 10_000, true, 'body');
|
|
113
|
+
}
|
|
114
|
+
function normalizeTags(tags) {
|
|
115
|
+
if (tags === undefined)
|
|
116
|
+
return [];
|
|
117
|
+
if (!Array.isArray(tags) || tags.length > 12)
|
|
118
|
+
throw invalid('A note takes at most 12 tags.');
|
|
119
|
+
return [...new Set(tags.map((tag) => bounded(typeof tag === 'string' ? tag.trim() : tag, 40, true, 'tag')))];
|
|
120
|
+
}
|
|
121
|
+
function validatePrincipal(principal) {
|
|
122
|
+
const value = (principal ?? {});
|
|
123
|
+
const result = {};
|
|
124
|
+
if (typeof value.sessionId === 'string' && value.sessionId)
|
|
125
|
+
result.sessionId = safeId(value.sessionId);
|
|
126
|
+
if (typeof value.agentId === 'string' && value.agentId)
|
|
127
|
+
result.agentId = safeId(value.agentId);
|
|
128
|
+
if (!result.sessionId === !result.agentId)
|
|
129
|
+
throw invalid('Share a note with exactly one session or one agent.');
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
const samePrincipal = (left, right) => left.sessionId === right.sessionId && left.agentId === right.agentId;
|
|
133
|
+
/** Whether a caller may read a note through the model tools. */
|
|
134
|
+
export function visibleTo(note, caller) {
|
|
135
|
+
return note.grants.some((grant) => (grant.principal.sessionId && grant.principal.sessionId === caller.sessionId) ||
|
|
136
|
+
(grant.principal.agentId && grant.principal.agentId === caller.agentId));
|
|
137
|
+
}
|
|
138
|
+
export function notesDir(root) {
|
|
139
|
+
return join(root, 'annotations');
|
|
140
|
+
}
|
|
141
|
+
function folder(root) {
|
|
142
|
+
const dir = notesDir(root);
|
|
143
|
+
if (existsSync(dir) && (lstatSync(dir).isSymbolicLink() || !lstatSync(dir).isDirectory()))
|
|
144
|
+
throw new HarnessError('invalid_data', 'Note storage must be a plain folder.');
|
|
145
|
+
mkdirSync(dir, { recursive: true });
|
|
146
|
+
return dir;
|
|
147
|
+
}
|
|
148
|
+
function file(root, id) {
|
|
149
|
+
return join(folder(root), `${safeId(id)}.json`);
|
|
150
|
+
}
|
|
151
|
+
function validNote(note, id) {
|
|
152
|
+
if (!note || note.id !== id || note.author !== 'user' || !Number.isSafeInteger(note.version) || note.version < 1 || !Array.isArray(note.grants) || !Array.isArray(note.history)) {
|
|
153
|
+
throw new HarnessError('invalid_data', `Note ${id} is not a valid note.`);
|
|
154
|
+
}
|
|
155
|
+
return note;
|
|
156
|
+
}
|
|
157
|
+
export function read(root, id) {
|
|
158
|
+
const path = file(root, id);
|
|
159
|
+
if (!existsSync(path))
|
|
160
|
+
throw notFound('Note');
|
|
161
|
+
if (lstatSync(path).isSymbolicLink())
|
|
162
|
+
throw new HarnessError('invalid_data', 'Note records must not be links.');
|
|
163
|
+
return validNote(readJson(path), id);
|
|
164
|
+
}
|
|
165
|
+
function all(root) {
|
|
166
|
+
const notes = [];
|
|
167
|
+
for (const name of readdirSync(folder(root))) {
|
|
168
|
+
if (!name.endsWith('.json'))
|
|
169
|
+
continue;
|
|
170
|
+
try {
|
|
171
|
+
notes.push(read(root, name.slice(0, -'.json'.length)));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// A damaged file is skipped, never shown as a note.
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return notes;
|
|
178
|
+
}
|
|
179
|
+
function matchingNotes(root, filter) {
|
|
180
|
+
const query = filter.query?.trim().toLowerCase();
|
|
181
|
+
return all(root)
|
|
182
|
+
.filter((note) => !filter.url || note.source.url === filter.url)
|
|
183
|
+
.filter((note) => !filter.status || note.status === filter.status)
|
|
184
|
+
.filter((note) => !query || [note.body, note.source.title, note.source.url, ...note.tags, note.target.kind === 'text' ? note.target.exact : note.target.kind === 'element' ? note.target.name : ''].join('\n').toLowerCase().includes(query))
|
|
185
|
+
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt) || left.id.localeCompare(right.id));
|
|
186
|
+
}
|
|
187
|
+
/** All matching notes for internal consumers that paginate after applying their own visibility filter. */
|
|
188
|
+
export function listAll(root, filter = {}) {
|
|
189
|
+
return matchingNotes(root, filter);
|
|
190
|
+
}
|
|
191
|
+
export function list(root, filter = {}) {
|
|
192
|
+
const matching = matchingNotes(root, filter);
|
|
193
|
+
const offset = Math.max(0, Math.floor(filter.offset ?? 0));
|
|
194
|
+
const limit = Math.max(1, Math.min(200, Math.floor(filter.limit ?? 50)));
|
|
195
|
+
return { notes: matching.slice(offset, offset + limit), total: matching.length };
|
|
196
|
+
}
|
|
197
|
+
function save(root, note, operation) {
|
|
198
|
+
note.version += 1;
|
|
199
|
+
note.updatedAt = now();
|
|
200
|
+
note.history.push({ version: note.version, operation, at: note.updatedAt });
|
|
201
|
+
if (note.history.length > MAX_HISTORY)
|
|
202
|
+
note.history.splice(0, note.history.length - MAX_HISTORY);
|
|
203
|
+
writeJson(file(root, note.id), note);
|
|
204
|
+
return note;
|
|
205
|
+
}
|
|
206
|
+
function current(root, id, expectedVersion) {
|
|
207
|
+
const note = read(root, id);
|
|
208
|
+
if (expectedVersion !== undefined && note.version !== expectedVersion)
|
|
209
|
+
throw new HarnessError('version_conflict', 'The note changed. Read it again before saving.');
|
|
210
|
+
return note;
|
|
211
|
+
}
|
|
212
|
+
export function create(root, input) {
|
|
213
|
+
const source = validateSource(input?.source);
|
|
214
|
+
const target = validateTarget(input?.target);
|
|
215
|
+
const body = normalizeBody(input?.body);
|
|
216
|
+
const tags = normalizeTags(input?.tags);
|
|
217
|
+
if (readdirSync(folder(root)).filter((name) => name.endsWith('.json')).length >= MAX_NOTES) {
|
|
218
|
+
throw new HarnessError('annotation_limit', `At most ${MAX_NOTES} notes may be kept.`);
|
|
219
|
+
}
|
|
220
|
+
const at = now();
|
|
221
|
+
const note = { id: newId(), version: 1, source, target, body, tags, status: 'open', author: 'user', createdAt: at, updatedAt: at, grants: [], history: [{ version: 1, operation: 'create', at }] };
|
|
222
|
+
writeJson(file(root, note.id), note);
|
|
223
|
+
return note;
|
|
224
|
+
}
|
|
225
|
+
export function update(root, id, expectedVersion, patch) {
|
|
226
|
+
const note = current(root, id, expectedVersion);
|
|
227
|
+
if (patch.body !== undefined)
|
|
228
|
+
note.body = normalizeBody(patch.body);
|
|
229
|
+
if (patch.tags !== undefined)
|
|
230
|
+
note.tags = normalizeTags(patch.tags);
|
|
231
|
+
if (patch.status !== undefined) {
|
|
232
|
+
if (patch.status !== 'open' && patch.status !== 'resolved')
|
|
233
|
+
throw invalid('A note is open or resolved.');
|
|
234
|
+
note.status = patch.status;
|
|
235
|
+
if (patch.status === 'resolved' && note.delivery?.state === 'queued')
|
|
236
|
+
note.delivery = null;
|
|
237
|
+
}
|
|
238
|
+
if (patch.target !== undefined)
|
|
239
|
+
note.target = validateTarget(patch.target);
|
|
240
|
+
return save(root, note, 'update');
|
|
241
|
+
}
|
|
242
|
+
export function remove(root, id, expectedVersion) {
|
|
243
|
+
current(root, id, expectedVersion);
|
|
244
|
+
rmSync(file(root, id));
|
|
245
|
+
}
|
|
246
|
+
/** A person lets one session or agent read the note through the model tools. */
|
|
247
|
+
export function share(root, id, principal, binding = null) {
|
|
248
|
+
const who = validatePrincipal(principal);
|
|
249
|
+
const note = current(root, id, undefined);
|
|
250
|
+
note.grants = note.grants.filter((grant) => !samePrincipal(grant.principal, who));
|
|
251
|
+
note.grants.push({ principal: who, ...(binding ? { binding: bounded(binding, 200, true, 'binding') } : {}), grantedAt: now() });
|
|
252
|
+
return save(root, note, 'share');
|
|
253
|
+
}
|
|
254
|
+
export function unshare(root, id, principal) {
|
|
255
|
+
const who = validatePrincipal(principal);
|
|
256
|
+
const note = current(root, id, undefined);
|
|
257
|
+
note.grants = note.grants.filter((grant) => !samePrincipal(grant.principal, who));
|
|
258
|
+
return save(root, note, 'unshare');
|
|
259
|
+
}
|
|
260
|
+
/** The host withdrew what a binding stood for (a tab closed or was shared again): every grant made with it ends. */
|
|
261
|
+
export function revokeBinding(root, binding) {
|
|
262
|
+
bounded(binding, 200, true, 'binding');
|
|
263
|
+
let changed = 0;
|
|
264
|
+
for (const note of all(root)) {
|
|
265
|
+
if (!note.grants.some((grant) => grant.binding === binding))
|
|
266
|
+
continue;
|
|
267
|
+
note.grants = note.grants.filter((grant) => grant.binding !== binding);
|
|
268
|
+
save(root, note, 'revoke_binding');
|
|
269
|
+
changed += 1;
|
|
270
|
+
}
|
|
271
|
+
return changed;
|
|
272
|
+
}
|
|
273
|
+
/** Takes notes another store kept, keeping their ids. A note whose id exists is skipped. */
|
|
274
|
+
export function importNotes(root, notes) {
|
|
275
|
+
const imported = [];
|
|
276
|
+
const skipped = [];
|
|
277
|
+
for (const raw of Array.isArray(notes) ? notes : []) {
|
|
278
|
+
const value = (raw ?? {});
|
|
279
|
+
const id = typeof value.id === 'string' ? value.id : null;
|
|
280
|
+
try {
|
|
281
|
+
if (!id)
|
|
282
|
+
throw invalid('A note needs an id.');
|
|
283
|
+
safeId(id);
|
|
284
|
+
if (existsSync(file(root, id))) {
|
|
285
|
+
skipped.push({ id, reason: 'exists' });
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const at = now();
|
|
289
|
+
const note = {
|
|
290
|
+
id,
|
|
291
|
+
version: 1,
|
|
292
|
+
source: validateSource(value.source),
|
|
293
|
+
target: validateTarget(value.target),
|
|
294
|
+
body: normalizeBody(value.body),
|
|
295
|
+
tags: normalizeTags(value.tags),
|
|
296
|
+
status: value.status === 'resolved' ? 'resolved' : 'open',
|
|
297
|
+
author: 'user',
|
|
298
|
+
createdAt: typeof value.createdAt === 'string' ? value.createdAt : at,
|
|
299
|
+
updatedAt: typeof value.updatedAt === 'string' ? value.updatedAt : at,
|
|
300
|
+
grants: Array.isArray(value.grants) ? value.grants.map((grant) => {
|
|
301
|
+
const entry = (grant ?? {});
|
|
302
|
+
return { principal: validatePrincipal(entry.principal), ...(typeof entry.binding === 'string' && entry.binding ? { binding: entry.binding } : {}), grantedAt: typeof entry.grantedAt === 'string' ? entry.grantedAt : at };
|
|
303
|
+
}) : [],
|
|
304
|
+
history: [{ version: 1, operation: 'import', at }]
|
|
305
|
+
};
|
|
306
|
+
writeJson(file(root, id), note);
|
|
307
|
+
imported.push(id);
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
skipped.push({ id, reason: error instanceof Error ? error.message : String(error) });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { imported, skipped };
|
|
314
|
+
}
|
|
315
|
+
// ---- Delivery to an agent (PROP-0018) ----------------------------------------------------------
|
|
316
|
+
/**
|
|
317
|
+
* A person asks a session to act on the note: it is shared with that session (if it was not) and
|
|
318
|
+
* waits in the session's queue until it is sent.
|
|
319
|
+
*/
|
|
320
|
+
export function queue(root, id, expectedVersion, sessionId, options = {}) {
|
|
321
|
+
const session = safeId(sessionId);
|
|
322
|
+
const note = current(root, id, expectedVersion);
|
|
323
|
+
if (note.status === 'resolved')
|
|
324
|
+
throw invalid('Reopen this note before queueing it.');
|
|
325
|
+
if (!note.grants.some((grant) => grant.principal.sessionId === session))
|
|
326
|
+
note.grants.push({ principal: { sessionId: session }, grantedAt: now() });
|
|
327
|
+
const confirmationRequired = options.confirm === true || (note.delivery?.confirm === true && options.confirmed !== true);
|
|
328
|
+
note.delivery = {
|
|
329
|
+
state: 'queued',
|
|
330
|
+
sessionId: session,
|
|
331
|
+
queuedAt: now(),
|
|
332
|
+
...(options.autoSend ? { autoSend: true } : {}),
|
|
333
|
+
...(confirmationRequired ? { confirm: true } : {})
|
|
334
|
+
};
|
|
335
|
+
return save(root, note, 'queue');
|
|
336
|
+
}
|
|
337
|
+
/** Takes the note out of the queue. It stays shared; unshare withdraws that. */
|
|
338
|
+
export function dequeue(root, id, expectedVersion) {
|
|
339
|
+
const note = current(root, id, expectedVersion);
|
|
340
|
+
if (note.delivery?.state !== 'queued')
|
|
341
|
+
throw invalid('This note is not waiting to be sent.');
|
|
342
|
+
note.delivery = null;
|
|
343
|
+
return save(root, note, 'dequeue');
|
|
344
|
+
}
|
|
345
|
+
/** The notes waiting for one session, oldest first. `auto` keeps only those to send when it is idle. */
|
|
346
|
+
export function queued(root, sessionId, filter = {}) {
|
|
347
|
+
const ids = filter.ids ? new Set(filter.ids) : null;
|
|
348
|
+
return all(root)
|
|
349
|
+
.filter((note) => note.status === 'open' && note.delivery?.state === 'queued' && note.delivery.sessionId === sessionId)
|
|
350
|
+
.filter((note) => !filter.auto || (note.delivery?.autoSend === true && note.delivery.confirm !== true))
|
|
351
|
+
.filter((note) => !ids || ids.has(note.id))
|
|
352
|
+
.sort((left, right) => (left.delivery.queuedAt).localeCompare(right.delivery.queuedAt) || left.id.localeCompare(right.id));
|
|
353
|
+
}
|
|
354
|
+
/** The notes went to the session as part of `runId`. */
|
|
355
|
+
export function markSent(root, ids, sessionId, runId) {
|
|
356
|
+
const session = safeId(sessionId);
|
|
357
|
+
const run = safeId(runId);
|
|
358
|
+
const notes = [...new Set(ids)].map((id) => current(root, id, undefined));
|
|
359
|
+
for (const note of notes) {
|
|
360
|
+
if (note.status !== 'open')
|
|
361
|
+
throw invalid('Resolved notes cannot be sent.');
|
|
362
|
+
if (note.delivery?.state !== 'queued' || note.delivery.sessionId !== session)
|
|
363
|
+
throw invalid('This note is not queued for this session.');
|
|
364
|
+
if (note.delivery.confirm)
|
|
365
|
+
throw invalid('Confirm this note before sending it.');
|
|
366
|
+
}
|
|
367
|
+
return notes.map((note) => {
|
|
368
|
+
note.delivery = { ...note.delivery, state: 'sent', sessionId: session, sentAt: now(), runId: run };
|
|
369
|
+
delete note.delivery.autoSend;
|
|
370
|
+
delete note.delivery.confirm;
|
|
371
|
+
return save(root, note, 'deliver');
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
/** The agent says it acted on a note shared with it. The note stays open until a person resolves it. */
|
|
375
|
+
export function markFixed(root, id, caller, summary) {
|
|
376
|
+
const note = current(root, id, undefined);
|
|
377
|
+
if (!visibleTo(note, caller))
|
|
378
|
+
throw notFound('Note');
|
|
379
|
+
const sessionId = note.delivery?.sessionId ?? caller.sessionId ?? note.grants.find((grant) => grant.principal.sessionId)?.principal.sessionId;
|
|
380
|
+
if (!sessionId)
|
|
381
|
+
throw invalid('This note was never sent to a session.');
|
|
382
|
+
note.delivery = { ...(note.delivery ?? { queuedAt: now() }), state: 'fixed', sessionId, fixedAt: now(), summary: bounded(summary.trim(), 2000, true, 'summary') };
|
|
383
|
+
delete note.delivery.autoSend;
|
|
384
|
+
delete note.delivery.confirm;
|
|
385
|
+
return save(root, note, 'mark_fixed');
|
|
386
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PluginDescriptor } from "../plugins/types.js";
|
|
2
|
-
import type { WorldPart } from "../world/world.js";
|
|
2
|
+
import type { WorldContext, WorldPart } from "../world/world.js";
|
|
3
|
+
import type { ToolSpec } from "../tools/types.js";
|
|
3
4
|
import { NetworkPolicy } from "./network.js";
|
|
4
5
|
import { BrowserSession, type Launcher } from "./session.js";
|
|
5
6
|
export declare const BROWSER_PLUGIN: PluginDescriptor;
|
|
@@ -12,6 +13,16 @@ export interface BrowserPartOptions {
|
|
|
12
13
|
network?: NetworkPolicy;
|
|
13
14
|
idleMs?: number;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
/** Foundation-owned isolated browser engine. Plugin tools receive sessions through this interface. */
|
|
17
|
+
export interface BrowserEngine {
|
|
16
18
|
sessions: Map<string, BrowserSession>;
|
|
17
|
-
|
|
19
|
+
diagnostics: NonNullable<WorldPart['diagnostics']>;
|
|
20
|
+
tools(context: WorldContext): ToolSpec[];
|
|
21
|
+
release(sessionKey: string): Promise<void>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createBrowserEngine(options: BrowserPartOptions): BrowserEngine;
|
|
25
|
+
/** Plugin adapter that exposes the Foundation engine's checked browser tools to a session. */
|
|
26
|
+
export declare function browserPluginPart(engine: BrowserEngine): WorldPart;
|
|
27
|
+
/** Combined adapter retained for direct browser tests and embedders that construct a WorldPart. */
|
|
28
|
+
export declare function browserPart(options: BrowserPartOptions): WorldPart & Pick<BrowserEngine, 'sessions' | 'release' | 'close'>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
// live browser per session.
|
|
1
|
+
// Foundation owns the isolated browser engine; the Browser plugin exposes its user-facing tools.
|
|
3
2
|
import { rmSync } from 'node:fs';
|
|
4
3
|
import { join } from 'node:path';
|
|
5
4
|
import { readBrowserConfig } from "./config.js";
|
|
@@ -18,7 +17,7 @@ export const BROWSER_PLUGIN = {
|
|
|
18
17
|
};
|
|
19
18
|
/** A browser closes after this long without a call. */
|
|
20
19
|
export const IDLE_MS = 15 * 60_000;
|
|
21
|
-
export function
|
|
20
|
+
export function createBrowserEngine(options) {
|
|
22
21
|
const sessions = new Map();
|
|
23
22
|
const diagnosticKeys = new Set();
|
|
24
23
|
const config = () => readBrowserConfig(options.stateDir);
|
|
@@ -53,7 +52,6 @@ export function browserPart(options) {
|
|
|
53
52
|
rmSync(join(options.stateDir, 'browser', 'downloads', fileName(key)), { recursive: true, force: true });
|
|
54
53
|
};
|
|
55
54
|
return {
|
|
56
|
-
plugin: BROWSER_PLUGIN,
|
|
57
55
|
diagnostics: () => [browserDiagnostic(config)],
|
|
58
56
|
sessions,
|
|
59
57
|
tools: (context) => browserTools(context, () => sessionFor(context)),
|
|
@@ -63,3 +61,12 @@ export function browserPart(options) {
|
|
|
63
61
|
}
|
|
64
62
|
};
|
|
65
63
|
}
|
|
64
|
+
/** Plugin adapter that exposes the Foundation engine's checked browser tools to a session. */
|
|
65
|
+
export function browserPluginPart(engine) {
|
|
66
|
+
return { plugin: BROWSER_PLUGIN, diagnostics: engine.diagnostics, tools: context => engine.tools(context) };
|
|
67
|
+
}
|
|
68
|
+
/** Combined adapter retained for direct browser tests and embedders that construct a WorldPart. */
|
|
69
|
+
export function browserPart(options) {
|
|
70
|
+
const engine = createBrowserEngine(options);
|
|
71
|
+
return { ...browserPluginPart(engine), sessions: engine.sessions, release: engine.release, close: engine.close };
|
|
72
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { pick } from "../server/params.js";
|
|
2
|
+
export function browserServerMethods(harness) {
|
|
3
|
+
return {
|
|
4
|
+
'browser.config': () => harness.world.browserConfig(),
|
|
5
|
+
'browser.configure': (params) => harness.world.configureBrowser(pick(params, ['headed', 'cdpUrl', 'executablePath', 'allowPrivate', 'allowedDomains']))
|
|
6
|
+
};
|
|
7
|
+
}
|
|
@@ -67,6 +67,7 @@ export declare class BrowserSession {
|
|
|
67
67
|
private touch;
|
|
68
68
|
private start;
|
|
69
69
|
private adopt;
|
|
70
|
+
private forget;
|
|
70
71
|
/** A tab by id, or the current one, starting the browser and opening a first tab when needed. */
|
|
71
72
|
tab(id?: string | null): Promise<Tab>;
|
|
72
73
|
open(): Promise<Tab>;
|
|
@@ -9,6 +9,9 @@ export const fileName = (name) => name.replace(/[^A-Za-z0-9._-]/g, '_').replace(
|
|
|
9
9
|
export const VIEWPORT = { width: 1280, height: 800 };
|
|
10
10
|
export const ACTION_TIMEOUT_MS = 15_000;
|
|
11
11
|
export const NAVIGATION_TIMEOUT_MS = 30_000;
|
|
12
|
+
function isClosedBrowserError(error) {
|
|
13
|
+
return error instanceof Error && /Target page, context or browser has been closed|browser has been closed|context has been closed/i.test(error.message);
|
|
14
|
+
}
|
|
12
15
|
export const launchBrowser = async ({ profileDir, downloads, config }) => {
|
|
13
16
|
const { chromium } = await import('playwright-core');
|
|
14
17
|
if (config.cdpUrl) {
|
|
@@ -87,17 +90,20 @@ export class BrowserSession {
|
|
|
87
90
|
this.context = launched.context;
|
|
88
91
|
this.browser = launched.browser;
|
|
89
92
|
this.attached = launched.attached;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
const context = launched.context;
|
|
94
|
+
context.on('close', () => this.forget(context));
|
|
95
|
+
launched.browser?.on('disconnected', () => this.forget(context));
|
|
96
|
+
context.setDefaultTimeout(ACTION_TIMEOUT_MS);
|
|
97
|
+
context.setDefaultNavigationTimeout(NAVIGATION_TIMEOUT_MS);
|
|
98
|
+
await context.route('**/*', async (route) => {
|
|
93
99
|
const refusal = await this.options.network.refusal(route.request().url());
|
|
94
100
|
if (refusal)
|
|
95
101
|
await route.abort('blockedbyclient');
|
|
96
102
|
else
|
|
97
103
|
await route.continue();
|
|
98
104
|
});
|
|
99
|
-
|
|
100
|
-
for (const page of
|
|
105
|
+
context.on('page', (page) => this.adopt(page));
|
|
106
|
+
for (const page of context.pages())
|
|
101
107
|
this.adopt(page);
|
|
102
108
|
})();
|
|
103
109
|
try {
|
|
@@ -132,6 +138,15 @@ export class BrowserSession {
|
|
|
132
138
|
});
|
|
133
139
|
return tab;
|
|
134
140
|
}
|
|
141
|
+
forget(context) {
|
|
142
|
+
if (this.context !== context)
|
|
143
|
+
return;
|
|
144
|
+
this.context = null;
|
|
145
|
+
this.browser = null;
|
|
146
|
+
this.attached = false;
|
|
147
|
+
this.tabs.clear();
|
|
148
|
+
this.current = null;
|
|
149
|
+
}
|
|
135
150
|
/** A tab by id, or the current one, starting the browser and opening a first tab when needed. */
|
|
136
151
|
async tab(id) {
|
|
137
152
|
await this.start();
|
|
@@ -146,10 +161,31 @@ export class BrowserSession {
|
|
|
146
161
|
return this.open();
|
|
147
162
|
}
|
|
148
163
|
async open() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
let lastClosedError;
|
|
165
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
166
|
+
await this.start();
|
|
167
|
+
const context = this.context;
|
|
168
|
+
if (!context)
|
|
169
|
+
continue;
|
|
170
|
+
try {
|
|
171
|
+
const page = await context.newPage();
|
|
172
|
+
if (this.context !== context) {
|
|
173
|
+
await page.close().catch(() => undefined);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const tab = this.adopt(page);
|
|
177
|
+
this.current = tab.id;
|
|
178
|
+
return tab;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (attempt !== 0 || !isClosedBrowserError(error))
|
|
182
|
+
throw error;
|
|
183
|
+
lastClosedError = error;
|
|
184
|
+
this.forget(context);
|
|
185
|
+
await context.close().catch(() => undefined);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
throw lastClosedError ?? new Error('The browser closed while opening a page.');
|
|
153
189
|
}
|
|
154
190
|
select(id) {
|
|
155
191
|
const tab = this.tabs.get(id);
|
package/dist/sdk/cli.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// The `
|
|
2
|
+
// The `xagent` command.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// xagent serve --state <dir> [--data <dir>] [--name <product>] [--builtins <dir>]…
|
|
5
|
+
// [--host-secrets] [--host-policy] [--host-tools] [--host-directory]
|
|
6
6
|
// Serves the harness to a host process over stdin/stdout (newline-delimited JSON).
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
7
|
+
// xagent wiki <command> Project notes, skills and history, from inside a terminal session.
|
|
8
|
+
// xagent refine <command> Refine a variant from evidence (refine demo needs no model).
|
|
9
|
+
// xagent mcp <command> Connected apps, from inside a terminal session.
|
|
10
|
+
// xagent plugins <command> List, install, switch and trust plugins.
|
|
11
|
+
// xagent web <command> Search keys for web_search.
|
|
12
|
+
// xagent browser <command> How the agent's browser runs.
|
|
13
|
+
// xagent worktree <command> Managed git worktrees of the repository you are in.
|
|
13
14
|
import { resolve } from 'node:path';
|
|
14
15
|
import manifest from "../../package.json" with { type: 'json' };
|
|
15
16
|
import { log } from "./core/bus.js";
|
|
@@ -23,8 +24,9 @@ import { RpcPeer, stdioTransport } from "./server/rpc.js";
|
|
|
23
24
|
import { attach } from "./server/serve.js";
|
|
24
25
|
import { runAppsCli, runWikiCli } from "./terminal/cli.js";
|
|
25
26
|
import { runStandaloneTerminal, standaloneArguments } from "./terminal/standalone.js";
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
import { runWorktreeCli } from "./worktrees/cli.js";
|
|
28
|
+
const USAGE = `Usage: xagent [--data <dir>] [--state <dir>]
|
|
29
|
+
xagent <terminal | serve | wiki | mcp | plugins | hub | refine | web | browser | worktree> [arguments]
|
|
28
30
|
|
|
29
31
|
--version Print the package version
|
|
30
32
|
(no command) Start the interactive Harness terminal
|
|
@@ -39,12 +41,16 @@ const USAGE = `Usage: xharness [--data <dir>] [--state <dir>]
|
|
|
39
41
|
refine <command> Refine a harness from evidence (refine demo, refine run)
|
|
40
42
|
web <command> Search keys for the web tools (web help)
|
|
41
43
|
browser <command> How the agent's browser runs (browser help)
|
|
44
|
+
worktree <command> Managed git worktrees (worktree help)
|
|
42
45
|
|
|
43
46
|
Standalone terminal options:
|
|
44
47
|
--data <dir> Data directory (installed default: ~/.xingular-harness/data;
|
|
45
48
|
npm run dev default: ~/.xingular-harness-dev/data)
|
|
46
49
|
--state <dir> State directory (installed default: ~/.xingular-harness/state;
|
|
47
50
|
npm run dev default: ~/.xingular-harness-dev/state)
|
|
51
|
+
--worktree [name], -w [name]
|
|
52
|
+
Start in a new managed worktree of this repository, or in
|
|
53
|
+
the named one
|
|
48
54
|
`;
|
|
49
55
|
function flags(argv) {
|
|
50
56
|
const values = {};
|
|
@@ -133,6 +139,8 @@ async function main() {
|
|
|
133
139
|
return runWebCli(rest);
|
|
134
140
|
if (command === 'browser')
|
|
135
141
|
return runBrowserCli(rest);
|
|
142
|
+
if (command === 'worktree')
|
|
143
|
+
return runWorktreeCli(rest);
|
|
136
144
|
process.stdout.write(USAGE);
|
|
137
145
|
return command ? 2 : 0;
|
|
138
146
|
}
|
package/dist/sdk/core/bus.js
CHANGED
|
@@ -36,7 +36,7 @@ export function logLine(text) {
|
|
|
36
36
|
export function redactLogText(text) {
|
|
37
37
|
return text
|
|
38
38
|
.replace(/\bBearer\s+\S+/gi, 'Bearer [redacted]')
|
|
39
|
-
.replace(/(["']?(?:authorization|proxy-authorization|cookie|set-cookie|x-[\w-]
|
|
39
|
+
.replace(/(["']?(?:authorization|proxy-authorization|cookie|set-cookie|x-[\w-]{0,64}(?:token|key)|[\w-]{0,64}(?:api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|token|secret|password|client[_-]?secret))["']?\s*[:=]\s*["']?)[^"'\s,;]+/gi, '$1[redacted]')
|
|
40
40
|
.replace(/\b(?:sk|sess)-[A-Za-z0-9_-]{16,}\b/gi, '[redacted]')
|
|
41
41
|
.replace(/\bhttps?:\/\/[^\s"'<>]+/gi, (raw) => {
|
|
42
42
|
const punctuation = /[),.;!?]+$/.exec(raw)?.[0] ?? '';
|
package/dist/sdk/core/env.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface Directory {
|
|
|
6
6
|
sessionAgent(sessionId: string): string | null;
|
|
7
7
|
}
|
|
8
8
|
/** The name used when an application gives none. */
|
|
9
|
-
export declare const DEFAULT_PRODUCT_NAME = "Xingular
|
|
9
|
+
export declare const DEFAULT_PRODUCT_NAME = "Xingular Agent";
|
|
10
10
|
export declare const EMPTY_DIRECTORY: Directory;
|
|
11
11
|
export interface HarnessEnv {
|
|
12
12
|
/** The data root: `wiki/`, `registry/`, `runs/`, `config/`, `index.sqlite`. */
|
package/dist/sdk/core/env.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// What every harness module is given: where the data lives, and what the embedding application
|
|
2
2
|
// knows that the harness does not.
|
|
3
3
|
/** The name used when an application gives none. */
|
|
4
|
-
export const DEFAULT_PRODUCT_NAME = 'Xingular
|
|
4
|
+
export const DEFAULT_PRODUCT_NAME = 'Xingular Agent';
|
|
5
5
|
export const EMPTY_DIRECTORY = { agentName: () => null, sessionAgent: () => null };
|
|
6
6
|
export function createEnv(root, options = {}) {
|
|
7
7
|
return { root, directory: options.directory ?? EMPTY_DIRECTORY, productName: options.productName ?? DEFAULT_PRODUCT_NAME };
|