minimal-forge-work-pack-sync 0.1.17 → 0.1.19
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 +159 -100
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7614,7 +7614,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
|
7614
7614
|
};
|
|
7615
7615
|
|
|
7616
7616
|
// packages/shared/src/contracts/settings.ts
|
|
7617
|
-
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.
|
|
7617
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.19";
|
|
7618
7618
|
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
7619
7619
|
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
7620
7620
|
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
@@ -7660,7 +7660,7 @@ function parseWorkPackFileManifest(value) {
|
|
|
7660
7660
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
7661
7661
|
const state = value;
|
|
7662
7662
|
if (state.schemaVersion !== 1 || typeof state.version !== "string" || !state.version || state.version.length > 14 * 1024) return void 0;
|
|
7663
|
-
const validPath = (name, filenameOnly = false) => typeof name === "string" && name.length > 0 && name.length <= 4096 && !/[
|
|
7663
|
+
const validPath = (name, filenameOnly = false) => typeof name === "string" && name.length > 0 && name.length <= 4096 && !/[\\\\\u0000-\u001f\u007f]/.test(name) && !/^[A-Za-z]:/.test(name) && name.split("/").every((part) => part && part !== "." && part !== "..") && (!filenameOnly || !name.includes("/"));
|
|
7664
7664
|
const digests = (entries, key) => {
|
|
7665
7665
|
if (!Array.isArray(entries) || entries.length > 5e3) return false;
|
|
7666
7666
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -20398,11 +20398,11 @@ async function checkWorkPackInstalledState(input) {
|
|
|
20398
20398
|
if (!state) return "missing";
|
|
20399
20399
|
return await matchesInstalledState(input, state) ? "match" : "changed";
|
|
20400
20400
|
}
|
|
20401
|
-
async function checkWorkPackTreeState(packDir) {
|
|
20401
|
+
async function checkWorkPackTreeState(packDir, allowAdditional = false) {
|
|
20402
20402
|
const state = await readInstalledState(packDir);
|
|
20403
20403
|
if (!state) return "missing";
|
|
20404
20404
|
const tree = await digestPackTree(packDir).catch(() => void 0);
|
|
20405
|
-
return tree && sameTree(tree, state) ? "match" : "changed";
|
|
20405
|
+
return tree && (allowAdditional ? containsOriginalTree(tree, state) : sameTree(tree, state)) ? "match" : "changed";
|
|
20406
20406
|
}
|
|
20407
20407
|
async function adoptWorkPackInstalledState(input) {
|
|
20408
20408
|
const state = await readInstalledState(input.expectedPackDir);
|
|
@@ -20410,34 +20410,6 @@ async function adoptWorkPackInstalledState(input) {
|
|
|
20410
20410
|
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
20411
20411
|
return checkWorkPackInstalledState(input).then((result) => result === "match");
|
|
20412
20412
|
}
|
|
20413
|
-
async function adoptVerifiedWorkPackState(input) {
|
|
20414
|
-
const tree = await digestPackTree(input.packDir);
|
|
20415
|
-
if (!tree) return false;
|
|
20416
|
-
const projections = async (kind, directory) => {
|
|
20417
|
-
const prefix = `${kind}/`;
|
|
20418
|
-
const expected = tree.files.filter((file2) => file2.path.startsWith(prefix) && !file2.path.slice(prefix.length).includes("/") && file2.path.endsWith(".md") && !file2.path.slice(prefix.length).startsWith("._"));
|
|
20419
|
-
const result = [];
|
|
20420
|
-
for (const file2 of expected) {
|
|
20421
|
-
const filename = file2.path.slice(prefix.length);
|
|
20422
|
-
const absolute = path3.join(directory, filename);
|
|
20423
|
-
const info = await lstat2(absolute);
|
|
20424
|
-
if (!info.isFile() || info.isSymbolicLink()) throw new Error("Unsafe projection");
|
|
20425
|
-
result.push({ filename, sha256: digest(await readFile2(absolute)) });
|
|
20426
|
-
}
|
|
20427
|
-
return result.sort((a, b2) => a.filename.localeCompare(b2.filename));
|
|
20428
|
-
};
|
|
20429
|
-
const state = {
|
|
20430
|
-
schemaVersion: 1,
|
|
20431
|
-
version: input.version,
|
|
20432
|
-
...tree,
|
|
20433
|
-
agents: await projections("agents", input.agentsDir),
|
|
20434
|
-
commands: await projections("commands", input.commandsDir)
|
|
20435
|
-
};
|
|
20436
|
-
if (digest(Buffer.from(canonicalWorkPackState(state))) !== input.fingerprint) return false;
|
|
20437
|
-
if (!await matchesInstalledState(input, state)) return false;
|
|
20438
|
-
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), state);
|
|
20439
|
-
return await checkWorkPackInstalledState(input) === "match";
|
|
20440
|
-
}
|
|
20441
20413
|
async function readInstalledState(packDir) {
|
|
20442
20414
|
const info = await lstat2(path3.join(packDir, WORK_PACK_LOCAL_STATE_FILENAME)).catch(() => void 0);
|
|
20443
20415
|
if (!info?.isFile() || info.isSymbolicLink() || info.size > 1024 * 1024) return void 0;
|
|
@@ -20458,6 +20430,8 @@ async function digestPackTree(root) {
|
|
|
20458
20430
|
if (!prefix && entry.name === WORK_PACK_LOCAL_STATE_FILENAME) continue;
|
|
20459
20431
|
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
20460
20432
|
const absolute = path3.join(directory, entry.name);
|
|
20433
|
+
const info = await lstat2(absolute);
|
|
20434
|
+
if (info.isSymbolicLink() || info.isFile() && info.nlink > 1) return false;
|
|
20461
20435
|
if (entry.isDirectory()) {
|
|
20462
20436
|
directories.push(relative);
|
|
20463
20437
|
if (!await visit(absolute, relative)) return false;
|
|
@@ -20485,7 +20459,7 @@ async function projectionsMatch(directory, expected) {
|
|
|
20485
20459
|
}
|
|
20486
20460
|
async function matchesInstalledState(input, state) {
|
|
20487
20461
|
const tree = await digestPackTree(input.packDir).catch(() => void 0);
|
|
20488
|
-
if (!tree || !sameTree(tree, state)) return false;
|
|
20462
|
+
if (!tree || !(input.allowAdditional ? containsOriginalTree(tree, state) : sameTree(tree, state))) return false;
|
|
20489
20463
|
if (!await projectionsMatch(input.agentsDir, state.agents)) return false;
|
|
20490
20464
|
return projectionsMatch(input.commandsDir, state.commands);
|
|
20491
20465
|
}
|
|
@@ -20507,6 +20481,24 @@ async function writeJsonAtomic(filePath, value) {
|
|
|
20507
20481
|
`);
|
|
20508
20482
|
await rename2(tempPath, filePath);
|
|
20509
20483
|
}
|
|
20484
|
+
async function adoptWorkPackFileManifest(input) {
|
|
20485
|
+
if (!await matchesInstalledState({ ...input, allowAdditional: true }, input.expected)) return false;
|
|
20486
|
+
await writeJsonAtomic(path3.join(input.packDir, WORK_PACK_LOCAL_STATE_FILENAME), input.expected);
|
|
20487
|
+
return true;
|
|
20488
|
+
}
|
|
20489
|
+
function containsOriginalTree(actual, expected) {
|
|
20490
|
+
const files = new Map(actual.files.map((file2) => [file2.path, file2.sha256]));
|
|
20491
|
+
const directories = new Set(actual.directories);
|
|
20492
|
+
return expected.files.every((file2) => files.get(file2.path) === file2.sha256) && expected.directories.every((directory) => directories.has(directory));
|
|
20493
|
+
}
|
|
20494
|
+
async function workPackExtrasTree(packDir) {
|
|
20495
|
+
const state = await readInstalledState(packDir);
|
|
20496
|
+
const tree = await digestPackTree(packDir);
|
|
20497
|
+
if (!state || !tree) return void 0;
|
|
20498
|
+
const files = new Set(state.files.map((file2) => file2.path));
|
|
20499
|
+
const directories = new Set(state.directories);
|
|
20500
|
+
return { files: tree.files.filter((file2) => !files.has(file2.path)), directories: tree.directories.filter((dir) => !directories.has(dir)) };
|
|
20501
|
+
}
|
|
20510
20502
|
|
|
20511
20503
|
// packages/cli/src/workPackIntegrity.ts
|
|
20512
20504
|
var MAX_ENTRIES = 1e4;
|
|
@@ -20538,6 +20530,7 @@ async function inspectWorkPackIntegrity(input) {
|
|
|
20538
20530
|
const root = await lstat3(packDir).catch(() => void 0);
|
|
20539
20531
|
if (!root?.isDirectory() || root.isSymbolicLink()) {
|
|
20540
20532
|
add(root ? "unsafe" : "unreadable", "pack", ".");
|
|
20533
|
+
result.summary.kind = "unsafe-or-unreadable";
|
|
20541
20534
|
return result;
|
|
20542
20535
|
}
|
|
20543
20536
|
const expected = input.expected ? parseWorkPackFileManifest(input.expected) : await readInstalledState(packDir);
|
|
@@ -20682,6 +20675,41 @@ async function regularFileDigest(filePath, budget) {
|
|
|
20682
20675
|
return void 0;
|
|
20683
20676
|
}
|
|
20684
20677
|
}
|
|
20678
|
+
async function fetchWorkPackFileManifest(credentials, slug, version2) {
|
|
20679
|
+
assertSlug(slug);
|
|
20680
|
+
const origin = new URL(credentials.forgeBaseUrl);
|
|
20681
|
+
if (origin.username || origin.password || origin.protocol !== "https:" && !(origin.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname))) return void 0;
|
|
20682
|
+
if (!version2 || Buffer.byteLength(version2) > 4096) return void 0;
|
|
20683
|
+
const url2 = new URL(`/sync/skills/${encodeURIComponent(slug)}/baseline/${encodeURIComponent(version2)}?details=1`, origin);
|
|
20684
|
+
try {
|
|
20685
|
+
const response = await fetch(url2, { headers: { authorization: `Bearer ${credentials.forgeApiKey}` }, redirect: "manual", signal: AbortSignal.timeout(1e4) });
|
|
20686
|
+
if (!response.ok || response.redirected || response.url && new URL(response.url).origin !== origin.origin) return void 0;
|
|
20687
|
+
const reader = response.body?.getReader();
|
|
20688
|
+
if (!reader) return void 0;
|
|
20689
|
+
const chunks = [];
|
|
20690
|
+
let size = 0;
|
|
20691
|
+
try {
|
|
20692
|
+
while (true) {
|
|
20693
|
+
const { done, value } = await reader.read();
|
|
20694
|
+
if (done) break;
|
|
20695
|
+
size += value.byteLength;
|
|
20696
|
+
if (size > 1024 * 1024) {
|
|
20697
|
+
await reader.cancel();
|
|
20698
|
+
return void 0;
|
|
20699
|
+
}
|
|
20700
|
+
chunks.push(value);
|
|
20701
|
+
}
|
|
20702
|
+
} finally {
|
|
20703
|
+
reader.releaseLock();
|
|
20704
|
+
}
|
|
20705
|
+
const payload = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
20706
|
+
const manifest = parseWorkPackFileManifest(payload.manifest);
|
|
20707
|
+
if (!manifest || manifest.version !== version2 || typeof payload.fingerprint !== "string" || createHash2("sha256").update(canonicalWorkPackState(manifest)).digest("hex") !== payload.fingerprint) return void 0;
|
|
20708
|
+
return manifest;
|
|
20709
|
+
} catch {
|
|
20710
|
+
return void 0;
|
|
20711
|
+
}
|
|
20712
|
+
}
|
|
20685
20713
|
function assertSlug(slug) {
|
|
20686
20714
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || slug.length > 64) throw new Error("Identificador de skill inv\xE1lido");
|
|
20687
20715
|
}
|
|
@@ -23806,7 +23834,7 @@ async function runOperation(operation, operate) {
|
|
|
23806
23834
|
code: stableCode(result.code),
|
|
23807
23835
|
...result.integrity ? { integrity: result.integrity } : {},
|
|
23808
23836
|
...result.projectionConflict ? { projectionConflict: result.projectionConflict } : {},
|
|
23809
|
-
message: `O pacote "${operation.pack.slug}" falhou, mas o estado anterior foi restaurado exatamente. Corrija a causa indicada e volte a sincronizar.`
|
|
23837
|
+
message: result.message ?? `O pacote "${operation.pack.slug}" falhou, mas o estado anterior foi restaurado exatamente. Corrija a causa indicada e volte a sincronizar.`
|
|
23810
23838
|
};
|
|
23811
23839
|
}
|
|
23812
23840
|
if (!validSuccessFor(operation.action, result.status)) return uncertainOutcome(operation, "invalid-callback-result");
|
|
@@ -23953,7 +23981,7 @@ async function collectWorkPackObservations(paths, reconciliation) {
|
|
|
23953
23981
|
return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
|
|
23954
23982
|
}
|
|
23955
23983
|
async function enrichIntegrityFailure(paths, operation, result) {
|
|
23956
|
-
if (result.status !== "failed" || !["local-edits-preserved", "local-baseline-missing"].includes(result.code)) return result;
|
|
23984
|
+
if (result.status !== "failed" || result.integrity || !["local-edits-preserved", "local-baseline-missing"].includes(result.code)) return result;
|
|
23957
23985
|
try {
|
|
23958
23986
|
const { summary } = await inspectWorkPackIntegrity({ paths, slug: operation.pack.slug });
|
|
23959
23987
|
if (summary.kind === "match") return result;
|
|
@@ -24005,24 +24033,39 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
24005
24033
|
try {
|
|
24006
24034
|
const currentVersion = await readFile3(path5.join(target, ".forge-version"), "utf8").catch(() => "");
|
|
24007
24035
|
const sameVersion = currentVersion.trim() === skill.version;
|
|
24008
|
-
if (
|
|
24036
|
+
if (ownership === "managed") {
|
|
24009
24037
|
let localState = await checkWorkPackInstalledState({
|
|
24010
24038
|
packDir: target,
|
|
24011
24039
|
agentsDir: paths.agentsDir,
|
|
24012
|
-
commandsDir: paths.commandsDir
|
|
24040
|
+
commandsDir: paths.commandsDir,
|
|
24041
|
+
allowAdditional: true
|
|
24013
24042
|
});
|
|
24014
24043
|
if (localState === "missing") {
|
|
24015
|
-
const
|
|
24016
|
-
|
|
24017
|
-
|
|
24018
|
-
|
|
24019
|
-
|
|
24020
|
-
|
|
24021
|
-
|
|
24022
|
-
|
|
24023
|
-
|
|
24024
|
-
|
|
24025
|
-
|
|
24044
|
+
const expected = await fetchWorkPackFileManifest(credentials, skill.slug, currentVersion.trim());
|
|
24045
|
+
if (expected) {
|
|
24046
|
+
const diagnosis = await inspectWorkPackIntegrity({ paths, slug: skill.slug, expected });
|
|
24047
|
+
if (diagnosis.summary.modified || diagnosis.summary.missing || diagnosis.summary.unsafe || diagnosis.summary.unreadable || diagnosis.summary.truncated) {
|
|
24048
|
+
return { status: "failed", restoration: "exact", code: "local-edits-preserved", integrity: diagnosis.summary };
|
|
24049
|
+
}
|
|
24050
|
+
localState = await adoptWorkPackFileManifest({
|
|
24051
|
+
packDir: target,
|
|
24052
|
+
agentsDir: paths.agentsDir,
|
|
24053
|
+
commandsDir: paths.commandsDir,
|
|
24054
|
+
expected
|
|
24055
|
+
}) ? "match" : "changed";
|
|
24056
|
+
} else if (sameVersion) {
|
|
24057
|
+
const candidateArchive = await downloadSkill(credentials, skill.url);
|
|
24058
|
+
if (createHash3("sha256").update(candidateArchive).digest("hex") !== skill.sha256)
|
|
24059
|
+
return { status: "failed", restoration: "exact", code: "local-baseline-missing" };
|
|
24060
|
+
localState = await adoptLegacyWorkPackState(paths, skill.slug, skill.version, candidateArchive, approvedModelIds) ? "match" : "changed";
|
|
24061
|
+
}
|
|
24062
|
+
}
|
|
24063
|
+
if (localState !== "match") return {
|
|
24064
|
+
status: "failed",
|
|
24065
|
+
restoration: "exact",
|
|
24066
|
+
code: localState === "missing" ? "local-baseline-missing" : "local-edits-preserved"
|
|
24067
|
+
};
|
|
24068
|
+
if (sameVersion && !await workPackNeedsModelNormalization(target, approvedModelIds, skill.slug)) {
|
|
24026
24069
|
return cleanupPendingSlugs.has(skill.slug) ? {
|
|
24027
24070
|
status: "unchanged",
|
|
24028
24071
|
warningCode: "cleanup-pending",
|
|
@@ -24030,36 +24073,6 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
24030
24073
|
} : { status: "unchanged" };
|
|
24031
24074
|
}
|
|
24032
24075
|
}
|
|
24033
|
-
if (ownership === "managed" && !sameVersion) {
|
|
24034
|
-
let localState = await checkWorkPackInstalledState({
|
|
24035
|
-
packDir: target,
|
|
24036
|
-
agentsDir: paths.agentsDir,
|
|
24037
|
-
commandsDir: paths.commandsDir
|
|
24038
|
-
});
|
|
24039
|
-
if (localState === "missing") {
|
|
24040
|
-
try {
|
|
24041
|
-
const baselineUrl = `/sync/skills/${encodeURIComponent(skill.slug)}/baseline/${encodeURIComponent(currentVersion.trim())}`;
|
|
24042
|
-
const baseline = JSON.parse(new TextDecoder().decode(await downloadSkill(credentials, baselineUrl)));
|
|
24043
|
-
if (typeof baseline.fingerprint === "string" && /^[a-f0-9]{64}$/.test(baseline.fingerprint)) {
|
|
24044
|
-
localState = await adoptVerifiedWorkPackState({
|
|
24045
|
-
packDir: target,
|
|
24046
|
-
agentsDir: paths.agentsDir,
|
|
24047
|
-
commandsDir: paths.commandsDir,
|
|
24048
|
-
version: currentVersion.trim(),
|
|
24049
|
-
fingerprint: baseline.fingerprint
|
|
24050
|
-
}) ? "match" : "missing";
|
|
24051
|
-
}
|
|
24052
|
-
} catch {
|
|
24053
|
-
}
|
|
24054
|
-
}
|
|
24055
|
-
if (localState !== "match") {
|
|
24056
|
-
return {
|
|
24057
|
-
status: "failed",
|
|
24058
|
-
restoration: "exact",
|
|
24059
|
-
code: localState === "missing" ? "local-baseline-missing" : "local-edits-preserved"
|
|
24060
|
-
};
|
|
24061
|
-
}
|
|
24062
|
-
}
|
|
24063
24076
|
previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
24064
24077
|
archive = await downloadSkill(credentials, skill.url);
|
|
24065
24078
|
const sha256 = createHash3("sha256").update(archive).digest("hex");
|
|
@@ -24100,7 +24113,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
24100
24113
|
}
|
|
24101
24114
|
function exactPackFailure(error45) {
|
|
24102
24115
|
if (error45 instanceof WorkPackLocalEditsError) {
|
|
24103
|
-
return { status: "failed", restoration: "exact", code: error45.code };
|
|
24116
|
+
return { status: "failed", restoration: "exact", code: error45.code, message: error45.message };
|
|
24104
24117
|
}
|
|
24105
24118
|
if (error45 instanceof WorkPackProjectionConflictError) {
|
|
24106
24119
|
return {
|
|
@@ -24173,21 +24186,24 @@ var WorkPackLocalEditsError = class extends Error {
|
|
|
24173
24186
|
}
|
|
24174
24187
|
code;
|
|
24175
24188
|
};
|
|
24176
|
-
async function assertWorkPackUnchangedAtBoundary(paths, target) {
|
|
24189
|
+
async function assertWorkPackUnchangedAtBoundary(paths, target, snapshot) {
|
|
24177
24190
|
const ownership = await workPackOwnership(target);
|
|
24178
24191
|
if (ownership === "absent") return;
|
|
24179
24192
|
if (ownership === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
24180
24193
|
const localState = await checkWorkPackInstalledState({
|
|
24181
24194
|
packDir: target,
|
|
24182
24195
|
agentsDir: paths.agentsDir,
|
|
24183
|
-
commandsDir: paths.commandsDir
|
|
24196
|
+
commandsDir: paths.commandsDir,
|
|
24197
|
+
allowAdditional: snapshot !== void 0
|
|
24184
24198
|
});
|
|
24185
24199
|
if (localState !== "match") {
|
|
24186
24200
|
throw new WorkPackLocalEditsError(localState === "missing" ? "local-baseline-missing" : "local-edits-preserved");
|
|
24187
24201
|
}
|
|
24202
|
+
if (snapshot) await assertWorkPackTreeUnchangedAtBoundary(target, snapshot);
|
|
24188
24203
|
}
|
|
24189
|
-
async function assertWorkPackTreeUnchangedAtBoundary(target) {
|
|
24190
|
-
const
|
|
24204
|
+
async function assertWorkPackTreeUnchangedAtBoundary(target, snapshot) {
|
|
24205
|
+
const actual = snapshot ? await digestPackTree(target) : void 0;
|
|
24206
|
+
const localState = snapshot ? actual && sameTree(actual, snapshot) ? "match" : "changed" : await checkWorkPackTreeState(target);
|
|
24191
24207
|
if (localState !== "match") {
|
|
24192
24208
|
throw new WorkPackLocalEditsError(localState === "missing" ? "local-baseline-missing" : "local-edits-preserved");
|
|
24193
24209
|
}
|
|
@@ -24199,6 +24215,31 @@ function skillSlugFromUrl(value) {
|
|
|
24199
24215
|
return value;
|
|
24200
24216
|
}
|
|
24201
24217
|
}
|
|
24218
|
+
async function preserveWorkPackExtras(target, nextPath, actual) {
|
|
24219
|
+
const expected = await readInstalledState(target);
|
|
24220
|
+
if (!expected) throw new WorkPackLocalEditsError("local-baseline-missing");
|
|
24221
|
+
const ownedFiles = new Set(expected.files.map((file2) => file2.path));
|
|
24222
|
+
const ownedDirectories = new Set(expected.directories);
|
|
24223
|
+
const next = await digestPackTree(nextPath);
|
|
24224
|
+
if (!next) throw new WorkPackLocalEditsError("local-edits-preserved");
|
|
24225
|
+
const newPaths = /* @__PURE__ */ new Set([...next.files.map((file2) => file2.path), ...next.directories]);
|
|
24226
|
+
const extras = actual.files.filter((file2) => !ownedFiles.has(file2.path));
|
|
24227
|
+
const directories = actual.directories.filter((directory) => !ownedDirectories.has(directory));
|
|
24228
|
+
for (const name of [...extras.map((file2) => file2.path), ...directories]) {
|
|
24229
|
+
if (newPaths.has(name)) throw new WorkPackLocalEditsError(
|
|
24230
|
+
"local-addition-collision",
|
|
24231
|
+
`A nova vers\xE3o usa o caminho adicional "${name}". O pacote anterior e os ficheiros locais foram preservados.`
|
|
24232
|
+
);
|
|
24233
|
+
}
|
|
24234
|
+
for (const directory of directories) await mkdir2(path5.join(nextPath, directory), { recursive: true });
|
|
24235
|
+
for (const file2 of extras) {
|
|
24236
|
+
const destination = path5.join(nextPath, file2.path);
|
|
24237
|
+
await mkdir2(path5.dirname(destination), { recursive: true });
|
|
24238
|
+
await cp(path5.join(target, file2.path), destination, { errorOnExist: true, force: false });
|
|
24239
|
+
if (createHash3("sha256").update(await readFile3(destination)).digest("hex") !== file2.sha256)
|
|
24240
|
+
throw new WorkPackLocalEditsError("local-edits-preserved");
|
|
24241
|
+
}
|
|
24242
|
+
}
|
|
24202
24243
|
async function installSkillArchive(paths, slug, version2, archive, options = {}) {
|
|
24203
24244
|
const tempRoot = await mkdtemp(path5.join(os4.tmpdir(), `forge-${slug}-`));
|
|
24204
24245
|
const archivePath = path5.join(tempRoot, `${slug}.tar`);
|
|
@@ -24270,9 +24311,18 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24270
24311
|
])
|
|
24271
24312
|
);
|
|
24272
24313
|
const previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
24314
|
+
let originalTree;
|
|
24315
|
+
let installedTree;
|
|
24273
24316
|
try {
|
|
24317
|
+
if (await workPackOwnership(target) === "managed") {
|
|
24318
|
+
originalTree = await digestPackTree(target);
|
|
24319
|
+
if (!originalTree) throw new WorkPackLocalEditsError("local-edits-preserved");
|
|
24320
|
+
await preserveWorkPackExtras(target, nextPath, originalTree);
|
|
24321
|
+
}
|
|
24322
|
+
installedTree = await digestPackTree(nextPath);
|
|
24323
|
+
if (!installedTree) throw new WorkPackLocalEditsError("local-edits-preserved");
|
|
24274
24324
|
if (previousManagedPaths.length > 0) await options.beforeManagedPathsRemoved?.(previousManagedPaths);
|
|
24275
|
-
await assertWorkPackUnchangedAtBoundary(paths, target);
|
|
24325
|
+
await assertWorkPackUnchangedAtBoundary(paths, target, originalTree);
|
|
24276
24326
|
} catch (error45) {
|
|
24277
24327
|
await rm(tempRoot, { recursive: true, force: true });
|
|
24278
24328
|
throw error45;
|
|
@@ -24296,7 +24346,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24296
24346
|
}
|
|
24297
24347
|
if (targetBackedUp) {
|
|
24298
24348
|
await options.installWorkPackBoundary?.("after-backup");
|
|
24299
|
-
await assertWorkPackUnchangedAtBoundary(paths, backup);
|
|
24349
|
+
await assertWorkPackUnchangedAtBoundary(paths, backup, originalTree);
|
|
24300
24350
|
}
|
|
24301
24351
|
await rename3(nextPath, target);
|
|
24302
24352
|
targetInstalled = true;
|
|
@@ -24330,12 +24380,13 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24330
24380
|
await writeProjection(filePath, command.content);
|
|
24331
24381
|
}
|
|
24332
24382
|
}
|
|
24333
|
-
if (targetBackedUp) await assertWorkPackTreeUnchangedAtBoundary(backup);
|
|
24383
|
+
if (targetBackedUp) await assertWorkPackTreeUnchangedAtBoundary(backup, originalTree);
|
|
24334
24384
|
if (targetBackedUp) await options.installWorkPackBoundary?.("before-commit");
|
|
24385
|
+
await assertWorkPackTreeUnchangedAtBoundary(target, installedTree);
|
|
24335
24386
|
if (targetBackedUp) {
|
|
24336
24387
|
await rename3(backup, claimedBackup);
|
|
24337
24388
|
backupClaimed = true;
|
|
24338
|
-
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
|
|
24389
|
+
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup, originalTree);
|
|
24339
24390
|
await writeFile3(path5.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
|
|
24340
24391
|
`);
|
|
24341
24392
|
await writeTextAtomic(transactionPath, "committed\n");
|
|
@@ -24343,6 +24394,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24343
24394
|
} catch (error45) {
|
|
24344
24395
|
try {
|
|
24345
24396
|
if (targetInstalled) {
|
|
24397
|
+
await assertWorkPackTreeUnchangedAtBoundary(target, installedTree);
|
|
24346
24398
|
await restoreProjectionState(agentSnapshot, agentTransactionState);
|
|
24347
24399
|
await restoreProjectionState(commandSnapshot, commandTransactionState);
|
|
24348
24400
|
}
|
|
@@ -24398,7 +24450,8 @@ async function adoptLegacyWorkPackState(paths, slug, version2, archive, approved
|
|
|
24398
24450
|
expectedPackDir: path5.join(comparisonPaths.skillsDir, slug),
|
|
24399
24451
|
packDir: path5.join(paths.skillsDir, slug),
|
|
24400
24452
|
agentsDir: paths.agentsDir,
|
|
24401
|
-
commandsDir: paths.commandsDir
|
|
24453
|
+
commandsDir: paths.commandsDir,
|
|
24454
|
+
allowAdditional: true
|
|
24402
24455
|
});
|
|
24403
24456
|
} finally {
|
|
24404
24457
|
await rm(comparisonRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
@@ -24464,17 +24517,23 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
24464
24517
|
}
|
|
24465
24518
|
const targetOwnership = await workPackOwnership(target);
|
|
24466
24519
|
if (targetOwnership === "managed") {
|
|
24467
|
-
const localState = await checkWorkPackTreeState(target);
|
|
24520
|
+
const localState = await checkWorkPackTreeState(target, true);
|
|
24468
24521
|
if (localState !== "match") {
|
|
24469
24522
|
return localState === "missing" ? "local-baseline-missing" : "local-edits-preserved";
|
|
24470
24523
|
}
|
|
24524
|
+
const currentExtras = await workPackExtrasTree(target);
|
|
24525
|
+
if (!currentExtras) return "local-edits-preserved";
|
|
24526
|
+
if (currentExtras.files.length || currentExtras.directories.length) {
|
|
24527
|
+
const backupExtras = await workPackExtrasTree(backup);
|
|
24528
|
+
if (!backupExtras || !sameTree(currentExtras, backupExtras)) return "local-edits-preserved";
|
|
24529
|
+
}
|
|
24471
24530
|
}
|
|
24472
24531
|
const currentAgents = await readAgentRecord(target);
|
|
24473
24532
|
const currentCommands = await readCommandRecord(target);
|
|
24474
|
-
const currentAgentFiles = await readPackAgentFiles(target);
|
|
24475
|
-
const currentCommandFiles = await readPackCommandFiles(target);
|
|
24476
|
-
const previousAgents = await readPackAgentFiles(backup);
|
|
24477
|
-
const previousCommands = await readPackCommandFiles(backup);
|
|
24533
|
+
const currentAgentFiles = await readPackAgentFiles(target, new Set(currentAgents));
|
|
24534
|
+
const currentCommandFiles = await readPackCommandFiles(target, new Set(currentCommands));
|
|
24535
|
+
const previousAgents = await readPackAgentFiles(backup, new Set(await readAgentRecord(backup)));
|
|
24536
|
+
const previousCommands = await readPackCommandFiles(backup, new Set(await readCommandRecord(backup)));
|
|
24478
24537
|
const removedProjections = transactionState === "remove" ? await readWorkPackRemovedProjections(backup) : { agents: /* @__PURE__ */ new Set(), commands: /* @__PURE__ */ new Set() };
|
|
24479
24538
|
const missingPreviousAgentPolicy = targetOwnership === "absent" ? transactionState === "remove" ? removedProjections.agents : true : false;
|
|
24480
24539
|
const missingPreviousCommandPolicy = targetOwnership === "absent" ? transactionState === "remove" ? removedProjections.commands : true : false;
|
|
@@ -24667,7 +24726,7 @@ async function restoreProjectionState(snapshot, transactionState) {
|
|
|
24667
24726
|
else await writeTextAtomic(filePath, content);
|
|
24668
24727
|
}
|
|
24669
24728
|
}
|
|
24670
|
-
async function readPackAgentFiles(skillFolder) {
|
|
24729
|
+
async function readPackAgentFiles(skillFolder, managedNames) {
|
|
24671
24730
|
const agentsFolder = path5.join(skillFolder, "agents");
|
|
24672
24731
|
const entries = await readdir3(agentsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24673
24732
|
if (error45.code === "ENOENT") return [];
|
|
@@ -24675,7 +24734,7 @@ async function readPackAgentFiles(skillFolder) {
|
|
|
24675
24734
|
});
|
|
24676
24735
|
const files = [];
|
|
24677
24736
|
for (const entry of entries) {
|
|
24678
|
-
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24737
|
+
if (!entry.isFile() || !entry.name.endsWith(".md") || managedNames && !managedNames.has(entry.name)) continue;
|
|
24679
24738
|
if (entry.name.startsWith("._")) continue;
|
|
24680
24739
|
const content = await readFile3(path5.join(agentsFolder, entry.name), "utf8");
|
|
24681
24740
|
validateAgentFile(entry.name, content);
|
|
@@ -24696,18 +24755,18 @@ async function normalizePackAgentModels(skillFolder, agentFiles, approvedModelId
|
|
|
24696
24755
|
}
|
|
24697
24756
|
async function workPackNeedsModelNormalization(target, approvedModelIds, slug) {
|
|
24698
24757
|
const approved = new Set(approvedModelIds);
|
|
24699
|
-
const agentsNeedNormalization = (await readPackAgentFiles(target)).some(
|
|
24758
|
+
const agentsNeedNormalization = (await readPackAgentFiles(target, new Set(await readAgentRecord(target)))).some(
|
|
24700
24759
|
(agent) => normalizePackExtensionModel(`agents/${agent.filename}`, agent.content, approved, slug) !== agent.content
|
|
24701
24760
|
);
|
|
24702
24761
|
if (agentsNeedNormalization) return true;
|
|
24703
|
-
return (await readPackCommandFiles(target)).some(
|
|
24762
|
+
return (await readPackCommandFiles(target, new Set(await readCommandRecord(target)))).some(
|
|
24704
24763
|
(command) => normalizePackExtensionModel(`commands/${command.filename}`, command.content, approved, slug) !== command.content
|
|
24705
24764
|
);
|
|
24706
24765
|
}
|
|
24707
24766
|
function normalizePackAgentModel(filename, content, approvedModelIds, slug) {
|
|
24708
24767
|
return normalizePackExtensionModel(`agents/${filename}`, content, approvedModelIds, slug);
|
|
24709
24768
|
}
|
|
24710
|
-
async function readPackCommandFiles(skillFolder) {
|
|
24769
|
+
async function readPackCommandFiles(skillFolder, managedNames) {
|
|
24711
24770
|
const commandsFolder = path5.join(skillFolder, "commands");
|
|
24712
24771
|
const entries = await readdir3(commandsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24713
24772
|
if (error45.code === "ENOENT") return [];
|
|
@@ -24715,7 +24774,7 @@ async function readPackCommandFiles(skillFolder) {
|
|
|
24715
24774
|
});
|
|
24716
24775
|
const files = [];
|
|
24717
24776
|
for (const entry of entries) {
|
|
24718
|
-
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24777
|
+
if (!entry.isFile() || !entry.name.endsWith(".md") || managedNames && !managedNames.has(entry.name)) continue;
|
|
24719
24778
|
if (entry.name.startsWith("._")) continue;
|
|
24720
24779
|
const content = await readFile3(path5.join(commandsFolder, entry.name), "utf8");
|
|
24721
24780
|
validateCommandFile(entry.name, content);
|
|
@@ -25040,7 +25099,7 @@ function isRecord(value) {
|
|
|
25040
25099
|
}
|
|
25041
25100
|
|
|
25042
25101
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
25043
|
-
var PLUGIN_VERSION = "0.1.
|
|
25102
|
+
var PLUGIN_VERSION = "0.1.19";
|
|
25044
25103
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
25045
25104
|
var activeSync = /* @__PURE__ */ new Map();
|
|
25046
25105
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|