minimal-forge-work-pack-sync 0.1.18 → 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 +157 -99
- 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";
|
|
@@ -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;
|
|
@@ -20683,6 +20675,41 @@ async function regularFileDigest(filePath, budget) {
|
|
|
20683
20675
|
return void 0;
|
|
20684
20676
|
}
|
|
20685
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
|
+
}
|
|
20686
20713
|
function assertSlug(slug) {
|
|
20687
20714
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || slug.length > 64) throw new Error("Identificador de skill inv\xE1lido");
|
|
20688
20715
|
}
|
|
@@ -23807,7 +23834,7 @@ async function runOperation(operation, operate) {
|
|
|
23807
23834
|
code: stableCode(result.code),
|
|
23808
23835
|
...result.integrity ? { integrity: result.integrity } : {},
|
|
23809
23836
|
...result.projectionConflict ? { projectionConflict: result.projectionConflict } : {},
|
|
23810
|
-
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.`
|
|
23811
23838
|
};
|
|
23812
23839
|
}
|
|
23813
23840
|
if (!validSuccessFor(operation.action, result.status)) return uncertainOutcome(operation, "invalid-callback-result");
|
|
@@ -23954,7 +23981,7 @@ async function collectWorkPackObservations(paths, reconciliation) {
|
|
|
23954
23981
|
return [...observations.values()].sort((a, b2) => a.slug.localeCompare(b2.slug));
|
|
23955
23982
|
}
|
|
23956
23983
|
async function enrichIntegrityFailure(paths, operation, result) {
|
|
23957
|
-
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;
|
|
23958
23985
|
try {
|
|
23959
23986
|
const { summary } = await inspectWorkPackIntegrity({ paths, slug: operation.pack.slug });
|
|
23960
23987
|
if (summary.kind === "match") return result;
|
|
@@ -24006,24 +24033,39 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
24006
24033
|
try {
|
|
24007
24034
|
const currentVersion = await readFile3(path5.join(target, ".forge-version"), "utf8").catch(() => "");
|
|
24008
24035
|
const sameVersion = currentVersion.trim() === skill.version;
|
|
24009
|
-
if (
|
|
24036
|
+
if (ownership === "managed") {
|
|
24010
24037
|
let localState = await checkWorkPackInstalledState({
|
|
24011
24038
|
packDir: target,
|
|
24012
24039
|
agentsDir: paths.agentsDir,
|
|
24013
|
-
commandsDir: paths.commandsDir
|
|
24040
|
+
commandsDir: paths.commandsDir,
|
|
24041
|
+
allowAdditional: true
|
|
24014
24042
|
});
|
|
24015
24043
|
if (localState === "missing") {
|
|
24016
|
-
const
|
|
24017
|
-
|
|
24018
|
-
|
|
24019
|
-
|
|
24020
|
-
|
|
24021
|
-
|
|
24022
|
-
|
|
24023
|
-
|
|
24024
|
-
|
|
24025
|
-
|
|
24026
|
-
|
|
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)) {
|
|
24027
24069
|
return cleanupPendingSlugs.has(skill.slug) ? {
|
|
24028
24070
|
status: "unchanged",
|
|
24029
24071
|
warningCode: "cleanup-pending",
|
|
@@ -24031,36 +24073,6 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
24031
24073
|
} : { status: "unchanged" };
|
|
24032
24074
|
}
|
|
24033
24075
|
}
|
|
24034
|
-
if (ownership === "managed" && !sameVersion) {
|
|
24035
|
-
let localState = await checkWorkPackInstalledState({
|
|
24036
|
-
packDir: target,
|
|
24037
|
-
agentsDir: paths.agentsDir,
|
|
24038
|
-
commandsDir: paths.commandsDir
|
|
24039
|
-
});
|
|
24040
|
-
if (localState === "missing") {
|
|
24041
|
-
try {
|
|
24042
|
-
const baselineUrl = `/sync/skills/${encodeURIComponent(skill.slug)}/baseline/${encodeURIComponent(currentVersion.trim())}`;
|
|
24043
|
-
const baseline = JSON.parse(new TextDecoder().decode(await downloadSkill(credentials, baselineUrl)));
|
|
24044
|
-
if (typeof baseline.fingerprint === "string" && /^[a-f0-9]{64}$/.test(baseline.fingerprint)) {
|
|
24045
|
-
localState = await adoptVerifiedWorkPackState({
|
|
24046
|
-
packDir: target,
|
|
24047
|
-
agentsDir: paths.agentsDir,
|
|
24048
|
-
commandsDir: paths.commandsDir,
|
|
24049
|
-
version: currentVersion.trim(),
|
|
24050
|
-
fingerprint: baseline.fingerprint
|
|
24051
|
-
}) ? "match" : "missing";
|
|
24052
|
-
}
|
|
24053
|
-
} catch {
|
|
24054
|
-
}
|
|
24055
|
-
}
|
|
24056
|
-
if (localState !== "match") {
|
|
24057
|
-
return {
|
|
24058
|
-
status: "failed",
|
|
24059
|
-
restoration: "exact",
|
|
24060
|
-
code: localState === "missing" ? "local-baseline-missing" : "local-edits-preserved"
|
|
24061
|
-
};
|
|
24062
|
-
}
|
|
24063
|
-
}
|
|
24064
24076
|
previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
24065
24077
|
archive = await downloadSkill(credentials, skill.url);
|
|
24066
24078
|
const sha256 = createHash3("sha256").update(archive).digest("hex");
|
|
@@ -24101,7 +24113,7 @@ async function operateWorkPack(paths, credentials, skillBySlug, approvedModelIds
|
|
|
24101
24113
|
}
|
|
24102
24114
|
function exactPackFailure(error45) {
|
|
24103
24115
|
if (error45 instanceof WorkPackLocalEditsError) {
|
|
24104
|
-
return { status: "failed", restoration: "exact", code: error45.code };
|
|
24116
|
+
return { status: "failed", restoration: "exact", code: error45.code, message: error45.message };
|
|
24105
24117
|
}
|
|
24106
24118
|
if (error45 instanceof WorkPackProjectionConflictError) {
|
|
24107
24119
|
return {
|
|
@@ -24174,21 +24186,24 @@ var WorkPackLocalEditsError = class extends Error {
|
|
|
24174
24186
|
}
|
|
24175
24187
|
code;
|
|
24176
24188
|
};
|
|
24177
|
-
async function assertWorkPackUnchangedAtBoundary(paths, target) {
|
|
24189
|
+
async function assertWorkPackUnchangedAtBoundary(paths, target, snapshot) {
|
|
24178
24190
|
const ownership = await workPackOwnership(target);
|
|
24179
24191
|
if (ownership === "absent") return;
|
|
24180
24192
|
if (ownership === "foreign") throw foreignWorkPackError(path5.basename(target));
|
|
24181
24193
|
const localState = await checkWorkPackInstalledState({
|
|
24182
24194
|
packDir: target,
|
|
24183
24195
|
agentsDir: paths.agentsDir,
|
|
24184
|
-
commandsDir: paths.commandsDir
|
|
24196
|
+
commandsDir: paths.commandsDir,
|
|
24197
|
+
allowAdditional: snapshot !== void 0
|
|
24185
24198
|
});
|
|
24186
24199
|
if (localState !== "match") {
|
|
24187
24200
|
throw new WorkPackLocalEditsError(localState === "missing" ? "local-baseline-missing" : "local-edits-preserved");
|
|
24188
24201
|
}
|
|
24202
|
+
if (snapshot) await assertWorkPackTreeUnchangedAtBoundary(target, snapshot);
|
|
24189
24203
|
}
|
|
24190
|
-
async function assertWorkPackTreeUnchangedAtBoundary(target) {
|
|
24191
|
-
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);
|
|
24192
24207
|
if (localState !== "match") {
|
|
24193
24208
|
throw new WorkPackLocalEditsError(localState === "missing" ? "local-baseline-missing" : "local-edits-preserved");
|
|
24194
24209
|
}
|
|
@@ -24200,6 +24215,31 @@ function skillSlugFromUrl(value) {
|
|
|
24200
24215
|
return value;
|
|
24201
24216
|
}
|
|
24202
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
|
+
}
|
|
24203
24243
|
async function installSkillArchive(paths, slug, version2, archive, options = {}) {
|
|
24204
24244
|
const tempRoot = await mkdtemp(path5.join(os4.tmpdir(), `forge-${slug}-`));
|
|
24205
24245
|
const archivePath = path5.join(tempRoot, `${slug}.tar`);
|
|
@@ -24271,9 +24311,18 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24271
24311
|
])
|
|
24272
24312
|
);
|
|
24273
24313
|
const previousManagedPaths = await managedWorkPackPaths(paths, target);
|
|
24314
|
+
let originalTree;
|
|
24315
|
+
let installedTree;
|
|
24274
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");
|
|
24275
24324
|
if (previousManagedPaths.length > 0) await options.beforeManagedPathsRemoved?.(previousManagedPaths);
|
|
24276
|
-
await assertWorkPackUnchangedAtBoundary(paths, target);
|
|
24325
|
+
await assertWorkPackUnchangedAtBoundary(paths, target, originalTree);
|
|
24277
24326
|
} catch (error45) {
|
|
24278
24327
|
await rm(tempRoot, { recursive: true, force: true });
|
|
24279
24328
|
throw error45;
|
|
@@ -24297,7 +24346,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24297
24346
|
}
|
|
24298
24347
|
if (targetBackedUp) {
|
|
24299
24348
|
await options.installWorkPackBoundary?.("after-backup");
|
|
24300
|
-
await assertWorkPackUnchangedAtBoundary(paths, backup);
|
|
24349
|
+
await assertWorkPackUnchangedAtBoundary(paths, backup, originalTree);
|
|
24301
24350
|
}
|
|
24302
24351
|
await rename3(nextPath, target);
|
|
24303
24352
|
targetInstalled = true;
|
|
@@ -24331,12 +24380,13 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24331
24380
|
await writeProjection(filePath, command.content);
|
|
24332
24381
|
}
|
|
24333
24382
|
}
|
|
24334
|
-
if (targetBackedUp) await assertWorkPackTreeUnchangedAtBoundary(backup);
|
|
24383
|
+
if (targetBackedUp) await assertWorkPackTreeUnchangedAtBoundary(backup, originalTree);
|
|
24335
24384
|
if (targetBackedUp) await options.installWorkPackBoundary?.("before-commit");
|
|
24385
|
+
await assertWorkPackTreeUnchangedAtBoundary(target, installedTree);
|
|
24336
24386
|
if (targetBackedUp) {
|
|
24337
24387
|
await rename3(backup, claimedBackup);
|
|
24338
24388
|
backupClaimed = true;
|
|
24339
|
-
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup);
|
|
24389
|
+
await assertWorkPackTreeUnchangedAtBoundary(claimedBackup, originalTree);
|
|
24340
24390
|
await writeFile3(path5.join(claimedBackup, WORK_PACK_COMMITTED_MARKER), `${version2}
|
|
24341
24391
|
`);
|
|
24342
24392
|
await writeTextAtomic(transactionPath, "committed\n");
|
|
@@ -24344,6 +24394,7 @@ async function installSkillArchive(paths, slug, version2, archive, options = {})
|
|
|
24344
24394
|
} catch (error45) {
|
|
24345
24395
|
try {
|
|
24346
24396
|
if (targetInstalled) {
|
|
24397
|
+
await assertWorkPackTreeUnchangedAtBoundary(target, installedTree);
|
|
24347
24398
|
await restoreProjectionState(agentSnapshot, agentTransactionState);
|
|
24348
24399
|
await restoreProjectionState(commandSnapshot, commandTransactionState);
|
|
24349
24400
|
}
|
|
@@ -24399,7 +24450,8 @@ async function adoptLegacyWorkPackState(paths, slug, version2, archive, approved
|
|
|
24399
24450
|
expectedPackDir: path5.join(comparisonPaths.skillsDir, slug),
|
|
24400
24451
|
packDir: path5.join(paths.skillsDir, slug),
|
|
24401
24452
|
agentsDir: paths.agentsDir,
|
|
24402
|
-
commandsDir: paths.commandsDir
|
|
24453
|
+
commandsDir: paths.commandsDir,
|
|
24454
|
+
allowAdditional: true
|
|
24403
24455
|
});
|
|
24404
24456
|
} finally {
|
|
24405
24457
|
await rm(comparisonRoot, { recursive: true, force: true }).catch(() => void 0);
|
|
@@ -24465,17 +24517,23 @@ async function recoverInterruptedWorkPackInstall(paths, target, cleanupWorkPackB
|
|
|
24465
24517
|
}
|
|
24466
24518
|
const targetOwnership = await workPackOwnership(target);
|
|
24467
24519
|
if (targetOwnership === "managed") {
|
|
24468
|
-
const localState = await checkWorkPackTreeState(target);
|
|
24520
|
+
const localState = await checkWorkPackTreeState(target, true);
|
|
24469
24521
|
if (localState !== "match") {
|
|
24470
24522
|
return localState === "missing" ? "local-baseline-missing" : "local-edits-preserved";
|
|
24471
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
|
+
}
|
|
24472
24530
|
}
|
|
24473
24531
|
const currentAgents = await readAgentRecord(target);
|
|
24474
24532
|
const currentCommands = await readCommandRecord(target);
|
|
24475
|
-
const currentAgentFiles = await readPackAgentFiles(target);
|
|
24476
|
-
const currentCommandFiles = await readPackCommandFiles(target);
|
|
24477
|
-
const previousAgents = await readPackAgentFiles(backup);
|
|
24478
|
-
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)));
|
|
24479
24537
|
const removedProjections = transactionState === "remove" ? await readWorkPackRemovedProjections(backup) : { agents: /* @__PURE__ */ new Set(), commands: /* @__PURE__ */ new Set() };
|
|
24480
24538
|
const missingPreviousAgentPolicy = targetOwnership === "absent" ? transactionState === "remove" ? removedProjections.agents : true : false;
|
|
24481
24539
|
const missingPreviousCommandPolicy = targetOwnership === "absent" ? transactionState === "remove" ? removedProjections.commands : true : false;
|
|
@@ -24668,7 +24726,7 @@ async function restoreProjectionState(snapshot, transactionState) {
|
|
|
24668
24726
|
else await writeTextAtomic(filePath, content);
|
|
24669
24727
|
}
|
|
24670
24728
|
}
|
|
24671
|
-
async function readPackAgentFiles(skillFolder) {
|
|
24729
|
+
async function readPackAgentFiles(skillFolder, managedNames) {
|
|
24672
24730
|
const agentsFolder = path5.join(skillFolder, "agents");
|
|
24673
24731
|
const entries = await readdir3(agentsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24674
24732
|
if (error45.code === "ENOENT") return [];
|
|
@@ -24676,7 +24734,7 @@ async function readPackAgentFiles(skillFolder) {
|
|
|
24676
24734
|
});
|
|
24677
24735
|
const files = [];
|
|
24678
24736
|
for (const entry of entries) {
|
|
24679
|
-
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24737
|
+
if (!entry.isFile() || !entry.name.endsWith(".md") || managedNames && !managedNames.has(entry.name)) continue;
|
|
24680
24738
|
if (entry.name.startsWith("._")) continue;
|
|
24681
24739
|
const content = await readFile3(path5.join(agentsFolder, entry.name), "utf8");
|
|
24682
24740
|
validateAgentFile(entry.name, content);
|
|
@@ -24697,18 +24755,18 @@ async function normalizePackAgentModels(skillFolder, agentFiles, approvedModelId
|
|
|
24697
24755
|
}
|
|
24698
24756
|
async function workPackNeedsModelNormalization(target, approvedModelIds, slug) {
|
|
24699
24757
|
const approved = new Set(approvedModelIds);
|
|
24700
|
-
const agentsNeedNormalization = (await readPackAgentFiles(target)).some(
|
|
24758
|
+
const agentsNeedNormalization = (await readPackAgentFiles(target, new Set(await readAgentRecord(target)))).some(
|
|
24701
24759
|
(agent) => normalizePackExtensionModel(`agents/${agent.filename}`, agent.content, approved, slug) !== agent.content
|
|
24702
24760
|
);
|
|
24703
24761
|
if (agentsNeedNormalization) return true;
|
|
24704
|
-
return (await readPackCommandFiles(target)).some(
|
|
24762
|
+
return (await readPackCommandFiles(target, new Set(await readCommandRecord(target)))).some(
|
|
24705
24763
|
(command) => normalizePackExtensionModel(`commands/${command.filename}`, command.content, approved, slug) !== command.content
|
|
24706
24764
|
);
|
|
24707
24765
|
}
|
|
24708
24766
|
function normalizePackAgentModel(filename, content, approvedModelIds, slug) {
|
|
24709
24767
|
return normalizePackExtensionModel(`agents/${filename}`, content, approvedModelIds, slug);
|
|
24710
24768
|
}
|
|
24711
|
-
async function readPackCommandFiles(skillFolder) {
|
|
24769
|
+
async function readPackCommandFiles(skillFolder, managedNames) {
|
|
24712
24770
|
const commandsFolder = path5.join(skillFolder, "commands");
|
|
24713
24771
|
const entries = await readdir3(commandsFolder, { withFileTypes: true }).catch((error45) => {
|
|
24714
24772
|
if (error45.code === "ENOENT") return [];
|
|
@@ -24716,7 +24774,7 @@ async function readPackCommandFiles(skillFolder) {
|
|
|
24716
24774
|
});
|
|
24717
24775
|
const files = [];
|
|
24718
24776
|
for (const entry of entries) {
|
|
24719
|
-
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
24777
|
+
if (!entry.isFile() || !entry.name.endsWith(".md") || managedNames && !managedNames.has(entry.name)) continue;
|
|
24720
24778
|
if (entry.name.startsWith("._")) continue;
|
|
24721
24779
|
const content = await readFile3(path5.join(commandsFolder, entry.name), "utf8");
|
|
24722
24780
|
validateCommandFile(entry.name, content);
|
|
@@ -25041,7 +25099,7 @@ function isRecord(value) {
|
|
|
25041
25099
|
}
|
|
25042
25100
|
|
|
25043
25101
|
// packages/cli/src/workPackSyncPlugin.ts
|
|
25044
|
-
var PLUGIN_VERSION = "0.1.
|
|
25102
|
+
var PLUGIN_VERSION = "0.1.19";
|
|
25045
25103
|
var STATUS_FILENAME = "work-pack-startup-status.json";
|
|
25046
25104
|
var activeSync = /* @__PURE__ */ new Map();
|
|
25047
25105
|
var ForgeWorkPackSyncServer = async (_input, options) => {
|