@aria-cli/tools 1.0.12 → 1.0.14
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/index.js +378 -70
- package/dist/network-runtime/index.js +8 -12
- package/dist-cjs/index.js +400 -435
- package/dist-cjs/network-runtime/index.js +8 -172
- package/package.json +8 -6
- package/dist/.tsbuildinfo +0 -1
- package/dist/ask-user-interaction.js +0 -22
- package/dist/cache/web-cache.js +0 -66
- package/dist/definitions/arion.js +0 -104
- package/dist/definitions/browser/browser.js +0 -418
- package/dist/definitions/browser/index.js +0 -4
- package/dist/definitions/browser/pw-downloads.js +0 -114
- package/dist/definitions/browser/pw-interactions.js +0 -199
- package/dist/definitions/browser/pw-responses.js +0 -76
- package/dist/definitions/browser/pw-session.js +0 -310
- package/dist/definitions/browser/pw-shared.js +0 -66
- package/dist/definitions/browser/pw-snapshot.js +0 -301
- package/dist/definitions/browser/pw-state.js +0 -62
- package/dist/definitions/browser/types.js +0 -4
- package/dist/definitions/code-intelligence.js +0 -470
- package/dist/definitions/core.js +0 -109
- package/dist/definitions/delegation.js +0 -512
- package/dist/definitions/deploy.js +0 -65
- package/dist/definitions/filesystem.js +0 -196
- package/dist/definitions/frg.js +0 -63
- package/dist/definitions/index.js +0 -20
- package/dist/definitions/memory.js +0 -123
- package/dist/definitions/messaging.js +0 -625
- package/dist/definitions/meta.js +0 -349
- package/dist/definitions/network.js +0 -159
- package/dist/definitions/outlook.js +0 -277
- package/dist/definitions/patch/apply-patch.js +0 -184
- package/dist/definitions/patch/fuzzy-match.js +0 -166
- package/dist/definitions/patch/index.js +0 -1
- package/dist/definitions/patch/patch-parser.js +0 -207
- package/dist/definitions/patch/sandbox-paths.js +0 -105
- package/dist/definitions/process/index.js +0 -4
- package/dist/definitions/process/process-registry.js +0 -213
- package/dist/definitions/process/process.js +0 -386
- package/dist/definitions/process/pty-keys.js +0 -254
- package/dist/definitions/process/session-slug.js +0 -142
- package/dist/definitions/quip.js +0 -195
- package/dist/definitions/search.js +0 -60
- package/dist/definitions/session-history.js +0 -69
- package/dist/definitions/shell.js +0 -181
- package/dist/definitions/slack.js +0 -180
- package/dist/definitions/web.js +0 -109
- package/dist/executors/apply-patch.js +0 -901
- package/dist/executors/arion.js +0 -119
- package/dist/executors/code-intelligence.js +0 -882
- package/dist/executors/deploy.js +0 -848
- package/dist/executors/filesystem.js +0 -1122
- package/dist/executors/frg-freshness.js +0 -576
- package/dist/executors/frg.js +0 -298
- package/dist/executors/index.js +0 -46
- package/dist/executors/learning-meta.js +0 -1146
- package/dist/executors/lsp-client.js +0 -296
- package/dist/executors/memory.js +0 -750
- package/dist/executors/meta.js +0 -220
- package/dist/executors/process-registry.js +0 -465
- package/dist/executors/pty-session-store.js +0 -30
- package/dist/executors/pty.js +0 -271
- package/dist/executors/restart.js +0 -119
- package/dist/executors/search-freshness.js +0 -195
- package/dist/executors/search-types.js +0 -52
- package/dist/executors/search.js +0 -66
- package/dist/executors/self-diagnose.js +0 -398
- package/dist/executors/session-history.js +0 -283
- package/dist/executors/shell-safety.js +0 -473
- package/dist/executors/shell.js +0 -954
- package/dist/executors/utils.js +0 -33
- package/dist/executors/web.js +0 -542
- package/dist/extraction/content-extraction.js +0 -235
- package/dist/extraction/index.js +0 -4
- package/dist/headless-control-contract.js +0 -967
- package/dist/local-control-http-auth.js +0 -2
- package/dist/mcp/client.js +0 -181
- package/dist/mcp/connection.js +0 -480
- package/dist/mcp/index.js +0 -10
- package/dist/mcp/jsonrpc.js +0 -144
- package/dist/mcp/types.js +0 -7
- package/dist/network-control-adapter.js +0 -72
- package/dist/network-runtime/address-types.js +0 -165
- package/dist/network-runtime/db-owner-fencing.js +0 -69
- package/dist/network-runtime/delivery-receipts.js +0 -267
- package/dist/network-runtime/direct-endpoint-authority.js +0 -25
- package/dist/network-runtime/local-control-contract.js +0 -627
- package/dist/network-runtime/node-store-contract.js +0 -34
- package/dist/network-runtime/pair-route-contract.js +0 -77
- package/dist/network-runtime/peer-capabilities.js +0 -28
- package/dist/network-runtime/peer-principal-ref.js +0 -12
- package/dist/network-runtime/peer-state-machine.js +0 -121
- package/dist/network-runtime/protocol-schemas.js +0 -205
- package/dist/network-runtime/runtime-bootstrap-contract.js +0 -60
- package/dist/outlook/desktop-session.js +0 -279
- package/dist/policy.js +0 -149
- package/dist/providers/brave.js +0 -62
- package/dist/providers/duckduckgo.js +0 -176
- package/dist/providers/exa.js +0 -63
- package/dist/providers/firecrawl.js +0 -55
- package/dist/providers/index.js +0 -7
- package/dist/providers/jina.js +0 -49
- package/dist/providers/router.js +0 -96
- package/dist/providers/search-provider.js +0 -32
- package/dist/providers/tavily.js +0 -54
- package/dist/quip/desktop-session.js +0 -317
- package/dist/registry/index.js +0 -1
- package/dist/registry/registry.js +0 -756
- package/dist/runtime-socket-local-control-client.js +0 -330
- package/dist/security/dns-normalization.js +0 -19
- package/dist/security/dns-pinning.js +0 -123
- package/dist/security/external-content.js +0 -91
- package/dist/security/ssrf.js +0 -181
- package/dist/slack/desktop-session.js +0 -324
- package/dist/tool-factory.js +0 -47
- package/dist/types.js +0 -7
- package/dist/utils/retry.js +0 -132
- package/dist/utils/safe-parse-json.js +0 -160
- package/dist/utils/url.js +0 -19
- package/dist-cjs/.tsbuildinfo +0 -1
- package/dist-cjs/ask-user-interaction.js +0 -27
- package/dist-cjs/cache/web-cache.js +0 -70
- package/dist-cjs/definitions/arion.js +0 -107
- package/dist-cjs/definitions/browser/browser.js +0 -421
- package/dist-cjs/definitions/browser/index.js +0 -8
- package/dist-cjs/definitions/browser/pw-downloads.js +0 -117
- package/dist-cjs/definitions/browser/pw-interactions.js +0 -213
- package/dist-cjs/definitions/browser/pw-responses.js +0 -84
- package/dist-cjs/definitions/browser/pw-session.js +0 -326
- package/dist-cjs/definitions/browser/pw-shared.js +0 -72
- package/dist-cjs/definitions/browser/pw-snapshot.js +0 -307
- package/dist-cjs/definitions/browser/pw-state.js +0 -70
- package/dist-cjs/definitions/browser/types.js +0 -5
- package/dist-cjs/definitions/code-intelligence.js +0 -473
- package/dist-cjs/definitions/core.js +0 -133
- package/dist-cjs/definitions/delegation.js +0 -515
- package/dist-cjs/definitions/deploy.js +0 -68
- package/dist-cjs/definitions/filesystem.js +0 -199
- package/dist-cjs/definitions/frg.js +0 -66
- package/dist-cjs/definitions/index.js +0 -43
- package/dist-cjs/definitions/memory.js +0 -126
- package/dist-cjs/definitions/messaging.js +0 -631
- package/dist-cjs/definitions/meta.js +0 -352
- package/dist-cjs/definitions/network.js +0 -162
- package/dist-cjs/definitions/outlook.js +0 -280
- package/dist-cjs/definitions/patch/apply-patch.js +0 -191
- package/dist-cjs/definitions/patch/fuzzy-match.js +0 -172
- package/dist-cjs/definitions/patch/index.js +0 -5
- package/dist-cjs/definitions/patch/patch-parser.js +0 -215
- package/dist-cjs/definitions/patch/sandbox-paths.js +0 -113
- package/dist-cjs/definitions/process/index.js +0 -8
- package/dist-cjs/definitions/process/process-registry.js +0 -231
- package/dist-cjs/definitions/process/process.js +0 -389
- package/dist-cjs/definitions/process/pty-keys.js +0 -259
- package/dist-cjs/definitions/process/session-slug.js +0 -145
- package/dist-cjs/definitions/quip.js +0 -198
- package/dist-cjs/definitions/search.js +0 -63
- package/dist-cjs/definitions/session-history.js +0 -72
- package/dist-cjs/definitions/shell.js +0 -184
- package/dist-cjs/definitions/slack.js +0 -183
- package/dist-cjs/definitions/web.js +0 -112
- package/dist-cjs/executors/apply-patch.js +0 -938
- package/dist-cjs/executors/arion.js +0 -125
- package/dist-cjs/executors/code-intelligence.js +0 -925
- package/dist-cjs/executors/deploy.js +0 -869
- package/dist-cjs/executors/filesystem.js +0 -1167
- package/dist-cjs/executors/frg-freshness.js +0 -627
- package/dist-cjs/executors/frg.js +0 -334
- package/dist-cjs/executors/index.js +0 -143
- package/dist-cjs/executors/learning-meta.js +0 -1165
- package/dist-cjs/executors/lsp-client.js +0 -310
- package/dist-cjs/executors/memory.js +0 -796
- package/dist-cjs/executors/meta.js +0 -226
- package/dist-cjs/executors/process-registry.js +0 -469
- package/dist-cjs/executors/pty-session-store.js +0 -34
- package/dist-cjs/executors/pty.js +0 -312
- package/dist-cjs/executors/restart.js +0 -155
- package/dist-cjs/executors/search-freshness.js +0 -234
- package/dist-cjs/executors/search-types.js +0 -56
- package/dist-cjs/executors/search.js +0 -102
- package/dist-cjs/executors/self-diagnose.js +0 -434
- package/dist-cjs/executors/session-history.js +0 -320
- package/dist-cjs/executors/shell-safety.js +0 -478
- package/dist-cjs/executors/shell.js +0 -1001
- package/dist-cjs/executors/utils.js +0 -73
- package/dist-cjs/executors/web.js +0 -547
- package/dist-cjs/extraction/content-extraction.js +0 -243
- package/dist-cjs/extraction/index.js +0 -8
- package/dist-cjs/headless-control-contract.js +0 -972
- package/dist-cjs/local-control-http-auth.js +0 -5
- package/dist-cjs/mcp/client.js +0 -185
- package/dist-cjs/mcp/connection.js +0 -484
- package/dist-cjs/mcp/index.js +0 -30
- package/dist-cjs/mcp/jsonrpc.js +0 -148
- package/dist-cjs/mcp/types.js +0 -8
- package/dist-cjs/network-control-adapter.js +0 -77
- package/dist-cjs/network-runtime/address-types.js +0 -168
- package/dist-cjs/network-runtime/db-owner-fencing.js +0 -76
- package/dist-cjs/network-runtime/delivery-receipts.js +0 -276
- package/dist-cjs/network-runtime/direct-endpoint-authority.js +0 -29
- package/dist-cjs/network-runtime/local-control-contract.js +0 -633
- package/dist-cjs/network-runtime/node-store-contract.js +0 -38
- package/dist-cjs/network-runtime/pair-route-contract.js +0 -80
- package/dist-cjs/network-runtime/peer-capabilities.js +0 -37
- package/dist-cjs/network-runtime/peer-principal-ref.js +0 -15
- package/dist-cjs/network-runtime/peer-state-machine.js +0 -129
- package/dist-cjs/network-runtime/protocol-schemas.js +0 -212
- package/dist-cjs/network-runtime/runtime-bootstrap-contract.js +0 -63
- package/dist-cjs/outlook/desktop-session.js +0 -318
- package/dist-cjs/policy.js +0 -155
- package/dist-cjs/providers/brave.js +0 -66
- package/dist-cjs/providers/duckduckgo.js +0 -180
- package/dist-cjs/providers/exa.js +0 -67
- package/dist-cjs/providers/firecrawl.js +0 -59
- package/dist-cjs/providers/index.js +0 -17
- package/dist-cjs/providers/jina.js +0 -53
- package/dist-cjs/providers/router.js +0 -100
- package/dist-cjs/providers/search-provider.js +0 -36
- package/dist-cjs/providers/tavily.js +0 -58
- package/dist-cjs/quip/desktop-session.js +0 -353
- package/dist-cjs/registry/index.js +0 -6
- package/dist-cjs/registry/registry.js +0 -761
- package/dist-cjs/runtime-socket-local-control-client.js +0 -367
- package/dist-cjs/security/dns-normalization.js +0 -22
- package/dist-cjs/security/dns-pinning.js +0 -160
- package/dist-cjs/security/external-content.js +0 -95
- package/dist-cjs/security/ssrf.js +0 -221
- package/dist-cjs/slack/desktop-session.js +0 -366
- package/dist-cjs/tool-factory.js +0 -50
- package/dist-cjs/types.js +0 -8
- package/dist-cjs/utils/retry.js +0 -169
- package/dist-cjs/utils/safe-parse-json.js +0 -164
- package/dist-cjs/utils/url.js +0 -23
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
// Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
|
|
2
|
-
// https://github.com/openclaw/openclaw
|
|
3
|
-
// Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
|
|
4
|
-
// ── Marker Constants ───────────────────────────────────────────────
|
|
5
|
-
export const BEGIN_PATCH_MARKER = "*** Begin Patch";
|
|
6
|
-
export const END_PATCH_MARKER = "*** End Patch";
|
|
7
|
-
export const ADD_FILE_MARKER = "*** Add File: ";
|
|
8
|
-
export const DELETE_FILE_MARKER = "*** Delete File: ";
|
|
9
|
-
export const UPDATE_FILE_MARKER = "*** Update File: ";
|
|
10
|
-
export const MOVE_TO_MARKER = "*** Move to: ";
|
|
11
|
-
export const EOF_MARKER = "*** End of File";
|
|
12
|
-
export const CHANGE_CONTEXT_MARKER = "@@ ";
|
|
13
|
-
export const EMPTY_CHANGE_CONTEXT_MARKER = "@@";
|
|
14
|
-
// ── Unicode Normalization ──────────────────────────────────────────
|
|
15
|
-
const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
16
|
-
export function normalizeUnicodeSpaces(value) {
|
|
17
|
-
return value.replace(UNICODE_SPACES, " ");
|
|
18
|
-
}
|
|
19
|
-
// ── Parser ─────────────────────────────────────────────────────────
|
|
20
|
-
export function parsePatchText(input) {
|
|
21
|
-
const trimmed = input.trim();
|
|
22
|
-
if (!trimmed) {
|
|
23
|
-
throw new Error("Invalid patch: input is empty.");
|
|
24
|
-
}
|
|
25
|
-
const lines = trimmed.split(/\r?\n/);
|
|
26
|
-
const validated = checkPatchBoundariesLenient(lines);
|
|
27
|
-
const hunks = [];
|
|
28
|
-
const lastLineIndex = validated.length - 1;
|
|
29
|
-
let remaining = validated.slice(1, lastLineIndex);
|
|
30
|
-
let lineNumber = 2;
|
|
31
|
-
while (remaining.length > 0) {
|
|
32
|
-
const { hunk, consumed } = parseOneHunk(remaining, lineNumber);
|
|
33
|
-
hunks.push(hunk);
|
|
34
|
-
lineNumber += consumed;
|
|
35
|
-
remaining = remaining.slice(consumed);
|
|
36
|
-
}
|
|
37
|
-
return { hunks, patch: validated.join("\n") };
|
|
38
|
-
}
|
|
39
|
-
export function checkPatchBoundariesLenient(lines) {
|
|
40
|
-
const strictError = checkPatchBoundariesStrict(lines);
|
|
41
|
-
if (!strictError) {
|
|
42
|
-
return lines;
|
|
43
|
-
}
|
|
44
|
-
if (lines.length < 4) {
|
|
45
|
-
throw new Error(strictError);
|
|
46
|
-
}
|
|
47
|
-
const first = lines[0];
|
|
48
|
-
const last = lines[lines.length - 1];
|
|
49
|
-
if ((first === "<<EOF" || first === "<<'EOF'" || first === '<<"EOF"') && last?.endsWith("EOF")) {
|
|
50
|
-
const inner = lines.slice(1, lines.length - 1);
|
|
51
|
-
const innerError = checkPatchBoundariesStrict(inner);
|
|
52
|
-
if (!innerError) {
|
|
53
|
-
return inner;
|
|
54
|
-
}
|
|
55
|
-
throw new Error(innerError);
|
|
56
|
-
}
|
|
57
|
-
throw new Error(strictError);
|
|
58
|
-
}
|
|
59
|
-
function checkPatchBoundariesStrict(lines) {
|
|
60
|
-
const firstLine = lines[0]?.trim();
|
|
61
|
-
const lastLine = lines[lines.length - 1]?.trim();
|
|
62
|
-
if (firstLine === BEGIN_PATCH_MARKER && lastLine === END_PATCH_MARKER) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
if (firstLine !== BEGIN_PATCH_MARKER) {
|
|
66
|
-
return "The first line of the patch must be '*** Begin Patch'";
|
|
67
|
-
}
|
|
68
|
-
return "The last line of the patch must be '*** End Patch'";
|
|
69
|
-
}
|
|
70
|
-
export function parseOneHunk(lines, lineNumber) {
|
|
71
|
-
if (lines.length === 0) {
|
|
72
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber}: empty hunk`);
|
|
73
|
-
}
|
|
74
|
-
const firstLine = lines[0].trim();
|
|
75
|
-
if (firstLine.startsWith(ADD_FILE_MARKER)) {
|
|
76
|
-
const targetPath = firstLine.slice(ADD_FILE_MARKER.length);
|
|
77
|
-
let contents = "";
|
|
78
|
-
let consumed = 1;
|
|
79
|
-
for (const addLine of lines.slice(1)) {
|
|
80
|
-
if (addLine.startsWith("+")) {
|
|
81
|
-
contents += `${addLine.slice(1)}\n`;
|
|
82
|
-
consumed += 1;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
hunk: { kind: "add", path: targetPath, contents },
|
|
90
|
-
consumed,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (firstLine.startsWith(DELETE_FILE_MARKER)) {
|
|
94
|
-
const targetPath = firstLine.slice(DELETE_FILE_MARKER.length);
|
|
95
|
-
return {
|
|
96
|
-
hunk: { kind: "delete", path: targetPath },
|
|
97
|
-
consumed: 1,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
if (firstLine.startsWith(UPDATE_FILE_MARKER)) {
|
|
101
|
-
const targetPath = firstLine.slice(UPDATE_FILE_MARKER.length);
|
|
102
|
-
let remaining = lines.slice(1);
|
|
103
|
-
let consumed = 1;
|
|
104
|
-
let movePath;
|
|
105
|
-
const moveCandidate = remaining[0]?.trim();
|
|
106
|
-
if (moveCandidate?.startsWith(MOVE_TO_MARKER)) {
|
|
107
|
-
movePath = moveCandidate.slice(MOVE_TO_MARKER.length);
|
|
108
|
-
remaining = remaining.slice(1);
|
|
109
|
-
consumed += 1;
|
|
110
|
-
}
|
|
111
|
-
const chunks = [];
|
|
112
|
-
while (remaining.length > 0) {
|
|
113
|
-
if (remaining[0].trim() === "") {
|
|
114
|
-
remaining = remaining.slice(1);
|
|
115
|
-
consumed += 1;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (remaining[0].startsWith("***")) {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
const { chunk, consumed: chunkLines } = parseUpdateFileChunk(remaining, lineNumber + consumed, chunks.length === 0);
|
|
122
|
-
chunks.push(chunk);
|
|
123
|
-
remaining = remaining.slice(chunkLines);
|
|
124
|
-
consumed += chunkLines;
|
|
125
|
-
}
|
|
126
|
-
if (chunks.length === 0) {
|
|
127
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber}: Update file hunk for path '${targetPath}' is empty`);
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
hunk: {
|
|
131
|
-
kind: "update",
|
|
132
|
-
path: targetPath,
|
|
133
|
-
movePath,
|
|
134
|
-
chunks,
|
|
135
|
-
},
|
|
136
|
-
consumed,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber}: '${lines[0]}' is not a valid hunk header. Valid hunk headers: '*** Add File: {path}', '*** Delete File: {path}', '*** Update File: {path}'`);
|
|
140
|
-
}
|
|
141
|
-
export function parseUpdateFileChunk(lines, lineNumber, allowMissingContext) {
|
|
142
|
-
if (lines.length === 0) {
|
|
143
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber}: Update hunk does not contain any lines`);
|
|
144
|
-
}
|
|
145
|
-
const firstLine = lines[0];
|
|
146
|
-
let changeContext;
|
|
147
|
-
let startIndex = 0;
|
|
148
|
-
if (firstLine === EMPTY_CHANGE_CONTEXT_MARKER) {
|
|
149
|
-
startIndex = 1;
|
|
150
|
-
}
|
|
151
|
-
else if (firstLine.startsWith(CHANGE_CONTEXT_MARKER)) {
|
|
152
|
-
changeContext = firstLine.slice(CHANGE_CONTEXT_MARKER.length);
|
|
153
|
-
startIndex = 1;
|
|
154
|
-
}
|
|
155
|
-
else if (!allowMissingContext) {
|
|
156
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber}: Expected update hunk to start with a @@ context marker, got: '${firstLine}'`);
|
|
157
|
-
}
|
|
158
|
-
if (startIndex >= lines.length) {
|
|
159
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber + 1}: Update hunk does not contain any lines`);
|
|
160
|
-
}
|
|
161
|
-
const chunk = {
|
|
162
|
-
changeContext,
|
|
163
|
-
oldLines: [],
|
|
164
|
-
newLines: [],
|
|
165
|
-
isEndOfFile: false,
|
|
166
|
-
};
|
|
167
|
-
let parsedLines = 0;
|
|
168
|
-
for (const line of lines.slice(startIndex)) {
|
|
169
|
-
if (line === EOF_MARKER) {
|
|
170
|
-
if (parsedLines === 0) {
|
|
171
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber + 1}: Update hunk does not contain any lines`);
|
|
172
|
-
}
|
|
173
|
-
chunk.isEndOfFile = true;
|
|
174
|
-
parsedLines += 1;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
const marker = line[0];
|
|
178
|
-
if (!marker) {
|
|
179
|
-
chunk.oldLines.push("");
|
|
180
|
-
chunk.newLines.push("");
|
|
181
|
-
parsedLines += 1;
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
if (marker === " ") {
|
|
185
|
-
const content = line.slice(1);
|
|
186
|
-
chunk.oldLines.push(content);
|
|
187
|
-
chunk.newLines.push(content);
|
|
188
|
-
parsedLines += 1;
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (marker === "+") {
|
|
192
|
-
chunk.newLines.push(line.slice(1));
|
|
193
|
-
parsedLines += 1;
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
if (marker === "-") {
|
|
197
|
-
chunk.oldLines.push(line.slice(1));
|
|
198
|
-
parsedLines += 1;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (parsedLines === 0) {
|
|
202
|
-
throw new Error(`Invalid patch hunk at line ${lineNumber + 1}: Unexpected line found in update hunk: '${line}'. Every line should start with ' ' (context line), '+' (added line), or '-' (removed line)`);
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
return { chunk, consumed: parsedLines + startIndex };
|
|
207
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
|
|
2
|
-
// https://github.com/openclaw/openclaw
|
|
3
|
-
// Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
|
|
4
|
-
import fs from "node:fs/promises";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
8
|
-
function normalizeUnicodeSpaces(str) {
|
|
9
|
-
return str.replace(UNICODE_SPACES, " ");
|
|
10
|
-
}
|
|
11
|
-
function expandPath(filePath) {
|
|
12
|
-
const normalized = normalizeUnicodeSpaces(filePath);
|
|
13
|
-
if (normalized === "~") {
|
|
14
|
-
return os.homedir();
|
|
15
|
-
}
|
|
16
|
-
if (normalized.startsWith("~/")) {
|
|
17
|
-
return os.homedir() + normalized.slice(1);
|
|
18
|
-
}
|
|
19
|
-
return normalized;
|
|
20
|
-
}
|
|
21
|
-
function resolveToCwd(filePath, cwd) {
|
|
22
|
-
const expanded = expandPath(filePath);
|
|
23
|
-
if (path.isAbsolute(expanded)) {
|
|
24
|
-
return expanded;
|
|
25
|
-
}
|
|
26
|
-
return path.resolve(cwd, expanded);
|
|
27
|
-
}
|
|
28
|
-
export function resolveSandboxInputPath(filePath, cwd) {
|
|
29
|
-
return resolveToCwd(filePath, cwd);
|
|
30
|
-
}
|
|
31
|
-
export function resolveSandboxPath(params) {
|
|
32
|
-
const resolved = resolveSandboxInputPath(params.filePath, params.cwd);
|
|
33
|
-
const rootResolved = path.resolve(params.root);
|
|
34
|
-
const relative = path.relative(rootResolved, resolved);
|
|
35
|
-
if (!relative || relative === "") {
|
|
36
|
-
return { resolved, relative: "" };
|
|
37
|
-
}
|
|
38
|
-
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
39
|
-
throw new Error(`Path escapes sandbox root (${shortPath(rootResolved)}): ${params.filePath}`);
|
|
40
|
-
}
|
|
41
|
-
return { resolved, relative };
|
|
42
|
-
}
|
|
43
|
-
export async function assertSandboxPath(params) {
|
|
44
|
-
const resolved = resolveSandboxPath(params);
|
|
45
|
-
await assertNoSymlinkEscape(resolved.relative, path.resolve(params.root), {
|
|
46
|
-
allowFinalSymlink: params.allowFinalSymlink,
|
|
47
|
-
});
|
|
48
|
-
return resolved;
|
|
49
|
-
}
|
|
50
|
-
async function assertNoSymlinkEscape(relative, root, options) {
|
|
51
|
-
if (!relative) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const rootReal = await tryRealpath(root);
|
|
55
|
-
const parts = relative.split(path.sep).filter(Boolean);
|
|
56
|
-
let current = root;
|
|
57
|
-
for (let idx = 0; idx < parts.length; idx += 1) {
|
|
58
|
-
const part = parts[idx];
|
|
59
|
-
const isLast = idx === parts.length - 1;
|
|
60
|
-
current = path.join(current, part);
|
|
61
|
-
try {
|
|
62
|
-
const stat = await fs.lstat(current);
|
|
63
|
-
if (stat.isSymbolicLink()) {
|
|
64
|
-
// Unlinking a symlink itself is safe even if it points outside the root. What we
|
|
65
|
-
// must prevent is traversing through a symlink to reach targets outside root.
|
|
66
|
-
if (options?.allowFinalSymlink && isLast) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const target = await tryRealpath(current);
|
|
70
|
-
if (!isPathInside(rootReal, target)) {
|
|
71
|
-
throw new Error(`Symlink escapes sandbox root (${shortPath(rootReal)}): ${shortPath(current)}`);
|
|
72
|
-
}
|
|
73
|
-
current = target;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
const anyErr = err;
|
|
78
|
-
if (anyErr.code === "ENOENT") {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async function tryRealpath(value) {
|
|
86
|
-
try {
|
|
87
|
-
return await fs.realpath(value);
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
return path.resolve(value);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function isPathInside(root, target) {
|
|
94
|
-
const relative = path.relative(root, target);
|
|
95
|
-
if (!relative || relative === "") {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
return !(relative.startsWith("..") || path.isAbsolute(relative));
|
|
99
|
-
}
|
|
100
|
-
function shortPath(value) {
|
|
101
|
-
if (value.startsWith(os.homedir())) {
|
|
102
|
-
return `~${value.slice(os.homedir().length)}`;
|
|
103
|
-
}
|
|
104
|
-
return value;
|
|
105
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
// Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
|
|
2
|
-
// https://github.com/openclaw/openclaw
|
|
3
|
-
// Modified for ARIA — stripped OpenClaw runtime (PI_BASH_JOB_TTL_MS env, gateway refs),
|
|
4
|
-
// rewired imports to local session-slug
|
|
5
|
-
import { createSessionSlug as createSessionSlugId } from "./session-slug.js";
|
|
6
|
-
const DEFAULT_JOB_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
7
|
-
const MIN_JOB_TTL_MS = 60 * 1000; // 1 minute
|
|
8
|
-
const MAX_JOB_TTL_MS = 3 * 60 * 60 * 1000; // 3 hours
|
|
9
|
-
const DEFAULT_PENDING_OUTPUT_CHARS = 30_000;
|
|
10
|
-
function clampTtl(value) {
|
|
11
|
-
if (!value || Number.isNaN(value)) {
|
|
12
|
-
return DEFAULT_JOB_TTL_MS;
|
|
13
|
-
}
|
|
14
|
-
return Math.min(Math.max(value, MIN_JOB_TTL_MS), MAX_JOB_TTL_MS);
|
|
15
|
-
}
|
|
16
|
-
let jobTtlMs = DEFAULT_JOB_TTL_MS;
|
|
17
|
-
const runningSessions = new Map();
|
|
18
|
-
const finishedSessions = new Map();
|
|
19
|
-
let sweeper = null;
|
|
20
|
-
function isSessionIdTaken(id) {
|
|
21
|
-
return runningSessions.has(id) || finishedSessions.has(id);
|
|
22
|
-
}
|
|
23
|
-
export function createSessionSlug() {
|
|
24
|
-
return createSessionSlugId(isSessionIdTaken);
|
|
25
|
-
}
|
|
26
|
-
export function addSession(session) {
|
|
27
|
-
runningSessions.set(session.id, session);
|
|
28
|
-
startSweeper();
|
|
29
|
-
}
|
|
30
|
-
export function getSession(id) {
|
|
31
|
-
return runningSessions.get(id);
|
|
32
|
-
}
|
|
33
|
-
export function getFinishedSession(id) {
|
|
34
|
-
return finishedSessions.get(id);
|
|
35
|
-
}
|
|
36
|
-
export function deleteSession(id) {
|
|
37
|
-
runningSessions.delete(id);
|
|
38
|
-
finishedSessions.delete(id);
|
|
39
|
-
}
|
|
40
|
-
export function appendOutput(session, stream, chunk) {
|
|
41
|
-
session.pendingStdout ??= [];
|
|
42
|
-
session.pendingStderr ??= [];
|
|
43
|
-
session.pendingStdoutChars ??= sumPendingChars(session.pendingStdout);
|
|
44
|
-
session.pendingStderrChars ??= sumPendingChars(session.pendingStderr);
|
|
45
|
-
const buffer = stream === "stdout" ? session.pendingStdout : session.pendingStderr;
|
|
46
|
-
const bufferChars = stream === "stdout" ? session.pendingStdoutChars : session.pendingStderrChars;
|
|
47
|
-
const pendingCap = Math.min(session.pendingMaxOutputChars ?? DEFAULT_PENDING_OUTPUT_CHARS, session.maxOutputChars);
|
|
48
|
-
buffer.push(chunk);
|
|
49
|
-
let pendingChars = bufferChars + chunk.length;
|
|
50
|
-
if (pendingChars > pendingCap) {
|
|
51
|
-
session.truncated = true;
|
|
52
|
-
pendingChars = capPendingBuffer(buffer, pendingChars, pendingCap);
|
|
53
|
-
}
|
|
54
|
-
if (stream === "stdout") {
|
|
55
|
-
session.pendingStdoutChars = pendingChars;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
session.pendingStderrChars = pendingChars;
|
|
59
|
-
}
|
|
60
|
-
session.totalOutputChars += chunk.length;
|
|
61
|
-
const aggregated = trimWithCap(session.aggregated + chunk, session.maxOutputChars);
|
|
62
|
-
session.truncated =
|
|
63
|
-
session.truncated || aggregated.length < session.aggregated.length + chunk.length;
|
|
64
|
-
session.aggregated = aggregated;
|
|
65
|
-
session.tail = tail(session.aggregated, 2000);
|
|
66
|
-
}
|
|
67
|
-
export function drainSession(session) {
|
|
68
|
-
const stdout = session.pendingStdout.join("");
|
|
69
|
-
const stderr = session.pendingStderr.join("");
|
|
70
|
-
session.pendingStdout = [];
|
|
71
|
-
session.pendingStderr = [];
|
|
72
|
-
session.pendingStdoutChars = 0;
|
|
73
|
-
session.pendingStderrChars = 0;
|
|
74
|
-
return { stdout, stderr };
|
|
75
|
-
}
|
|
76
|
-
export function markExited(session, exitCode, exitSignal, status) {
|
|
77
|
-
session.exited = true;
|
|
78
|
-
session.exitCode = exitCode;
|
|
79
|
-
session.exitSignal = exitSignal;
|
|
80
|
-
session.tail = tail(session.aggregated, 2000);
|
|
81
|
-
moveToFinished(session, status);
|
|
82
|
-
}
|
|
83
|
-
export function markBackgrounded(session) {
|
|
84
|
-
session.backgrounded = true;
|
|
85
|
-
}
|
|
86
|
-
function moveToFinished(session, status) {
|
|
87
|
-
runningSessions.delete(session.id);
|
|
88
|
-
// Clean up child process stdio streams to prevent FD leaks
|
|
89
|
-
if (session.child) {
|
|
90
|
-
session.child.stdin?.destroy?.();
|
|
91
|
-
session.child.stdout?.destroy?.();
|
|
92
|
-
session.child.stderr?.destroy?.();
|
|
93
|
-
session.child.removeAllListeners();
|
|
94
|
-
delete session.child;
|
|
95
|
-
}
|
|
96
|
-
// Clean up stdin wrapper
|
|
97
|
-
if (session.stdin) {
|
|
98
|
-
if (typeof session.stdin.destroy === "function") {
|
|
99
|
-
session.stdin.destroy();
|
|
100
|
-
}
|
|
101
|
-
else if (typeof session.stdin.end === "function") {
|
|
102
|
-
session.stdin.end();
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
session.stdin.destroyed = true;
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
// Ignore if read-only
|
|
109
|
-
}
|
|
110
|
-
delete session.stdin;
|
|
111
|
-
}
|
|
112
|
-
if (!session.backgrounded) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
finishedSessions.set(session.id, {
|
|
116
|
-
id: session.id,
|
|
117
|
-
command: session.command,
|
|
118
|
-
startedAt: session.startedAt,
|
|
119
|
-
endedAt: Date.now(),
|
|
120
|
-
cwd: session.cwd,
|
|
121
|
-
status,
|
|
122
|
-
exitCode: session.exitCode,
|
|
123
|
-
exitSignal: session.exitSignal,
|
|
124
|
-
aggregated: session.aggregated,
|
|
125
|
-
tail: session.tail,
|
|
126
|
-
truncated: session.truncated,
|
|
127
|
-
totalOutputChars: session.totalOutputChars,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
export function tail(text, max = 2000) {
|
|
131
|
-
if (text.length <= max) {
|
|
132
|
-
return text;
|
|
133
|
-
}
|
|
134
|
-
return text.slice(text.length - max);
|
|
135
|
-
}
|
|
136
|
-
function sumPendingChars(buffer) {
|
|
137
|
-
let total = 0;
|
|
138
|
-
for (const chunk of buffer) {
|
|
139
|
-
total += chunk.length;
|
|
140
|
-
}
|
|
141
|
-
return total;
|
|
142
|
-
}
|
|
143
|
-
function capPendingBuffer(buffer, pendingChars, cap) {
|
|
144
|
-
if (pendingChars <= cap) {
|
|
145
|
-
return pendingChars;
|
|
146
|
-
}
|
|
147
|
-
const last = buffer.at(-1);
|
|
148
|
-
if (last && last.length >= cap) {
|
|
149
|
-
buffer.length = 0;
|
|
150
|
-
buffer.push(last.slice(last.length - cap));
|
|
151
|
-
return cap;
|
|
152
|
-
}
|
|
153
|
-
while (buffer.length && buffer[0] !== undefined && pendingChars - buffer[0].length >= cap) {
|
|
154
|
-
pendingChars -= buffer[0].length;
|
|
155
|
-
buffer.shift();
|
|
156
|
-
}
|
|
157
|
-
if (buffer.length && buffer[0] !== undefined && pendingChars > cap) {
|
|
158
|
-
const overflow = pendingChars - cap;
|
|
159
|
-
buffer[0] = buffer[0].slice(overflow);
|
|
160
|
-
pendingChars = cap;
|
|
161
|
-
}
|
|
162
|
-
return pendingChars;
|
|
163
|
-
}
|
|
164
|
-
export function trimWithCap(text, max) {
|
|
165
|
-
if (text.length <= max) {
|
|
166
|
-
return text;
|
|
167
|
-
}
|
|
168
|
-
return text.slice(text.length - max);
|
|
169
|
-
}
|
|
170
|
-
export function listRunningSessions() {
|
|
171
|
-
return Array.from(runningSessions.values()).filter((s) => s.backgrounded);
|
|
172
|
-
}
|
|
173
|
-
export function listFinishedSessions() {
|
|
174
|
-
return Array.from(finishedSessions.values());
|
|
175
|
-
}
|
|
176
|
-
export function clearFinished() {
|
|
177
|
-
finishedSessions.clear();
|
|
178
|
-
}
|
|
179
|
-
export function resetProcessRegistryForTests() {
|
|
180
|
-
runningSessions.clear();
|
|
181
|
-
finishedSessions.clear();
|
|
182
|
-
stopSweeper();
|
|
183
|
-
}
|
|
184
|
-
export function setJobTtlMs(value) {
|
|
185
|
-
if (value === undefined || Number.isNaN(value)) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
jobTtlMs = clampTtl(value);
|
|
189
|
-
stopSweeper();
|
|
190
|
-
startSweeper();
|
|
191
|
-
}
|
|
192
|
-
function pruneFinishedSessions() {
|
|
193
|
-
const cutoff = Date.now() - jobTtlMs;
|
|
194
|
-
for (const [id, session] of finishedSessions.entries()) {
|
|
195
|
-
if (session.endedAt < cutoff) {
|
|
196
|
-
finishedSessions.delete(id);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function startSweeper() {
|
|
201
|
-
if (sweeper) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
sweeper = setInterval(pruneFinishedSessions, Math.max(30_000, jobTtlMs / 6));
|
|
205
|
-
sweeper.unref?.();
|
|
206
|
-
}
|
|
207
|
-
function stopSweeper() {
|
|
208
|
-
if (!sweeper) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
clearInterval(sweeper);
|
|
212
|
-
sweeper = null;
|
|
213
|
-
}
|