@andorra-labs/code 0.1.16 → 0.1.18
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/dist/src/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-execution.js +108 -19
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +3 -0
- package/dist/src/agent-mcp.js +33 -1
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +30 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +108 -0
- package/dist/src/app-server/workspace.js +608 -11
- package/dist/src/app-server.d.ts +390 -33
- package/dist/src/app-server.js +3033 -565
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +359 -0
- package/dist/src/bridge/control.d.ts +70 -0
- package/dist/src/bridge/control.js +238 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/github.d.ts +108 -0
- package/dist/src/bridge/github.js +378 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +139 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +543 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/tokens.css +1 -1
- package/dist/src/bug-report-attachments.d.ts +48 -0
- package/dist/src/bug-report-attachments.js +327 -0
- package/dist/src/bug-report.d.ts +23 -3
- package/dist/src/bug-report.js +72 -9
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +191 -35
- package/dist/src/codex-provider.js +1 -1
- package/dist/src/coding-tools.js +24 -17
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +14 -11
- package/dist/src/commands.d.ts +15 -3
- package/dist/src/commands.js +2 -1
- package/dist/src/compaction-phrases.js +1 -1
- package/dist/src/completion.js +89 -8
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +205 -78
- package/dist/src/context-budget.js +15 -2
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +11 -0
- package/dist/src/decision/DecisionManager.js +36 -0
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/hostedPolicy.js +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.js +12 -0
- package/dist/src/decision/requestPhrases.js +0 -1
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/types.d.ts +1 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +5 -0
- package/dist/src/efficiency.js +5 -1
- package/dist/src/effort-routing.d.ts +27 -0
- package/dist/src/effort-routing.js +34 -0
- package/dist/src/evidence.d.ts +110 -0
- package/dist/src/evidence.js +195 -0
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +368 -0
- package/dist/src/github-app/client.js +830 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-names.d.ts +15 -0
- package/dist/src/github-names.js +15 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +6 -1
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +48 -0
- package/dist/src/graph-preview.js +56 -0
- package/dist/src/graph-provider-portability.js +2 -1
- package/dist/src/graph-runner.js +65 -4
- package/dist/src/graph-server.js +7 -5
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +121 -7
- package/dist/src/graph-ui/icons.js +2 -1
- package/dist/src/graph-ui/studio.js +15 -1
- package/dist/src/graph-ui/tokens.css +1 -1
- package/dist/src/graphs.d.ts +40 -1
- package/dist/src/graphs.js +164 -15
- package/dist/src/hardened-runtime.js +32 -21
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +10 -0
- package/dist/src/membership.js +19 -4
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +6 -0
- package/dist/src/model-metadata.js +35 -15
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/model-tiers.d.ts +3 -0
- package/dist/src/model-tiers.js +3 -3
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +74 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +28 -2
- package/dist/src/providers.js +59 -12
- package/dist/src/pull-request-logs.d.ts +12 -1
- package/dist/src/pull-request-logs.js +14 -3
- package/dist/src/pull-requests.d.ts +338 -8
- package/dist/src/pull-requests.js +482 -53
- package/dist/src/react-runtime.js +99 -16
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +367 -90
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +7 -0
- package/dist/src/run-control.js +23 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +34 -2
- package/dist/src/runtime.js +18 -2
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +35 -1
- package/dist/src/sessions.js +70 -4
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/task-checkout.d.ts +141 -0
- package/dist/src/task-checkout.js +558 -0
- package/dist/src/telemetry/emitter.d.ts +15 -0
- package/dist/src/telemetry/emitter.js +35 -1
- package/dist/src/telemetry/schema.d.ts +25 -2
- package/dist/src/telemetry/schema.js +52 -4
- package/dist/src/telemetry/surface.d.ts +2 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +37 -0
- package/dist/src/test-edit-guard.js +216 -3
- package/dist/src/thinking-level-detect.d.ts +11 -0
- package/dist/src/thinking-level-detect.js +47 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +124 -0
- package/dist/src/timers.d.ts +3 -0
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +59 -9
- package/dist/src/transcript.js +1 -1
- package/dist/src/types.d.ts +34 -0
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ProviderConfig, type ReasoningEffort } from './providers.js';
|
|
2
|
+
/** The thinking levels one model accepts and the ones the user switched off, as saved on its provider. */
|
|
3
|
+
export interface ModelThinkingLevels {
|
|
4
|
+
supported?: ReasoningEffort[];
|
|
5
|
+
disabled?: ReasoningEffort[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The levels a model may run at, lowest first: the ones it accepts minus the ones switched off. A model nobody has
|
|
9
|
+
* detected yet counts as accepting every level, which is what the engine sent before levels were tracked.
|
|
10
|
+
*/
|
|
11
|
+
export declare function enabledLevels(provider: Pick<ProviderConfig, 'type' | 'thinkingLevels'> | undefined, model: string): ReasoningEffort[];
|
|
12
|
+
/**
|
|
13
|
+
* The levels Auto may pick for a model. For a detected model these are its enabled levels. For one nobody has
|
|
14
|
+
* detected, Auto stays inside the widely accepted levels, so that it never sends a level the provider would refuse
|
|
15
|
+
* and fail the run; a level the user sets by hand is still sent as written.
|
|
16
|
+
*/
|
|
17
|
+
export declare function autoLevels(provider: Pick<ProviderConfig, 'type' | 'thinkingLevels'> | undefined, model: string): ReasoningEffort[];
|
|
18
|
+
/** The wanted level when it is enabled, else the closest enabled one, the higher of two equally close. */
|
|
19
|
+
export declare function nearestEnabled(levels: readonly ReasoningEffort[], wanted: ReasoningEffort): ReasoningEffort | undefined;
|
|
20
|
+
export declare function validateThinkingLevels(value: unknown, providerType: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Which levels a model accepts. A catalogued model answers from the catalog. Any other is asked once per level with
|
|
23
|
+
* `send`, which returns the HTTP status of one minimal request at that level; a 2xx keeps the level. Returns undefined,
|
|
24
|
+
* so that nothing is saved, when the server could not be reached or refused for a reason unrelated to the level.
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectLevels(send: (effort: ReasoningEffort, signal: AbortSignal) => Promise<number>, signal: AbortSignal, catalog?: readonly ReasoningEffort[]): Promise<ReasoningEffort[] | undefined>;
|
|
27
|
+
/** The provider with a model's detected levels saved. The user's switched-off levels are kept where still accepted. */
|
|
28
|
+
export declare function withDetectedLevels<T extends Pick<ProviderConfig, 'thinkingLevels'>>(provider: T, model: string, supported: readonly ReasoningEffort[]): T;
|
|
29
|
+
/** The provider with a model's switched-off levels replaced. Throws when that would leave no level enabled. */
|
|
30
|
+
export declare function withDisabledLevels<T extends Pick<ProviderConfig, 'thinkingLevels'>>(provider: T, model: string, disabled: readonly ReasoningEffort[]): T;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { REASONING_EFFORTS, supportsReasoningEffort } from './providers.js';
|
|
2
|
+
// Read at call time, not at load: this module and the provider module can be loaded in either order.
|
|
3
|
+
const position = (level) => REASONING_EFFORTS.indexOf(level);
|
|
4
|
+
const isLevel = (value) => typeof value === 'string' && REASONING_EFFORTS.includes(value);
|
|
5
|
+
const ordered = (levels) => REASONING_EFFORTS.filter(level => new Set(levels).has(level));
|
|
6
|
+
/**
|
|
7
|
+
* The levels a model may run at, lowest first: the ones it accepts minus the ones switched off. A model nobody has
|
|
8
|
+
* detected yet counts as accepting every level, which is what the engine sent before levels were tracked.
|
|
9
|
+
*/
|
|
10
|
+
export function enabledLevels(provider, model) {
|
|
11
|
+
if (!provider || !supportsReasoningEffort(provider.type))
|
|
12
|
+
return [];
|
|
13
|
+
const entry = provider.thinkingLevels?.[model];
|
|
14
|
+
const disabled = new Set(entry?.disabled ?? []);
|
|
15
|
+
return ordered(entry?.supported ?? REASONING_EFFORTS).filter(level => !disabled.has(level));
|
|
16
|
+
}
|
|
17
|
+
/** The levels nearly every provider that takes a level accepts. */
|
|
18
|
+
const WIDELY_ACCEPTED = ['low', 'medium', 'high'];
|
|
19
|
+
/**
|
|
20
|
+
* The levels Auto may pick for a model. For a detected model these are its enabled levels. For one nobody has
|
|
21
|
+
* detected, Auto stays inside the widely accepted levels, so that it never sends a level the provider would refuse
|
|
22
|
+
* and fail the run; a level the user sets by hand is still sent as written.
|
|
23
|
+
*/
|
|
24
|
+
export function autoLevels(provider, model) {
|
|
25
|
+
const enabled = enabledLevels(provider, model);
|
|
26
|
+
return provider?.thinkingLevels?.[model]?.supported === undefined ? enabled.filter(level => WIDELY_ACCEPTED.includes(level)) : enabled;
|
|
27
|
+
}
|
|
28
|
+
/** The wanted level when it is enabled, else the closest enabled one, the higher of two equally close. */
|
|
29
|
+
export function nearestEnabled(levels, wanted) {
|
|
30
|
+
if (levels.includes(wanted))
|
|
31
|
+
return wanted;
|
|
32
|
+
const at = position(wanted);
|
|
33
|
+
let best;
|
|
34
|
+
let distance = Infinity;
|
|
35
|
+
for (const level of levels) {
|
|
36
|
+
const gap = Math.abs(position(level) - at);
|
|
37
|
+
if (gap < distance || (gap === distance && position(level) > at)) {
|
|
38
|
+
best = level;
|
|
39
|
+
distance = gap;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return best;
|
|
43
|
+
}
|
|
44
|
+
export function validateThinkingLevels(value, providerType) {
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return;
|
|
47
|
+
const fail = () => { throw new Error('Invalid thinkingLevels: a map of model ids to { supported, disabled } lists of none, minimal, low, medium, high, xhigh or max, with at least one thinking level left enabled'); };
|
|
48
|
+
if (!supportsReasoningEffort(providerType))
|
|
49
|
+
throw new Error('thinkingLevels belongs to a provider that accepts a thinking level');
|
|
50
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
51
|
+
fail();
|
|
52
|
+
for (const [model, entry] of Object.entries(value)) {
|
|
53
|
+
if (!model.trim() || model.length > 500 || typeof entry !== 'object' || entry === null || Array.isArray(entry))
|
|
54
|
+
fail();
|
|
55
|
+
const { supported, disabled, ...rest } = entry;
|
|
56
|
+
if (Object.keys(rest).length)
|
|
57
|
+
fail();
|
|
58
|
+
for (const list of [supported, disabled]) {
|
|
59
|
+
if (list === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
if (!Array.isArray(list) || list.some(level => !isLevel(level)) || new Set(list).size !== list.length)
|
|
62
|
+
fail();
|
|
63
|
+
}
|
|
64
|
+
const off = new Set(disabled ?? []);
|
|
65
|
+
if (!(supported ?? REASONING_EFFORTS).some(level => !off.has(level))
|
|
66
|
+
&& (supported?.length ?? 1) > 0)
|
|
67
|
+
fail();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** HTTP answers that say nothing about the level asked for: the request never reached a decision on it. */
|
|
71
|
+
const INCONCLUSIVE = new Set([401, 403, 404, 408, 429]);
|
|
72
|
+
/**
|
|
73
|
+
* Which levels a model accepts. A catalogued model answers from the catalog. Any other is asked once per level with
|
|
74
|
+
* `send`, which returns the HTTP status of one minimal request at that level; a 2xx keeps the level. Returns undefined,
|
|
75
|
+
* so that nothing is saved, when the server could not be reached or refused for a reason unrelated to the level.
|
|
76
|
+
*/
|
|
77
|
+
export async function detectLevels(send, signal, catalog) {
|
|
78
|
+
if (catalog)
|
|
79
|
+
return ordered(catalog);
|
|
80
|
+
const accepted = [];
|
|
81
|
+
for (const level of REASONING_EFFORTS) {
|
|
82
|
+
signal.throwIfAborted();
|
|
83
|
+
let status;
|
|
84
|
+
try {
|
|
85
|
+
status = await send(level, signal);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
signal.throwIfAborted();
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
if (INCONCLUSIVE.has(status) || status >= 500)
|
|
92
|
+
return undefined;
|
|
93
|
+
if (status >= 200 && status < 300)
|
|
94
|
+
accepted.push(level);
|
|
95
|
+
}
|
|
96
|
+
return accepted;
|
|
97
|
+
}
|
|
98
|
+
/** The provider with a model's detected levels saved. The user's switched-off levels are kept where still accepted. */
|
|
99
|
+
export function withDetectedLevels(provider, model, supported) {
|
|
100
|
+
const levels = ordered(supported);
|
|
101
|
+
const kept = (provider.thinkingLevels?.[model]?.disabled ?? []).filter(level => levels.includes(level));
|
|
102
|
+
const disabled = kept.length >= levels.length ? [] : ordered(kept);
|
|
103
|
+
return { ...provider, thinkingLevels: { ...provider.thinkingLevels, [model]: { supported: levels, ...(disabled.length ? { disabled } : {}) } } };
|
|
104
|
+
}
|
|
105
|
+
/** The provider with a model's switched-off levels replaced. Throws when that would leave no level enabled. */
|
|
106
|
+
export function withDisabledLevels(provider, model, disabled) {
|
|
107
|
+
const entry = provider.thinkingLevels?.[model];
|
|
108
|
+
const supported = entry?.supported ?? [...REASONING_EFFORTS];
|
|
109
|
+
const off = ordered(disabled.filter(level => supported.includes(level)));
|
|
110
|
+
if (supported.length > 0 && off.length >= supported.length)
|
|
111
|
+
throw new Error('At least one thinking level must stay enabled');
|
|
112
|
+
const next = { ...(entry?.supported ? { supported: entry.supported } : {}), ...(off.length ? { disabled: off } : {}) };
|
|
113
|
+
const all = { ...provider.thinkingLevels };
|
|
114
|
+
if (Object.keys(next).length)
|
|
115
|
+
all[model] = next;
|
|
116
|
+
else
|
|
117
|
+
delete all[model];
|
|
118
|
+
const result = { ...provider };
|
|
119
|
+
if (Object.keys(all).length)
|
|
120
|
+
result.thinkingLevels = all;
|
|
121
|
+
else
|
|
122
|
+
delete result.thinkingLevels;
|
|
123
|
+
return result;
|
|
124
|
+
}
|
package/dist/src/timers.d.ts
CHANGED
|
@@ -7,9 +7,12 @@ export interface WakeCarry {
|
|
|
7
7
|
graph?: string;
|
|
8
8
|
provider?: string;
|
|
9
9
|
model?: string;
|
|
10
|
+
/** A thinking level, or 'auto' for a run whose own level is Auto. */
|
|
10
11
|
reasoningEffort?: string;
|
|
11
12
|
overrideAllNodes?: boolean;
|
|
12
13
|
panelBrowserRelay?: boolean;
|
|
14
|
+
/** The session's run used a desktop's providers: a wake cannot start it here, only a resume from that desktop can. */
|
|
15
|
+
relayed?: boolean;
|
|
13
16
|
input?: Record<string, unknown>;
|
|
14
17
|
state?: Record<string, unknown>;
|
|
15
18
|
}
|
package/dist/src/tool-catalog.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toolFamily } from './decision/toolFamilies.js';
|
|
2
2
|
import { canonicalToolName } from './tool-names.js';
|
|
3
3
|
import { identifierTokens } from './context-selection.js';
|
|
4
|
-
const PROTECTED = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'submit_bug_report', 'load_project_skill', 'restore_tools', 'prepare_steps', 'update_widget', 'Skill', 'read_skill_resource', 'expand_tool_output', 'read_artifact', 'write_artifact']);
|
|
4
|
+
const PROTECTED = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'submit_bug_report', 'list_bug_report_sessions', 'load_project_skill', 'restore_tools', 'prepare_steps', 'update_widget', 'Skill', 'read_skill_resource', 'expand_tool_output', 'read_artifact', 'write_artifact']);
|
|
5
5
|
const GIT_WORDS = /\b(git|commit|branch|rebase|merge|stash|diff|blame|checkout|pull request|pr\b|push|history|log)\b/i;
|
|
6
6
|
const MEMORY_WORDS = /\b(remember|recall|memory|previous(ly)?|last time|earlier|convention|decision history)\b/i;
|
|
7
7
|
const WEB_WORDS = /\b(docs?|documentation|https?:\/\/|url|website|web|online|latest version|api reference|changelog|npm package|look up|search the)\b/i;
|
package/dist/src/tools.js
CHANGED
|
@@ -17,7 +17,8 @@ import { READ_IMAGE_FILE_LIMIT } from './read-image.js';
|
|
|
17
17
|
import { decodeLegacyText, sniffDocument } from './read-document.js';
|
|
18
18
|
import { READ_DOCUMENT_FILE_LIMIT } from './read-document-tool.js';
|
|
19
19
|
import { clipText } from './text.js';
|
|
20
|
-
import { pullRequestSettings } from './pull-requests.js';
|
|
20
|
+
import { pullRequestSettings, REVIEW_BUMP_COMMENT, REVIEW_INSTRUCTION_BYTES, REVIEW_ROUNDS_DEFAULT, REVIEW_ROUNDS_MAX, reviewLoopActive, reviewLoopSettings } from './pull-requests.js';
|
|
21
|
+
import { agentWriteFromArgs } from './github-app/agent-writes.js';
|
|
21
22
|
import { approveOperation } from './capabilities.js';
|
|
22
23
|
import { HARNESS_HOME_OFF_LIMITS, assertCommandAvoidsHarnessHome, guardsHarnessHome, insideHarnessHome } from './harness-home.js';
|
|
23
24
|
const OUTPUT_LIMIT = 32_768;
|
|
@@ -599,13 +600,44 @@ function qaPermissionTool(tool) {
|
|
|
599
600
|
} };
|
|
600
601
|
}
|
|
601
602
|
const AWAIT_REVIEW_DEFAULT_MINUTES = 360;
|
|
603
|
+
const REVIEW_PHASE_TEXT = { waiting: 'waiting to review', reviewing: 'reviewing', posting: 'posting a review', fixing: 'waiting for your fixes', ended: 'ended' };
|
|
604
|
+
/** The Andorra review loop in the tool's status: on with its round and phase, or off with how the last loop ended. */
|
|
605
|
+
function describeReview(pr) {
|
|
606
|
+
const review = pr.review;
|
|
607
|
+
if (review === undefined)
|
|
608
|
+
return 'Andorra review off';
|
|
609
|
+
if (reviewLoopActive(pr))
|
|
610
|
+
return `Andorra review on (${review.round} of ${review.rounds} reviews posted, ${REVIEW_PHASE_TEXT[review.phase]})`;
|
|
611
|
+
if (review.ended === undefined)
|
|
612
|
+
return `Andorra review off (${review.rounds} rounds when on)`;
|
|
613
|
+
return `Andorra review off (the last loop ended ${review.ended.reason} after ${review.round} of ${review.rounds} reviews${review.ended.detail === undefined ? '' : `: ${review.ended.detail}`})`;
|
|
614
|
+
}
|
|
615
|
+
/** What an Andorra review loop's end means for the agent waiting on it. */
|
|
616
|
+
const REVIEW_END_TEXT = {
|
|
617
|
+
'signed-off': 'Its last review found no P1 or P2 findings.',
|
|
618
|
+
'rounds-used': 'Its last round still found something, and those findings are left for the user: do not fix them unless the user asks.',
|
|
619
|
+
'review-only': 'This task cannot push to the pull request\'s head repository, so the review\'s findings are left for the user.',
|
|
620
|
+
'no-new-commits': 'The turn that took its findings ended without a new commit.',
|
|
621
|
+
'switched-off': 'Andorra review was switched off.',
|
|
622
|
+
};
|
|
623
|
+
function reviewLoopEndAnswer(ended) {
|
|
624
|
+
const why = REVIEW_END_TEXT[ended.reason] ?? (ended.detail === undefined ? '' : ended.detail);
|
|
625
|
+
const next = ended.pullRequest.autoFix
|
|
626
|
+
? 'Auto-fix is still on: call await_review again to wait for other reviewers, or finish and report.'
|
|
627
|
+
: 'There is no review left to wait for; finish your work and report.';
|
|
628
|
+
return `The Andorra review loop ended: ${ended.reason}.${why ? ` ${why}` : ''} ${next}`;
|
|
629
|
+
}
|
|
602
630
|
function reviewWaitAnswer(ended, minutes, signal) {
|
|
603
631
|
switch (ended.kind) {
|
|
632
|
+
// The loop's wake text already says to call await_review once the round is pushed and answered.
|
|
633
|
+
case 'review': return ended.prompt;
|
|
634
|
+
case 'review-ended': return reviewLoopEndAnswer(ended);
|
|
604
635
|
case 'comments': return `${ended.prompt}
|
|
605
636
|
|
|
606
637
|
When this round is pushed and its threads are answered, call pull_request with action await_review again to wait for the next review.`;
|
|
638
|
+
case 'approved': return `Codex signed off on ${ended.pullRequest.url}${ended.headSha === undefined ? '' : ` at ${ended.headSha.slice(0, 10)}`}: it reviewed that commit and found nothing (its thumbs-up on the pull request, or a review with no findings), and no new review comment is waiting. Treat this as an approval of that commit. There is no review left to wait for; finish your work and report, and merge only if the user asked you to. Call await_review again only after you push another commit.`;
|
|
607
639
|
case 'finished': return `${ended.pullRequest.url} is ${ended.pullRequest.state}, so Auto-fix is off and there is no review left to wait for. Finish your work and report.`;
|
|
608
|
-
case 'off': return `Auto-fix is off for ${ended.pullRequest.url}, so no review will be waited for. Finish your work and report; switch Auto-fix on only if the user asks.`;
|
|
640
|
+
case 'off': return `Auto-fix is off for ${ended.pullRequest.url} and no Andorra review loop is running, so no review will be waited for. Finish your work and report; switch Auto-fix or Andorra review on only if the user asks.`;
|
|
609
641
|
case 'none': return 'No pull request is tracked for this session, so there is no review to wait for.';
|
|
610
642
|
case 'timeout': return `No new review arrived in ${minutes} minute${minutes === 1 ? '' : 's'}. Call await_review again to keep waiting, or finish and report.`;
|
|
611
643
|
case 'steered': return 'The user sent you a message while you were waiting for a review. Read and answer it; call await_review again afterwards if the review loop should continue.';
|
|
@@ -751,20 +783,27 @@ export function createTools() {
|
|
|
751
783
|
context.wakesArmed?.push(timer.id);
|
|
752
784
|
return `Timer ${timer.id.slice(0, 8)} armed: your prompt will be delivered in ${args.seconds} second${args.seconds === 1 ? '' : 's'}, at ${new Date(timer.fireAt).toISOString()}. It fires once.`;
|
|
753
785
|
}),
|
|
754
|
-
{ ...tool('pull_request',
|
|
755
|
-
action: { type: 'string', enum: ['status', 'attach', 'update', 'await_review', 'dismiss'], description: 'status shows the tracked PR; attach starts tracking url; update changes settings; await_review waits for the next review round; dismiss stops tracking' },
|
|
786
|
+
{ ...tool('pull_request', `Show or change the pull request this session tracks in the desktop Plan card. A PR you open with \`gh pr create\` is attached automatically; use attach for one opened another way. update changes its settings when the user asks: mergeWhenReady enables GitHub auto-merge (gh pr merge --auto), draft converts to a draft or marks it ready, autoFix wakes you with a prompt when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments and switches itself off once the PR is merged or closed. review switches on Andorra review: the Andorra Code bot reviews the PR up to reviewRounds times (1 to ${REVIEW_ROUNDS_MAX}, default ${REVIEW_ROUNDS_DEFAULT}) and you are woken to fix its findings between reviews; reviewInstruction tells the reviewer what to focus on, reviewModel picks its provider/model (default: this task's), and review false switches it off. It needs a paid Andorra plan and a pull request the Andorra Code GitHub App covers; the result says why when it cannot be switched on. await_review keeps you in this run while Auto-fix or Andorra review is on: it waits, without using the model, until new review comments arrive (and returns them), Andorra review posts its next round (and returns it) or ends, Codex signs off on the head commit (its thumbs-up on the pull request, which is its approval), the PR is merged or closed, the user messages you, or timeoutMinutes pass. Use it to own the review loop: fix a round, push, resolve the threads you fixed, then call await_review again, until the PR is merged or closed. Never wait for a review with sleep, a shell loop or set_timer. Where Codex reviews the repository but shows no sign of having picked up the head commit after 30 seconds (no eyes reaction, no review, no comment), the wait posts "@codex review" on the PR once for that commit, as the gh account that reads the PR; do not post that comment yourself. reply answers a review thread (threadId, body), resolve resolves one (resolved false reopens it), and comment posts on the PR's conversation (body); they act only on the tracked PR. Where the Andorra Code GitHub App covers the PR they post as its bot, otherwise as the gh account that reads the PR; the result says who posted and why. dismiss stops tracking an open PR, and only when the user asks you to: never dismiss as cleanup after a merge, because a merged or closed PR stays on the task as its record and dismiss refuses one. Only change a setting the user asked you to change.`, {
|
|
787
|
+
action: { type: 'string', enum: ['status', 'attach', 'update', 'await_review', 'reply', 'resolve', 'comment', 'dismiss'], description: 'status shows the tracked PR; attach starts tracking url; update changes settings; await_review waits for the next review round; reply, resolve and comment write on the tracked PR; dismiss stops tracking an open PR when the user asks (refused once it is merged or closed)' },
|
|
788
|
+
threadId: property('The review thread\'s id, PRRT_…, from gh\'s reviewThreads query (reply and resolve only)'),
|
|
789
|
+
body: property('The text to post (reply and comment only)'),
|
|
790
|
+
resolved: { type: 'boolean', description: 'resolve only: false reopens a resolved thread (default true)' },
|
|
756
791
|
url: property('The GitHub pull request URL (attach only)'),
|
|
757
792
|
autoFix: { type: 'boolean', description: 'Wake this session when a code-review bot (Codex, CodeRabbit, Greptile, Copilot) comments, until the PR is merged or closed' },
|
|
758
793
|
mergeWhenReady: { type: 'boolean', description: 'GitHub auto-merge once checks and reviews pass' },
|
|
759
794
|
draft: { type: 'boolean', description: 'true converts to a draft, false marks it ready for review' },
|
|
795
|
+
review: { type: 'boolean', description: 'Andorra review: true has the Andorra Code bot review the PR in rounds and wakes you to fix its findings between them; false stops it' },
|
|
796
|
+
reviewRounds: { type: 'integer', minimum: 1, maximum: REVIEW_ROUNDS_MAX, description: `How many reviews Andorra review posts at most (1 to ${REVIEW_ROUNDS_MAX}, default ${REVIEW_ROUNDS_DEFAULT})` },
|
|
797
|
+
reviewInstruction: property(`What Andorra review's reviewer should focus on, for example "focus on security" (at most ${REVIEW_INSTRUCTION_BYTES} bytes; empty clears it)`),
|
|
798
|
+
reviewModel: property('The reviewer\'s provider/model, for example anthropic/claude-sonnet-4-5 (empty: this task\'s model)'),
|
|
760
799
|
timeoutMinutes: { type: 'integer', minimum: 1, maximum: 1440, description: `How long await_review waits for a review before returning (1 to 1440, default ${AWAIT_REVIEW_DEFAULT_MINUTES})` },
|
|
761
800
|
}, ['action'], async (args, context) => {
|
|
762
801
|
const control = context.pullRequests;
|
|
763
802
|
if (!control)
|
|
764
803
|
throw new Error('pull_request is unavailable here; no session tracks a pull request for this run.');
|
|
765
|
-
const settings = pullRequestSettings(args);
|
|
804
|
+
const settings = { ...pullRequestSettings(args), ...reviewLoopSettings(args) };
|
|
766
805
|
const approve = () => approveOperation(context, 'pull_request', { ...args, warning: 'Changes the pull request on GitHub, or what Andorra does on its own when the PR changes.' });
|
|
767
|
-
const describe = (pr) => `${pr.url} (${pr.state})${pr.title ? ` "${pr.title}"` : ''}: autoFix ${pr.autoFix ? 'on' : 'off'}, mergeWhenReady ${pr.mergeWhenReady ? 'on' : 'off'}`;
|
|
806
|
+
const describe = (pr) => `${pr.url} (${pr.state})${pr.title ? ` "${pr.title}"` : ''}: autoFix ${pr.autoFix ? 'on' : 'off'}, mergeWhenReady ${pr.mergeWhenReady ? 'on' : 'off'}, ${describeReview(pr)}`;
|
|
768
807
|
switch (args.action) {
|
|
769
808
|
case 'status': {
|
|
770
809
|
const pr = await control.status();
|
|
@@ -778,7 +817,7 @@ export function createTools() {
|
|
|
778
817
|
}
|
|
779
818
|
case 'update': {
|
|
780
819
|
if (!Object.keys(settings).length)
|
|
781
|
-
throw new Error('update needs at least one of autoFix, mergeWhenReady, draft');
|
|
820
|
+
throw new Error('update needs at least one of autoFix, mergeWhenReady, draft, review, reviewRounds, reviewInstruction, reviewModel');
|
|
782
821
|
await approve();
|
|
783
822
|
return `Updated ${describe(await control.update(settings, context.wakeOrigin))}`;
|
|
784
823
|
}
|
|
@@ -789,14 +828,25 @@ export function createTools() {
|
|
|
789
828
|
if (typeof minutes !== 'number' || !Number.isSafeInteger(minutes) || minutes < 1 || minutes > 1_440)
|
|
790
829
|
throw new Error('timeoutMinutes must be an integer from 1 to 1440');
|
|
791
830
|
const awaitReview = control.awaitReview.bind(control);
|
|
792
|
-
const
|
|
831
|
+
const approveBump = (detail) => approveOperation(context, 'pull_request', { ...args, body: REVIEW_BUMP_COMMENT, warning: `Changes the pull request on GitHub. ${detail}` });
|
|
832
|
+
const wait = () => awaitReview(context.signal, minutes * 60_000, context.wakeOrigin, { approveBump });
|
|
793
833
|
const ended = await (context.waitOutside ? context.waitOutside(wait) : wait());
|
|
794
834
|
return reviewWaitAnswer(ended, minutes, context.signal);
|
|
795
835
|
}
|
|
836
|
+
case 'reply':
|
|
837
|
+
case 'resolve':
|
|
838
|
+
case 'comment': {
|
|
839
|
+
const write = agentWriteFromArgs(args);
|
|
840
|
+
if (!control.write)
|
|
841
|
+
throw new Error(`${args.action} is unavailable here; this surface cannot write on the pull request.`);
|
|
842
|
+
// Asked by the write once it knows the route and the write passes that route's checks (the bot's 16 KiB), before
|
|
843
|
+
// anything is sent; `detail` says who it posts as.
|
|
844
|
+
return control.write(write, { signal: context.signal, approve: detail => approveOperation(context, 'pull_request', { ...args, warning: `Changes the pull request on GitHub. ${detail}` }) });
|
|
845
|
+
}
|
|
796
846
|
case 'dismiss':
|
|
797
847
|
await control.dismiss();
|
|
798
848
|
return 'The pull request is no longer tracked for this session.';
|
|
799
|
-
default: throw new Error('action must be status, attach, update, await_review, or dismiss');
|
|
849
|
+
default: throw new Error('action must be status, attach, update, await_review, reply, resolve, comment, or dismiss');
|
|
800
850
|
}
|
|
801
851
|
}), family: 'git', executionMode: 'sequential' },
|
|
802
852
|
...createCodingTools({ safePath, read, readImage, readDocument, readLegacyText, atomicWrite, authorize, files, fileLimit: FILE_LIMIT }),
|
package/dist/src/transcript.js
CHANGED
|
@@ -104,7 +104,7 @@ export function formatEvent(event) {
|
|
|
104
104
|
if (event.type === 'decision.fallback' && data.reason !== 'low_confidence') {
|
|
105
105
|
const reasons = {
|
|
106
106
|
authentication_required: 'Sign in required', decision_daily_limit_reached: 'Daily quota reached',
|
|
107
|
-
decision_window_limit_reached: '
|
|
107
|
+
decision_window_limit_reached: 'Jev limit reached',
|
|
108
108
|
decision_service_unavailable: 'Service unavailable', invalid_response: 'Invalid response',
|
|
109
109
|
decision_protocol_unsupported: 'Request not accepted by the service',
|
|
110
110
|
decision_input_too_large: 'Context exceeds hosted size limits; evaluation skipped locally',
|
package/dist/src/types.d.ts
CHANGED
|
@@ -3,6 +3,18 @@ export interface ToolCall {
|
|
|
3
3
|
name: string;
|
|
4
4
|
arguments: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* One entry of the `reasoning_details` Andorra's router adds to an answer from a model it serves through Anthropic's
|
|
8
|
+
* Messages API: a block of Claude's answer (signed thinking, redacted thinking, a text length or a tool call's place),
|
|
9
|
+
* sealed for the router to rebuild the turn from. The client keeps it as received and sends it back unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export interface RouterReasoningDetail {
|
|
12
|
+
type: 'reasoning.encrypted';
|
|
13
|
+
format: 'anthropic-messages-v1';
|
|
14
|
+
index: number;
|
|
15
|
+
data: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
6
18
|
export interface ProviderContinuation {
|
|
7
19
|
api: string;
|
|
8
20
|
provider: string;
|
|
@@ -13,6 +25,8 @@ export interface ProviderContinuation {
|
|
|
13
25
|
thinkingSignature?: string;
|
|
14
26
|
redacted?: boolean;
|
|
15
27
|
}[];
|
|
28
|
+
/** Andorra's router only: the answer's `reasoning_details`, sent back on the same assistant message. */
|
|
29
|
+
reasoningDetails?: RouterReasoningDetail[];
|
|
16
30
|
}
|
|
17
31
|
export interface ToolImage {
|
|
18
32
|
mimeType: 'image/png' | 'image/jpeg';
|
|
@@ -50,6 +64,11 @@ export interface ModelResponse {
|
|
|
50
64
|
stopReason?: string;
|
|
51
65
|
reasoningContent?: string;
|
|
52
66
|
providerContinuation?: ProviderContinuation;
|
|
67
|
+
/**
|
|
68
|
+
* Messages an adapter added at the end of the request this answer replies to, which the run keeps in its history right
|
|
69
|
+
* before the answer: Claude's thinking comes back from Andorra's router only while its earlier conversation is unchanged.
|
|
70
|
+
*/
|
|
71
|
+
requestTail?: Message[];
|
|
53
72
|
}
|
|
54
73
|
export interface ModelRequestContext {
|
|
55
74
|
runId?: string;
|
|
@@ -112,6 +131,8 @@ export interface ToolRuntimeState {
|
|
|
112
131
|
fileReads: Map<string, ToolFileReadState>;
|
|
113
132
|
}
|
|
114
133
|
export interface ToolContext {
|
|
134
|
+
/** The project a task is filed under, when it works elsewhere (its own worktree); `workspace` is where it works. */
|
|
135
|
+
project?: string;
|
|
115
136
|
automationDirectory?: string;
|
|
116
137
|
browserSessionOwner?: object;
|
|
117
138
|
browserToolBatch?: object;
|
|
@@ -139,6 +160,18 @@ export interface ToolContext {
|
|
|
139
160
|
onApprovalEvent?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
140
161
|
onBrowserEvent?: (type: string, data: Record<string, unknown>) => void | Promise<void>;
|
|
141
162
|
onCommandOutput?: (chunk: string) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Records a shell command the agent runs, for the turn's evidence: called before it starts (the runtime reads the
|
|
165
|
+
* revision it runs against), and the returned function when it ends.
|
|
166
|
+
*/
|
|
167
|
+
observeCommand?: (start: {
|
|
168
|
+
command: string;
|
|
169
|
+
directory: string;
|
|
170
|
+
signal?: AbortSignal;
|
|
171
|
+
}) => Promise<(end: {
|
|
172
|
+
exitCode?: number;
|
|
173
|
+
output: string;
|
|
174
|
+
}) => void>;
|
|
142
175
|
onFilePathAuthorized?: (canonicalTarget: string) => void | Promise<void>;
|
|
143
176
|
toolState?: ToolRuntimeState;
|
|
144
177
|
timers?: import('./timers.js').TimerRegistry;
|
|
@@ -146,6 +179,7 @@ export interface ToolContext {
|
|
|
146
179
|
wakeOrigin?: import('./timers.js').WakeOrigin;
|
|
147
180
|
wakesArmed?: string[];
|
|
148
181
|
sessionScope?: string;
|
|
182
|
+
sessionId?: string;
|
|
149
183
|
pullRequests?: import('./pull-requests.js').PullRequestControl;
|
|
150
184
|
fileChanges?: import('./session-changes.js').FileChangeRecorder;
|
|
151
185
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andorra-labs/code",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Terminal-first coding agent with a ReAct graph runtime",
|
|
5
5
|
"homepage": "https://andorracode.com",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"typebox": "1.3.27",
|
|
81
81
|
"yaml": "2.9.0"
|
|
82
82
|
},
|
|
83
|
+
"overrides": {
|
|
84
|
+
"@npmcli/package-json": {
|
|
85
|
+
"glob": "14.0.6"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
83
88
|
"lavamoat": {
|
|
84
89
|
"allowScripts": {
|
|
85
90
|
"@google/genai#2.21.0": false,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export interface RemoteTlsIdentity {
|
|
3
|
-
keyPem: string;
|
|
4
|
-
certPem: string;
|
|
5
|
-
fingerprint: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function certificateFingerprint(certPem: string): string;
|
|
8
|
-
export { pemFromDer } from './pem.js';
|
|
9
|
-
export declare function ensureRemoteTlsIdentity(tlsDirectory: string, options?: {
|
|
10
|
-
rotate?: boolean;
|
|
11
|
-
}): Promise<RemoteTlsIdentity>;
|
package/dist/src/remote/cert.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { createHash, createPrivateKey, createPublicKey, randomBytes, X509Certificate as NodeX509Certificate, webcrypto } from 'node:crypto';
|
|
2
|
-
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import 'reflect-metadata';
|
|
5
|
-
import * as x509 from '@peculiar/x509';
|
|
6
|
-
import { acquireSaveLock, SaveLockBusyError } from '../save-lock.js';
|
|
7
|
-
import { toPem } from './pem.js';
|
|
8
|
-
x509.cryptoProvider.set(webcrypto);
|
|
9
|
-
const CERTIFICATE_LIFETIME_MS = 10 * 365 * 24 * 60 * 60 * 1000;
|
|
10
|
-
export function certificateFingerprint(certPem) {
|
|
11
|
-
const der = new NodeX509Certificate(certPem).raw;
|
|
12
|
-
return createHash('sha256').update(der).digest('base64url');
|
|
13
|
-
}
|
|
14
|
-
export { pemFromDer } from './pem.js';
|
|
15
|
-
function storedPairUsable(certPem, keyPem) {
|
|
16
|
-
try {
|
|
17
|
-
const cert = new NodeX509Certificate(certPem);
|
|
18
|
-
const publicKeyPem = cert.publicKey.export({ type: 'spki', format: 'pem' });
|
|
19
|
-
const storedPublicKeyPem = createPublicKey(createPrivateKey(keyPem)).export({ type: 'spki', format: 'pem' });
|
|
20
|
-
return Date.parse(cert.validTo) >= Date.now() && publicKeyPem === storedPublicKeyPem;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async function loadStablePair(tlsDirectory) {
|
|
27
|
-
try {
|
|
28
|
-
const [certPem, keyPem] = await Promise.all([
|
|
29
|
-
readFile(join(tlsDirectory, 'cert.pem'), 'utf8'),
|
|
30
|
-
readFile(join(tlsDirectory, 'key.pem'), 'utf8'),
|
|
31
|
-
]);
|
|
32
|
-
if (!storedPairUsable(certPem, keyPem))
|
|
33
|
-
return null;
|
|
34
|
-
return { certPem, keyPem, fingerprint: certificateFingerprint(certPem) };
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export async function ensureRemoteTlsIdentity(tlsDirectory, options = {}) {
|
|
41
|
-
await mkdir(tlsDirectory, { recursive: true });
|
|
42
|
-
let release;
|
|
43
|
-
for (let attempt = 0; release === undefined; attempt += 1) {
|
|
44
|
-
try {
|
|
45
|
-
release = await acquireSaveLock(tlsDirectory);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (!(error instanceof SaveLockBusyError))
|
|
49
|
-
throw error;
|
|
50
|
-
if (attempt >= 200) {
|
|
51
|
-
const published = await loadStablePair(tlsDirectory);
|
|
52
|
-
if (published)
|
|
53
|
-
return published;
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
await new Promise(resolve => setTimeout(resolve, 25));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
if (!options.rotate) {
|
|
61
|
-
const existing = await loadStablePair(tlsDirectory);
|
|
62
|
-
if (existing)
|
|
63
|
-
return existing;
|
|
64
|
-
}
|
|
65
|
-
const keys = await webcrypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']);
|
|
66
|
-
const now = Date.now();
|
|
67
|
-
const certificate = await x509.X509CertificateGenerator.createSelfSigned({
|
|
68
|
-
serialNumber: randomBytes(8).toString('hex'),
|
|
69
|
-
name: 'CN=andorra-remote',
|
|
70
|
-
notBefore: new Date(now - 60_000),
|
|
71
|
-
notAfter: new Date(now + CERTIFICATE_LIFETIME_MS),
|
|
72
|
-
keys,
|
|
73
|
-
}, webcrypto);
|
|
74
|
-
const keyPem = toPem('PRIVATE KEY', new Uint8Array(await webcrypto.subtle.exportKey('pkcs8', keys.privateKey)));
|
|
75
|
-
const certPem = certificate.toString('pem');
|
|
76
|
-
const stagedKey = join(tlsDirectory, `key-${randomBytes(6).toString('hex')}.tmp`);
|
|
77
|
-
const stagedCert = join(tlsDirectory, `cert-${randomBytes(6).toString('hex')}.tmp`);
|
|
78
|
-
await writeFile(stagedKey, keyPem, { mode: 0o600 });
|
|
79
|
-
await writeFile(stagedCert, certPem, { mode: 0o600 });
|
|
80
|
-
await rename(stagedKey, join(tlsDirectory, 'key.pem'));
|
|
81
|
-
await rename(stagedCert, join(tlsDirectory, 'cert.pem'));
|
|
82
|
-
return { keyPem, certPem, fingerprint: certificateFingerprint(certPem) };
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
await release();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
export interface PeerTarget {
|
|
2
|
-
host: string;
|
|
3
|
-
port: number;
|
|
4
|
-
transport: 'https' | 'http';
|
|
5
|
-
fingerprint: string;
|
|
6
|
-
certPem?: string;
|
|
7
|
-
token?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface PeerListing {
|
|
10
|
-
rootId: string;
|
|
11
|
-
rel: string;
|
|
12
|
-
parent: string | null;
|
|
13
|
-
entries: {
|
|
14
|
-
name: string;
|
|
15
|
-
type: 'file' | 'directory';
|
|
16
|
-
}[];
|
|
17
|
-
hasMore: boolean;
|
|
18
|
-
}
|
|
19
|
-
export declare function addressAttemptBudgetMs(deadlineAt: number | undefined, now: number): number;
|
|
20
|
-
export interface PeerWhoami {
|
|
21
|
-
hostname: string;
|
|
22
|
-
platform: string;
|
|
23
|
-
version: string;
|
|
24
|
-
grant?: 'browse' | 'full';
|
|
25
|
-
relay?: boolean;
|
|
26
|
-
capabilities?: string[];
|
|
27
|
-
}
|
|
28
|
-
export declare function peerWhoami(target: PeerTarget, hostOrder?: string, deadlineAt?: number, signal?: AbortSignal): Promise<PeerWhoami>;
|
|
29
|
-
export declare function peerProjects(target: PeerTarget, hostOrder?: string): Promise<{
|
|
30
|
-
projects: {
|
|
31
|
-
rootId: string;
|
|
32
|
-
name: string;
|
|
33
|
-
}[];
|
|
34
|
-
}>;
|
|
35
|
-
export declare function peerRoots(target: PeerTarget, hostOrder?: string): Promise<{
|
|
36
|
-
roots: {
|
|
37
|
-
id: string;
|
|
38
|
-
label: string;
|
|
39
|
-
kind: 'project' | 'share';
|
|
40
|
-
}[];
|
|
41
|
-
}>;
|
|
42
|
-
export interface PeerProviderExport {
|
|
43
|
-
providers: unknown[];
|
|
44
|
-
}
|
|
45
|
-
export declare function peerProviderExport(target: PeerTarget, hostOrder?: string, deadlineAt?: number, signal?: AbortSignal): Promise<PeerProviderExport>;
|
|
46
|
-
export declare function peerBrowse(target: PeerTarget, rootId: string, rel: string, hostOrder?: string): Promise<PeerListing>;
|
|
47
|
-
export interface PeerOwnerDirectory {
|
|
48
|
-
path: string;
|
|
49
|
-
parent: string | null;
|
|
50
|
-
entries: {
|
|
51
|
-
name: string;
|
|
52
|
-
path: string;
|
|
53
|
-
type: 'directory' | 'file';
|
|
54
|
-
}[];
|
|
55
|
-
hasMore: boolean;
|
|
56
|
-
}
|
|
57
|
-
export declare function peerOwnerRoots(target: PeerTarget, hostOrder?: string): Promise<{
|
|
58
|
-
roots: {
|
|
59
|
-
path: string;
|
|
60
|
-
name: string;
|
|
61
|
-
}[];
|
|
62
|
-
}>;
|
|
63
|
-
export declare function peerOwnerBrowse(target: PeerTarget, path: string, hostOrder?: string): Promise<PeerOwnerDirectory>;
|
|
64
|
-
export declare function peerOwnerAddProject(target: PeerTarget, path: string, hostOrder?: string): Promise<{
|
|
65
|
-
rootId: string;
|
|
66
|
-
name: string;
|
|
67
|
-
}>;
|
|
68
|
-
export declare function capturePeerCertificate(host: string, port: number, transport: 'https' | 'http', expectedFingerprint: string): Promise<{
|
|
69
|
-
host: string;
|
|
70
|
-
certPem: string;
|
|
71
|
-
}>;
|
|
72
|
-
export interface PairingPlan {
|
|
73
|
-
hosts: string[];
|
|
74
|
-
port: number;
|
|
75
|
-
transport: 'https' | 'http';
|
|
76
|
-
fingerprint: string;
|
|
77
|
-
invite: string;
|
|
78
|
-
name: string;
|
|
79
|
-
}
|
|
80
|
-
export declare function redeemPairingPlan(plan: PairingPlan, options?: {
|
|
81
|
-
label?: string;
|
|
82
|
-
}): Promise<{
|
|
83
|
-
deviceId: string;
|
|
84
|
-
credential: string;
|
|
85
|
-
hostname: string;
|
|
86
|
-
platform: string;
|
|
87
|
-
version: string;
|
|
88
|
-
grant: 'browse' | 'full';
|
|
89
|
-
host: string;
|
|
90
|
-
certPem: string;
|
|
91
|
-
}>;
|
|
92
|
-
export declare function newWorkspaceIdForClient(): string;
|
|
93
|
-
export interface PeerEngineCall {
|
|
94
|
-
connectionId: string;
|
|
95
|
-
viewerWorkspaceId?: string;
|
|
96
|
-
engine: string;
|
|
97
|
-
method: string;
|
|
98
|
-
params?: Record<string, unknown>;
|
|
99
|
-
deadlineMs?: number;
|
|
100
|
-
}
|
|
101
|
-
export interface PeerEngineAnswer {
|
|
102
|
-
result?: unknown;
|
|
103
|
-
error?: {
|
|
104
|
-
code: string;
|
|
105
|
-
message: string;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
export declare function peerEngineRequest(target: PeerTarget, call: PeerEngineCall, hostOrder?: string, deadlineAt?: number): Promise<PeerEngineAnswer>;
|
|
109
|
-
export type PeerEventsOutcome = {
|
|
110
|
-
kind: 'ended';
|
|
111
|
-
} | {
|
|
112
|
-
kind: 'unauthorized' | 'identity' | 'rejected';
|
|
113
|
-
message: string;
|
|
114
|
-
};
|
|
115
|
-
export declare function peerEngineEvents(target: PeerTarget, host: string, connectionId: string, viewerWorkspaceId: string | undefined, onEvent: (frame: {
|
|
116
|
-
engine: string;
|
|
117
|
-
event: string;
|
|
118
|
-
data: Record<string, unknown>;
|
|
119
|
-
}) => void, signal: AbortSignal): Promise<PeerEventsOutcome>;
|