@orbit-build/cli 0.5.3 → 0.5.4
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 +460 -118
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -238396,6 +238396,20 @@ function redactSecrets(text2) {
|
|
|
238396
238396
|
}
|
|
238397
238397
|
return redacted;
|
|
238398
238398
|
}
|
|
238399
|
+
var ANSI_ESCAPE_PATTERN = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
238400
|
+
var CONTROL_CHARACTER_PATTERN = /[\u0000-\u0009\u000b\u000c\u000e-\u001f\u007f]+/g;
|
|
238401
|
+
function sanitizeExternalErrorMessage(value, options = {}) {
|
|
238402
|
+
const maxLength = options.maxLength ?? 2e3;
|
|
238403
|
+
if (!Number.isSafeInteger(maxLength) || maxLength < 1) {
|
|
238404
|
+
throw new RangeError(
|
|
238405
|
+
"External error maxLength must be a positive integer."
|
|
238406
|
+
);
|
|
238407
|
+
}
|
|
238408
|
+
const source = value instanceof Error ? value.message : String(value);
|
|
238409
|
+
const withoutTerminalControls = source.replace(ANSI_ESCAPE_PATTERN, "").replace(CONTROL_CHARACTER_PATTERN, " ");
|
|
238410
|
+
const normalized = options.singleLine ? withoutTerminalControls.replace(/[\r\n]+/g, " ") : withoutTerminalControls;
|
|
238411
|
+
return redactSecrets(normalized).trim().slice(0, maxLength);
|
|
238412
|
+
}
|
|
238399
238413
|
var LogTruncator = class {
|
|
238400
238414
|
static truncate(output, maxLines = 150, maxChars = 2e4) {
|
|
238401
238415
|
if (!output) return "";
|
|
@@ -254378,8 +254392,7 @@ function assertSupportedProtocolVersion(initializeResult) {
|
|
|
254378
254392
|
}
|
|
254379
254393
|
}
|
|
254380
254394
|
function safeMessage(error) {
|
|
254381
|
-
|
|
254382
|
-
return redactSecrets(message2).replace(/[\r\n]+/g, " ").slice(0, 2e3);
|
|
254395
|
+
return sanitizeExternalErrorMessage(error, { singleLine: true });
|
|
254383
254396
|
}
|
|
254384
254397
|
var DynamicMCPTool = class {
|
|
254385
254398
|
constructor(serverName, toolDefinition, risk, client) {
|
|
@@ -255195,7 +255208,7 @@ function parseSseJson(body, expectedId) {
|
|
|
255195
255208
|
throw new Error("MCP SSE response contained no matching JSON-RPC response.");
|
|
255196
255209
|
}
|
|
255197
255210
|
function safeMessage2(value) {
|
|
255198
|
-
return
|
|
255211
|
+
return sanitizeExternalErrorMessage(value, { singleLine: true });
|
|
255199
255212
|
}
|
|
255200
255213
|
function assertSecureMcpUrl(value, label) {
|
|
255201
255214
|
const url = new URL(value);
|
|
@@ -255300,7 +255313,7 @@ async function runMcpPkceLogin(options) {
|
|
|
255300
255313
|
finish(400, "Authorization failed. Close this window and retry.");
|
|
255301
255314
|
fail(
|
|
255302
255315
|
new Error(
|
|
255303
|
-
`MCP OAuth authorization failed: ${oauthError
|
|
255316
|
+
`MCP OAuth authorization failed: ${sanitizeExternalErrorMessage(oauthError, { maxLength: 200, singleLine: true })}`
|
|
255304
255317
|
)
|
|
255305
255318
|
);
|
|
255306
255319
|
return;
|
|
@@ -264780,30 +264793,59 @@ ${diff.substring(0, 2e4)}`
|
|
|
264780
264793
|
return true;
|
|
264781
264794
|
}
|
|
264782
264795
|
rollbackFileToCheckpoint(filePath) {
|
|
264796
|
+
const result = this.rollbackFilesToCheckpoints([filePath]);
|
|
264797
|
+
return result.success && result.restored.length === 1;
|
|
264798
|
+
}
|
|
264799
|
+
/** Restore the latest available backup for each path as one transaction. */
|
|
264800
|
+
rollbackFilesToCheckpoints(filePaths) {
|
|
264783
264801
|
this.sessionReviewCache = void 0;
|
|
264784
|
-
let targetAbs;
|
|
264785
|
-
try {
|
|
264786
|
-
targetAbs = resolveSafePath(this.cwd, filePath);
|
|
264787
|
-
} catch {
|
|
264788
|
-
return false;
|
|
264789
|
-
}
|
|
264790
264802
|
const checkpoints = this.checkpointManager.getCheckpoints().reverse();
|
|
264791
|
-
|
|
264792
|
-
|
|
264793
|
-
|
|
264794
|
-
|
|
264795
|
-
|
|
264796
|
-
|
|
264803
|
+
const selected = [];
|
|
264804
|
+
const unresolved = [];
|
|
264805
|
+
for (const requestedPath of [...new Set(filePaths)]) {
|
|
264806
|
+
let targetAbs;
|
|
264807
|
+
try {
|
|
264808
|
+
targetAbs = resolveSafePath(this.cwd, requestedPath);
|
|
264809
|
+
} catch {
|
|
264810
|
+
unresolved.push(requestedPath);
|
|
264811
|
+
continue;
|
|
264812
|
+
}
|
|
264813
|
+
let match;
|
|
264814
|
+
for (const checkpoint of checkpoints) {
|
|
264815
|
+
const backup = checkpoint.backups.find((candidate) => {
|
|
264816
|
+
try {
|
|
264817
|
+
return resolveSafePath(this.cwd, candidate.path) === targetAbs;
|
|
264818
|
+
} catch {
|
|
264819
|
+
return false;
|
|
264820
|
+
}
|
|
264821
|
+
});
|
|
264822
|
+
if (backup) {
|
|
264823
|
+
match = { requestedPath, checkpoint, backup };
|
|
264824
|
+
break;
|
|
264797
264825
|
}
|
|
264798
|
-
});
|
|
264799
|
-
if (backup) {
|
|
264800
|
-
return this.rollbackManager.rollback({
|
|
264801
|
-
...cp,
|
|
264802
|
-
backups: [backup]
|
|
264803
|
-
}).success;
|
|
264804
264826
|
}
|
|
264827
|
+
if (match) selected.push(match);
|
|
264828
|
+
else unresolved.push(requestedPath);
|
|
264805
264829
|
}
|
|
264806
|
-
|
|
264830
|
+
const result = this.rollbackManager.rollbackMany(
|
|
264831
|
+
selected.map(({ checkpoint, backup }) => ({
|
|
264832
|
+
...checkpoint,
|
|
264833
|
+
backups: [backup]
|
|
264834
|
+
}))
|
|
264835
|
+
);
|
|
264836
|
+
if (!result.success) {
|
|
264837
|
+
return {
|
|
264838
|
+
success: false,
|
|
264839
|
+
restored: [],
|
|
264840
|
+
unresolved,
|
|
264841
|
+
error: result.error
|
|
264842
|
+
};
|
|
264843
|
+
}
|
|
264844
|
+
return {
|
|
264845
|
+
success: true,
|
|
264846
|
+
restored: selected.map(({ requestedPath }) => requestedPath),
|
|
264847
|
+
unresolved
|
|
264848
|
+
};
|
|
264807
264849
|
}
|
|
264808
264850
|
accumulateCost(model, usage2) {
|
|
264809
264851
|
const pricing = this.resolvePricing(model);
|
|
@@ -274196,7 +274238,7 @@ var FullscreenTui = class {
|
|
|
274196
274238
|
// src/runtime/ReplController.ts
|
|
274197
274239
|
import picocolors19 from "picocolors";
|
|
274198
274240
|
import { rmSync as rmSync6, watch } from "fs";
|
|
274199
|
-
import { dirname as
|
|
274241
|
+
import { dirname as dirname13, resolve as resolve14 } from "path";
|
|
274200
274242
|
import { homedir as homedir10 } from "os";
|
|
274201
274243
|
import http3 from "http";
|
|
274202
274244
|
import { randomBytes as randomBytes4, randomUUID as randomUUID11, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
@@ -280359,6 +280401,20 @@ import { relative as relative5 } from "path";
|
|
|
280359
280401
|
// src/runtime/webui/WebUiSecurity.ts
|
|
280360
280402
|
import { timingSafeEqual } from "crypto";
|
|
280361
280403
|
import { z as z51 } from "zod";
|
|
280404
|
+
|
|
280405
|
+
// src/runtime/webui/WebUiErrors.ts
|
|
280406
|
+
var WebUiRequestError = class extends Error {
|
|
280407
|
+
constructor(code, statusCode, message2) {
|
|
280408
|
+
super(message2);
|
|
280409
|
+
this.code = code;
|
|
280410
|
+
this.statusCode = statusCode;
|
|
280411
|
+
}
|
|
280412
|
+
code;
|
|
280413
|
+
statusCode;
|
|
280414
|
+
name = "WebUiRequestError";
|
|
280415
|
+
};
|
|
280416
|
+
|
|
280417
|
+
// src/runtime/webui/WebUiSecurity.ts
|
|
280362
280418
|
function sanitizeWebEventPayload(type, payload) {
|
|
280363
280419
|
if (!isRecord4(payload)) return void 0;
|
|
280364
280420
|
switch (type) {
|
|
@@ -280586,10 +280642,7 @@ function isAuthorizedWebEventRequest(req, expectedToken, url) {
|
|
|
280586
280642
|
);
|
|
280587
280643
|
}
|
|
280588
280644
|
function safeWebMessage(error) {
|
|
280589
|
-
return
|
|
280590
|
-
error instanceof Error ? error.message : String(error),
|
|
280591
|
-
2e3
|
|
280592
|
-
);
|
|
280645
|
+
return sanitizeExternalErrorMessage(error, { maxLength: 2e3 });
|
|
280593
280646
|
}
|
|
280594
280647
|
function summarizeWebToolValue(value, options = {}) {
|
|
280595
280648
|
let candidate = value;
|
|
@@ -280668,9 +280721,7 @@ function sanitizeBaseUrl(value) {
|
|
|
280668
280721
|
}
|
|
280669
280722
|
function webRequestErrorStatus(error) {
|
|
280670
280723
|
if (error instanceof z51.ZodError) return 400;
|
|
280671
|
-
if (error instanceof
|
|
280672
|
-
return 413;
|
|
280673
|
-
}
|
|
280724
|
+
if (error instanceof WebUiRequestError) return error.statusCode;
|
|
280674
280725
|
return 500;
|
|
280675
280726
|
}
|
|
280676
280727
|
function isNodeError3(error) {
|
|
@@ -281517,12 +281568,25 @@ async function readJsonBody(req) {
|
|
|
281517
281568
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
281518
281569
|
totalBytes += buffer.length;
|
|
281519
281570
|
if (totalBytes > WEB_UI_BODY_LIMIT_BYTES) {
|
|
281520
|
-
throw new
|
|
281571
|
+
throw new WebUiRequestError(
|
|
281572
|
+
"request_body_too_large",
|
|
281573
|
+
413,
|
|
281574
|
+
"Request body too large."
|
|
281575
|
+
);
|
|
281521
281576
|
}
|
|
281522
281577
|
chunks.push(buffer);
|
|
281523
281578
|
}
|
|
281524
281579
|
const body = Buffer.concat(chunks).toString("utf8").trim();
|
|
281525
|
-
|
|
281580
|
+
if (!body) return {};
|
|
281581
|
+
try {
|
|
281582
|
+
return JSON.parse(body);
|
|
281583
|
+
} catch {
|
|
281584
|
+
throw new WebUiRequestError(
|
|
281585
|
+
"invalid_json",
|
|
281586
|
+
400,
|
|
281587
|
+
"Invalid JSON request body."
|
|
281588
|
+
);
|
|
281589
|
+
}
|
|
281526
281590
|
}
|
|
281527
281591
|
async function readBinaryBody(req, limitBytes) {
|
|
281528
281592
|
const chunks = [];
|
|
@@ -281530,7 +281594,13 @@ async function readBinaryBody(req, limitBytes) {
|
|
|
281530
281594
|
for await (const chunk of req) {
|
|
281531
281595
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
281532
281596
|
totalBytes += buffer.length;
|
|
281533
|
-
if (totalBytes > limitBytes)
|
|
281597
|
+
if (totalBytes > limitBytes) {
|
|
281598
|
+
throw new WebUiRequestError(
|
|
281599
|
+
"attachment_too_large",
|
|
281600
|
+
413,
|
|
281601
|
+
"Attachment is too large."
|
|
281602
|
+
);
|
|
281603
|
+
}
|
|
281534
281604
|
chunks.push(buffer);
|
|
281535
281605
|
}
|
|
281536
281606
|
return Buffer.concat(chunks);
|
|
@@ -291054,29 +291124,103 @@ async function handleContextCommand(command, argument, dependencies) {
|
|
|
291054
291124
|
|
|
291055
291125
|
// src/runtime/commands/RollbackCommandHandler.ts
|
|
291056
291126
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
291057
|
-
import { existsSync as existsSync19, rmSync as rmSync5 } from "fs";
|
|
291127
|
+
import { existsSync as existsSync19, lstatSync as lstatSync7, mkdirSync as mkdirSync6, rmSync as rmSync5, writeFileSync as writeFileSync8 } from "fs";
|
|
291128
|
+
import { dirname as dirname11 } from "path";
|
|
291058
291129
|
import picocolors13 from "picocolors";
|
|
291059
291130
|
import { z as z56 } from "zod";
|
|
291060
291131
|
var GitStatusCodeSchema = z56.string().length(2).regex(/^[ MADRCU?!]{2}$/);
|
|
291061
291132
|
var GitStatusPathSchema = z56.string().min(1).max(32768);
|
|
291133
|
+
var ROLLBACK_SNAPSHOT_FILE_MAX_BYTES = 16 * 1024 * 1024;
|
|
291134
|
+
var ROLLBACK_SNAPSHOT_TOTAL_MAX_BYTES = 128 * 1024 * 1024;
|
|
291135
|
+
var ROLLBACK_SNAPSHOT_MAX_PATHS = 1e4;
|
|
291136
|
+
var GIT_INDEX_PATCH_MAX_BYTES = 64 * 1024 * 1024;
|
|
291062
291137
|
var defaultGitAdapter = {
|
|
291063
|
-
status: (cwd) => execFileSync7(
|
|
291064
|
-
|
|
291065
|
-
|
|
291066
|
-
|
|
291067
|
-
|
|
291068
|
-
|
|
291138
|
+
status: (cwd) => execFileSync7(
|
|
291139
|
+
"git",
|
|
291140
|
+
["status", "--porcelain=v1", "-z", "--untracked-files=all"],
|
|
291141
|
+
{
|
|
291142
|
+
...HIDDEN_CHILD_PROCESS_OPTIONS,
|
|
291143
|
+
cwd,
|
|
291144
|
+
encoding: "utf8",
|
|
291145
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
291146
|
+
}
|
|
291147
|
+
),
|
|
291148
|
+
reset: (cwd, filePaths) => {
|
|
291149
|
+
if (filePaths.length === 0) return;
|
|
291150
|
+
let hasHead = true;
|
|
291151
|
+
try {
|
|
291152
|
+
execFileSync7("git", ["rev-parse", "--verify", "HEAD"], {
|
|
291153
|
+
...HIDDEN_CHILD_PROCESS_OPTIONS,
|
|
291154
|
+
cwd,
|
|
291155
|
+
stdio: "ignore"
|
|
291156
|
+
});
|
|
291157
|
+
} catch {
|
|
291158
|
+
hasHead = false;
|
|
291159
|
+
}
|
|
291160
|
+
const args = hasHead ? ["reset", "--quiet", "HEAD", "--", ...filePaths] : [
|
|
291161
|
+
"rm",
|
|
291162
|
+
"--cached",
|
|
291163
|
+
"--force",
|
|
291164
|
+
"-r",
|
|
291165
|
+
"--ignore-unmatch",
|
|
291166
|
+
"--",
|
|
291167
|
+
...filePaths
|
|
291168
|
+
];
|
|
291169
|
+
execFileSync7("git", args, {
|
|
291170
|
+
...HIDDEN_CHILD_PROCESS_OPTIONS,
|
|
291171
|
+
cwd,
|
|
291172
|
+
stdio: "ignore"
|
|
291173
|
+
});
|
|
291174
|
+
},
|
|
291069
291175
|
checkout: (cwd, filePath) => {
|
|
291070
|
-
execFileSync7("git", ["checkout", "--", filePath], {
|
|
291176
|
+
execFileSync7("git", ["checkout", "HEAD", "--", filePath], {
|
|
291071
291177
|
...HIDDEN_CHILD_PROCESS_OPTIONS,
|
|
291072
291178
|
cwd,
|
|
291073
291179
|
stdio: "ignore"
|
|
291074
291180
|
});
|
|
291181
|
+
},
|
|
291182
|
+
snapshotIndex: (cwd, filePaths) => {
|
|
291183
|
+
if (filePaths.length === 0) return Buffer.alloc(0);
|
|
291184
|
+
return execFileSync7(
|
|
291185
|
+
"git",
|
|
291186
|
+
[
|
|
291187
|
+
"diff",
|
|
291188
|
+
"--cached",
|
|
291189
|
+
"--binary",
|
|
291190
|
+
"--full-index",
|
|
291191
|
+
"--no-ext-diff",
|
|
291192
|
+
"--",
|
|
291193
|
+
...filePaths
|
|
291194
|
+
],
|
|
291195
|
+
{
|
|
291196
|
+
...HIDDEN_CHILD_PROCESS_OPTIONS,
|
|
291197
|
+
cwd,
|
|
291198
|
+
encoding: "buffer",
|
|
291199
|
+
maxBuffer: GIT_INDEX_PATCH_MAX_BYTES,
|
|
291200
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
291201
|
+
}
|
|
291202
|
+
);
|
|
291203
|
+
},
|
|
291204
|
+
restoreIndex: (cwd, filePaths, snapshot) => {
|
|
291205
|
+
if (filePaths.length === 0) return;
|
|
291206
|
+
defaultGitAdapter.reset(cwd, filePaths);
|
|
291207
|
+
if (snapshot.length === 0) return;
|
|
291208
|
+
execFileSync7(
|
|
291209
|
+
"git",
|
|
291210
|
+
["apply", "--cached", "--whitespace=nowarn", "--recount", "-"],
|
|
291211
|
+
{
|
|
291212
|
+
...HIDDEN_CHILD_PROCESS_OPTIONS,
|
|
291213
|
+
cwd,
|
|
291214
|
+
input: snapshot,
|
|
291215
|
+
maxBuffer: GIT_INDEX_PATCH_MAX_BYTES,
|
|
291216
|
+
stdio: ["pipe", "ignore", "ignore"]
|
|
291217
|
+
}
|
|
291218
|
+
);
|
|
291075
291219
|
}
|
|
291076
291220
|
};
|
|
291077
|
-
function
|
|
291221
|
+
function parseGitStatusEntries(output) {
|
|
291078
291222
|
const fields = output.split("\0");
|
|
291079
|
-
const
|
|
291223
|
+
const entries = [];
|
|
291080
291224
|
for (let index = 0; index < fields.length; index++) {
|
|
291081
291225
|
const record = fields[index];
|
|
291082
291226
|
if (!record) continue;
|
|
@@ -291085,14 +291229,20 @@ function parseGitStatusPaths(output) {
|
|
|
291085
291229
|
}
|
|
291086
291230
|
const status = GitStatusCodeSchema.parse(record.slice(0, 2));
|
|
291087
291231
|
const filePath = GitStatusPathSchema.parse(record.slice(3));
|
|
291088
|
-
|
|
291232
|
+
let originalPath;
|
|
291089
291233
|
if (status.includes("R") || status.includes("C")) {
|
|
291090
|
-
|
|
291091
|
-
GitStatusPathSchema.parse(originalPath);
|
|
291234
|
+
originalPath = GitStatusPathSchema.parse(fields[index + 1]);
|
|
291092
291235
|
index++;
|
|
291093
291236
|
}
|
|
291237
|
+
entries.push({
|
|
291238
|
+
status,
|
|
291239
|
+
path: filePath,
|
|
291240
|
+
...originalPath ? { originalPath } : {}
|
|
291241
|
+
});
|
|
291094
291242
|
}
|
|
291095
|
-
return [
|
|
291243
|
+
return [
|
|
291244
|
+
...new Map(entries.map((entry) => [entry.path, entry])).values()
|
|
291245
|
+
];
|
|
291096
291246
|
}
|
|
291097
291247
|
async function handleRollbackCommand(command, argument, dependencies) {
|
|
291098
291248
|
const isZh = dependencies.language !== "en";
|
|
@@ -291110,11 +291260,14 @@ async function handleRollbackCommand(command, argument, dependencies) {
|
|
|
291110
291260
|
return HANDLED_COMMAND;
|
|
291111
291261
|
}
|
|
291112
291262
|
const git = dependencies.git ?? defaultGitAdapter;
|
|
291113
|
-
let
|
|
291263
|
+
let entries;
|
|
291114
291264
|
try {
|
|
291115
|
-
|
|
291116
|
-
for (const
|
|
291117
|
-
resolveSafePath(dependencies.cwd,
|
|
291265
|
+
entries = parseGitStatusEntries(git.status(dependencies.cwd));
|
|
291266
|
+
for (const entry of entries) {
|
|
291267
|
+
resolveSafePath(dependencies.cwd, entry.path);
|
|
291268
|
+
if (entry.originalPath) {
|
|
291269
|
+
resolveSafePath(dependencies.cwd, entry.originalPath);
|
|
291270
|
+
}
|
|
291118
291271
|
}
|
|
291119
291272
|
} catch (error) {
|
|
291120
291273
|
if (error instanceof Error && error.message.includes("outside workspace")) {
|
|
@@ -291128,7 +291281,7 @@ async function handleRollbackCommand(command, argument, dependencies) {
|
|
|
291128
291281
|
await dependencies.loop.rollbackLastCheckpoint();
|
|
291129
291282
|
return HANDLED_COMMAND;
|
|
291130
291283
|
}
|
|
291131
|
-
if (
|
|
291284
|
+
if (entries.length === 0) {
|
|
291132
291285
|
dependencies.printOutput(
|
|
291133
291286
|
picocolors13.yellow(
|
|
291134
291287
|
isZh ? "\u5F53\u524D\u5DE5\u4F5C\u533A\u6CA1\u6709\u68C0\u6D4B\u5230\u4EFB\u4F55\u672A\u63D0\u4EA4\u7684\u4EE3\u7801\u53D8\u66F4\u3002" : "No uncommitted changes detected in the workspace."
|
|
@@ -291141,7 +291294,7 @@ async function handleRollbackCommand(command, argument, dependencies) {
|
|
|
291141
291294
|
value: "all",
|
|
291142
291295
|
label: isZh ? "\u3010\u5168\u90E8\u56DE\u6EDA\u3011 \u64A4\u9500\u6240\u6709\u53D8\u66F4" : "[Rollback All] Discard all changes"
|
|
291143
291296
|
},
|
|
291144
|
-
...
|
|
291297
|
+
...entries.map((entry) => ({ value: entry.path, label: entry.path }))
|
|
291145
291298
|
];
|
|
291146
291299
|
const selected = await (dependencies.prompt ?? Prompt).askMultiSelect(
|
|
291147
291300
|
isZh ? "\u9009\u62E9\u8981\u56DE\u6EDA\uFF08\u64A4\u9500\u53D8\u66F4\uFF09\u7684\u6587\u4EF6\uFF1A" : "Select files to rollback (discard changes):",
|
|
@@ -291158,16 +291311,52 @@ async function handleRollbackCommand(command, argument, dependencies) {
|
|
|
291158
291311
|
return HANDLED_COMMAND;
|
|
291159
291312
|
}
|
|
291160
291313
|
try {
|
|
291161
|
-
|
|
291162
|
-
|
|
291163
|
-
|
|
291314
|
+
const selectedEntries = revalidateSelectedEntries(
|
|
291315
|
+
selected,
|
|
291316
|
+
entries,
|
|
291317
|
+
parseGitStatusEntries(git.status(dependencies.cwd))
|
|
291318
|
+
);
|
|
291319
|
+
const indexPaths = collectIndexPaths(selectedEntries);
|
|
291320
|
+
const workspaceSnapshot = snapshotWorkspacePaths(
|
|
291321
|
+
dependencies.cwd,
|
|
291322
|
+
collectWorkspacePaths(selectedEntries)
|
|
291323
|
+
);
|
|
291324
|
+
const indexSnapshot = git.snapshotIndex?.(dependencies.cwd, indexPaths);
|
|
291325
|
+
try {
|
|
291326
|
+
if (indexPaths.length > 0) git.reset(dependencies.cwd, indexPaths);
|
|
291327
|
+
const checkpointResult = dependencies.loop.rollbackFilesToCheckpoints ? dependencies.loop.rollbackFilesToCheckpoints(
|
|
291328
|
+
selectedEntries.map((entry) => entry.path)
|
|
291329
|
+
) : rollbackFilesIndividually(selectedEntries, dependencies.loop);
|
|
291330
|
+
if (!checkpointResult.success) {
|
|
291331
|
+
throw new Error(
|
|
291332
|
+
checkpointResult.error || "Checkpoint rollback transaction failed."
|
|
291333
|
+
);
|
|
291334
|
+
}
|
|
291335
|
+
const checkpointRestored = new Set(checkpointResult.restored);
|
|
291336
|
+
const gitEntries = selectedEntries.filter(
|
|
291337
|
+
(entry) => !checkpointRestored.has(entry.path)
|
|
291338
|
+
);
|
|
291339
|
+
for (const entry of gitEntries) {
|
|
291340
|
+
restoreGitStatusEntry(entry, dependencies, git);
|
|
291341
|
+
}
|
|
291342
|
+
} catch (error) {
|
|
291343
|
+
const compensationErrors = [];
|
|
291164
291344
|
try {
|
|
291165
|
-
|
|
291166
|
-
} catch {
|
|
291167
|
-
|
|
291168
|
-
|
|
291345
|
+
restoreWorkspaceSnapshot(dependencies.cwd, workspaceSnapshot);
|
|
291346
|
+
} catch (compensationError) {
|
|
291347
|
+
compensationErrors.push(toErrorMessage3(compensationError));
|
|
291348
|
+
}
|
|
291349
|
+
if (indexPaths.length > 0 && indexSnapshot && git.restoreIndex) {
|
|
291350
|
+
try {
|
|
291351
|
+
git.restoreIndex(dependencies.cwd, indexPaths, indexSnapshot);
|
|
291352
|
+
} catch (compensationError) {
|
|
291353
|
+
compensationErrors.push(toErrorMessage3(compensationError));
|
|
291169
291354
|
}
|
|
291355
|
+
} else if (indexPaths.length > 0) {
|
|
291356
|
+
compensationErrors.push("Git index compensation is unavailable.");
|
|
291170
291357
|
}
|
|
291358
|
+
const detail = compensationErrors.length === 0 ? " Previous workspace state was restored." : ` Compensation was incomplete: ${compensationErrors.join("; ")}`;
|
|
291359
|
+
throw new Error(`${toErrorMessage3(error)}${detail}`);
|
|
291171
291360
|
}
|
|
291172
291361
|
dependencies.printOutput(
|
|
291173
291362
|
picocolors13.green(
|
|
@@ -291184,6 +291373,159 @@ async function handleRollbackCommand(command, argument, dependencies) {
|
|
|
291184
291373
|
}
|
|
291185
291374
|
return HANDLED_COMMAND;
|
|
291186
291375
|
}
|
|
291376
|
+
function rollbackFilesIndividually(entries, loop) {
|
|
291377
|
+
const restored = entries.filter((entry) => loop.rollbackFileToCheckpoint(entry.path)).map((entry) => entry.path);
|
|
291378
|
+
const restoredSet = new Set(restored);
|
|
291379
|
+
return {
|
|
291380
|
+
success: true,
|
|
291381
|
+
restored,
|
|
291382
|
+
unresolved: entries.map((entry) => entry.path).filter((filePath) => !restoredSet.has(filePath))
|
|
291383
|
+
};
|
|
291384
|
+
}
|
|
291385
|
+
function revalidateSelectedEntries(selected, displayed, current) {
|
|
291386
|
+
const displayedByPath = new Map(
|
|
291387
|
+
displayed.map((entry) => [entry.path, entry])
|
|
291388
|
+
);
|
|
291389
|
+
const currentByPath = new Map(current.map((entry) => [entry.path, entry]));
|
|
291390
|
+
return selected.map((filePath) => {
|
|
291391
|
+
const previous = displayedByPath.get(filePath);
|
|
291392
|
+
const latest = currentByPath.get(filePath);
|
|
291393
|
+
if (!previous || !latest || !sameStatusEntry(previous, latest)) {
|
|
291394
|
+
throw new Error(
|
|
291395
|
+
`Git status changed while choosing rollback paths: ${filePath}`
|
|
291396
|
+
);
|
|
291397
|
+
}
|
|
291398
|
+
if (isUnmergedStatus(latest.status)) {
|
|
291399
|
+
throw new Error(
|
|
291400
|
+
`Resolve merge conflicts before rolling back this path: ${filePath}`
|
|
291401
|
+
);
|
|
291402
|
+
}
|
|
291403
|
+
return latest;
|
|
291404
|
+
});
|
|
291405
|
+
}
|
|
291406
|
+
function isUnmergedStatus(status) {
|
|
291407
|
+
return status.includes("U") || status === "AA" || status === "DD";
|
|
291408
|
+
}
|
|
291409
|
+
function sameStatusEntry(left, right) {
|
|
291410
|
+
return left.status === right.status && left.path === right.path && left.originalPath === right.originalPath;
|
|
291411
|
+
}
|
|
291412
|
+
function collectIndexPaths(entries) {
|
|
291413
|
+
return [
|
|
291414
|
+
...new Set(
|
|
291415
|
+
entries.flatMap((entry) => {
|
|
291416
|
+
if (entry.status === "??") return [];
|
|
291417
|
+
return entry.originalPath ? [entry.path, entry.originalPath] : [entry.path];
|
|
291418
|
+
})
|
|
291419
|
+
)
|
|
291420
|
+
];
|
|
291421
|
+
}
|
|
291422
|
+
function collectWorkspacePaths(entries) {
|
|
291423
|
+
return [
|
|
291424
|
+
...new Set(
|
|
291425
|
+
entries.flatMap(
|
|
291426
|
+
(entry) => entry.originalPath ? [entry.path, entry.originalPath] : [entry.path]
|
|
291427
|
+
)
|
|
291428
|
+
)
|
|
291429
|
+
];
|
|
291430
|
+
}
|
|
291431
|
+
function snapshotWorkspacePaths(cwd, filePaths) {
|
|
291432
|
+
if (filePaths.length > ROLLBACK_SNAPSHOT_MAX_PATHS) {
|
|
291433
|
+
throw new Error(
|
|
291434
|
+
`Rollback selection exceeds ${ROLLBACK_SNAPSHOT_MAX_PATHS} paths.`
|
|
291435
|
+
);
|
|
291436
|
+
}
|
|
291437
|
+
const snapshots = [];
|
|
291438
|
+
let totalBytes = 0;
|
|
291439
|
+
for (const filePath of filePaths) {
|
|
291440
|
+
const absolutePath = resolveSafePath(cwd, filePath);
|
|
291441
|
+
try {
|
|
291442
|
+
const stats = lstatSync7(absolutePath);
|
|
291443
|
+
if (stats.isSymbolicLink() || !stats.isFile()) {
|
|
291444
|
+
throw new Error(
|
|
291445
|
+
`Rollback transaction supports regular files only: ${filePath}`
|
|
291446
|
+
);
|
|
291447
|
+
}
|
|
291448
|
+
const content = readBoundedRegularFileBuffer(
|
|
291449
|
+
absolutePath,
|
|
291450
|
+
ROLLBACK_SNAPSHOT_FILE_MAX_BYTES
|
|
291451
|
+
);
|
|
291452
|
+
if (content === void 0) {
|
|
291453
|
+
throw new Error(`Rollback target disappeared: ${filePath}`);
|
|
291454
|
+
}
|
|
291455
|
+
totalBytes += content.length;
|
|
291456
|
+
if (totalBytes > ROLLBACK_SNAPSHOT_TOTAL_MAX_BYTES) {
|
|
291457
|
+
throw new Error(
|
|
291458
|
+
"Rollback selection exceeds the 128 MiB transaction snapshot limit."
|
|
291459
|
+
);
|
|
291460
|
+
}
|
|
291461
|
+
snapshots.push({ path: filePath, content });
|
|
291462
|
+
} catch (error) {
|
|
291463
|
+
if (isFileSystemError3(error, "ENOENT")) {
|
|
291464
|
+
snapshots.push({ path: filePath, content: null });
|
|
291465
|
+
continue;
|
|
291466
|
+
}
|
|
291467
|
+
throw error;
|
|
291468
|
+
}
|
|
291469
|
+
}
|
|
291470
|
+
return snapshots;
|
|
291471
|
+
}
|
|
291472
|
+
function restoreWorkspaceSnapshot(cwd, snapshots) {
|
|
291473
|
+
const failures = [];
|
|
291474
|
+
for (const snapshot of snapshots.slice().reverse()) {
|
|
291475
|
+
try {
|
|
291476
|
+
const absolutePath = resolveSafePath(cwd, snapshot.path);
|
|
291477
|
+
if (snapshot.content === null) {
|
|
291478
|
+
rmSync5(absolutePath, { recursive: true, force: true });
|
|
291479
|
+
continue;
|
|
291480
|
+
}
|
|
291481
|
+
if (existsSync19(absolutePath)) {
|
|
291482
|
+
const stats = lstatSync7(absolutePath);
|
|
291483
|
+
if (stats.isSymbolicLink() || !stats.isFile()) {
|
|
291484
|
+
throw new Error(
|
|
291485
|
+
`Compensation target is not a regular file: ${snapshot.path}`
|
|
291486
|
+
);
|
|
291487
|
+
}
|
|
291488
|
+
}
|
|
291489
|
+
mkdirSync6(dirname11(absolutePath), { recursive: true });
|
|
291490
|
+
writeFileSync8(resolveSafePath(cwd, snapshot.path), snapshot.content);
|
|
291491
|
+
} catch (error) {
|
|
291492
|
+
failures.push(`${snapshot.path}: ${toErrorMessage3(error)}`);
|
|
291493
|
+
}
|
|
291494
|
+
}
|
|
291495
|
+
if (failures.length > 0) {
|
|
291496
|
+
throw new Error(failures.join("; "));
|
|
291497
|
+
}
|
|
291498
|
+
}
|
|
291499
|
+
function isFileSystemError3(error, code) {
|
|
291500
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
291501
|
+
}
|
|
291502
|
+
function toErrorMessage3(error) {
|
|
291503
|
+
return error instanceof Error ? error.message : String(error);
|
|
291504
|
+
}
|
|
291505
|
+
function restoreGitStatusEntry(entry, dependencies, git) {
|
|
291506
|
+
const removePath = dependencies.removePath ?? removeWorkspacePath;
|
|
291507
|
+
const removeDestination = () => {
|
|
291508
|
+
const absolutePath = resolveSafePath(dependencies.cwd, entry.path);
|
|
291509
|
+
if (existsSync19(absolutePath)) removePath(absolutePath);
|
|
291510
|
+
};
|
|
291511
|
+
if (entry.status === "??" || entry.status.includes("A")) {
|
|
291512
|
+
removeDestination();
|
|
291513
|
+
return;
|
|
291514
|
+
}
|
|
291515
|
+
if (entry.status.includes("R")) {
|
|
291516
|
+
if (!entry.originalPath) {
|
|
291517
|
+
throw new Error(`Git rename is missing its original path: ${entry.path}`);
|
|
291518
|
+
}
|
|
291519
|
+
git.checkout(dependencies.cwd, entry.originalPath);
|
|
291520
|
+
removeDestination();
|
|
291521
|
+
return;
|
|
291522
|
+
}
|
|
291523
|
+
if (entry.status.includes("C")) {
|
|
291524
|
+
removeDestination();
|
|
291525
|
+
return;
|
|
291526
|
+
}
|
|
291527
|
+
git.checkout(dependencies.cwd, entry.path);
|
|
291528
|
+
}
|
|
291187
291529
|
function printCheckpointTimeline(checkpoints, dependencies) {
|
|
291188
291530
|
const isZh = dependencies.language !== "en";
|
|
291189
291531
|
if (checkpoints.length === 0) {
|
|
@@ -291889,8 +292231,8 @@ function copyBooleanCapability(source, sourceKey, target, targetKey) {
|
|
|
291889
292231
|
|
|
291890
292232
|
// src/runtime/ProjectLauncher.ts
|
|
291891
292233
|
import { spawn as spawn4 } from "child_process";
|
|
291892
|
-
import { existsSync as existsSync20, mkdirSync as
|
|
291893
|
-
import { dirname as
|
|
292234
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync7, realpathSync as realpathSync3, statSync as statSync4 } from "fs";
|
|
292235
|
+
import { dirname as dirname12, isAbsolute as isAbsolute7, parse as parse4, resolve as resolve13 } from "path";
|
|
291894
292236
|
var PROJECT_WEB_UI_READY_MESSAGE = "orbit-webui-ready";
|
|
291895
292237
|
async function launchOrbitProject(request, options = {}) {
|
|
291896
292238
|
if (!isAbsolute7(request.path)) {
|
|
@@ -291983,7 +292325,7 @@ function createProjectDirectory(projectPath) {
|
|
|
291983
292325
|
if (existsSync20(projectPath)) {
|
|
291984
292326
|
throw new Error("Project folder already exists. Use Open folder instead.");
|
|
291985
292327
|
}
|
|
291986
|
-
const parentPath =
|
|
292328
|
+
const parentPath = dirname12(projectPath);
|
|
291987
292329
|
if (!existsSync20(parentPath)) {
|
|
291988
292330
|
throw new Error(
|
|
291989
292331
|
"The parent folder does not exist. Choose an existing location first."
|
|
@@ -291993,7 +292335,7 @@ function createProjectDirectory(projectPath) {
|
|
|
291993
292335
|
throw new Error("The project parent path must be a directory.");
|
|
291994
292336
|
}
|
|
291995
292337
|
try {
|
|
291996
|
-
|
|
292338
|
+
mkdirSync7(projectPath);
|
|
291997
292339
|
} catch (error) {
|
|
291998
292340
|
if (isNodeError4(error) && error.code === "EEXIST") {
|
|
291999
292341
|
throw new Error(
|
|
@@ -295094,7 +295436,7 @@ Risk Warning: ${reason}`);
|
|
|
295094
295436
|
});
|
|
295095
295437
|
const normCwd = resolve14(this.cwd).toLowerCase().replace(/\\/g, "/");
|
|
295096
295438
|
const normHome = resolve14(homedir10()).toLowerCase().replace(/\\/g, "/");
|
|
295097
|
-
const isHomeOrRoot = normCwd === normHome || normCwd === "/" || /^[a-zA-Z]:\/$/.test(normCwd) ||
|
|
295439
|
+
const isHomeOrRoot = normCwd === normHome || normCwd === "/" || /^[a-zA-Z]:\/$/.test(normCwd) || dirname13(normCwd) === normCwd;
|
|
295098
295440
|
if (!isHomeOrRoot) {
|
|
295099
295441
|
const indexer = new SymbolIndexer(this.cwd);
|
|
295100
295442
|
this.watcher = watch(
|
|
@@ -296516,13 +296858,13 @@ async function runSkillsCommand(action, options = {}) {
|
|
|
296516
296858
|
// src/commands/trace.ts
|
|
296517
296859
|
import {
|
|
296518
296860
|
existsSync as existsSync21,
|
|
296519
|
-
lstatSync as
|
|
296520
|
-
mkdirSync as
|
|
296861
|
+
lstatSync as lstatSync8,
|
|
296862
|
+
mkdirSync as mkdirSync8,
|
|
296521
296863
|
renameSync as renameSync6,
|
|
296522
296864
|
rmSync as rmSync7,
|
|
296523
|
-
writeFileSync as
|
|
296865
|
+
writeFileSync as writeFileSync9
|
|
296524
296866
|
} from "fs";
|
|
296525
|
-
import { dirname as
|
|
296867
|
+
import { dirname as dirname14, resolve as resolve15 } from "path";
|
|
296526
296868
|
import { randomUUID as randomUUID12 } from "crypto";
|
|
296527
296869
|
import { z as z68 } from "zod";
|
|
296528
296870
|
var TraceOptionsSchema = z68.object({
|
|
@@ -296542,18 +296884,18 @@ function runTraceExport(cwd, sessionId, options = {}) {
|
|
|
296542
296884
|
return void 0;
|
|
296543
296885
|
}
|
|
296544
296886
|
const outputPath = resolveSafePath(cwd, value.out);
|
|
296545
|
-
const directory =
|
|
296887
|
+
const directory = dirname14(outputPath);
|
|
296546
296888
|
if (existsSync21(directory)) {
|
|
296547
|
-
const stats =
|
|
296889
|
+
const stats = lstatSync8(directory);
|
|
296548
296890
|
if (stats.isSymbolicLink() || !stats.isDirectory()) {
|
|
296549
296891
|
throw new Error("Trace output directory must be a real directory.");
|
|
296550
296892
|
}
|
|
296551
296893
|
} else {
|
|
296552
|
-
|
|
296894
|
+
mkdirSync8(directory, { recursive: true });
|
|
296553
296895
|
}
|
|
296554
296896
|
const temporaryPath = `${outputPath}.${process.pid}.${randomUUID12()}.tmp`;
|
|
296555
296897
|
try {
|
|
296556
|
-
|
|
296898
|
+
writeFileSync9(temporaryPath, serialized, {
|
|
296557
296899
|
encoding: "utf8",
|
|
296558
296900
|
flag: "wx",
|
|
296559
296901
|
mode: 384
|
|
@@ -296571,13 +296913,13 @@ import { exec as execCallback, execFileSync as execFileSync8 } from "child_proce
|
|
|
296571
296913
|
import {
|
|
296572
296914
|
copyFileSync,
|
|
296573
296915
|
existsSync as existsSync28,
|
|
296574
|
-
lstatSync as
|
|
296575
|
-
mkdirSync as
|
|
296916
|
+
lstatSync as lstatSync9,
|
|
296917
|
+
mkdirSync as mkdirSync9,
|
|
296576
296918
|
renameSync as renameSync7,
|
|
296577
296919
|
rmSync as rmSync8,
|
|
296578
|
-
writeFileSync as
|
|
296920
|
+
writeFileSync as writeFileSync10
|
|
296579
296921
|
} from "fs";
|
|
296580
|
-
import { basename as basename5, dirname as
|
|
296922
|
+
import { basename as basename5, dirname as dirname15, join as join19 } from "path";
|
|
296581
296923
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
296582
296924
|
import { promisify as promisify5 } from "util";
|
|
296583
296925
|
import picocolors25 from "picocolors";
|
|
@@ -296750,7 +297092,7 @@ async function runEval(cwd, suiteFile, options = {}) {
|
|
|
296750
297092
|
}
|
|
296751
297093
|
function loadAcceptanceSuite(cwd, suiteFile) {
|
|
296752
297094
|
const filePath = resolveSafePath(cwd, suiteFile);
|
|
296753
|
-
const stats =
|
|
297095
|
+
const stats = lstatSync9(filePath);
|
|
296754
297096
|
if (stats.isSymbolicLink() || !stats.isFile()) {
|
|
296755
297097
|
throw new Error("Acceptance suite must be a real file.");
|
|
296756
297098
|
}
|
|
@@ -296847,9 +297189,9 @@ function snapshotWorkspaceIntoWorktree(sourceCwd, worktreeCwd) {
|
|
|
296847
297189
|
if (isSensitiveSnapshotPath2(relativePath)) continue;
|
|
296848
297190
|
const sourcePath = resolveSafePath(sourceCwd, relativePath);
|
|
296849
297191
|
const targetPath = resolveSafePath(worktreeCwd, relativePath);
|
|
296850
|
-
const stats =
|
|
297192
|
+
const stats = lstatSync9(sourcePath);
|
|
296851
297193
|
if (stats.isSymbolicLink() || !stats.isFile()) continue;
|
|
296852
|
-
|
|
297194
|
+
mkdirSync9(dirname15(targetPath), { recursive: true });
|
|
296853
297195
|
copyFileSync(sourcePath, targetPath);
|
|
296854
297196
|
}
|
|
296855
297197
|
execFileSync8("git", ["add", "-A"], {
|
|
@@ -296908,18 +297250,18 @@ function writeEvaluationReport(cwd, runId, report) {
|
|
|
296908
297250
|
return filePath;
|
|
296909
297251
|
}
|
|
296910
297252
|
function writeJsonAtomically2(filePath, value) {
|
|
296911
|
-
const directory =
|
|
297253
|
+
const directory = dirname15(filePath);
|
|
296912
297254
|
if (existsSync28(directory)) {
|
|
296913
|
-
const stats =
|
|
297255
|
+
const stats = lstatSync9(directory);
|
|
296914
297256
|
if (stats.isSymbolicLink() || !stats.isDirectory()) {
|
|
296915
297257
|
throw new Error("Evaluation output directory must be a real directory.");
|
|
296916
297258
|
}
|
|
296917
297259
|
} else {
|
|
296918
|
-
|
|
297260
|
+
mkdirSync9(directory, { recursive: true });
|
|
296919
297261
|
}
|
|
296920
297262
|
const temporaryPath = `${filePath}.${process.pid}.${randomUUID13()}.tmp`;
|
|
296921
297263
|
try {
|
|
296922
|
-
|
|
297264
|
+
writeFileSync10(temporaryPath, JSON.stringify(value, null, 2), {
|
|
296923
297265
|
encoding: "utf8",
|
|
296924
297266
|
flag: "wx",
|
|
296925
297267
|
mode: 384
|
|
@@ -296942,7 +297284,7 @@ import { resolve as resolve17 } from "path";
|
|
|
296942
297284
|
import { z as z71 } from "zod";
|
|
296943
297285
|
|
|
296944
297286
|
// src/runtime/CleanupManager.ts
|
|
296945
|
-
import { lstatSync as
|
|
297287
|
+
import { lstatSync as lstatSync10, readdirSync as readdirSync9, rmSync as rmSync9 } from "fs";
|
|
296946
297288
|
import { homedir as homedir11 } from "os";
|
|
296947
297289
|
import { basename as basename6, join as join20, parse as parse5, resolve as resolve16 } from "path";
|
|
296948
297290
|
import { z as z70 } from "zod";
|
|
@@ -297012,7 +297354,7 @@ function inspectPath(targetPath) {
|
|
|
297012
297354
|
const visit = (currentPath) => {
|
|
297013
297355
|
let stat;
|
|
297014
297356
|
try {
|
|
297015
|
-
stat =
|
|
297357
|
+
stat = lstatSync10(currentPath);
|
|
297016
297358
|
} catch (error) {
|
|
297017
297359
|
warnings.push(safeInventoryWarning(currentPath, error));
|
|
297018
297360
|
return;
|
|
@@ -297059,7 +297401,7 @@ function pathIdentity(targetPath) {
|
|
|
297059
297401
|
}
|
|
297060
297402
|
function pathExists(targetPath) {
|
|
297061
297403
|
try {
|
|
297062
|
-
|
|
297404
|
+
lstatSync10(targetPath);
|
|
297063
297405
|
return true;
|
|
297064
297406
|
} catch {
|
|
297065
297407
|
return false;
|
|
@@ -297196,15 +297538,15 @@ import { z as z75 } from "zod";
|
|
|
297196
297538
|
// src/runtime/ProjectBackup.ts
|
|
297197
297539
|
import {
|
|
297198
297540
|
existsSync as existsSync29,
|
|
297199
|
-
lstatSync as
|
|
297200
|
-
mkdirSync as
|
|
297541
|
+
lstatSync as lstatSync11,
|
|
297542
|
+
mkdirSync as mkdirSync10,
|
|
297201
297543
|
readdirSync as readdirSync10,
|
|
297202
297544
|
renameSync as renameSync8,
|
|
297203
297545
|
rmSync as rmSync10,
|
|
297204
|
-
writeFileSync as
|
|
297546
|
+
writeFileSync as writeFileSync11
|
|
297205
297547
|
} from "fs";
|
|
297206
297548
|
import { createHash as createHash9, randomUUID as randomUUID14 } from "crypto";
|
|
297207
|
-
import { dirname as
|
|
297549
|
+
import { dirname as dirname16, isAbsolute as isAbsolute8, join as join21, relative as relative9, resolve as resolve18, sep as sep2 } from "path";
|
|
297208
297550
|
import { z as z74 } from "zod";
|
|
297209
297551
|
var MAX_BACKUP_BYTES = 64 * 1024 * 1024;
|
|
297210
297552
|
var MAX_SERIALIZED_BACKUP_BYTES = 96 * 1024 * 1024;
|
|
@@ -297313,10 +297655,10 @@ function createProjectBackup(projectDirectory) {
|
|
|
297313
297655
|
}
|
|
297314
297656
|
function writeProjectBackup(outputPath, bundle) {
|
|
297315
297657
|
const destination = resolve18(outputPath);
|
|
297316
|
-
|
|
297658
|
+
mkdirSync10(dirname16(destination), { recursive: true });
|
|
297317
297659
|
const temporaryPath = `${destination}.${process.pid}.${randomUUID14()}.tmp`;
|
|
297318
297660
|
try {
|
|
297319
|
-
|
|
297661
|
+
writeFileSync11(
|
|
297320
297662
|
temporaryPath,
|
|
297321
297663
|
`${JSON.stringify(ProjectBackupBundleSchema.parse(bundle), null, 2)}
|
|
297322
297664
|
`,
|
|
@@ -297358,11 +297700,11 @@ function restoreProjectBackup(projectDirectory, bundle, options = {}) {
|
|
|
297358
297700
|
}
|
|
297359
297701
|
const restored = [];
|
|
297360
297702
|
for (const { file, destination } of planned) {
|
|
297361
|
-
assertDirectoryChainHasNoSymlink(orbitRoot,
|
|
297362
|
-
|
|
297703
|
+
assertDirectoryChainHasNoSymlink(orbitRoot, dirname16(destination));
|
|
297704
|
+
mkdirSync10(dirname16(destination), { recursive: true });
|
|
297363
297705
|
const temporaryPath = `${destination}.${process.pid}.${randomUUID14()}.tmp`;
|
|
297364
297706
|
try {
|
|
297365
|
-
|
|
297707
|
+
writeFileSync11(temporaryPath, Buffer.from(file.content, "base64"), {
|
|
297366
297708
|
mode: 384
|
|
297367
297709
|
});
|
|
297368
297710
|
replaceFileAtomically2(temporaryPath, destination);
|
|
@@ -297393,7 +297735,7 @@ function listBackupFiles(root) {
|
|
|
297393
297735
|
const relativePath = relative9(root, absolutePath).split(sep2).join("/");
|
|
297394
297736
|
const topLevel = relativePath.split("/")[0]?.toLowerCase() ?? "";
|
|
297395
297737
|
if (EXCLUDED_TOP_LEVEL.has(topLevel)) continue;
|
|
297396
|
-
const status =
|
|
297738
|
+
const status = lstatSync11(absolutePath);
|
|
297397
297739
|
if (status.isSymbolicLink()) continue;
|
|
297398
297740
|
if (status.isDirectory()) visit(absolutePath, depth + 1);
|
|
297399
297741
|
else if (status.isFile()) {
|
|
@@ -297437,12 +297779,12 @@ function assertDirectoryChainHasNoSymlink(root, target) {
|
|
|
297437
297779
|
throw new Error("Backup restore directory escapes the project.");
|
|
297438
297780
|
}
|
|
297439
297781
|
let current = absoluteRoot;
|
|
297440
|
-
if (existsSync29(current) &&
|
|
297782
|
+
if (existsSync29(current) && lstatSync11(current).isSymbolicLink()) {
|
|
297441
297783
|
throw new Error(`Refusing to restore through symbolic link: ${current}`);
|
|
297442
297784
|
}
|
|
297443
297785
|
for (const part of relativeTarget.split(sep2).filter(Boolean)) {
|
|
297444
297786
|
current = join21(current, part);
|
|
297445
|
-
if (existsSync29(current) &&
|
|
297787
|
+
if (existsSync29(current) && lstatSync11(current).isSymbolicLink()) {
|
|
297446
297788
|
throw new Error(`Refusing to restore through symbolic link: ${current}`);
|
|
297447
297789
|
}
|
|
297448
297790
|
}
|
|
@@ -297571,15 +297913,15 @@ import picocolors28 from "picocolors";
|
|
|
297571
297913
|
// src/runtime/ExtensionManager.ts
|
|
297572
297914
|
import {
|
|
297573
297915
|
existsSync as existsSync30,
|
|
297574
|
-
lstatSync as
|
|
297575
|
-
mkdirSync as
|
|
297916
|
+
lstatSync as lstatSync12,
|
|
297917
|
+
mkdirSync as mkdirSync11,
|
|
297576
297918
|
readdirSync as readdirSync11,
|
|
297577
297919
|
renameSync as renameSync9,
|
|
297578
297920
|
rmSync as rmSync11,
|
|
297579
|
-
writeFileSync as
|
|
297921
|
+
writeFileSync as writeFileSync12
|
|
297580
297922
|
} from "fs";
|
|
297581
297923
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
297582
|
-
import { dirname as
|
|
297924
|
+
import { dirname as dirname17, isAbsolute as isAbsolute9, join as join26, relative as relative10, resolve as resolve20, sep as sep3 } from "path";
|
|
297583
297925
|
import { homedir as homedir12 } from "os";
|
|
297584
297926
|
import { z as z76 } from "zod";
|
|
297585
297927
|
var InstalledExtensionSchema2 = z76.object({
|
|
@@ -297609,7 +297951,7 @@ var ExtensionManager = class {
|
|
|
297609
297951
|
list() {
|
|
297610
297952
|
try {
|
|
297611
297953
|
return this.readRegistry().filter(
|
|
297612
|
-
(extension) => this.isManagedExtensionPath(extension) && existsSync30(extension.path) && !
|
|
297954
|
+
(extension) => this.isManagedExtensionPath(extension) && existsSync30(extension.path) && !lstatSync12(extension.path).isSymbolicLink()
|
|
297613
297955
|
);
|
|
297614
297956
|
} catch {
|
|
297615
297957
|
return [];
|
|
@@ -297618,7 +297960,7 @@ var ExtensionManager = class {
|
|
|
297618
297960
|
install(cwd, manifestPath, options = {}) {
|
|
297619
297961
|
const manifest = loadOrbitExtensionManifest(cwd, manifestPath);
|
|
297620
297962
|
verifyOrbitCompatibility(manifest, readCliVersion());
|
|
297621
|
-
const sourceRoot =
|
|
297963
|
+
const sourceRoot = dirname17(resolve20(cwd, manifestPath));
|
|
297622
297964
|
validateContributionFiles(sourceRoot, manifest);
|
|
297623
297965
|
validateContributionPermissions(manifest);
|
|
297624
297966
|
const requiresTrust = extensionRequiresTrust(manifest);
|
|
@@ -297655,7 +297997,7 @@ var ExtensionManager = class {
|
|
|
297655
297997
|
{ cause: error }
|
|
297656
297998
|
);
|
|
297657
297999
|
}
|
|
297658
|
-
|
|
298000
|
+
mkdirSync11(this.extensionsDir, { recursive: true });
|
|
297659
298001
|
let targetBackedUp = false;
|
|
297660
298002
|
let targetInstalled = false;
|
|
297661
298003
|
let promptMutationStarted = false;
|
|
@@ -297668,7 +298010,7 @@ var ExtensionManager = class {
|
|
|
297668
298010
|
}
|
|
297669
298011
|
for (const prompt of promptTargets) {
|
|
297670
298012
|
if (!existsSync30(prompt.target)) continue;
|
|
297671
|
-
|
|
298013
|
+
mkdirSync11(dirname17(prompt.backup), { recursive: true });
|
|
297672
298014
|
renameSync9(prompt.target, prompt.backup);
|
|
297673
298015
|
prompt.backedUp = true;
|
|
297674
298016
|
}
|
|
@@ -297711,7 +298053,7 @@ var ExtensionManager = class {
|
|
|
297711
298053
|
rmSync11(prompt.target, { recursive: true, force: true });
|
|
297712
298054
|
}
|
|
297713
298055
|
if (prompt.backedUp && existsSync30(prompt.backup)) {
|
|
297714
|
-
|
|
298056
|
+
mkdirSync11(dirname17(prompt.target), { recursive: true });
|
|
297715
298057
|
renameSync9(prompt.backup, prompt.target);
|
|
297716
298058
|
}
|
|
297717
298059
|
}
|
|
@@ -297738,7 +298080,7 @@ var ExtensionManager = class {
|
|
|
297738
298080
|
);
|
|
297739
298081
|
}
|
|
297740
298082
|
const installed = registry.find(
|
|
297741
|
-
(entry) => entry.id === id && existsSync30(entry.path) && !
|
|
298083
|
+
(entry) => entry.id === id && existsSync30(entry.path) && !lstatSync12(entry.path).isSymbolicLink()
|
|
297742
298084
|
);
|
|
297743
298085
|
if (!installed) return false;
|
|
297744
298086
|
const rollbackRoot = join26(
|
|
@@ -297759,7 +298101,7 @@ var ExtensionManager = class {
|
|
|
297759
298101
|
try {
|
|
297760
298102
|
for (const entry of targets) {
|
|
297761
298103
|
if (!existsSync30(entry.target)) continue;
|
|
297762
|
-
|
|
298104
|
+
mkdirSync11(dirname17(entry.backup), { recursive: true });
|
|
297763
298105
|
renameSync9(entry.target, entry.backup);
|
|
297764
298106
|
entry.backedUp = true;
|
|
297765
298107
|
}
|
|
@@ -297770,7 +298112,7 @@ var ExtensionManager = class {
|
|
|
297770
298112
|
try {
|
|
297771
298113
|
for (const entry of targets) {
|
|
297772
298114
|
if (!entry.backedUp || !existsSync30(entry.backup)) continue;
|
|
297773
|
-
|
|
298115
|
+
mkdirSync11(dirname17(entry.target), { recursive: true });
|
|
297774
298116
|
renameSync9(entry.backup, entry.target);
|
|
297775
298117
|
}
|
|
297776
298118
|
rmSync11(rollbackRoot, { recursive: true, force: true });
|
|
@@ -297898,7 +298240,7 @@ function validateContributionFiles(root, manifest) {
|
|
|
297898
298240
|
`Invalid extension contribution path: ${contribution.path}`
|
|
297899
298241
|
);
|
|
297900
298242
|
}
|
|
297901
|
-
if (!existsSync30(target) ||
|
|
298243
|
+
if (!existsSync30(target) || lstatSync12(target).isSymbolicLink()) {
|
|
297902
298244
|
throw new Error(
|
|
297903
298245
|
`Extension contribution is missing or unsafe: ${contribution.path}`
|
|
297904
298246
|
);
|
|
@@ -297916,11 +298258,11 @@ function copyDirectoryEntry(source, target, budget, depth) {
|
|
|
297916
298258
|
if (budget.entries > MAX_EXTENSION_TREE_ENTRIES) {
|
|
297917
298259
|
throw new Error("Extension tree contains too many entries.");
|
|
297918
298260
|
}
|
|
297919
|
-
const stats =
|
|
298261
|
+
const stats = lstatSync12(source);
|
|
297920
298262
|
if (stats.isSymbolicLink())
|
|
297921
298263
|
throw new Error("Extension directories cannot contain symlinks.");
|
|
297922
298264
|
if (stats.isDirectory()) {
|
|
297923
|
-
|
|
298265
|
+
mkdirSync11(target, { recursive: true });
|
|
297924
298266
|
for (const entry of readdirSync11(source)) {
|
|
297925
298267
|
if (entry === "node_modules" || entry === ".git") continue;
|
|
297926
298268
|
copyDirectoryEntry(
|
|
@@ -297940,8 +298282,8 @@ function copyDirectoryEntry(source, target, budget, depth) {
|
|
|
297940
298282
|
if (budget.bytes > MAX_EXTENSION_TREE_BYTES) {
|
|
297941
298283
|
throw new Error("Extension tree exceeds the 256 MiB limit.");
|
|
297942
298284
|
}
|
|
297943
|
-
|
|
297944
|
-
|
|
298285
|
+
mkdirSync11(dirname17(target), { recursive: true });
|
|
298286
|
+
writeFileSync12(target, data, { mode: 384 });
|
|
297945
298287
|
}
|
|
297946
298288
|
function materializePromptContributions(extensionRoot, manifest, orbitDir) {
|
|
297947
298289
|
for (const [kind, contributions] of [
|
|
@@ -297952,7 +298294,7 @@ function materializePromptContributions(extensionRoot, manifest, orbitDir) {
|
|
|
297952
298294
|
rmSync11(destinationRoot, { recursive: true, force: true });
|
|
297953
298295
|
for (const contribution of contributions) {
|
|
297954
298296
|
const source = resolve20(extensionRoot, contribution.path);
|
|
297955
|
-
const sourceIsDirectory =
|
|
298297
|
+
const sourceIsDirectory = lstatSync12(source).isDirectory();
|
|
297956
298298
|
const destination = sourceIsDirectory ? join26(destinationRoot, contribution.name) : kind === "commands" ? join26(destinationRoot, `${contribution.name}.md`) : join26(destinationRoot, contribution.name, "SKILL.md");
|
|
297957
298299
|
copyDirectorySafely(source, destination);
|
|
297958
298300
|
}
|