@andorra-labs/code 0.1.11 → 0.1.12
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 +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/agent-execution.js +15 -3
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +8 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +15 -0
- package/dist/src/app-server.js +89 -10
- package/dist/src/browser-panel-tool.d.ts +24 -3
- package/dist/src/browser-panel-tool.js +80 -6
- package/dist/src/browser-runner.js +3 -1
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +38 -2
- package/dist/src/claude-provider.js +15 -2
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.js +175 -43
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
- package/dist/src/codex-provider.js +6 -3
- package/dist/src/coding-tools.d.ts +2 -1
- package/dist/src/coding-tools.js +39 -31
- package/dist/src/completion.d.ts +43 -1
- package/dist/src/completion.js +145 -4
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/delegation-changes.js +19 -2
- package/dist/src/diff-preview.d.ts +1 -0
- package/dist/src/diff-preview.js +12 -3
- package/dist/src/engine-streams.d.ts +22 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.js +17 -6
- package/dist/src/file-read-key.d.ts +8 -0
- package/dist/src/file-read-key.js +12 -0
- package/dist/src/graph-editor-session.js +2 -1
- package/dist/src/graph-health.d.ts +21 -0
- package/dist/src/graph-health.js +46 -0
- package/dist/src/graph-manager-chat.d.ts +52 -3
- package/dist/src/graph-manager-chat.js +50 -5
- package/dist/src/graph-runner.js +23 -3
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +39 -18
- package/dist/src/graph-ui/app.js +100 -30
- package/dist/src/graph-ui/controls.css +52 -0
- package/dist/src/graph-ui/icons.js +3 -0
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/manager-state.js +141 -3
- package/dist/src/graph-ui/manager.css +2 -2
- package/dist/src/graph-ui/manager.js +328 -66
- package/dist/src/graph-ui/model-picker.js +279 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graphs.d.ts +2 -0
- package/dist/src/graphs.js +7 -7
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- package/dist/src/memory/ProjectMemory.d.ts +77 -0
- package/dist/src/memory/ProjectMemory.js +310 -0
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/opencode-provider.js +5 -6
- package/dist/src/package-name.d.ts +3 -0
- package/dist/src/package-name.js +3 -0
- package/dist/src/provider-engine.js +2 -2
- package/dist/src/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +16 -8
- package/dist/src/remote/cert.d.ts +1 -1
- package/dist/src/remote/cert.js +2 -7
- package/dist/src/remote/client.js +1 -1
- package/dist/src/remote/pem.d.ts +6 -0
- package/dist/src/remote/pem.js +11 -0
- package/dist/src/run-records.js +49 -10
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- package/dist/src/sign-in-detection.d.ts +82 -0
- package/dist/src/sign-in-detection.js +197 -0
- package/dist/src/sign-in-offer.d.ts +35 -0
- package/dist/src/sign-in-offer.js +116 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +1 -1
- package/dist/src/skills/runtime-skills.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +13 -0
- package/dist/src/stray-files.d.ts +14 -0
- package/dist/src/stray-files.js +81 -0
- package/dist/src/subagent-run.js +6 -1
- package/dist/src/terminal-ui.d.ts +1 -1
- package/dist/src/terminal-ui.js +9 -3
- package/dist/src/tool-activity.js +1 -1
- package/dist/src/tool-schema-compatibility.d.ts +7 -2
- package/dist/src/tool-schema-compatibility.js +8 -4
- package/dist/src/transcript.d.ts +5 -0
- package/dist/src/transcript.js +11 -3
- package/dist/src/types.d.ts +2 -0
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +125 -0
- package/dist/src/update-check.js +1 -1
- package/dist/src/update.d.ts +11 -1
- package/dist/src/update.js +27 -5
- package/dist/src/workspace-git-metadata.d.ts +15 -0
- package/dist/src/workspace-git-metadata.js +50 -1
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,13 +6,19 @@ Work runs on a **graph**: visible stages, decisions and handoffs that you can in
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
macOS and Linux:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
curl -fsSL https://updates.andorralabs.com/cli/install.sh | sh
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The script brings its own Node.js 22 runtime into `~/.andorracode`, so the Node.js on your machine (or none at all) does not matter. With Node.js 22.19 or newer already installed, npm works too, and it is the way to install on Windows:
|
|
10
16
|
|
|
11
17
|
```sh
|
|
12
18
|
npm install -g @andorra-labs/code
|
|
13
19
|
```
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
Either way you get `andorra` and the alias `andorracode`. Keep it current with `andorra update`.
|
|
16
22
|
|
|
17
23
|
## First run
|
|
18
24
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -70,3 +70,18 @@ version 3.0.0; no source from either project is copied into this repository.
|
|
|
70
70
|
|
|
71
71
|
The WebAssembly build links the libraries PDFium vendors under `third_party`, among them FreeType
|
|
72
72
|
and OpenJPEG, each under its own permissive license recorded in the PDFium source tree.
|
|
73
|
+
|
|
74
|
+
## ELK (elkjs)
|
|
75
|
+
|
|
76
|
+
The desktop app lays out the diagrams it draws from `mermaid` fences with the Eclipse Layout Kernel
|
|
77
|
+
(`desktop/src/engine/diagram.ts`). It is installed as the npm dependency `elkjs` version 0.9.3,
|
|
78
|
+
through `@mermaid-js/layout-elk` version 0.2.3 (MIT, Copyright (c) 2014 - 2022 Knut Sveidqvist), and
|
|
79
|
+
is bundled into the desktop app unmodified. No source from either project is copied into this
|
|
80
|
+
repository.
|
|
81
|
+
|
|
82
|
+
- Project: https://github.com/kieler/elkjs, compiled from https://github.com/eclipse/elk
|
|
83
|
+
- Copyright: Copyright (c) 2017 Kiel University and others
|
|
84
|
+
- License: Eclipse Public License 2.0
|
|
85
|
+
- License copy: `licenses/ELKJS-EPL-2.0.txt`
|
|
86
|
+
- Source code: elkjs is made available under the EPL-2.0 by its authors. The source of the version
|
|
87
|
+
shipped is at https://github.com/kieler/elkjs/tree/0.9.3 and in the npm package `elkjs@0.9.3`.
|
|
@@ -25,13 +25,13 @@ import { createAgentEngine } from './hardened-runtime.js';
|
|
|
25
25
|
import { completionTool } from './completion.js';
|
|
26
26
|
import { DELIVERED_OUTCOME, GRAPH_MANAGER_GRAPH_ID, capabilitySubset, delegatesWriting, effectiveCapabilities, intakeCapabilities, isTestingNode, isWritingRole, laterAgentNodes, permitsBuiltInTool, testerOnEveryRoute } from './graphs.js';
|
|
27
27
|
import { DELEGATION_DIFF_LIMIT, LandingRestoreError, addChangeWorktree, assertDelegationGit, applyLanding, collectChange, prepareLanding, removeChangeWorktree, repositoryRoot, snapshotWorkspace } from './delegation-changes.js';
|
|
28
|
-
import { classifyWorkspaceWrites } from './tools.js';
|
|
29
28
|
import { stopQaProcessesUnder } from './qa/runtime/ProcessManager.js';
|
|
30
29
|
import { qaGuidance } from './qa/guidance.js';
|
|
31
30
|
import { disposePooledPowerShellUnder } from './powershell-pool.js';
|
|
32
31
|
import { validateValue } from './handoffs.js';
|
|
33
32
|
import { ArtifactStore } from './artifacts.js';
|
|
34
33
|
import { approveOperation, capabilityTools, gitReadTool } from './capabilities.js';
|
|
34
|
+
import { removeUntrackedFileTool } from './untracked-file-removal.js';
|
|
35
35
|
import { permissionMode, serializeApprovals, assertPlanMutationAllowed } from './permissions.js';
|
|
36
36
|
import { adaptLegacyCodingToolArguments, canonicalToolName, canonicalizeToolList } from './tool-names.js';
|
|
37
37
|
const exec = promisify(execFile);
|
|
@@ -58,7 +58,7 @@ Clarify first on either path: publish the plan with update_todos, research, and
|
|
|
58
58
|
Delegate implementation to the writing roles with spawn_subagent, several in parallel when their tasks are independent. Each runs in its own Git worktree started from the working folder as it stands and may run commands and tests there. Give each one a bounded task carrying the confirmed requirements and acceptance criteria, and ask it to report the commands and tests it ran.
|
|
59
59
|
Each writing spawn returns a change record: an id (use it exactly as returned), the changed files, the diff (the full diff is behind read_artifact when truncated), the worktree path, and the tests report the subagent gave. Review every change: read the diff, read files inside the worktree with your read tools when the diff is not enough, and weigh the tests report; a failure report is grounds for a fix.
|
|
60
60
|
Decide every change: accept_change with its id lands it in the working folder as uncommitted edits; discard_change drops it. A new subagent starts from the working folder, so it sees landed work only, never a change still waiting for your decision. To build on a change, accept it first and then spawn the follow-up. When work is wrong or incomplete, discard it and spawn a redo whose task carries your review findings, then review the redo. A conflict lands nothing and names the files: the change no longer fits the working folder and accepting it again conflicts again, so discard it, spawn a redo (it starts from the folder as it now stands) and accept the redo.
|
|
61
|
-
Complete with "delivered" only when no subagent is still running, at least one change landed, and every change is accepted or discarded. Never write code or run commands yourself: you have no write or shell tools, and the change tools take only an id.`;
|
|
61
|
+
Complete with "delivered" only when no subagent is still running, at least one change landed, and every change is accepted or discarded. Never write code or run commands yourself: you have no write or shell tools, and the change tools take only an id. The one exception is remove_untracked_file, for a stray untracked file left by mistake (such as one named nul or after a sentence); remove it yourself instead of asking the user to.`;
|
|
62
62
|
/**
|
|
63
63
|
* Appended to a delegating Orchestrator's instructions when it continues a resumed conversation:
|
|
64
64
|
* the change registry is per visit and is not restored.
|
|
@@ -463,6 +463,13 @@ export async function executeAgentNode(node, options) {
|
|
|
463
463
|
}
|
|
464
464
|
if (codeLedger && codeIntel)
|
|
465
465
|
tools.push(codeIntel.exploreTool(codeLedger));
|
|
466
|
+
// Project memory is a session facility like update_todos: node allowlists and capability
|
|
467
|
+
// policies do not govern it (it never touches the workspace); contextPolicy.projectMemory
|
|
468
|
+
// false turns it off for a node. Delegated children work from their parent's brief.
|
|
469
|
+
if (options.projectMemory && depth === 0 && configured.contextPolicy?.projectMemory !== false) {
|
|
470
|
+
const present = new Set(tools.map(tool => tool.name));
|
|
471
|
+
tools.push(...options.projectMemory.tools().filter(tool => !present.has(tool.name)));
|
|
472
|
+
}
|
|
466
473
|
if (orchestrator)
|
|
467
474
|
for (let index = 0; index < tools.length; index++) {
|
|
468
475
|
const tool = tools[index];
|
|
@@ -510,8 +517,12 @@ export async function executeAgentNode(node, options) {
|
|
|
510
517
|
// the user watches the question scroll past while the run keeps working. It is offered only
|
|
511
518
|
// where a person can answer; a headless run keeps the complete_agent handoff, and a delegated
|
|
512
519
|
// child reports to its parent rather than to the user.
|
|
520
|
+
// The one write an Orchestrator makes itself: clearing a stray untracked file, which can be what
|
|
521
|
+
// stops a subagent from starting. It takes a path and nothing else, so it cannot write code.
|
|
522
|
+
if (orchestrator && depth === 0 && effectiveCapabilities(configured).filesystem !== 'none')
|
|
523
|
+
tools.push(removeUntrackedFileTool());
|
|
513
524
|
if (!orchestrator && depth === 0 && options.context.approvalMode !== 'headless' && options.context.askUser)
|
|
514
|
-
tools.push({ name: 'ask_user', executionMode: 'sequential', description: 'Ask the user a question only they can answer and wait for the answer. Use it whenever a choice is theirs to make: a skill or instruction that says to ask, a preference, a missing requirement. A question written in your reply does not pause the run and may go unseen, so never ask that way. Ask one short question per call in plain language; when the options are known give 2-4 short choices, the recommended one first and labelled (Recommended). Do not ask what your tools can find out or what you can reasonably decide yourself.',
|
|
525
|
+
tools.push({ name: 'ask_user', executionMode: 'sequential', description: 'Ask the user a question only they can answer and wait for the answer. Use it whenever a choice is theirs to make: a skill or instruction that says to ask, a preference, a missing requirement. A question written in your reply does not pause the run and may go unseen, so never ask that way. Ask one short question per call in plain language; when the options are known give 2-4 short choices, the recommended one first and labelled (Recommended). Do not ask what your tools can find out or what you can reasonably decide yourself. Before asking where something is or what a name refers to, finish a search for it by file name and by content; a search that was cut short or timed out does not count.',
|
|
515
526
|
parameters: { type: 'object', properties: { question: { type: 'string', minLength: 1, maxLength: 500, description: 'One plain-language question.' }, choices: { type: 'array', items: { type: 'string', minLength: 1, maxLength: 200 }, minItems: 2, maxItems: 8, description: 'Short answers the user can pick from; they can always type their own.' } }, required: ['question'], additionalProperties: false },
|
|
516
527
|
execute: async (args, ctx) => {
|
|
517
528
|
ctx.signal.throwIfAborted();
|
|
@@ -904,6 +915,7 @@ export async function executeAgentNode(node, options) {
|
|
|
904
915
|
// workspace, the modes that auto-approve workspace writes land without a prompt and
|
|
905
916
|
// audit the grant.
|
|
906
917
|
const files = prepared.landing.files;
|
|
918
|
+
const { classifyWorkspaceWrites } = await import('./tools.js');
|
|
907
919
|
const { outside, protected: protectedPaths } = await classifyWorkspaceWrites(ctx.workspace, prepared.landing.root, files);
|
|
908
920
|
const automatic = () => !outside.length && !protectedPaths.length && ['ask-for-approval', 'approve-for-me'].includes(permissionMode(ctx) ?? '');
|
|
909
921
|
while (!(asked && files.every(file => granted.has(file)))) {
|
package/dist/src/agent-mcp.js
CHANGED
|
@@ -38,6 +38,11 @@ export const GRAPH_AGENT_GUIDE = [
|
|
|
38
38
|
' For multi-outcome agents supply completion: {mode: "outcomes", outcomes: ["pass", "fail"]}.',
|
|
39
39
|
' Every declared outcome must have an outgoing edge unless completion.requireRoutes is explicitly false.',
|
|
40
40
|
' Agents created or modified through MCP must set provider; never assume the active provider is inherited.',
|
|
41
|
+
' subagents {enabled, maxConcurrent, maxTotal, maxDepth, workspace, modelPolicy, toolInheritance, context, roles}:',
|
|
42
|
+
' workspace is shared-read-only (default; roles only read), shared-write (writes in place; maxConcurrent 1 when roles write)',
|
|
43
|
+
' or worktree (each child gets its own Git worktree; required for writing roles on an Orchestrator; needs parent git write).',
|
|
44
|
+
' modelPolicy: inherit | specific | per-role. toolInheritance: restricted | inherit. context: selected | task-only.',
|
|
45
|
+
' Validation messages name the field and the values to set. This guide and those messages are the whole reference: never search source code for them.',
|
|
41
46
|
'condition: requires condition {source, path, equals}; ports true and false; source must run before it on every path.',
|
|
42
47
|
'loop: requires loop {maxIterations}; ports body and done. A body edge may return to the loop.',
|
|
43
48
|
' Node visits are unlimited unless the graph sets graph.limits.maxNodeVisits; 0 means unlimited there too.',
|
|
@@ -44,7 +44,7 @@ export declare const APP_SERVER_PROTOCOL_VERSION = 2;
|
|
|
44
44
|
* one when a client omits it. An engine without it rebuilds a replaced entry from its own field
|
|
45
45
|
* list, so a save through it silently drops the rename and every surface falls back to the id; a
|
|
46
46
|
* client that can show the field must refuse the write first. */
|
|
47
|
-
export declare const APP_SERVER_CAPABILITIES: readonly ["run.start.runPermissions", "automations", "providers.models", "providers.test", "providers.test.model", "providers.streamIdleTimeout", "providers.modelContextWindows", "providers.name", "providers.claude", "providers.claudeAuth", "providers.grok", "providers.opencode", "providers.auth.submit", "providers.opencodeGo", "providers.discover.draft", "providers.codexAuth", "providers.codexAuth.logout", "providers.codexAccounts", "providers.anthropicConsole", "run.resume.direction", "run.resume.model", "run.steer", "run.overrideAllNodes", "run.setModel", "run.setModel.node", "run.setPermissions", "run.start.continueSession", "run.start.entryHistory", "remote.owner.projects", "remote.workspaces.probe", "remote.engine.relay", "remote.hosting.device.grant", "extensions.manage", "extensions.resources", "skills.invoke", "mcp.manage", "mcp.edit", "mcp.status", "runs.files", "sessions.files", "account.profile", "sessions.stats", "sessions.usage", "config.analytics", "config.analytics.planGate", "sessions.trajectory", "config.externalSubagent", "config.decisions", "browser.view", "attachments.read", "config.general", "sessions.pullRequest", "browser.view.go", "config.browser", "config.webSearch", "background.tasks", "workspace.warm", "browser.cookies.firefox", "sessions.compact", "sessions.changes"];
|
|
47
|
+
export declare const APP_SERVER_CAPABILITIES: readonly ["run.start.runPermissions", "automations", "providers.models", "providers.test", "providers.test.model", "providers.streamIdleTimeout", "providers.modelContextWindows", "providers.name", "providers.claude", "providers.claudeAuth", "providers.grok", "providers.opencode", "providers.auth.submit", "providers.opencodeGo", "providers.discover.draft", "providers.detectSignIns", "providers.codexAuth", "providers.codexAuth.logout", "providers.codexAccounts", "providers.anthropicConsole", "run.resume.direction", "run.resume.model", "run.steer", "run.overrideAllNodes", "run.setModel", "run.setModel.node", "run.setPermissions", "run.start.continueSession", "run.start.entryHistory", "remote.owner.projects", "remote.workspaces.probe", "remote.engine.relay", "remote.hosting.device.grant", "extensions.manage", "extensions.resources", "skills.invoke", "mcp.manage", "mcp.edit", "mcp.status", "runs.files", "sessions.files", "account.profile", "sessions.stats", "sessions.usage", "config.analytics", "config.analytics.planGate", "sessions.trajectory", "config.externalSubagent", "config.codeIntel", "config.decisions", "browser.view", "attachments.read", "config.general", "sessions.pullRequest", "browser.view.go", "config.browser", "config.webSearch", "background.tasks", "workspace.warm", "browser.cookies.firefox", "sessions.compact", "sessions.changes"];
|
|
48
48
|
/** One client call. `params` is omitted only for calls that take no arguments. */
|
|
49
49
|
export interface AppServerRequest {
|
|
50
50
|
id: number | string;
|
|
@@ -195,6 +195,13 @@ export interface AppServerConfig {
|
|
|
195
195
|
jevEnabled?: boolean;
|
|
196
196
|
decisions?: import('../decision/types.js').DecisionConfig;
|
|
197
197
|
commandMemory?: boolean;
|
|
198
|
+
/** The saved CodeGraph default and its per-repository overrides. Absent means the default: on. */
|
|
199
|
+
codeIntel?: {
|
|
200
|
+
enabled?: boolean;
|
|
201
|
+
disabledRepos?: string[];
|
|
202
|
+
enabledRepos?: string[];
|
|
203
|
+
};
|
|
204
|
+
projectMemory?: boolean;
|
|
198
205
|
/**
|
|
199
206
|
* The anonymous-feedback preference. An absent block means the default: reporting is on.
|
|
200
207
|
*
|
|
@@ -130,4 +130,4 @@ export const APP_SERVER_PROTOCOL_VERSION = 2;
|
|
|
130
130
|
// carries the pending set, without diffs, whenever it changes. A completed Write or Edit also reports its
|
|
131
131
|
// own change as `fileDiff` on `node.tool.completed`. An engine without it answers `unknown-method` and sends
|
|
132
132
|
// neither, so a window on such an engine shows no review bar and no Keep or Undo.
|
|
133
|
-
export const APP_SERVER_CAPABILITIES = ['run.start.runPermissions', 'automations', 'providers.models', 'providers.test', 'providers.test.model', 'providers.streamIdleTimeout', 'providers.modelContextWindows', 'providers.name', 'providers.claude', 'providers.claudeAuth', 'providers.grok', 'providers.opencode', 'providers.auth.submit', 'providers.opencodeGo', 'providers.discover.draft', 'providers.codexAuth', 'providers.codexAuth.logout', 'providers.codexAccounts', 'providers.anthropicConsole', 'run.resume.direction', 'run.resume.model', 'run.steer', 'run.overrideAllNodes', 'run.setModel', 'run.setModel.node', 'run.setPermissions', 'run.start.continueSession', 'run.start.entryHistory', 'remote.owner.projects', 'remote.workspaces.probe', 'remote.engine.relay', 'remote.hosting.device.grant', 'extensions.manage', 'extensions.resources', 'skills.invoke', 'mcp.manage', 'mcp.edit', 'mcp.status', 'runs.files', 'sessions.files', 'account.profile', 'sessions.stats', 'sessions.usage', 'config.analytics', 'config.analytics.planGate', 'sessions.trajectory', 'config.externalSubagent', 'config.decisions', 'browser.view', 'attachments.read', 'config.general', 'sessions.pullRequest', 'browser.view.go', 'config.browser', 'config.webSearch', 'background.tasks', 'workspace.warm', 'browser.cookies.firefox', 'sessions.compact', 'sessions.changes'];
|
|
133
|
+
export const APP_SERVER_CAPABILITIES = ['run.start.runPermissions', 'automations', 'providers.models', 'providers.test', 'providers.test.model', 'providers.streamIdleTimeout', 'providers.modelContextWindows', 'providers.name', 'providers.claude', 'providers.claudeAuth', 'providers.grok', 'providers.opencode', 'providers.auth.submit', 'providers.opencodeGo', 'providers.discover.draft', 'providers.detectSignIns', 'providers.codexAuth', 'providers.codexAuth.logout', 'providers.codexAccounts', 'providers.anthropicConsole', 'run.resume.direction', 'run.resume.model', 'run.steer', 'run.overrideAllNodes', 'run.setModel', 'run.setModel.node', 'run.setPermissions', 'run.start.continueSession', 'run.start.entryHistory', 'remote.owner.projects', 'remote.workspaces.probe', 'remote.engine.relay', 'remote.hosting.device.grant', 'extensions.manage', 'extensions.resources', 'skills.invoke', 'mcp.manage', 'mcp.edit', 'mcp.status', 'runs.files', 'sessions.files', 'account.profile', 'sessions.stats', 'sessions.usage', 'config.analytics', 'config.analytics.planGate', 'sessions.trajectory', 'config.externalSubagent', 'config.codeIntel', 'config.decisions', 'browser.view', 'attachments.read', 'config.general', 'sessions.pullRequest', 'browser.view.go', 'config.browser', 'config.webSearch', 'background.tasks', 'workspace.warm', 'browser.cookies.firefox', 'sessions.compact', 'sessions.changes'];
|
package/dist/src/app-server.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { removeCodexAccount } from './codex-auth.js';
|
|
|
3
3
|
import { CodexAccountAuth } from './codex-browser-auth.js';
|
|
4
4
|
import { AnthropicConsoleAuth } from './anthropic-console-auth.js';
|
|
5
5
|
import { OpenCodeSignIn } from './managed-sign-in.js';
|
|
6
|
+
import { type SignInProbes } from './sign-in-detection.js';
|
|
6
7
|
import type { CliSignIn } from './cli-sign-in.js';
|
|
7
8
|
import { checkGraphModelHealth } from './graph-health.js';
|
|
8
9
|
import { loadAccessibleGraph } from './membership.js';
|
|
@@ -111,6 +112,8 @@ export interface AppServerOptions {
|
|
|
111
112
|
grok?: ManagedSignInService;
|
|
112
113
|
opencode?: OpenCodeSignInService;
|
|
113
114
|
};
|
|
115
|
+
/** How each vendor CLI is asked whether it is signed in; overridable so a test never spawns one. */
|
|
116
|
+
signInProbes?: Partial<SignInProbes>;
|
|
114
117
|
/** Overridable so a test can answer `gh` without reaching GitHub. */
|
|
115
118
|
gh?: GhRunner;
|
|
116
119
|
/** How often the pull request watcher polls; a test shortens it. */
|
|
@@ -138,6 +141,9 @@ export declare class AppServer {
|
|
|
138
141
|
private readonly claudeSignIn;
|
|
139
142
|
private readonly grokSignIn;
|
|
140
143
|
private readonly openCodeSignIn;
|
|
144
|
+
private readonly signInProbes;
|
|
145
|
+
/** The last detection of each tool: an import names a type and a model, and is checked against this. */
|
|
146
|
+
private readonly detectedSignIns;
|
|
141
147
|
/** Retires a removed provider's slot home; a seam so a test never has to spawn the Codex CLI. */
|
|
142
148
|
private readonly retireCodexAccount;
|
|
143
149
|
/** The `gh` the pull request settings and watcher run through. */
|
|
@@ -456,6 +462,15 @@ export declare class AppServer {
|
|
|
456
462
|
*/
|
|
457
463
|
private retireSlots;
|
|
458
464
|
private discoverModels;
|
|
465
|
+
/**
|
|
466
|
+
* Which vendor CLIs on this machine are signed in and have no provider yet.
|
|
467
|
+
*
|
|
468
|
+
* Local-client only, like the sign-ins themselves: these logins belong to this machine. Only display
|
|
469
|
+
* fields and model ids are answered; a probe that fails says nothing rather than surfacing CLI output.
|
|
470
|
+
*/
|
|
471
|
+
private detectProviderSignIns;
|
|
472
|
+
/** Add the chosen detected sign-ins as providers; each must name a tool and model the last detection reported. */
|
|
473
|
+
private importProviderSignIns;
|
|
459
474
|
/** Local-client only. The remote engine relay deliberately does not admit these methods. */
|
|
460
475
|
private providerAuth;
|
|
461
476
|
/**
|
package/dist/src/app-server.js
CHANGED
|
@@ -16,6 +16,7 @@ import { testProviderConnection } from './provider-connection.js';
|
|
|
16
16
|
import { CodexAccountAuth } from './codex-browser-auth.js';
|
|
17
17
|
import { AnthropicConsoleAuth, droppedAnthropicAccounts } from './anthropic-console-auth.js';
|
|
18
18
|
import { claudeSignIn, grokSignIn, OpenCodeSignIn } from './managed-sign-in.js';
|
|
19
|
+
import { applySignInImports, detectSignIns, isDetectableSignInType } from './sign-in-detection.js';
|
|
19
20
|
import { OPENCODE_BASE_URL, sharedOpenCodeServer } from './opencode-cli-provider.js';
|
|
20
21
|
import { GROK_BASE_URL } from './grok-provider.js';
|
|
21
22
|
import { anthropicAccountHome } from './anthropic-credentials.js';
|
|
@@ -71,6 +72,7 @@ import { BackgroundTasks } from './background-tasks.js';
|
|
|
71
72
|
import { disposePooledPowerShell } from './powershell-pool.js';
|
|
72
73
|
import { TodoStore } from './todos.js';
|
|
73
74
|
import { LocalToolMemory } from './memory/LocalToolMemory.js';
|
|
75
|
+
import { ProjectMemory } from './memory/ProjectMemory.js';
|
|
74
76
|
import { CodeIntelligenceManager } from './code-intelligence/CodeIntelligenceManager.js';
|
|
75
77
|
import { startGraphServer } from './graph-server.js';
|
|
76
78
|
import { createSessionTrajectory } from './trajectory.js';
|
|
@@ -78,7 +80,7 @@ import { readUsageAnalytics } from './usage-analytics.js';
|
|
|
78
80
|
import { TerminalFlow, TerminalManager } from './app-server/terminal.js';
|
|
79
81
|
import { BrowserViewManager, browserViewUrl } from './browser-view.js';
|
|
80
82
|
import { listFirefoxProfiles, readFirefoxCookies } from './firefox-cookies.js';
|
|
81
|
-
import { createBrowserIncognitoTool, createBrowserPanelTool, runPanelOperation, validatePanelArguments } from './browser-panel-tool.js';
|
|
83
|
+
import { createBrowserIncognitoTool, createBrowserPanelTool, createPanelBrowserHold, runPanelOperation, validatePanelArguments } from './browser-panel-tool.js';
|
|
82
84
|
import { resolveCapsolverKey } from './capsolver.js';
|
|
83
85
|
import { resolveWebSearchProvider } from './web-search.js';
|
|
84
86
|
import { checkoutBranch, gitDiff, gitStatus, listBranches, listExtensions, listRuns, readRun, readSessionTrajectory, runRecordFile, sessionTrajectoryFile, readTree, readWorkspaceFile, summarizeMcpServer, workspaceRoot } from './app-server/workspace.js';
|
|
@@ -164,7 +166,7 @@ const RELAY_LONG_DEADLINE_MS = 1_260_000;
|
|
|
164
166
|
*/
|
|
165
167
|
const MAX_RESUME_LINEAGE = 32;
|
|
166
168
|
/** Fields a client may change through `config.set`. Anything else is rejected rather than merged. */
|
|
167
|
-
const EDITABLE_CONFIG_KEYS = ['provider', 'providers', 'graph', 'graphSelections', 'jevEnabled', 'decisions', 'commandMemory', 'limits', 'workspacePermissions', 'mcpServers', 'extensions', 'memory', 'codeIntel', 'externalSubagent', 'analytics', 'systemPromptOverride', 'autoArchiveDays', 'browser', 'webSearch'];
|
|
169
|
+
const EDITABLE_CONFIG_KEYS = ['provider', 'providers', 'graph', 'graphSelections', 'jevEnabled', 'decisions', 'commandMemory', 'projectMemory', 'limits', 'workspacePermissions', 'mcpServers', 'extensions', 'memory', 'codeIntel', 'externalSubagent', 'analytics', 'systemPromptOverride', 'autoArchiveDays', 'browser', 'webSearch'];
|
|
168
170
|
function message(error) { return error instanceof Error ? error.message : String(error); }
|
|
169
171
|
/** Project an owned authentication result instead of forwarding any official CLI payload wholesale. */
|
|
170
172
|
function providerAuthView(view, includeUrl) {
|
|
@@ -489,6 +491,8 @@ function configView(config, analytics) {
|
|
|
489
491
|
...(config.jevEnabled === undefined ? {} : { jevEnabled: config.jevEnabled }),
|
|
490
492
|
...(config.decisions === undefined ? {} : { decisions: structuredClone(config.decisions) }),
|
|
491
493
|
...(config.commandMemory === undefined ? {} : { commandMemory: config.commandMemory }),
|
|
494
|
+
...(config.codeIntel === undefined ? {} : { codeIntel: structuredClone(config.codeIntel) }),
|
|
495
|
+
...(config.projectMemory === undefined ? {} : { projectMemory: config.projectMemory }),
|
|
492
496
|
...(config.analytics === undefined && analytics === undefined ? {} : { analytics: { ...config.analytics, ...(analytics === undefined ? {} : { plan: analytics.plan, canOptOut: analytics.canOptOut }) } }),
|
|
493
497
|
...(config.limits === undefined ? {} : { limits: { ...config.limits } }),
|
|
494
498
|
...(config.workspacePermissions === undefined ? {} : { workspacePermissions: config.workspacePermissions }),
|
|
@@ -923,6 +927,9 @@ export class AppServer {
|
|
|
923
927
|
claudeSignIn;
|
|
924
928
|
grokSignIn;
|
|
925
929
|
openCodeSignIn;
|
|
930
|
+
signInProbes;
|
|
931
|
+
/** The last detection of each tool: an import names a type and a model, and is checked against this. */
|
|
932
|
+
detectedSignIns = new Map();
|
|
926
933
|
/** Retires a removed provider's slot home; a seam so a test never has to spawn the Codex CLI. */
|
|
927
934
|
retireCodexAccount;
|
|
928
935
|
/** The `gh` the pull request settings and watcher run through. */
|
|
@@ -1115,6 +1122,7 @@ export class AppServer {
|
|
|
1115
1122
|
this.claudeSignIn = options.managedSignIn?.claude ?? claudeSignIn();
|
|
1116
1123
|
this.grokSignIn = options.managedSignIn?.grok ?? grokSignIn();
|
|
1117
1124
|
this.openCodeSignIn = options.managedSignIn?.opencode ?? new OpenCodeSignIn();
|
|
1125
|
+
this.signInProbes = options.signInProbes;
|
|
1118
1126
|
this.retireCodexAccount = options.removeCodexAccount ?? removeCodexAccount;
|
|
1119
1127
|
this.gh = options.gh ?? runGh;
|
|
1120
1128
|
this.pullRequestWatcher = new PullRequestWatcher({
|
|
@@ -1385,6 +1393,8 @@ export class AppServer {
|
|
|
1385
1393
|
case 'providers.update': return this.updateProviders(params);
|
|
1386
1394
|
case 'providers.discover': return this.discoverModels(params);
|
|
1387
1395
|
case 'providers.test': return this.testProviderEndpoint(params);
|
|
1396
|
+
case 'providers.detectSignIns': return this.detectProviderSignIns(params);
|
|
1397
|
+
case 'providers.importSignIns': return this.importProviderSignIns(params);
|
|
1388
1398
|
case 'providers.auth.status': return this.providerAuth('status', params);
|
|
1389
1399
|
case 'providers.auth.start': return this.providerAuth('start', params);
|
|
1390
1400
|
case 'providers.auth.cancel': return this.providerAuth('cancel', params);
|
|
@@ -1457,7 +1467,10 @@ export class AppServer {
|
|
|
1457
1467
|
case 'timers.list': return this.listTimers();
|
|
1458
1468
|
case 'run.start': return this.startRun(params);
|
|
1459
1469
|
case 'workspace.warm': return this.warmWorkspace(params);
|
|
1460
|
-
|
|
1470
|
+
// A person pressing Resume is asking for the work to continue, and the attempt they resume most
|
|
1471
|
+
// often stopped because it spent its budget; restoring that spent budget would stop the new run
|
|
1472
|
+
// before it took a turn, so a run that ran out of time could never be resumed at all.
|
|
1473
|
+
case 'run.resume': return this.resumeRun(params, { freshAllowance: true });
|
|
1461
1474
|
case 'run.cancel': return this.cancelRun(params.runId);
|
|
1462
1475
|
case 'run.setModel': return this.setRunModel(params);
|
|
1463
1476
|
case 'run.setPermissions': return this.setRunPermissions(params);
|
|
@@ -2399,6 +2412,66 @@ export class AppServer {
|
|
|
2399
2412
|
throw new AppServerError('network', message(error));
|
|
2400
2413
|
}
|
|
2401
2414
|
}
|
|
2415
|
+
/**
|
|
2416
|
+
* Which vendor CLIs on this machine are signed in and have no provider yet.
|
|
2417
|
+
*
|
|
2418
|
+
* Local-client only, like the sign-ins themselves: these logins belong to this machine. Only display
|
|
2419
|
+
* fields and model ids are answered; a probe that fails says nothing rather than surfacing CLI output.
|
|
2420
|
+
*/
|
|
2421
|
+
async detectProviderSignIns(params) {
|
|
2422
|
+
const skip = params.skip;
|
|
2423
|
+
if (Object.keys(params).some(key => key !== 'skip') || (skip !== undefined && (!Array.isArray(skip) || skip.length > 8 || skip.some(type => !isDetectableSignInType(type))))) {
|
|
2424
|
+
throw new AppServerError('invalid-params', 'Sign-in detection accepts only skip, a list of claude, codex, grok or opencode.');
|
|
2425
|
+
}
|
|
2426
|
+
const config = await loadConfig(this.directory);
|
|
2427
|
+
const { signIns } = await this.operation(60_000, signal => detectSignIns(config, signal, {
|
|
2428
|
+
...(skip === undefined ? {} : { skip: skip }), ...(this.signInProbes ? { probes: this.signInProbes } : {}),
|
|
2429
|
+
}));
|
|
2430
|
+
for (const found of signIns)
|
|
2431
|
+
this.detectedSignIns.set(found.type, found);
|
|
2432
|
+
return { signIns };
|
|
2433
|
+
}
|
|
2434
|
+
/** Add the chosen detected sign-ins as providers; each must name a tool and model the last detection reported. */
|
|
2435
|
+
async importProviderSignIns(params) {
|
|
2436
|
+
const list = params.imports;
|
|
2437
|
+
const refuse = () => { throw new AppServerError('invalid-params', 'Those accounts are no longer available to add. Look for signed-in accounts again, then choose from that list.'); };
|
|
2438
|
+
if (Object.keys(params).some(key => key !== 'imports') || !Array.isArray(list) || !list.length || list.length > 4)
|
|
2439
|
+
refuse();
|
|
2440
|
+
const imports = [];
|
|
2441
|
+
const detected = [];
|
|
2442
|
+
for (const value of list) {
|
|
2443
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
2444
|
+
refuse();
|
|
2445
|
+
const item = value;
|
|
2446
|
+
if (Object.keys(item).some(key => key !== 'type' && key !== 'model') || !isDetectableSignInType(item.type) || typeof item.model !== 'string')
|
|
2447
|
+
refuse();
|
|
2448
|
+
const type = item.type;
|
|
2449
|
+
const found = this.detectedSignIns.get(type);
|
|
2450
|
+
if (!found || !found.models.includes(item.model) || imports.some(entry => entry.type === type))
|
|
2451
|
+
refuse();
|
|
2452
|
+
imports.push({ type, model: item.model });
|
|
2453
|
+
detected.push(found);
|
|
2454
|
+
}
|
|
2455
|
+
let added = [];
|
|
2456
|
+
const saved = await this.serializeConfig(async () => {
|
|
2457
|
+
try {
|
|
2458
|
+
return await changeConfigFile(this.directory, current => {
|
|
2459
|
+
const applied = applySignInImports(current, detected, imports);
|
|
2460
|
+
added = applied.added;
|
|
2461
|
+
return applied.config;
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
catch (error) {
|
|
2465
|
+
throw error instanceof ConfigConflictError ? new AppServerError('busy', message(error)) : new AppServerError('invalid-params', message(error));
|
|
2466
|
+
}
|
|
2467
|
+
});
|
|
2468
|
+
for (const entry of imports)
|
|
2469
|
+
this.detectedSignIns.delete(entry.type);
|
|
2470
|
+
const view = await this.analyticsConfigView(saved);
|
|
2471
|
+
if (added.length)
|
|
2472
|
+
this.emit('config.changed', { config: view });
|
|
2473
|
+
return { config: view, added };
|
|
2474
|
+
}
|
|
2402
2475
|
/** Local-client only. The remote engine relay deliberately does not admit these methods. */
|
|
2403
2476
|
async providerAuth(action, params) {
|
|
2404
2477
|
if (params.providerType === 'claude' || params.providerType === 'grok' || params.providerType === 'opencode')
|
|
@@ -3755,10 +3828,10 @@ export class AppServer {
|
|
|
3755
3828
|
}
|
|
3756
3829
|
}
|
|
3757
3830
|
lineage = [...chain];
|
|
3758
|
-
// A timer continuation
|
|
3759
|
-
//
|
|
3760
|
-
//
|
|
3761
|
-
//
|
|
3831
|
+
// A Resume (or a timer continuation, the agent coming back on its own deadline) usually continues an
|
|
3832
|
+
// attempt that stopped because it ran out of budget. Restored as-is, a spent allowance would end the
|
|
3833
|
+
// node before it took a turn, so the resume would be refused or stop at once. It gets a fresh
|
|
3834
|
+
// allowance instead: every restored conversation keeps all its messages
|
|
3762
3835
|
// and the completed work stays completed (nothing is replayed), but the counters it spent are cleared
|
|
3763
3836
|
// and the lineage's tool spend no longer counts against the new run.
|
|
3764
3837
|
if (internal?.freshAllowance === true) {
|
|
@@ -4538,6 +4611,8 @@ export class AppServer {
|
|
|
4538
4611
|
async executeRun(input) {
|
|
4539
4612
|
const { runId, startedAt, telemetryRunId, accountSubject, task, selection, providerId, modelId, root, permissions, liveSteers, boundPermissions, reasoningEffort, overrideAllNodes = false, modelPinned = overrideAllNodes, panelBrowserRelay = false, entryHistory = false, runInput, runState, automationContext, direction, wake, carriedDirections, ownDirectionId, armedRunIds, pendingDirections, directionNode, startNode, controller, attachments, openingAttachments, resumedFrom, resumeFrom, lineage, lineageArtifacts, prepared, nodeModelOverrides } = input;
|
|
4540
4613
|
const signal = controller.signal;
|
|
4614
|
+
// Keeps a panel browser the agent drove open while this attempt lives; stopped in the finally below.
|
|
4615
|
+
const panelHold = createPanelBrowserHold(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined);
|
|
4541
4616
|
const liveRun = this.run?.runId === runId ? this.run : undefined;
|
|
4542
4617
|
if (liveRun)
|
|
4543
4618
|
liveRun.graphSelection = selection;
|
|
@@ -4681,6 +4756,7 @@ export class AppServer {
|
|
|
4681
4756
|
};
|
|
4682
4757
|
let mcp;
|
|
4683
4758
|
let commandMemory;
|
|
4759
|
+
let projectMemory;
|
|
4684
4760
|
let result;
|
|
4685
4761
|
let failure;
|
|
4686
4762
|
let runConfig;
|
|
@@ -4980,6 +5056,8 @@ export class AppServer {
|
|
|
4980
5056
|
bootMark('run.exec.extensions.loaded');
|
|
4981
5057
|
if (config.commandMemory !== false)
|
|
4982
5058
|
commandMemory = await LocalToolMemory.open({ directory: this.directory, workspace: root });
|
|
5059
|
+
if (config.projectMemory !== false)
|
|
5060
|
+
projectMemory = await ProjectMemory.open({ home: this.directory, workspace: root });
|
|
4983
5061
|
// The run's own spooled attachments plus every replayed history turn's, readable under any
|
|
4984
5062
|
// permission mode: the user attached them, and the reference blocks the model reads name
|
|
4985
5063
|
// those very files — a follow-up with no new attachment still tells the model to read them.
|
|
@@ -5098,11 +5176,11 @@ export class AppServer {
|
|
|
5098
5176
|
// desktop relay to the engine that does. It is keyed to the saved session id both the pane
|
|
5099
5177
|
// and this run's browser events already use, so agent-driven tabs are the pane's tabs. The
|
|
5100
5178
|
// CLI builds its toolset without an app-server and never sees it.
|
|
5101
|
-
tools: [...createTools(), createBrowserPanelTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined),
|
|
5102
|
-
createBrowserIncognitoTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined), ...extension.tools, ...(mcp?.tools ?? [])], installedSkillClaims: extension.claimsSkillName, history: contextSeed,
|
|
5179
|
+
tools: [...createTools(), createBrowserPanelTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined, panelHold),
|
|
5180
|
+
createBrowserIncognitoTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined, panelHold), ...extension.tools, ...(mcp?.tools ?? [])], installedSkillClaims: extension.claimsSkillName, history: contextSeed,
|
|
5103
5181
|
...(runSkill.skill ? { inheritedSkills: [runSkill.skill.id], skillInvocationInstruction: runSkill.skill.instruction } : {}),
|
|
5104
5182
|
instructions: `${await loadWorkspaceInstructions(root, signal, config.systemPromptOverride)}${extension.instructions}`,
|
|
5105
|
-
codeIntel, todoStore: new TodoStore(), ...(commandMemory ? { commandMemory } : {}),
|
|
5183
|
+
codeIntel, todoStore: new TodoStore(), ...(commandMemory ? { commandMemory } : {}), ...(projectMemory ? { projectMemory } : {}),
|
|
5106
5184
|
limits: resolveConfiguredLimits(config),
|
|
5107
5185
|
...hostedDecisionPolicy(membership, config.jevEnabled !== false, config.decisions),
|
|
5108
5186
|
...(config.efficiency ? { efficiency: config.efficiency } : {}),
|
|
@@ -5300,6 +5378,7 @@ export class AppServer {
|
|
|
5300
5378
|
failure = error;
|
|
5301
5379
|
}
|
|
5302
5380
|
finally {
|
|
5381
|
+
panelHold.stop();
|
|
5303
5382
|
// A setup step that failed leaves the model preflight in flight; a run that reached the graph
|
|
5304
5383
|
// settled it long ago, and this is then a no-op.
|
|
5305
5384
|
healthAbort.abort();
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Tool, ToolImage } from './types.js';
|
|
2
2
|
import type { BrowserViewManager } from './browser-view.js';
|
|
3
|
+
/** How long one renewal keeps the panel browser from being idle-reaped. */
|
|
4
|
+
export declare const PANEL_HOLD_LEASE_MS: number;
|
|
5
|
+
/** How often a live run renews it: well inside the lease, so one lost renewal does not lapse it. */
|
|
6
|
+
export declare const PANEL_HOLD_RENEW_MS: number;
|
|
3
7
|
export interface PanelArguments {
|
|
4
8
|
operation: string;
|
|
5
9
|
url?: string;
|
|
@@ -28,19 +32,36 @@ export type PanelBrowserRelay = (operation: string, args: Record<string, unknown
|
|
|
28
32
|
image?: ToolImage;
|
|
29
33
|
error?: string;
|
|
30
34
|
}>;
|
|
35
|
+
/** A run's lease on its session's panel browser: armed by the agent's first panel operation, ended with the run. */
|
|
36
|
+
export interface PanelBrowserHold {
|
|
37
|
+
/** Called after each successful panel operation: takes the lease now and starts renewing it. */
|
|
38
|
+
touch(): void;
|
|
39
|
+
/** The run is over: stop renewing, and let the browser fall back to the ordinary idle window. */
|
|
40
|
+
stop(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Keep the session's panel browser open while the run that drove it lives.
|
|
44
|
+
*
|
|
45
|
+
* The owning engine reaps a panel browser nobody streams after `VIEW_IDLE_CLOSE_MS`. A run that
|
|
46
|
+
* opened a page and then waits — on the user's answer to a question about that page, typically —
|
|
47
|
+
* would otherwise lose the page under them. The lease is renewed on an unref'd timer, through the
|
|
48
|
+
* same relay as the agent's operations when another engine owns the browser; a renewal that fails
|
|
49
|
+
* is retried on the next tick, and an owner that never hears from us again reaps on its own.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createPanelBrowserHold(views: BrowserViewManager, sessionId: string, relay?: PanelBrowserRelay): PanelBrowserHold;
|
|
31
52
|
/**
|
|
32
53
|
* The agent's handle on the session's browser panel: the same tabs, cookies and
|
|
33
54
|
* login state the user sees and shares in the desktop's Browser panel. Created
|
|
34
55
|
* per run by the app-server: on the engine that owns the panel the operations
|
|
35
56
|
* run locally; on a task engine they relay through the desktop to the owning
|
|
36
57
|
* engine. Environments without a panel (the CLI) never create one, so the tool
|
|
37
|
-
* never appears there.
|
|
58
|
+
* never appears there. `hold`, when given, keeps the browser open while the run lives.
|
|
38
59
|
*/
|
|
39
|
-
export declare function createBrowserPanelTool(views: BrowserViewManager, sessionId: string, relay?: PanelBrowserRelay): Tool;
|
|
60
|
+
export declare function createBrowserPanelTool(views: BrowserViewManager, sessionId: string, relay?: PanelBrowserRelay, hold?: PanelBrowserHold): Tool;
|
|
40
61
|
/**
|
|
41
62
|
* The agent's switch between the project profile and a throwaway incognito
|
|
42
63
|
* browser in the session's Browser panel. A tool of its own rather than another
|
|
43
64
|
* `browser.panel` operation, so the agent sees plainly that a signed-out, fresh
|
|
44
65
|
* browser is available to it. It shares the panel tool's local and relayed paths.
|
|
45
66
|
*/
|
|
46
|
-
export declare function createBrowserIncognitoTool(views: BrowserViewManager, sessionId: string, relay?: PanelBrowserRelay): Tool;
|
|
67
|
+
export declare function createBrowserIncognitoTool(views: BrowserViewManager, sessionId: string, relay?: PanelBrowserRelay, hold?: PanelBrowserHold): Tool;
|
|
@@ -5,7 +5,17 @@ import { browserEventArguments, IMAGE_LIMIT, PENDING_IMAGE_LIMIT, reserveBrowser
|
|
|
5
5
|
const PAGE_OPERATIONS = ['open', 'navigate', 'back', 'forward', 'refresh', 'tabs', 'activate', 'close_tab', 'snapshot', 'click', 'fill', 'press', 'scroll', 'wait', 'screenshot'];
|
|
6
6
|
/** Whole-browser switches: exposed to the agent as `browser.incognito`, relayed like any panel operation. */
|
|
7
7
|
const INCOGNITO_OPERATIONS = ['incognito_start', 'incognito_end'];
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The run's own lease on the panel browser (see `BrowserViewManager.hold`): never offered to the
|
|
10
|
+
* agent, sent by the tool itself while its run lives, and relayed like any panel operation so it
|
|
11
|
+
* reaches the engine that owns the browser.
|
|
12
|
+
*/
|
|
13
|
+
const HOLD_OPERATION = 'hold';
|
|
14
|
+
const OPERATIONS = [...PAGE_OPERATIONS, ...INCOGNITO_OPERATIONS, HOLD_OPERATION];
|
|
15
|
+
/** How long one renewal keeps the panel browser from being idle-reaped. */
|
|
16
|
+
export const PANEL_HOLD_LEASE_MS = 3 * 60 * 1000;
|
|
17
|
+
/** How often a live run renews it: well inside the lease, so one lost renewal does not lapse it. */
|
|
18
|
+
export const PANEL_HOLD_RENEW_MS = 60 * 1000;
|
|
9
19
|
const ARGUMENTS = ['operation', 'url', 'tabId', 'selector', 'value', 'key', 'button', 'deltaY'];
|
|
10
20
|
function text(args, name, max = 2048) {
|
|
11
21
|
const value = args[name];
|
|
@@ -98,6 +108,8 @@ export async function runPanelOperation(views, sessionId, args, signal) {
|
|
|
98
108
|
const { operation, url, tabId, selector } = args;
|
|
99
109
|
if (operation === 'tabs')
|
|
100
110
|
return { result: panelTabsResult(views, sessionId) };
|
|
111
|
+
if (operation === HOLD_OPERATION)
|
|
112
|
+
return { result: JSON.stringify({ sessionId, ...views.hold(sessionId, PANEL_HOLD_LEASE_MS) }) };
|
|
101
113
|
if (operation === 'incognito_start') {
|
|
102
114
|
const opened = await cancellable(signal, owned => views.startIncognito(sessionId, owned), 35_000, 'Starting the incognito browser exceeded the 35-second timeout.');
|
|
103
115
|
return { result: JSON.stringify({ sessionId, profile: 'incognito', tabId: opened.tabId,
|
|
@@ -179,15 +191,68 @@ function panelTabsResult(views, sessionId) {
|
|
|
179
191
|
const summary = views.agentTabs(sessionId);
|
|
180
192
|
return JSON.stringify({ sessionId, tabs: summary.tabs.map(tab => ({ tabId: tab.id, active: tab.id === summary.activeTabId, url: tab.url, title: tab.title })) });
|
|
181
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Keep the session's panel browser open while the run that drove it lives.
|
|
196
|
+
*
|
|
197
|
+
* The owning engine reaps a panel browser nobody streams after `VIEW_IDLE_CLOSE_MS`. A run that
|
|
198
|
+
* opened a page and then waits — on the user's answer to a question about that page, typically —
|
|
199
|
+
* would otherwise lose the page under them. The lease is renewed on an unref'd timer, through the
|
|
200
|
+
* same relay as the agent's operations when another engine owns the browser; a renewal that fails
|
|
201
|
+
* is retried on the next tick, and an owner that never hears from us again reaps on its own.
|
|
202
|
+
*/
|
|
203
|
+
export function createPanelBrowserHold(views, sessionId, relay) {
|
|
204
|
+
let timer;
|
|
205
|
+
let stopped = false;
|
|
206
|
+
let renewing = false;
|
|
207
|
+
const renew = async () => {
|
|
208
|
+
if (stopped || renewing)
|
|
209
|
+
return;
|
|
210
|
+
renewing = true;
|
|
211
|
+
try {
|
|
212
|
+
if (!relay) {
|
|
213
|
+
views.hold(sessionId, PANEL_HOLD_LEASE_MS);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const deadline = new AbortController();
|
|
217
|
+
const bound = setTimeout(() => deadline.abort(), PANEL_HOLD_RENEW_MS);
|
|
218
|
+
bound.unref?.();
|
|
219
|
+
try {
|
|
220
|
+
await relay(HOLD_OPERATION, { operation: HOLD_OPERATION }, deadline.signal);
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
clearTimeout(bound);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch { /* The next tick retries; the lease outlasts one missed renewal. */ }
|
|
227
|
+
finally {
|
|
228
|
+
renewing = false;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
touch: () => {
|
|
233
|
+
if (stopped || timer)
|
|
234
|
+
return;
|
|
235
|
+
void renew();
|
|
236
|
+
timer = setInterval(() => { void renew(); }, PANEL_HOLD_RENEW_MS);
|
|
237
|
+
timer.unref?.();
|
|
238
|
+
},
|
|
239
|
+
stop: () => {
|
|
240
|
+
stopped = true;
|
|
241
|
+
if (timer)
|
|
242
|
+
clearInterval(timer);
|
|
243
|
+
timer = undefined;
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
182
247
|
/**
|
|
183
248
|
* The agent's handle on the session's browser panel: the same tabs, cookies and
|
|
184
249
|
* login state the user sees and shares in the desktop's Browser panel. Created
|
|
185
250
|
* per run by the app-server: on the engine that owns the panel the operations
|
|
186
251
|
* run locally; on a task engine they relay through the desktop to the owning
|
|
187
252
|
* engine. Environments without a panel (the CLI) never create one, so the tool
|
|
188
|
-
* never appears there.
|
|
253
|
+
* never appears there. `hold`, when given, keeps the browser open while the run lives.
|
|
189
254
|
*/
|
|
190
|
-
export function createBrowserPanelTool(views, sessionId, relay) {
|
|
255
|
+
export function createBrowserPanelTool(views, sessionId, relay, hold) {
|
|
191
256
|
/** Captured screenshots awaiting the runtime's resultImages collection. */
|
|
192
257
|
const pending = new Map();
|
|
193
258
|
return {
|
|
@@ -225,6 +290,8 @@ export function createBrowserPanelTool(views, sessionId, relay) {
|
|
|
225
290
|
const validated = validatePanelArguments(args);
|
|
226
291
|
if (INCOGNITO_OPERATIONS.includes(validated.operation))
|
|
227
292
|
throw new Error('Use browser.incognito to switch the panel browser to or from incognito');
|
|
293
|
+
if (validated.operation === HOLD_OPERATION)
|
|
294
|
+
throw new Error('Invalid browser panel operation or argument');
|
|
228
295
|
await authorize('browser.panel', browserEventArguments(args), context);
|
|
229
296
|
context.signal.throwIfAborted();
|
|
230
297
|
// One operation, whichever engine's browser executes it: the owning
|
|
@@ -249,6 +316,7 @@ export function createBrowserPanelTool(views, sessionId, relay) {
|
|
|
249
316
|
let committed = false;
|
|
250
317
|
try {
|
|
251
318
|
const captured = await run();
|
|
319
|
+
hold?.touch();
|
|
252
320
|
const bytes = Number.isSafeInteger(JSON.parse(captured.result).bytes) ? JSON.parse(captured.result).bytes : IMAGE_LIMIT;
|
|
253
321
|
reservation.commit(bytes);
|
|
254
322
|
committed = true;
|
|
@@ -261,7 +329,10 @@ export function createBrowserPanelTool(views, sessionId, relay) {
|
|
|
261
329
|
reservation.refund();
|
|
262
330
|
}
|
|
263
331
|
}
|
|
264
|
-
|
|
332
|
+
const { result } = await run();
|
|
333
|
+
// The agent has used the panel this run: from here the browser stays open while the run lives.
|
|
334
|
+
hold?.touch();
|
|
335
|
+
return result;
|
|
265
336
|
},
|
|
266
337
|
};
|
|
267
338
|
}
|
|
@@ -271,7 +342,7 @@ export function createBrowserPanelTool(views, sessionId, relay) {
|
|
|
271
342
|
* `browser.panel` operation, so the agent sees plainly that a signed-out, fresh
|
|
272
343
|
* browser is available to it. It shares the panel tool's local and relayed paths.
|
|
273
344
|
*/
|
|
274
|
-
export function createBrowserIncognitoTool(views, sessionId, relay) {
|
|
345
|
+
export function createBrowserIncognitoTool(views, sessionId, relay, hold) {
|
|
275
346
|
return {
|
|
276
347
|
name: 'browser.incognito', family: 'browser', capability: 'browser', executionMode: 'sequential',
|
|
277
348
|
description: 'Switch this session\'s Browser panel between the project profile and a fresh incognito browser. The panel normally runs on the project\'s persistent profile: logins, cookies, history and cache shared with the user and every session of this project. start closes the panel browser (its tabs close; the saved project profile is untouched) and opens an incognito browser with one blank tab and no logins, cookies, storage, history or cache — use it to test as a signed-out or first-time visitor, then drive it with browser.panel. Nothing from incognito is saved. end closes the incognito browser so the next browser.panel open uses the project profile again; incognito also ends on its own when the panel browser closes (last tab closed, idle, or app restart). Browser capability and normal approvals are required.',
|
|
@@ -290,9 +361,12 @@ export function createBrowserIncognitoTool(views, sessionId, relay) {
|
|
|
290
361
|
throw new Error(answer.error);
|
|
291
362
|
if (answer.result === undefined)
|
|
292
363
|
throw new Error('The panel browser relay returned no result');
|
|
364
|
+
hold?.touch();
|
|
293
365
|
return answer.result;
|
|
294
366
|
}
|
|
295
|
-
|
|
367
|
+
const { result } = await runPanelOperation(views, sessionId, { operation }, context.signal);
|
|
368
|
+
hold?.touch();
|
|
369
|
+
return result;
|
|
296
370
|
},
|
|
297
371
|
};
|
|
298
372
|
}
|