@primitive.ai/prim 0.1.0-alpha.102 → 0.1.0-alpha.103
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/README.md +16 -0
- package/SKILL.md +49 -0
- package/dist/chunk-6WCBVSND.js +107 -0
- package/dist/{chunk-MXVCP33E.js → chunk-LNFWFYSN.js} +60 -0
- package/dist/{chunk-QIHXTYRD.js → chunk-RCFDZ4DY.js} +1 -1
- package/dist/hook-runtime/hooks/post-tool-use.js +497 -358
- package/dist/hook-runtime/hooks/pre-tool-use.js +214 -74
- package/dist/hook-runtime/hooks/prim-hook.js +260 -123
- package/dist/hook-runtime/index.js +2000 -1412
- package/dist/hooks/post-tool-use.js +9 -2
- package/dist/hooks/pre-tool-use.js +10 -1
- package/dist/hooks/prim-hook.js +9 -2
- package/dist/index.js +611 -80
- package/package.json +1 -1
|
@@ -4963,7 +4963,7 @@ var require_rc = __commonJS({
|
|
|
4963
4963
|
"node_modules/.pnpm/rc@1.2.8/node_modules/rc/index.js"(exports, module) {
|
|
4964
4964
|
"use strict";
|
|
4965
4965
|
var cc = require_utils();
|
|
4966
|
-
var
|
|
4966
|
+
var join35 = __require("path").join;
|
|
4967
4967
|
var deepExtend = require_deep_extend();
|
|
4968
4968
|
var etc = "/etc";
|
|
4969
4969
|
var win = process.platform === "win32";
|
|
@@ -4988,15 +4988,15 @@ var require_rc = __commonJS({
|
|
|
4988
4988
|
}
|
|
4989
4989
|
if (!win)
|
|
4990
4990
|
[
|
|
4991
|
-
|
|
4992
|
-
|
|
4991
|
+
join35(etc, name, "config"),
|
|
4992
|
+
join35(etc, name + "rc")
|
|
4993
4993
|
].forEach(addConfigFile);
|
|
4994
4994
|
if (home)
|
|
4995
4995
|
[
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
4996
|
+
join35(home, ".config", name, "config"),
|
|
4997
|
+
join35(home, ".config", name),
|
|
4998
|
+
join35(home, "." + name, "config"),
|
|
4999
|
+
join35(home, "." + name + "rc")
|
|
5000
5000
|
].forEach(addConfigFile);
|
|
5001
5001
|
addConfigFile(cc.find("." + name + "rc"));
|
|
5002
5002
|
if (env4.config) addConfigFile(env4.config);
|
|
@@ -6340,11 +6340,11 @@ var require_util = __commonJS({
|
|
|
6340
6340
|
if (files.includes("node_modules") || files.includes("package.json") || files.includes("package.json5") || files.includes("package.yaml") || files.includes("pnpm-workspace.yaml")) {
|
|
6341
6341
|
return name2;
|
|
6342
6342
|
}
|
|
6343
|
-
const
|
|
6344
|
-
if (
|
|
6343
|
+
const dirname22 = path9.dirname(name2);
|
|
6344
|
+
if (dirname22 === name2) {
|
|
6345
6345
|
return original;
|
|
6346
6346
|
}
|
|
6347
|
-
return find(
|
|
6347
|
+
return find(dirname22, original);
|
|
6348
6348
|
} catch (error) {
|
|
6349
6349
|
if (name2 === original) {
|
|
6350
6350
|
if (error.code === "ENOENT") {
|
|
@@ -8896,8 +8896,8 @@ var require_ucs2length = __commonJS({
|
|
|
8896
8896
|
});
|
|
8897
8897
|
|
|
8898
8898
|
// src/index.ts
|
|
8899
|
-
import { readFileSync as
|
|
8900
|
-
import { dirname as
|
|
8899
|
+
import { readFileSync as readFileSync28 } from "fs";
|
|
8900
|
+
import { dirname as dirname21, resolve as resolve12 } from "path";
|
|
8901
8901
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
8902
8902
|
|
|
8903
8903
|
// node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
|
|
@@ -8998,7 +8998,7 @@ var retryifyAsync = (fn, options) => {
|
|
|
8998
8998
|
throw error;
|
|
8999
8999
|
const delay2 = Math.round(interval * Math.random());
|
|
9000
9000
|
if (delay2 > 0) {
|
|
9001
|
-
const delayPromise = new Promise((
|
|
9001
|
+
const delayPromise = new Promise((resolve13) => setTimeout(resolve13, delay2));
|
|
9002
9002
|
return delayPromise.then(() => attempt.apply(void 0, args));
|
|
9003
9003
|
} else {
|
|
9004
9004
|
return attempt.apply(void 0, args);
|
|
@@ -9257,14 +9257,14 @@ var Temp = {
|
|
|
9257
9257
|
}
|
|
9258
9258
|
},
|
|
9259
9259
|
truncate: (filePath) => {
|
|
9260
|
-
const
|
|
9261
|
-
if (
|
|
9260
|
+
const basename6 = path2.basename(filePath);
|
|
9261
|
+
if (basename6.length <= LIMIT_BASENAME_LENGTH)
|
|
9262
9262
|
return filePath;
|
|
9263
|
-
const truncable = /^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(
|
|
9263
|
+
const truncable = /^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(basename6);
|
|
9264
9264
|
if (!truncable)
|
|
9265
9265
|
return filePath;
|
|
9266
|
-
const truncationLength =
|
|
9267
|
-
return `${filePath.slice(0, -
|
|
9266
|
+
const truncationLength = basename6.length - LIMIT_BASENAME_LENGTH;
|
|
9267
|
+
return `${filePath.slice(0, -basename6.length)}${truncable[1]}${truncable[2].slice(0, -truncationLength)}${truncable[3]}`;
|
|
9268
9268
|
}
|
|
9269
9269
|
};
|
|
9270
9270
|
node_default(Temp.purgeSyncAll);
|
|
@@ -10564,14 +10564,14 @@ var TimeoutError = class extends Error {
|
|
|
10564
10564
|
|
|
10565
10565
|
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/timeout.js
|
|
10566
10566
|
async function timeout(request2, init, abortController, options) {
|
|
10567
|
-
return new Promise((
|
|
10567
|
+
return new Promise((resolve13, reject) => {
|
|
10568
10568
|
const timeoutId = setTimeout(() => {
|
|
10569
10569
|
if (abortController) {
|
|
10570
10570
|
abortController.abort();
|
|
10571
10571
|
}
|
|
10572
10572
|
reject(new TimeoutError(request2));
|
|
10573
10573
|
}, options.timeout);
|
|
10574
|
-
void options.fetch(request2, init).then(
|
|
10574
|
+
void options.fetch(request2, init).then(resolve13).catch(reject).then(() => {
|
|
10575
10575
|
clearTimeout(timeoutId);
|
|
10576
10576
|
});
|
|
10577
10577
|
});
|
|
@@ -10579,7 +10579,7 @@ async function timeout(request2, init, abortController, options) {
|
|
|
10579
10579
|
|
|
10580
10580
|
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/delay.js
|
|
10581
10581
|
async function delay(ms, { signal }) {
|
|
10582
|
-
return new Promise((
|
|
10582
|
+
return new Promise((resolve13, reject) => {
|
|
10583
10583
|
if (signal) {
|
|
10584
10584
|
signal.throwIfAborted();
|
|
10585
10585
|
signal.addEventListener("abort", abortHandler, { once: true });
|
|
@@ -10590,7 +10590,7 @@ async function delay(ms, { signal }) {
|
|
|
10590
10590
|
}
|
|
10591
10591
|
const timeoutId = setTimeout(() => {
|
|
10592
10592
|
signal?.removeEventListener("abort", abortHandler);
|
|
10593
|
-
|
|
10593
|
+
resolve13();
|
|
10594
10594
|
}, ms);
|
|
10595
10595
|
});
|
|
10596
10596
|
}
|
|
@@ -12564,7 +12564,7 @@ function providerError(value) {
|
|
|
12564
12564
|
return exactString(error, "error", MAX_USER_CODE_LENGTH);
|
|
12565
12565
|
}
|
|
12566
12566
|
async function defaultSleep(milliseconds, signal) {
|
|
12567
|
-
await new Promise((
|
|
12567
|
+
await new Promise((resolve13, reject) => {
|
|
12568
12568
|
if (signal.aborted) {
|
|
12569
12569
|
reject(signal.reason);
|
|
12570
12570
|
return;
|
|
@@ -12575,7 +12575,7 @@ async function defaultSleep(milliseconds, signal) {
|
|
|
12575
12575
|
};
|
|
12576
12576
|
const timer = setTimeout(() => {
|
|
12577
12577
|
signal.removeEventListener("abort", abort);
|
|
12578
|
-
|
|
12578
|
+
resolve13();
|
|
12579
12579
|
}, milliseconds);
|
|
12580
12580
|
signal.addEventListener("abort", abort, { once: true });
|
|
12581
12581
|
});
|
|
@@ -12820,7 +12820,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
12820
12820
|
...caller ? { caller } : {}
|
|
12821
12821
|
};
|
|
12822
12822
|
const timeoutMs2 = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
12823
|
-
return new Promise((
|
|
12823
|
+
return new Promise((resolve13) => {
|
|
12824
12824
|
let settled = false;
|
|
12825
12825
|
let socket;
|
|
12826
12826
|
let buffer = Buffer.alloc(0);
|
|
@@ -12835,7 +12835,7 @@ function daemonRequest(method, params = {}, opts = {}) {
|
|
|
12835
12835
|
} catch {
|
|
12836
12836
|
}
|
|
12837
12837
|
}
|
|
12838
|
-
|
|
12838
|
+
resolve13(value);
|
|
12839
12839
|
};
|
|
12840
12840
|
const timer = setTimeout(() => settle(null), timeoutMs2);
|
|
12841
12841
|
timer.unref();
|
|
@@ -13359,14 +13359,14 @@ function throwIfAborted(signal) {
|
|
|
13359
13359
|
}
|
|
13360
13360
|
async function defaultSleep2(ms, signal) {
|
|
13361
13361
|
if (!signal) {
|
|
13362
|
-
await new Promise((
|
|
13362
|
+
await new Promise((resolve13) => setTimeout(resolve13, ms));
|
|
13363
13363
|
return;
|
|
13364
13364
|
}
|
|
13365
13365
|
throwIfAborted(signal);
|
|
13366
|
-
await new Promise((
|
|
13366
|
+
await new Promise((resolve13, reject) => {
|
|
13367
13367
|
const timer = setTimeout(() => {
|
|
13368
13368
|
signal.removeEventListener("abort", onAbort);
|
|
13369
|
-
|
|
13369
|
+
resolve13();
|
|
13370
13370
|
}, ms);
|
|
13371
13371
|
const onAbort = () => {
|
|
13372
13372
|
clearTimeout(timer);
|
|
@@ -33237,7 +33237,7 @@ var OPEN_WORDS = /* @__PURE__ */ new Set(["then", "do", "else", "{", "(", "&&",
|
|
|
33237
33237
|
function canonicalHookBlock(text) {
|
|
33238
33238
|
const tokens = [];
|
|
33239
33239
|
let word = "";
|
|
33240
|
-
let
|
|
33240
|
+
let quote2;
|
|
33241
33241
|
const separate = () => {
|
|
33242
33242
|
const last = tokens.at(-1);
|
|
33243
33243
|
if (last !== void 0 && last !== ";" && !OPEN_WORDS.has(last)) tokens.push(";");
|
|
@@ -33252,13 +33252,13 @@ function canonicalHookBlock(text) {
|
|
|
33252
33252
|
};
|
|
33253
33253
|
for (let index = 0; index < text.length; index += 1) {
|
|
33254
33254
|
const char = text[index];
|
|
33255
|
-
if (
|
|
33255
|
+
if (quote2) {
|
|
33256
33256
|
word += char;
|
|
33257
|
-
if (char ===
|
|
33257
|
+
if (char === quote2) quote2 = void 0;
|
|
33258
33258
|
continue;
|
|
33259
33259
|
}
|
|
33260
33260
|
if (char === "'" || char === '"') {
|
|
33261
|
-
|
|
33261
|
+
quote2 = char;
|
|
33262
33262
|
word += char;
|
|
33263
33263
|
} else if (char === "#" && word === "") {
|
|
33264
33264
|
const end = text.indexOf("\n", index);
|
|
@@ -35939,8 +35939,8 @@ ${verificationUrl}`);
|
|
|
35939
35939
|
const state = base64url(randomBytes5(16));
|
|
35940
35940
|
const redirectUri = `http://${LOCALHOST}:${CALLBACK_PORT}/callback`;
|
|
35941
35941
|
let settle;
|
|
35942
|
-
const outcome = new Promise((
|
|
35943
|
-
settle =
|
|
35942
|
+
const outcome = new Promise((resolve13) => {
|
|
35943
|
+
settle = resolve13;
|
|
35944
35944
|
});
|
|
35945
35945
|
const server = createServer((req, res) => {
|
|
35946
35946
|
const url = new URL(req.url ?? "/", `http://${LOCALHOST}`);
|
|
@@ -35954,12 +35954,12 @@ ${verificationUrl}`);
|
|
|
35954
35954
|
res.end(page.html, () => settle(page.result));
|
|
35955
35955
|
});
|
|
35956
35956
|
try {
|
|
35957
|
-
await new Promise((
|
|
35957
|
+
await new Promise((resolve13, reject) => {
|
|
35958
35958
|
const onError = (err) => reject(err);
|
|
35959
35959
|
server.once("error", onError);
|
|
35960
35960
|
server.listen(CALLBACK_PORT, LOCALHOST, () => {
|
|
35961
35961
|
server.removeListener("error", onError);
|
|
35962
|
-
|
|
35962
|
+
resolve13();
|
|
35963
35963
|
});
|
|
35964
35964
|
});
|
|
35965
35965
|
} catch (err) {
|
|
@@ -37925,7 +37925,7 @@ async function runPinnedEnsure(options) {
|
|
|
37925
37925
|
npm_config_fetch_retry_maxtimeout: "5000",
|
|
37926
37926
|
npm_config_fetch_timeout: "15000"
|
|
37927
37927
|
};
|
|
37928
|
-
return await new Promise((
|
|
37928
|
+
return await new Promise((resolve13) => {
|
|
37929
37929
|
let settled = false;
|
|
37930
37930
|
let child;
|
|
37931
37931
|
try {
|
|
@@ -37935,7 +37935,7 @@ async function runPinnedEnsure(options) {
|
|
|
37935
37935
|
{ env: env4, stdio: "ignore" }
|
|
37936
37936
|
);
|
|
37937
37937
|
} catch {
|
|
37938
|
-
|
|
37938
|
+
resolve13(false);
|
|
37939
37939
|
return;
|
|
37940
37940
|
}
|
|
37941
37941
|
const timer = setTimeout(() => {
|
|
@@ -37946,7 +37946,7 @@ async function runPinnedEnsure(options) {
|
|
|
37946
37946
|
if (settled) return;
|
|
37947
37947
|
settled = true;
|
|
37948
37948
|
clearTimeout(timer);
|
|
37949
|
-
|
|
37949
|
+
resolve13(result);
|
|
37950
37950
|
};
|
|
37951
37951
|
timer.unref();
|
|
37952
37952
|
child.once("error", () => finish(false));
|
|
@@ -39360,7 +39360,7 @@ function clearStaleArtifacts() {
|
|
|
39360
39360
|
}
|
|
39361
39361
|
}
|
|
39362
39362
|
function sleep(ms) {
|
|
39363
|
-
return new Promise((
|
|
39363
|
+
return new Promise((resolve13) => setTimeout(resolve13, ms));
|
|
39364
39364
|
}
|
|
39365
39365
|
function spawnDaemon(options) {
|
|
39366
39366
|
const file = binFile(DAEMON_BIN);
|
|
@@ -42510,531 +42510,1582 @@ function registerDecisionsCommands(program3) {
|
|
|
42510
42510
|
});
|
|
42511
42511
|
}
|
|
42512
42512
|
|
|
42513
|
-
//
|
|
42514
|
-
|
|
42515
|
-
|
|
42516
|
-
// src/decisions/feedback.ts
|
|
42517
|
-
var FEEDBACK_PROTOCOL_VERSION = 2;
|
|
42518
|
-
var FEEDBACK_MIN_PROTOCOL_VERSION = 1;
|
|
42519
|
-
var STATUS_PATH = "/api/cli/decisions/feedback/status";
|
|
42520
|
-
function isRecord2(value) {
|
|
42521
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42522
|
-
}
|
|
42523
|
-
function isSupportedProtocolVersion(value) {
|
|
42524
|
-
return Number.isSafeInteger(value) && Number(value) >= FEEDBACK_MIN_PROTOCOL_VERSION && Number(value) <= FEEDBACK_PROTOCOL_VERSION;
|
|
42525
|
-
}
|
|
42526
|
-
function parseFeedbackCapability(value) {
|
|
42527
|
-
if (!isRecord2(value) || !isSupportedProtocolVersion(value.protocolVersion)) return void 0;
|
|
42528
|
-
if (value.status === "available") return { status: "available" };
|
|
42529
|
-
if (value.status === "unavailable" && value.reason === "organization_unbound") {
|
|
42530
|
-
return { status: "unavailable", reason: "organization_unbound" };
|
|
42531
|
-
}
|
|
42532
|
-
return void 0;
|
|
42533
|
-
}
|
|
42534
|
-
async function fetchFeedbackCapability(signal, client = getClient()) {
|
|
42535
|
-
const result = parseFeedbackCapability(await client.get(STATUS_PATH, { signal }));
|
|
42536
|
-
if (!result) throw new Error("server returned an unsupported decision-feedback contract");
|
|
42537
|
-
return result;
|
|
42538
|
-
}
|
|
42539
|
-
|
|
42540
|
-
// src/protocol/decision-lifecycle.ts
|
|
42541
|
-
var DECISION_LIFECYCLE_PROTOCOL_VERSION = 2;
|
|
42542
|
-
|
|
42543
|
-
// src/journal-organization.ts
|
|
42544
|
-
var ORGANIZATION_BINDING_VERSION = 1;
|
|
42545
|
-
var ORGANIZATION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
42546
|
-
var UNBOUND_BUCKET = "_unbound";
|
|
42547
|
-
var InvalidJournalEnvelopeError = class extends Error {
|
|
42548
|
-
constructor() {
|
|
42549
|
-
super("Invalid locally journaled move");
|
|
42550
|
-
this.name = "InvalidJournalEnvelopeError";
|
|
42551
|
-
}
|
|
42552
|
-
};
|
|
42553
|
-
function safeOrganizationId(value) {
|
|
42554
|
-
return typeof value === "string" && ORGANIZATION_ID_RE.test(value);
|
|
42555
|
-
}
|
|
42556
|
-
function isCaptureAuthorityKind(value) {
|
|
42557
|
-
return value === "workos" || value === "service_token";
|
|
42513
|
+
// node_modules/.pnpm/diff@5.2.2/node_modules/diff/lib/index.mjs
|
|
42514
|
+
function Diff() {
|
|
42558
42515
|
}
|
|
42559
|
-
|
|
42560
|
-
|
|
42561
|
-
|
|
42562
|
-
|
|
42563
|
-
|
|
42564
|
-
|
|
42565
|
-
|
|
42566
|
-
|
|
42567
|
-
if (record3.organizationId === null && record3.workosOrganizationId === null) {
|
|
42568
|
-
return { state: "no_current_organization" };
|
|
42569
|
-
}
|
|
42570
|
-
if (safeOrganizationId(record3.organizationId) && record3.workosOrganizationId === null) {
|
|
42571
|
-
return { state: "organization_identity_unreconciled" };
|
|
42572
|
-
}
|
|
42573
|
-
if (!safeOrganizationId(record3.organizationId) || !safeOrganizationId(record3.workosOrganizationId)) {
|
|
42574
|
-
return { state: "server_contract_unavailable" };
|
|
42575
|
-
}
|
|
42576
|
-
return {
|
|
42577
|
-
state: "current",
|
|
42578
|
-
binding: {
|
|
42579
|
-
captureAuthorityKind: record3.captureAuthorityKind,
|
|
42580
|
-
organizationId: record3.organizationId,
|
|
42581
|
-
workosOrganizationId: record3.workosOrganizationId
|
|
42516
|
+
Diff.prototype = {
|
|
42517
|
+
diff: function diff(oldString, newString) {
|
|
42518
|
+
var _options$timeout;
|
|
42519
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
42520
|
+
var callback = options.callback;
|
|
42521
|
+
if (typeof options === "function") {
|
|
42522
|
+
callback = options;
|
|
42523
|
+
options = {};
|
|
42582
42524
|
}
|
|
42583
|
-
|
|
42584
|
-
|
|
42585
|
-
function
|
|
42586
|
-
|
|
42587
|
-
|
|
42588
|
-
|
|
42589
|
-
|
|
42590
|
-
|
|
42591
|
-
}
|
|
42592
|
-
|
|
42593
|
-
|
|
42594
|
-
const retainedBuckets = [];
|
|
42595
|
-
for (const bucket of [...new Set(buckets)].sort()) {
|
|
42596
|
-
if (bucket === UNBOUND_BUCKET) {
|
|
42597
|
-
retainedBuckets.push({ bucket, reason: "unbound" });
|
|
42598
|
-
continue;
|
|
42525
|
+
this.options = options;
|
|
42526
|
+
var self = this;
|
|
42527
|
+
function done(value) {
|
|
42528
|
+
if (callback) {
|
|
42529
|
+
setTimeout(function() {
|
|
42530
|
+
callback(void 0, value);
|
|
42531
|
+
}, 0);
|
|
42532
|
+
return true;
|
|
42533
|
+
} else {
|
|
42534
|
+
return value;
|
|
42535
|
+
}
|
|
42599
42536
|
}
|
|
42600
|
-
|
|
42601
|
-
|
|
42602
|
-
|
|
42537
|
+
oldString = this.castInput(oldString);
|
|
42538
|
+
newString = this.castInput(newString);
|
|
42539
|
+
oldString = this.removeEmpty(this.tokenize(oldString));
|
|
42540
|
+
newString = this.removeEmpty(this.tokenize(newString));
|
|
42541
|
+
var newLen = newString.length, oldLen = oldString.length;
|
|
42542
|
+
var editLength = 1;
|
|
42543
|
+
var maxEditLength = newLen + oldLen;
|
|
42544
|
+
if (options.maxEditLength) {
|
|
42545
|
+
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
42603
42546
|
}
|
|
42604
|
-
|
|
42605
|
-
|
|
42606
|
-
|
|
42607
|
-
|
|
42547
|
+
var maxExecutionTime = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : Infinity;
|
|
42548
|
+
var abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
42549
|
+
var bestPath = [{
|
|
42550
|
+
oldPos: -1,
|
|
42551
|
+
lastComponent: void 0
|
|
42552
|
+
}];
|
|
42553
|
+
var newPos = this.extractCommon(bestPath[0], newString, oldString, 0);
|
|
42554
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
42555
|
+
return done([{
|
|
42556
|
+
value: this.join(newString),
|
|
42557
|
+
count: newString.length
|
|
42558
|
+
}]);
|
|
42608
42559
|
}
|
|
42609
|
-
|
|
42610
|
-
|
|
42611
|
-
|
|
42612
|
-
|
|
42613
|
-
|
|
42614
|
-
|
|
42615
|
-
|
|
42616
|
-
|
|
42617
|
-
|
|
42560
|
+
var minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
42561
|
+
function execEditLength() {
|
|
42562
|
+
for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
42563
|
+
var basePath = void 0;
|
|
42564
|
+
var removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
42565
|
+
if (removePath) {
|
|
42566
|
+
bestPath[diagonalPath - 1] = void 0;
|
|
42567
|
+
}
|
|
42568
|
+
var canAdd = false;
|
|
42569
|
+
if (addPath) {
|
|
42570
|
+
var addPathNewPos = addPath.oldPos - diagonalPath;
|
|
42571
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
42572
|
+
}
|
|
42573
|
+
var canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
42574
|
+
if (!canAdd && !canRemove) {
|
|
42575
|
+
bestPath[diagonalPath] = void 0;
|
|
42576
|
+
continue;
|
|
42577
|
+
}
|
|
42578
|
+
if (!canRemove || canAdd && removePath.oldPos + 1 < addPath.oldPos) {
|
|
42579
|
+
basePath = self.addToPath(addPath, true, void 0, 0);
|
|
42580
|
+
} else {
|
|
42581
|
+
basePath = self.addToPath(removePath, void 0, true, 1);
|
|
42582
|
+
}
|
|
42583
|
+
newPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
|
|
42584
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
42585
|
+
return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken));
|
|
42586
|
+
} else {
|
|
42587
|
+
bestPath[diagonalPath] = basePath;
|
|
42588
|
+
if (basePath.oldPos + 1 >= oldLen) {
|
|
42589
|
+
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
42590
|
+
}
|
|
42591
|
+
if (newPos + 1 >= newLen) {
|
|
42592
|
+
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
42593
|
+
}
|
|
42594
|
+
}
|
|
42595
|
+
}
|
|
42596
|
+
editLength++;
|
|
42597
|
+
}
|
|
42598
|
+
if (callback) {
|
|
42599
|
+
(function exec2() {
|
|
42600
|
+
setTimeout(function() {
|
|
42601
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
42602
|
+
return callback();
|
|
42603
|
+
}
|
|
42604
|
+
if (!execEditLength()) {
|
|
42605
|
+
exec2();
|
|
42606
|
+
}
|
|
42607
|
+
}, 0);
|
|
42608
|
+
})();
|
|
42609
|
+
} else {
|
|
42610
|
+
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
42611
|
+
var ret = execEditLength();
|
|
42612
|
+
if (ret) {
|
|
42613
|
+
return ret;
|
|
42614
|
+
}
|
|
42618
42615
|
}
|
|
42616
|
+
}
|
|
42617
|
+
},
|
|
42618
|
+
addToPath: function addToPath(path9, added, removed, oldPosInc) {
|
|
42619
|
+
var last = path9.lastComponent;
|
|
42620
|
+
if (last && last.added === added && last.removed === removed) {
|
|
42619
42621
|
return {
|
|
42620
|
-
|
|
42621
|
-
|
|
42622
|
-
|
|
42623
|
-
|
|
42624
|
-
|
|
42622
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
42623
|
+
lastComponent: {
|
|
42624
|
+
count: last.count + 1,
|
|
42625
|
+
added,
|
|
42626
|
+
removed,
|
|
42627
|
+
previousComponent: last.previousComponent
|
|
42628
|
+
}
|
|
42625
42629
|
};
|
|
42626
|
-
}
|
|
42627
|
-
|
|
42628
|
-
|
|
42629
|
-
|
|
42630
|
+
} else {
|
|
42631
|
+
return {
|
|
42632
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
42633
|
+
lastComponent: {
|
|
42634
|
+
count: 1,
|
|
42635
|
+
added,
|
|
42636
|
+
removed,
|
|
42637
|
+
previousComponent: last
|
|
42638
|
+
}
|
|
42639
|
+
};
|
|
42640
|
+
}
|
|
42641
|
+
},
|
|
42642
|
+
extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
|
|
42643
|
+
var newLen = newString.length, oldLen = oldString.length, oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
42644
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
|
|
42645
|
+
newPos++;
|
|
42646
|
+
oldPos++;
|
|
42647
|
+
commonCount++;
|
|
42648
|
+
}
|
|
42649
|
+
if (commonCount) {
|
|
42650
|
+
basePath.lastComponent = {
|
|
42651
|
+
count: commonCount,
|
|
42652
|
+
previousComponent: basePath.lastComponent
|
|
42653
|
+
};
|
|
42654
|
+
}
|
|
42655
|
+
basePath.oldPos = oldPos;
|
|
42656
|
+
return newPos;
|
|
42657
|
+
},
|
|
42658
|
+
equals: function equals(left, right) {
|
|
42659
|
+
if (this.options.comparator) {
|
|
42660
|
+
return this.options.comparator(left, right);
|
|
42661
|
+
} else {
|
|
42662
|
+
return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
42663
|
+
}
|
|
42664
|
+
},
|
|
42665
|
+
removeEmpty: function removeEmpty(array) {
|
|
42666
|
+
var ret = [];
|
|
42667
|
+
for (var i = 0; i < array.length; i++) {
|
|
42668
|
+
if (array[i]) {
|
|
42669
|
+
ret.push(array[i]);
|
|
42670
|
+
}
|
|
42671
|
+
}
|
|
42672
|
+
return ret;
|
|
42673
|
+
},
|
|
42674
|
+
castInput: function castInput(value) {
|
|
42675
|
+
return value;
|
|
42676
|
+
},
|
|
42677
|
+
tokenize: function tokenize(value) {
|
|
42678
|
+
return value.split("");
|
|
42679
|
+
},
|
|
42680
|
+
join: function join20(chars) {
|
|
42681
|
+
return chars.join("");
|
|
42630
42682
|
}
|
|
42631
|
-
|
|
42632
|
-
|
|
42633
|
-
|
|
42634
|
-
|
|
42635
|
-
|
|
42636
|
-
|
|
42637
|
-
|
|
42638
|
-
|
|
42639
|
-
|
|
42683
|
+
};
|
|
42684
|
+
function buildValues(diff2, lastComponent, newString, oldString, useLongestToken) {
|
|
42685
|
+
var components = [];
|
|
42686
|
+
var nextComponent;
|
|
42687
|
+
while (lastComponent) {
|
|
42688
|
+
components.push(lastComponent);
|
|
42689
|
+
nextComponent = lastComponent.previousComponent;
|
|
42690
|
+
delete lastComponent.previousComponent;
|
|
42691
|
+
lastComponent = nextComponent;
|
|
42640
42692
|
}
|
|
42641
|
-
|
|
42642
|
-
|
|
42643
|
-
|
|
42644
|
-
|
|
42645
|
-
|
|
42646
|
-
|
|
42647
|
-
|
|
42648
|
-
|
|
42649
|
-
|
|
42650
|
-
|
|
42693
|
+
components.reverse();
|
|
42694
|
+
var componentPos = 0, componentLen = components.length, newPos = 0, oldPos = 0;
|
|
42695
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
42696
|
+
var component = components[componentPos];
|
|
42697
|
+
if (!component.removed) {
|
|
42698
|
+
if (!component.added && useLongestToken) {
|
|
42699
|
+
var value = newString.slice(newPos, newPos + component.count);
|
|
42700
|
+
value = value.map(function(value2, i) {
|
|
42701
|
+
var oldValue = oldString[oldPos + i];
|
|
42702
|
+
return oldValue.length > value2.length ? oldValue : value2;
|
|
42703
|
+
});
|
|
42704
|
+
component.value = diff2.join(value);
|
|
42705
|
+
} else {
|
|
42706
|
+
component.value = diff2.join(newString.slice(newPos, newPos + component.count));
|
|
42707
|
+
}
|
|
42708
|
+
newPos += component.count;
|
|
42709
|
+
if (!component.added) {
|
|
42710
|
+
oldPos += component.count;
|
|
42711
|
+
}
|
|
42712
|
+
} else {
|
|
42713
|
+
component.value = diff2.join(oldString.slice(oldPos, oldPos + component.count));
|
|
42714
|
+
oldPos += component.count;
|
|
42715
|
+
if (componentPos && components[componentPos - 1].added) {
|
|
42716
|
+
var tmp = components[componentPos - 1];
|
|
42717
|
+
components[componentPos - 1] = components[componentPos];
|
|
42718
|
+
components[componentPos] = tmp;
|
|
42719
|
+
}
|
|
42720
|
+
}
|
|
42651
42721
|
}
|
|
42652
|
-
|
|
42653
|
-
|
|
42722
|
+
var finalComponent = components[componentLen - 1];
|
|
42723
|
+
if (componentLen > 1 && typeof finalComponent.value === "string" && (finalComponent.added || finalComponent.removed) && diff2.equals("", finalComponent.value)) {
|
|
42724
|
+
components[componentLen - 2].value += finalComponent.value;
|
|
42725
|
+
components.pop();
|
|
42654
42726
|
}
|
|
42655
|
-
return
|
|
42656
|
-
client,
|
|
42657
|
-
binding: parsed.binding,
|
|
42658
|
-
...classifyJournalBuckets(bucketList, parsed.binding)
|
|
42659
|
-
};
|
|
42660
|
-
}
|
|
42661
|
-
|
|
42662
|
-
// src/journal.ts
|
|
42663
|
-
import {
|
|
42664
|
-
appendFileSync,
|
|
42665
|
-
closeSync as closeSync5,
|
|
42666
|
-
existsSync as existsSync14,
|
|
42667
|
-
fstatSync as fstatSync2,
|
|
42668
|
-
mkdirSync as mkdirSync11,
|
|
42669
|
-
openSync as openSync5,
|
|
42670
|
-
opendirSync,
|
|
42671
|
-
readFileSync as readFileSync17,
|
|
42672
|
-
readSync as readSync2,
|
|
42673
|
-
readdirSync as readdirSync6
|
|
42674
|
-
} from "fs";
|
|
42675
|
-
import { dirname as dirname12, join as join21 } from "path";
|
|
42676
|
-
|
|
42677
|
-
// src/drain-progress.ts
|
|
42678
|
-
import {
|
|
42679
|
-
chmodSync as chmodSync6,
|
|
42680
|
-
existsSync as existsSync13,
|
|
42681
|
-
readFileSync as readFileSync16,
|
|
42682
|
-
readdirSync as readdirSync5,
|
|
42683
|
-
rmSync as rmSync6,
|
|
42684
|
-
rmdirSync
|
|
42685
|
-
} from "fs";
|
|
42686
|
-
import { basename as basename4, dirname as dirname11, join as join20 } from "path";
|
|
42687
|
-
var DIRECTORY_MODE3 = 448;
|
|
42688
|
-
var FILE_MODE2 = 384;
|
|
42689
|
-
var DRAIN_PROGRESS_DIRNAME = "drain-progress";
|
|
42690
|
-
var CHECKPOINT_NAME = /^(.+)\.json(?:\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.tmp)?$/;
|
|
42691
|
-
function rotationIdentity(stat) {
|
|
42692
|
-
return { size: stat.size, ino: stat.ino, dev: stat.dev };
|
|
42693
|
-
}
|
|
42694
|
-
function drainProgressDirectory(flushingPath) {
|
|
42695
|
-
return join20(dirname11(flushingPath), DRAIN_PROGRESS_DIRNAME);
|
|
42696
|
-
}
|
|
42697
|
-
function drainProgressPath(flushingPath) {
|
|
42698
|
-
return join20(drainProgressDirectory(flushingPath), `${basename4(flushingPath)}.json`);
|
|
42699
|
-
}
|
|
42700
|
-
function isByteCount(value) {
|
|
42701
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
42727
|
+
return components;
|
|
42702
42728
|
}
|
|
42703
|
-
|
|
42704
|
-
|
|
42705
|
-
|
|
42706
|
-
|
|
42707
|
-
|
|
42708
|
-
|
|
42709
|
-
|
|
42710
|
-
|
|
42711
|
-
return 0;
|
|
42712
|
-
}
|
|
42713
|
-
const { v, offset, size, ino, dev } = parsed;
|
|
42714
|
-
if (v !== 2 || ino !== rotation.ino || dev !== rotation.dev || size !== rotation.size || !isByteCount(offset) || offset > rotation.size) {
|
|
42715
|
-
return 0;
|
|
42729
|
+
var characterDiff = new Diff();
|
|
42730
|
+
var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
|
|
42731
|
+
var reWhitespace = /\S/;
|
|
42732
|
+
var wordDiff = new Diff();
|
|
42733
|
+
wordDiff.equals = function(left, right) {
|
|
42734
|
+
if (this.options.ignoreCase) {
|
|
42735
|
+
left = left.toLowerCase();
|
|
42736
|
+
right = right.toLowerCase();
|
|
42716
42737
|
}
|
|
42717
|
-
return
|
|
42718
|
-
}
|
|
42719
|
-
function
|
|
42720
|
-
|
|
42721
|
-
|
|
42722
|
-
|
|
42723
|
-
|
|
42724
|
-
|
|
42725
|
-
|
|
42726
|
-
});
|
|
42727
|
-
}
|
|
42728
|
-
function removeEmptyDirectory(directory) {
|
|
42729
|
-
try {
|
|
42730
|
-
rmdirSync(directory);
|
|
42731
|
-
} catch (error) {
|
|
42732
|
-
const code = error.code;
|
|
42733
|
-
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST") {
|
|
42734
|
-
throw error;
|
|
42738
|
+
return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
|
|
42739
|
+
};
|
|
42740
|
+
wordDiff.tokenize = function(value) {
|
|
42741
|
+
var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/);
|
|
42742
|
+
for (var i = 0; i < tokens.length - 1; i++) {
|
|
42743
|
+
if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
|
|
42744
|
+
tokens[i] += tokens[i + 2];
|
|
42745
|
+
tokens.splice(i + 1, 2);
|
|
42746
|
+
i--;
|
|
42735
42747
|
}
|
|
42736
42748
|
}
|
|
42737
|
-
|
|
42738
|
-
|
|
42739
|
-
|
|
42740
|
-
|
|
42741
|
-
|
|
42742
|
-
|
|
42743
|
-
const directory = join20(bucketDirectory, DRAIN_PROGRESS_DIRNAME);
|
|
42744
|
-
let names;
|
|
42745
|
-
try {
|
|
42746
|
-
names = readdirSync5(directory);
|
|
42747
|
-
} catch {
|
|
42748
|
-
return;
|
|
42749
|
+
return tokens;
|
|
42750
|
+
};
|
|
42751
|
+
var lineDiff = new Diff();
|
|
42752
|
+
lineDiff.tokenize = function(value) {
|
|
42753
|
+
if (this.options.stripTrailingCr) {
|
|
42754
|
+
value = value.replace(/\r\n/g, "\n");
|
|
42749
42755
|
}
|
|
42750
|
-
|
|
42751
|
-
|
|
42752
|
-
|
|
42753
|
-
continue;
|
|
42754
|
-
}
|
|
42755
|
-
try {
|
|
42756
|
-
rmSync6(join20(directory, name), { force: true });
|
|
42757
|
-
} catch {
|
|
42758
|
-
}
|
|
42756
|
+
var retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
42757
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
42758
|
+
linesAndNewlines.pop();
|
|
42759
42759
|
}
|
|
42760
|
-
|
|
42761
|
-
|
|
42762
|
-
|
|
42760
|
+
for (var i = 0; i < linesAndNewlines.length; i++) {
|
|
42761
|
+
var line = linesAndNewlines[i];
|
|
42762
|
+
if (i % 2 && !this.options.newlineIsToken) {
|
|
42763
|
+
retLines[retLines.length - 1] += line;
|
|
42764
|
+
} else {
|
|
42765
|
+
if (this.options.ignoreWhitespace) {
|
|
42766
|
+
line = line.trim();
|
|
42767
|
+
}
|
|
42768
|
+
retLines.push(line);
|
|
42769
|
+
}
|
|
42763
42770
|
}
|
|
42771
|
+
return retLines;
|
|
42772
|
+
};
|
|
42773
|
+
function diffLines(oldStr, newStr, callback) {
|
|
42774
|
+
return lineDiff.diff(oldStr, newStr, callback);
|
|
42764
42775
|
}
|
|
42765
|
-
|
|
42766
|
-
|
|
42767
|
-
|
|
42768
|
-
|
|
42769
|
-
var
|
|
42770
|
-
|
|
42771
|
-
|
|
42772
|
-
|
|
42773
|
-
|
|
42774
|
-
|
|
42776
|
+
var sentenceDiff = new Diff();
|
|
42777
|
+
sentenceDiff.tokenize = function(value) {
|
|
42778
|
+
return value.split(/(\S.+?[.!?])(?=\s+|$)/);
|
|
42779
|
+
};
|
|
42780
|
+
var cssDiff = new Diff();
|
|
42781
|
+
cssDiff.tokenize = function(value) {
|
|
42782
|
+
return value.split(/([{}:;,]|\s+)/);
|
|
42783
|
+
};
|
|
42784
|
+
function _typeof(obj) {
|
|
42785
|
+
"@babel/helpers - typeof";
|
|
42786
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
42787
|
+
_typeof = function(obj2) {
|
|
42788
|
+
return typeof obj2;
|
|
42789
|
+
};
|
|
42790
|
+
} else {
|
|
42791
|
+
_typeof = function(obj2) {
|
|
42792
|
+
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
42793
|
+
};
|
|
42775
42794
|
}
|
|
42776
|
-
return
|
|
42795
|
+
return _typeof(obj);
|
|
42777
42796
|
}
|
|
42778
|
-
function
|
|
42779
|
-
return
|
|
42797
|
+
function _toConsumableArray(arr) {
|
|
42798
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
42780
42799
|
}
|
|
42781
|
-
function
|
|
42782
|
-
|
|
42783
|
-
for (const line of content.split("\n")) {
|
|
42784
|
-
if (line.length === 0) {
|
|
42785
|
-
continue;
|
|
42786
|
-
}
|
|
42787
|
-
try {
|
|
42788
|
-
moves.push(JSON.parse(line));
|
|
42789
|
-
} catch {
|
|
42790
|
-
}
|
|
42791
|
-
}
|
|
42792
|
-
return moves;
|
|
42800
|
+
function _arrayWithoutHoles(arr) {
|
|
42801
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
42793
42802
|
}
|
|
42794
|
-
function
|
|
42795
|
-
if (
|
|
42796
|
-
return [];
|
|
42797
|
-
}
|
|
42798
|
-
return parseMoves(readFileSync17(path9, "utf-8"));
|
|
42803
|
+
function _iterableToArray(iter) {
|
|
42804
|
+
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
|
42799
42805
|
}
|
|
42800
|
-
function
|
|
42801
|
-
|
|
42802
|
-
|
|
42803
|
-
|
|
42804
|
-
|
|
42806
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
42807
|
+
if (!o) return;
|
|
42808
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
42809
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
42810
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
42811
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
42812
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
42813
|
+
}
|
|
42814
|
+
function _arrayLikeToArray(arr, len) {
|
|
42815
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
42816
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
42817
|
+
return arr2;
|
|
42818
|
+
}
|
|
42819
|
+
function _nonIterableSpread() {
|
|
42820
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
42821
|
+
}
|
|
42822
|
+
var objectPrototypeToString = Object.prototype.toString;
|
|
42823
|
+
var jsonDiff = new Diff();
|
|
42824
|
+
jsonDiff.useLongestToken = true;
|
|
42825
|
+
jsonDiff.tokenize = lineDiff.tokenize;
|
|
42826
|
+
jsonDiff.castInput = function(value) {
|
|
42827
|
+
var _this$options = this.options, undefinedReplacement = _this$options.undefinedReplacement, _this$options$stringi = _this$options.stringifyReplacer, stringifyReplacer = _this$options$stringi === void 0 ? function(k, v) {
|
|
42828
|
+
return typeof v === "undefined" ? undefinedReplacement : v;
|
|
42829
|
+
} : _this$options$stringi;
|
|
42830
|
+
return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, " ");
|
|
42831
|
+
};
|
|
42832
|
+
jsonDiff.equals = function(left, right) {
|
|
42833
|
+
return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"));
|
|
42834
|
+
};
|
|
42835
|
+
function canonicalize(obj, stack, replacementStack, replacer, key) {
|
|
42836
|
+
stack = stack || [];
|
|
42837
|
+
replacementStack = replacementStack || [];
|
|
42838
|
+
if (replacer) {
|
|
42839
|
+
obj = replacer(key, obj);
|
|
42805
42840
|
}
|
|
42806
|
-
|
|
42807
|
-
|
|
42808
|
-
|
|
42809
|
-
|
|
42810
|
-
const path9 = join21(envDir, entry.name, JOURNAL_BASENAME);
|
|
42811
|
-
if (existsSync14(path9)) {
|
|
42812
|
-
out.push({ bucket: entry.name, path: path9 });
|
|
42841
|
+
var i;
|
|
42842
|
+
for (i = 0; i < stack.length; i += 1) {
|
|
42843
|
+
if (stack[i] === obj) {
|
|
42844
|
+
return replacementStack[i];
|
|
42813
42845
|
}
|
|
42814
42846
|
}
|
|
42815
|
-
|
|
42816
|
-
|
|
42817
|
-
|
|
42818
|
-
|
|
42819
|
-
|
|
42820
|
-
|
|
42821
|
-
|
|
42822
|
-
continue;
|
|
42847
|
+
var canonicalizedObj;
|
|
42848
|
+
if ("[object Array]" === objectPrototypeToString.call(obj)) {
|
|
42849
|
+
stack.push(obj);
|
|
42850
|
+
canonicalizedObj = new Array(obj.length);
|
|
42851
|
+
replacementStack.push(canonicalizedObj);
|
|
42852
|
+
for (i = 0; i < obj.length; i += 1) {
|
|
42853
|
+
canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
|
|
42823
42854
|
}
|
|
42824
|
-
|
|
42855
|
+
stack.pop();
|
|
42856
|
+
replacementStack.pop();
|
|
42857
|
+
return canonicalizedObj;
|
|
42825
42858
|
}
|
|
42826
|
-
|
|
42827
|
-
|
|
42828
|
-
|
|
42829
|
-
|
|
42830
|
-
|
|
42831
|
-
|
|
42832
|
-
|
|
42833
|
-
|
|
42834
|
-
|
|
42835
|
-
|
|
42836
|
-
|
|
42837
|
-
const count = readSync2(fd, buffer, sampledBytes, target - sampledBytes, start + sampledBytes);
|
|
42838
|
-
if (count === 0) {
|
|
42839
|
-
break;
|
|
42859
|
+
if (obj && obj.toJSON) {
|
|
42860
|
+
obj = obj.toJSON();
|
|
42861
|
+
}
|
|
42862
|
+
if (_typeof(obj) === "object" && obj !== null) {
|
|
42863
|
+
stack.push(obj);
|
|
42864
|
+
canonicalizedObj = {};
|
|
42865
|
+
replacementStack.push(canonicalizedObj);
|
|
42866
|
+
var sortedKeys = [], _key;
|
|
42867
|
+
for (_key in obj) {
|
|
42868
|
+
if (obj.hasOwnProperty(_key)) {
|
|
42869
|
+
sortedKeys.push(_key);
|
|
42840
42870
|
}
|
|
42841
|
-
sampledBytes += count;
|
|
42842
42871
|
}
|
|
42843
|
-
|
|
42844
|
-
|
|
42845
|
-
|
|
42846
|
-
|
|
42847
|
-
const lastNewline = content.lastIndexOf("\n");
|
|
42848
|
-
content = lastNewline === -1 ? "" : content.slice(0, lastNewline + 1);
|
|
42872
|
+
sortedKeys.sort();
|
|
42873
|
+
for (i = 0; i < sortedKeys.length; i += 1) {
|
|
42874
|
+
_key = sortedKeys[i];
|
|
42875
|
+
canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
|
|
42849
42876
|
}
|
|
42850
|
-
|
|
42851
|
-
|
|
42852
|
-
|
|
42853
|
-
|
|
42854
|
-
pendingBytes: Math.max(0, stat.size - start),
|
|
42855
|
-
mtimeMs: stat.mtimeMs,
|
|
42856
|
-
lineCount: sampled && stat.size > 0 ? Math.max(1, lines.length) : lines.length,
|
|
42857
|
-
oldestCapturedAt: oldestCapturedAt(moves),
|
|
42858
|
-
sampled,
|
|
42859
|
-
sampledBytes
|
|
42860
|
-
};
|
|
42861
|
-
} finally {
|
|
42862
|
-
closeSync5(fd);
|
|
42877
|
+
stack.pop();
|
|
42878
|
+
replacementStack.pop();
|
|
42879
|
+
} else {
|
|
42880
|
+
canonicalizedObj = obj;
|
|
42863
42881
|
}
|
|
42882
|
+
return canonicalizedObj;
|
|
42864
42883
|
}
|
|
42865
|
-
|
|
42866
|
-
|
|
42867
|
-
|
|
42868
|
-
|
|
42869
|
-
|
|
42870
|
-
return
|
|
42871
|
-
}
|
|
42872
|
-
function
|
|
42873
|
-
if (!
|
|
42874
|
-
|
|
42884
|
+
var arrayDiff = new Diff();
|
|
42885
|
+
arrayDiff.tokenize = function(value) {
|
|
42886
|
+
return value.slice();
|
|
42887
|
+
};
|
|
42888
|
+
arrayDiff.join = arrayDiff.removeEmpty = function(value) {
|
|
42889
|
+
return value;
|
|
42890
|
+
};
|
|
42891
|
+
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
42892
|
+
if (!options) {
|
|
42893
|
+
options = {};
|
|
42875
42894
|
}
|
|
42876
|
-
|
|
42877
|
-
|
|
42878
|
-
|
|
42879
|
-
|
|
42880
|
-
|
|
42881
|
-
|
|
42882
|
-
|
|
42883
|
-
|
|
42884
|
-
|
|
42885
|
-
|
|
42895
|
+
if (typeof options.context === "undefined") {
|
|
42896
|
+
options.context = 4;
|
|
42897
|
+
}
|
|
42898
|
+
var diff2 = diffLines(oldStr, newStr, options);
|
|
42899
|
+
if (!diff2) {
|
|
42900
|
+
return;
|
|
42901
|
+
}
|
|
42902
|
+
diff2.push({
|
|
42903
|
+
value: "",
|
|
42904
|
+
lines: []
|
|
42905
|
+
});
|
|
42906
|
+
function contextLines(lines) {
|
|
42907
|
+
return lines.map(function(entry) {
|
|
42908
|
+
return " " + entry;
|
|
42909
|
+
});
|
|
42910
|
+
}
|
|
42911
|
+
var hunks = [];
|
|
42912
|
+
var oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
42913
|
+
var _loop = function _loop2(i2) {
|
|
42914
|
+
var current = diff2[i2], lines = current.lines || current.value.replace(/\n$/, "").split("\n");
|
|
42915
|
+
current.lines = lines;
|
|
42916
|
+
if (current.added || current.removed) {
|
|
42917
|
+
var _curRange;
|
|
42918
|
+
if (!oldRangeStart) {
|
|
42919
|
+
var prev = diff2[i2 - 1];
|
|
42920
|
+
oldRangeStart = oldLine;
|
|
42921
|
+
newRangeStart = newLine;
|
|
42922
|
+
if (prev) {
|
|
42923
|
+
curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
|
|
42924
|
+
oldRangeStart -= curRange.length;
|
|
42925
|
+
newRangeStart -= curRange.length;
|
|
42926
|
+
}
|
|
42886
42927
|
}
|
|
42887
|
-
|
|
42888
|
-
|
|
42889
|
-
|
|
42890
|
-
|
|
42891
|
-
|
|
42892
|
-
|
|
42893
|
-
|
|
42894
|
-
|
|
42928
|
+
(_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function(entry) {
|
|
42929
|
+
return (current.added ? "+" : "-") + entry;
|
|
42930
|
+
})));
|
|
42931
|
+
if (current.added) {
|
|
42932
|
+
newLine += lines.length;
|
|
42933
|
+
} else {
|
|
42934
|
+
oldLine += lines.length;
|
|
42935
|
+
}
|
|
42936
|
+
} else {
|
|
42937
|
+
if (oldRangeStart) {
|
|
42938
|
+
if (lines.length <= options.context * 2 && i2 < diff2.length - 2) {
|
|
42939
|
+
var _curRange2;
|
|
42940
|
+
(_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
|
|
42941
|
+
} else {
|
|
42942
|
+
var _curRange3;
|
|
42943
|
+
var contextSize = Math.min(lines.length, options.context);
|
|
42944
|
+
(_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
|
|
42945
|
+
var hunk = {
|
|
42946
|
+
oldStart: oldRangeStart,
|
|
42947
|
+
oldLines: oldLine - oldRangeStart + contextSize,
|
|
42948
|
+
newStart: newRangeStart,
|
|
42949
|
+
newLines: newLine - newRangeStart + contextSize,
|
|
42950
|
+
lines: curRange
|
|
42951
|
+
};
|
|
42952
|
+
if (i2 >= diff2.length - 2 && lines.length <= options.context) {
|
|
42953
|
+
var oldEOFNewline = /\n$/.test(oldStr);
|
|
42954
|
+
var newEOFNewline = /\n$/.test(newStr);
|
|
42955
|
+
var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
|
|
42956
|
+
if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
|
|
42957
|
+
curRange.splice(hunk.oldLines, 0, "\");
|
|
42958
|
+
}
|
|
42959
|
+
if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
|
|
42960
|
+
curRange.push("\");
|
|
42961
|
+
}
|
|
42962
|
+
}
|
|
42963
|
+
hunks.push(hunk);
|
|
42964
|
+
oldRangeStart = 0;
|
|
42965
|
+
newRangeStart = 0;
|
|
42966
|
+
curRange = [];
|
|
42895
42967
|
}
|
|
42896
|
-
throw err;
|
|
42897
42968
|
}
|
|
42898
|
-
|
|
42899
|
-
|
|
42900
|
-
bucket,
|
|
42901
|
-
path: path9,
|
|
42902
|
-
pid: parseFlushingPid(entry.name),
|
|
42903
|
-
...sample
|
|
42904
|
-
});
|
|
42905
|
-
entry = entries.readSync();
|
|
42969
|
+
oldLine += lines.length;
|
|
42970
|
+
newLine += lines.length;
|
|
42906
42971
|
}
|
|
42907
|
-
}
|
|
42908
|
-
|
|
42972
|
+
};
|
|
42973
|
+
for (var i = 0; i < diff2.length; i++) {
|
|
42974
|
+
_loop(i);
|
|
42909
42975
|
}
|
|
42910
|
-
return
|
|
42976
|
+
return {
|
|
42977
|
+
oldFileName,
|
|
42978
|
+
newFileName,
|
|
42979
|
+
oldHeader,
|
|
42980
|
+
newHeader,
|
|
42981
|
+
hunks
|
|
42982
|
+
};
|
|
42911
42983
|
}
|
|
42912
|
-
function
|
|
42913
|
-
|
|
42914
|
-
|
|
42915
|
-
return [];
|
|
42984
|
+
function formatPatch(diff2) {
|
|
42985
|
+
if (Array.isArray(diff2)) {
|
|
42986
|
+
return diff2.map(formatPatch).join("\n");
|
|
42916
42987
|
}
|
|
42917
|
-
|
|
42918
|
-
|
|
42919
|
-
|
|
42920
|
-
|
|
42921
|
-
|
|
42922
|
-
|
|
42988
|
+
var ret = [];
|
|
42989
|
+
if (diff2.oldFileName == diff2.newFileName) {
|
|
42990
|
+
ret.push("Index: " + diff2.oldFileName);
|
|
42991
|
+
}
|
|
42992
|
+
ret.push("===================================================================");
|
|
42993
|
+
ret.push("--- " + diff2.oldFileName + (typeof diff2.oldHeader === "undefined" ? "" : " " + diff2.oldHeader));
|
|
42994
|
+
ret.push("+++ " + diff2.newFileName + (typeof diff2.newHeader === "undefined" ? "" : " " + diff2.newHeader));
|
|
42995
|
+
for (var i = 0; i < diff2.hunks.length; i++) {
|
|
42996
|
+
var hunk = diff2.hunks[i];
|
|
42997
|
+
if (hunk.oldLines === 0) {
|
|
42998
|
+
hunk.oldStart -= 1;
|
|
42923
42999
|
}
|
|
42924
|
-
if (
|
|
42925
|
-
|
|
42926
|
-
sampleBytes: remainingBytes,
|
|
42927
|
-
maxFiles: maxFiles - out.length
|
|
42928
|
-
});
|
|
42929
|
-
out.push(...found);
|
|
42930
|
-
remainingBytes = Math.max(
|
|
42931
|
-
0,
|
|
42932
|
-
remainingBytes - found.reduce((count, file) => count + file.sampledBytes, 0)
|
|
42933
|
-
);
|
|
43000
|
+
if (hunk.newLines === 0) {
|
|
43001
|
+
hunk.newStart -= 1;
|
|
42934
43002
|
}
|
|
43003
|
+
ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
|
|
43004
|
+
ret.push.apply(ret, hunk.lines);
|
|
42935
43005
|
}
|
|
42936
|
-
return
|
|
43006
|
+
return ret.join("\n") + "\n";
|
|
42937
43007
|
}
|
|
42938
|
-
function
|
|
42939
|
-
|
|
42940
|
-
|
|
43008
|
+
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
43009
|
+
return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
|
|
43010
|
+
}
|
|
43011
|
+
function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
43012
|
+
return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
43013
|
+
}
|
|
43014
|
+
|
|
43015
|
+
// src/demo/sandbox.ts
|
|
43016
|
+
import {
|
|
43017
|
+
existsSync as existsSync14,
|
|
43018
|
+
lstatSync as lstatSync9,
|
|
43019
|
+
mkdtempSync as mkdtempSync3,
|
|
43020
|
+
readFileSync as readFileSync17,
|
|
43021
|
+
readdirSync as readdirSync6,
|
|
43022
|
+
realpathSync as realpathSync5,
|
|
43023
|
+
rmdirSync,
|
|
43024
|
+
unlinkSync as unlinkSync5
|
|
43025
|
+
} from "fs";
|
|
43026
|
+
import { tmpdir } from "os";
|
|
43027
|
+
import { basename as basename4, dirname as dirname11, join as join22 } from "path";
|
|
43028
|
+
|
|
43029
|
+
// src/demo/scenario.ts
|
|
43030
|
+
var SAMPLE_NOTE = [
|
|
43031
|
+
"Fictional engineering conversation:",
|
|
43032
|
+
"Maya: Could we call fetch directly for the order service?",
|
|
43033
|
+
"Ravi: Use the shared HTTP client for service calls. We need retries and request tracing to stay consistent.",
|
|
43034
|
+
"Maya: Agreed. Let's reject direct fetch calls because they duplicate that policy.",
|
|
43035
|
+
"Ravi: Also, the team demo is at three."
|
|
43036
|
+
].join("\n");
|
|
43037
|
+
var SAMPLE_DECISIONS = [
|
|
43038
|
+
{
|
|
43039
|
+
id: "demo-http-client",
|
|
43040
|
+
decision: "Use the shared HTTP client for service calls",
|
|
43041
|
+
stage: "provisional",
|
|
43042
|
+
source: "Fictional engineering conversation",
|
|
43043
|
+
evidence: [
|
|
43044
|
+
"Use the shared HTTP client for service calls. We need retries and request tracing to stay consistent.",
|
|
43045
|
+
"Let's reject direct fetch calls because they duplicate that policy."
|
|
43046
|
+
],
|
|
43047
|
+
rationale: "Centralize retries and request tracing.",
|
|
43048
|
+
files: ["service.ts"],
|
|
43049
|
+
scopeBasis: "Demo mapping from service calls to service.ts; the conversation names no file.",
|
|
43050
|
+
alternativesRejected: ["Direct fetch calls with duplicated retry and tracing policy"]
|
|
43051
|
+
},
|
|
43052
|
+
{
|
|
43053
|
+
id: "demo-order-repository",
|
|
43054
|
+
decision: "Persist orders through the shared order repository",
|
|
43055
|
+
stage: "adopted",
|
|
43056
|
+
source: "User confirmation of this fictional proposal",
|
|
43057
|
+
rationale: "Keep validation and persistence consistent across order writers.",
|
|
43058
|
+
files: ["orders.ts"],
|
|
43059
|
+
alternativesRejected: ["Direct local-storage writes that bypass repository validation"]
|
|
43060
|
+
}
|
|
43061
|
+
];
|
|
43062
|
+
var SAMPLE_FILES = {
|
|
43063
|
+
"service.ts": 'import { http } from "./shared";\nexport const loadOrders = () => http.get("/orders");\n',
|
|
43064
|
+
"orders.ts": "export const saveOrder = (_order: unknown) => {\n // TODO: persist this order.\n};\n",
|
|
43065
|
+
"shared.ts": "// Fictional interfaces; this tour does not execute network or storage operations.\nexport declare const http: { get(path: string): Promise<unknown> };\nexport declare const orders: { save(order: unknown): void };\n"
|
|
43066
|
+
};
|
|
43067
|
+
var WARNING_EDIT = 'export const loadOrders = () => fetch("/orders");\n';
|
|
43068
|
+
var BLOCKED_EDIT = 'export const saveOrder = (order: unknown) => localStorage.setItem("order", JSON.stringify(order));\n';
|
|
43069
|
+
var REPOSITORY_EDIT = 'import { orders } from "./shared";\nexport const saveOrder = (order: unknown) => orders.save(order);\n';
|
|
43070
|
+
|
|
43071
|
+
// src/demo/state.ts
|
|
43072
|
+
import { createHash as createHash9, randomUUID as randomUUID3 } from "crypto";
|
|
43073
|
+
import { existsSync as existsSync13, lstatSync as lstatSync8, readFileSync as readFileSync16, readdirSync as readdirSync5 } from "fs";
|
|
43074
|
+
import { join as join21, resolve as resolve8 } from "path";
|
|
43075
|
+
var RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
43076
|
+
var demoDirectory = () => join21(primConfigDirectory(), "demo");
|
|
43077
|
+
var runPath = (id) => {
|
|
43078
|
+
if (!RUN_ID.test(id)) throw new Error("invalid demo run ID");
|
|
43079
|
+
return join21(demoDirectory(), "runs", `${id}.json`);
|
|
43080
|
+
};
|
|
43081
|
+
function readDemoJson(path9) {
|
|
43082
|
+
const stat = lstatSync8(path9);
|
|
43083
|
+
if (!stat.isFile() || stat.size > 16384) throw new Error(`invalid demo state: ${path9}`);
|
|
43084
|
+
return JSON.parse(readFileSync16(path9, "utf8"));
|
|
43085
|
+
}
|
|
43086
|
+
function saveDemoJson(path9, value) {
|
|
43087
|
+
atomicWriteFile(path9, `${JSON.stringify(value)}
|
|
43088
|
+
`, { mode: 384, ensureParent: true });
|
|
43089
|
+
}
|
|
43090
|
+
function readRun(id) {
|
|
43091
|
+
const run = readDemoJson(runPath(id));
|
|
43092
|
+
if (run.version !== 1 || run.id !== id || !["prepared", "proposal", "conflict", "completed", "skipped"].includes(run.stage) || typeof run.terminal !== "boolean" || !Array.isArray(run.launcher) || run.launcher.length !== 2 || run.launcher.some((value) => typeof value !== "string" || !value.startsWith("/")) || run.agent !== void 0 && !["claude_code", "codex", "cursor", "hermes"].includes(run.agent)) {
|
|
43093
|
+
throw new Error("invalid demo run state");
|
|
43094
|
+
}
|
|
43095
|
+
return run;
|
|
43096
|
+
}
|
|
43097
|
+
var saveRun = (run) => saveDemoJson(runPath(run.id), run);
|
|
43098
|
+
var lockRun = (id, action) => withFileLockSync(`${runPath(id)}.lock`, () => action(readRun(id)), { timeoutMs: 500 });
|
|
43099
|
+
function prepareRun(agent, terminal = false) {
|
|
43100
|
+
const run = {
|
|
43101
|
+
version: 1,
|
|
43102
|
+
id: randomUUID3(),
|
|
43103
|
+
stage: "prepared",
|
|
43104
|
+
terminal,
|
|
43105
|
+
agent,
|
|
43106
|
+
launcher: [process.execPath, resolve8(process.argv[1])]
|
|
43107
|
+
};
|
|
43108
|
+
saveRun(run);
|
|
43109
|
+
return run;
|
|
43110
|
+
}
|
|
43111
|
+
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
43112
|
+
function demoCommand(run, action, choice) {
|
|
43113
|
+
return [
|
|
43114
|
+
...run.launcher,
|
|
43115
|
+
"demo",
|
|
43116
|
+
action,
|
|
43117
|
+
run.id,
|
|
43118
|
+
...choice === void 0 ? [] : ["--choice", choice]
|
|
43119
|
+
].map(quote).join(" ");
|
|
43120
|
+
}
|
|
43121
|
+
function onboardingFinished() {
|
|
43122
|
+
const path9 = join21(demoDirectory(), "onboarding.json");
|
|
43123
|
+
if (!existsSync13(path9)) return false;
|
|
43124
|
+
const value = readDemoJson(path9);
|
|
43125
|
+
if (value.outcome !== "completed" && value.outcome !== "skipped") {
|
|
43126
|
+
throw new Error("invalid local onboarding outcome");
|
|
43127
|
+
}
|
|
43128
|
+
return true;
|
|
43129
|
+
}
|
|
43130
|
+
function finishOnboarding(outcome) {
|
|
43131
|
+
saveDemoJson(join21(demoDirectory(), "onboarding.json"), { outcome });
|
|
43132
|
+
}
|
|
43133
|
+
function pendingRuns() {
|
|
43134
|
+
const path9 = join21(demoDirectory(), "runs");
|
|
43135
|
+
if (!existsSync13(path9)) return [];
|
|
43136
|
+
return readdirSync5(path9).filter((name) => name.endsWith(".json") && RUN_ID.test(name.slice(0, -5))).map((name) => name.slice(0, -5)).filter((id) => !["completed", "skipped"].includes(readRun(id).stage));
|
|
43137
|
+
}
|
|
43138
|
+
function exclusionPath(key) {
|
|
43139
|
+
if (!/^[0-9a-f]{64}$/u.test(key)) throw new Error("invalid demo session identity");
|
|
43140
|
+
return join21(demoDirectory(), "excluded-sessions", `${key}.json`);
|
|
43141
|
+
}
|
|
43142
|
+
|
|
43143
|
+
// src/demo/sandbox.ts
|
|
43144
|
+
var decisionBytes = (adopted) => `${JSON.stringify(adopted ? SAMPLE_DECISIONS : SAMPLE_DECISIONS.slice(0, 1), null, 2)}
|
|
43145
|
+
`;
|
|
43146
|
+
function allowedFiles(run) {
|
|
43147
|
+
return {
|
|
43148
|
+
".owner": [run.id],
|
|
43149
|
+
"note.md": [SAMPLE_NOTE],
|
|
43150
|
+
"decisions.json": [decisionBytes(false), decisionBytes(true)],
|
|
43151
|
+
...Object.fromEntries(Object.entries(SAMPLE_FILES).map(([name, value]) => [name, [value]])),
|
|
43152
|
+
"service.ts": [SAMPLE_FILES["service.ts"], WARNING_EDIT],
|
|
43153
|
+
"orders.ts": [SAMPLE_FILES["orders.ts"], REPOSITORY_EDIT]
|
|
43154
|
+
};
|
|
43155
|
+
}
|
|
43156
|
+
function inspectSandbox(run) {
|
|
43157
|
+
const sandbox = run.sandbox;
|
|
43158
|
+
if (!sandbox || dirname11(sandbox.path) !== realpathSync5(tmpdir()) || !basename4(sandbox.path).startsWith("prim-demo-")) {
|
|
43159
|
+
throw new Error("invalid demo sandbox ownership");
|
|
43160
|
+
}
|
|
43161
|
+
const stat = lstatSync9(sandbox.path);
|
|
43162
|
+
if (!stat.isDirectory() || stat.dev !== sandbox.device || stat.ino !== sandbox.inode) {
|
|
43163
|
+
throw new Error(`demo sandbox changed; retained ${sandbox.path}`);
|
|
43164
|
+
}
|
|
43165
|
+
const allowed = allowedFiles(run);
|
|
43166
|
+
for (const name of readdirSync6(sandbox.path)) {
|
|
43167
|
+
const path9 = join22(sandbox.path, name);
|
|
43168
|
+
const file = lstatSync9(path9);
|
|
43169
|
+
if (!Object.hasOwn(allowed, name) || !file.isFile() || file.nlink !== 1 || file.size > 16384 || !allowed[name].includes(readFileSync17(path9, "utf8"))) {
|
|
43170
|
+
throw new Error(`unexpected demo contents; retained ${sandbox.path}`);
|
|
43171
|
+
}
|
|
43172
|
+
}
|
|
43173
|
+
return sandbox.path;
|
|
43174
|
+
}
|
|
43175
|
+
function createSandbox(run) {
|
|
43176
|
+
if (!run.sandbox) {
|
|
43177
|
+
const path9 = mkdtempSync3(join22(realpathSync5(tmpdir()), "prim-demo-"));
|
|
43178
|
+
const stat = lstatSync9(path9);
|
|
43179
|
+
run.sandbox = { path: path9, device: stat.dev, inode: stat.ino };
|
|
43180
|
+
saveRun(run);
|
|
43181
|
+
}
|
|
43182
|
+
const root = inspectSandbox(run);
|
|
43183
|
+
for (const [name, content] of Object.entries({
|
|
43184
|
+
".owner": run.id,
|
|
43185
|
+
"note.md": SAMPLE_NOTE,
|
|
43186
|
+
...SAMPLE_FILES,
|
|
43187
|
+
"decisions.json": decisionBytes(false)
|
|
43188
|
+
})) {
|
|
43189
|
+
const path9 = join22(root, name);
|
|
43190
|
+
if (!existsSync14(path9)) atomicWriteFile(path9, content, { mode: 384 });
|
|
43191
|
+
}
|
|
43192
|
+
}
|
|
43193
|
+
function writeSample(run, name, bytes) {
|
|
43194
|
+
const root = inspectSandbox(run);
|
|
43195
|
+
if (!allowedFiles(run)[name].includes(bytes)) throw new Error("unsupported demo edit");
|
|
43196
|
+
atomicWriteFile(join22(root, name), bytes, { mode: 384 });
|
|
43197
|
+
}
|
|
43198
|
+
function readSample(run, name) {
|
|
43199
|
+
return readFileSync17(join22(inspectSandbox(run), name), "utf8");
|
|
43200
|
+
}
|
|
43201
|
+
function cleanSandbox(run) {
|
|
43202
|
+
if (!run.sandbox) return;
|
|
43203
|
+
try {
|
|
43204
|
+
lstatSync9(run.sandbox.path);
|
|
43205
|
+
} catch (error) {
|
|
43206
|
+
if (error.code !== "ENOENT") throw error;
|
|
43207
|
+
run.sandbox = void 0;
|
|
42941
43208
|
return;
|
|
42942
43209
|
}
|
|
42943
|
-
|
|
42944
|
-
|
|
42945
|
-
|
|
42946
|
-
|
|
43210
|
+
const root = inspectSandbox(run);
|
|
43211
|
+
for (const name of readdirSync6(root)) {
|
|
43212
|
+
inspectSandbox(run);
|
|
43213
|
+
unlinkSync5(join22(root, name));
|
|
43214
|
+
}
|
|
43215
|
+
rmdirSync(root);
|
|
43216
|
+
run.sandbox = void 0;
|
|
43217
|
+
}
|
|
43218
|
+
|
|
43219
|
+
// src/commands/demo.ts
|
|
43220
|
+
var intro = "SIMULATED TOUR \u2014 fictional Decisions and scripted verdicts; no live ingestion or enforcement check.";
|
|
43221
|
+
var handoff = "Sample files removed. Next: ask your agent to propose one real Decision from your project's shared memory for your individual approval.";
|
|
43222
|
+
var captureNotice = "Passive Decision capture is excluded for the rest of this agent session, including resumed use. Start a new session for normal capture. Explicitly approved real Decisions can still be created.";
|
|
43223
|
+
var completionReceipt = [
|
|
43224
|
+
"Extracted a Decision with supporting evidence",
|
|
43225
|
+
"Adopted a Decision with your confirmation",
|
|
43226
|
+
"Surfaced a warning and allowed the edit",
|
|
43227
|
+
"Refused a conflicting write",
|
|
43228
|
+
"Applied the compliant implementation"
|
|
43229
|
+
];
|
|
43230
|
+
function resultFor2(run) {
|
|
43231
|
+
const action = run.stage === "prepared" ? "start" : run.stage === "proposal" ? "confirm" : "resolve";
|
|
43232
|
+
const done = run.stage === "completed" || run.stage === "skipped";
|
|
43233
|
+
return {
|
|
43234
|
+
simulated: true,
|
|
43235
|
+
runId: run.id,
|
|
43236
|
+
stage: run.stage,
|
|
43237
|
+
...done ? { message: handoff, nextAction: `prim welcome${run.binding ? " --capture-excluded" : ""}` } : {
|
|
43238
|
+
nextAction: demoCommand(run, action, action === "resolve" ? "repository" : void 0),
|
|
43239
|
+
skipAction: demoCommand(run, "skip")
|
|
43240
|
+
},
|
|
43241
|
+
...run.sandbox ? { sandbox: run.sandbox.path } : {},
|
|
43242
|
+
...run.stage === "conflict" ? { retryAction: demoCommand(run, "resolve", "local-storage") } : {}
|
|
43243
|
+
};
|
|
43244
|
+
}
|
|
43245
|
+
function demoTrustGuidance(agent) {
|
|
43246
|
+
if (agent === "codex")
|
|
43247
|
+
return "Trust the installed prim hooks with /hooks in Codex, then retry the exact nextAction.";
|
|
43248
|
+
if (agent === "hermes")
|
|
43249
|
+
return "Approve the installed prim hooks when Hermes prompts, then retry the exact nextAction.";
|
|
43250
|
+
if (agent === "cursor")
|
|
43251
|
+
return "Trust this Cursor workspace and activate its installed hooks, then retry the exact nextAction.";
|
|
43252
|
+
return "Activate the installed prim hooks in your agent, then retry the exact nextAction.";
|
|
43253
|
+
}
|
|
43254
|
+
function consumeAcknowledgment(run, action, choice) {
|
|
43255
|
+
if (run.terminal) return Boolean(process.stdin.isTTY && process.stderr.isTTY);
|
|
43256
|
+
const ack = run.acknowledgment;
|
|
43257
|
+
run.acknowledgment = void 0;
|
|
43258
|
+
saveRun(run);
|
|
43259
|
+
if (!run.binding || !ack || ack.command !== demoCommand(run, action, choice)) return false;
|
|
43260
|
+
const age = Date.now() - ack.at;
|
|
43261
|
+
if (!Number.isFinite(age) || age < 0 || age > 3e4) return false;
|
|
43262
|
+
try {
|
|
43263
|
+
const exclusion = readDemoJson(exclusionPath(run.binding));
|
|
43264
|
+
return typeof exclusion.runId === "string" && RUN_ID.test(exclusion.runId);
|
|
43265
|
+
} catch {
|
|
43266
|
+
return false;
|
|
42947
43267
|
}
|
|
42948
43268
|
}
|
|
42949
|
-
function
|
|
42950
|
-
const
|
|
42951
|
-
|
|
42952
|
-
const
|
|
42953
|
-
|
|
42954
|
-
|
|
42955
|
-
|
|
43269
|
+
function narrateDecision(index) {
|
|
43270
|
+
const item = SAMPLE_DECISIONS[index];
|
|
43271
|
+
const status = index === 1 ? "proposed adoption, awaiting confirmation" : item.stage;
|
|
43272
|
+
const source = index === 1 ? "Fictional authoring proposal" : item.source;
|
|
43273
|
+
process.stderr.write(
|
|
43274
|
+
`
|
|
43275
|
+
Decision: ${item.decision}
|
|
43276
|
+
Status: ${status} (sample)
|
|
43277
|
+
Source: ${source}
|
|
43278
|
+
Rationale: ${item.rationale}
|
|
43279
|
+
Scope: ${item.files.join(", ")}
|
|
43280
|
+
Alternatives rejected: ${item.alternativesRejected.join("; ")}
|
|
43281
|
+
`
|
|
43282
|
+
);
|
|
43283
|
+
if (index === 0) {
|
|
43284
|
+
const extracted = SAMPLE_DECISIONS[0];
|
|
43285
|
+
process.stderr.write(
|
|
43286
|
+
`Source evidence:
|
|
43287
|
+
${extracted.evidence.map((quote2) => ` "${quote2}"`).join("\n")}
|
|
43288
|
+
Scope basis: ${extracted.scopeBasis}
|
|
43289
|
+
`
|
|
43290
|
+
);
|
|
43291
|
+
}
|
|
43292
|
+
}
|
|
43293
|
+
function narrateBlockedAttempt(unchanged) {
|
|
43294
|
+
process.stderr.write(`
|
|
43295
|
+
${bold(color("BLOCKED \u2014 file unchanged (simulated)", "red"))}
|
|
43296
|
+
`);
|
|
43297
|
+
process.stderr.write(
|
|
43298
|
+
`Attempt: save the order with localStorage.setItem(...).
|
|
43299
|
+
Decision (adopted sample): ${SAMPLE_DECISIONS[1].decision}
|
|
43300
|
+
Conflict: direct storage bypasses the shared repository and its validation.
|
|
43301
|
+
Outcome: this scenario refuses the proposed write.
|
|
43302
|
+
`
|
|
43303
|
+
);
|
|
43304
|
+
process.stderr.write(createPatch("orders.ts (refused proposal)", unchanged, BLOCKED_EDIT));
|
|
43305
|
+
process.stderr.write(
|
|
43306
|
+
`Proof: orders.ts is unchanged. Actual file:
|
|
43307
|
+
${unchanged}
|
|
43308
|
+
Next: save through orders.save(...) to preserve repository validation.
|
|
43309
|
+
`
|
|
43310
|
+
);
|
|
43311
|
+
}
|
|
43312
|
+
function narrateCompletion(run) {
|
|
43313
|
+
process.stderr.write(`
|
|
43314
|
+
${bold(color("WALKTHROUGH COMPLETE \u2014 simulated", "green"))}
|
|
43315
|
+
`);
|
|
43316
|
+
process.stderr.write(`${completionReceipt.map((item) => `\u2713 ${item}`).join("\n")}
|
|
43317
|
+
`);
|
|
43318
|
+
process.stderr.write(`${handoff}
|
|
43319
|
+
${run.terminal ? "" : `${captureNotice}
|
|
43320
|
+
`}`);
|
|
43321
|
+
}
|
|
43322
|
+
function advanceDemo(id, action, choice) {
|
|
43323
|
+
return lockRun(id, (run) => {
|
|
43324
|
+
if (action === "skip") {
|
|
43325
|
+
cleanSandbox(run);
|
|
43326
|
+
run.stage = "skipped";
|
|
43327
|
+
saveRun(run);
|
|
43328
|
+
finishOnboarding("skipped");
|
|
43329
|
+
process.stderr.write(`[prim] ${handoff}
|
|
43330
|
+
`);
|
|
43331
|
+
if (run.binding) process.stderr.write(`${captureNotice}
|
|
43332
|
+
`);
|
|
43333
|
+
return resultFor2(run);
|
|
43334
|
+
}
|
|
43335
|
+
if (!consumeAcknowledgment(run, action, choice)) {
|
|
43336
|
+
const message = `Tour pending: session isolation has not been acknowledged. ${demoTrustGuidance(run.agent)}`;
|
|
43337
|
+
process.stderr.write(`[prim] ${message}
|
|
43338
|
+
`);
|
|
43339
|
+
return {
|
|
43340
|
+
...resultFor2(run),
|
|
43341
|
+
stage: "pending",
|
|
43342
|
+
message,
|
|
43343
|
+
nextAction: demoCommand(run, action, choice)
|
|
43344
|
+
};
|
|
43345
|
+
}
|
|
43346
|
+
if (action === "confirm" && run.stage === "prepared") {
|
|
43347
|
+
throw new Error("start the demo before confirming its proposal");
|
|
43348
|
+
}
|
|
43349
|
+
if (action === "resolve" && (run.stage === "prepared" || run.stage === "proposal")) {
|
|
43350
|
+
throw new Error("confirm the sample Decision before resolving");
|
|
42956
43351
|
}
|
|
42957
|
-
let sample;
|
|
42958
43352
|
try {
|
|
42959
|
-
|
|
42960
|
-
|
|
42961
|
-
if (
|
|
42962
|
-
|
|
43353
|
+
process.stderr.write(`${bold(intro)}
|
|
43354
|
+
`);
|
|
43355
|
+
if (!run.terminal && action === "start") process.stderr.write(`${captureNotice}
|
|
43356
|
+
`);
|
|
43357
|
+
if (run.stage === "completed") {
|
|
43358
|
+
narrateCompletion(run);
|
|
43359
|
+
return { ...resultFor2(run), receipt: completionReceipt };
|
|
43360
|
+
}
|
|
43361
|
+
if (run.stage === "skipped") return resultFor2(run);
|
|
43362
|
+
if (action === "start") {
|
|
43363
|
+
if (run.stage === "prepared") {
|
|
43364
|
+
createSandbox(run);
|
|
43365
|
+
run.stage = "proposal";
|
|
43366
|
+
saveRun(run);
|
|
43367
|
+
}
|
|
43368
|
+
if (run.stage === "proposal") {
|
|
43369
|
+
process.stderr.write(
|
|
43370
|
+
`
|
|
43371
|
+
${bold("YOUR MISSION: add order saving")}
|
|
43372
|
+
Your fictional team discussed how this should work. Watch that context become Decisions, then guide an agent's implementation.
|
|
43373
|
+
Local simulation \xB7 fictional examples \xB7 disposable files
|
|
43374
|
+
`
|
|
43375
|
+
);
|
|
43376
|
+
process.stderr.write(`
|
|
43377
|
+
Sample ingestion (scripted extraction):
|
|
43378
|
+
${SAMPLE_NOTE}
|
|
43379
|
+
`);
|
|
43380
|
+
process.stderr.write(`
|
|
43381
|
+
${bold(color("DECISION EXTRACTED \u2014 simulated", "green"))}
|
|
43382
|
+
`);
|
|
43383
|
+
narrateDecision(0);
|
|
43384
|
+
process.stderr.write("The choice, its reason, and its source now travel together.\n");
|
|
43385
|
+
process.stderr.write("\nNow explicitly author another sample Decision:\n");
|
|
43386
|
+
narrateDecision(1);
|
|
43387
|
+
process.stderr.write("Confirm this fictional Decision to adopt it, or skip the tour.\n");
|
|
43388
|
+
}
|
|
43389
|
+
return {
|
|
43390
|
+
...resultFor2(run),
|
|
43391
|
+
decisions: SAMPLE_DECISIONS.slice(0, run.stage === "proposal" ? 1 : 2)
|
|
43392
|
+
};
|
|
42963
43393
|
}
|
|
42964
|
-
|
|
43394
|
+
if (action === "confirm") {
|
|
43395
|
+
const before2 = SAMPLE_FILES["service.ts"];
|
|
43396
|
+
if (run.stage === "proposal") {
|
|
43397
|
+
writeSample(run, "decisions.json", decisionBytes(true));
|
|
43398
|
+
writeSample(run, "service.ts", WARNING_EDIT);
|
|
43399
|
+
run.stage = "conflict";
|
|
43400
|
+
saveRun(run);
|
|
43401
|
+
process.stderr.write(
|
|
43402
|
+
`
|
|
43403
|
+
${bold(color("SAMPLE DECISION ADOPTED \u2014 simulated", "green"))}
|
|
43404
|
+
${SAMPLE_DECISIONS[1].decision}
|
|
43405
|
+
Your confirmation changed this proposal into an adopted sample Decision.
|
|
43406
|
+
`
|
|
43407
|
+
);
|
|
43408
|
+
}
|
|
43409
|
+
const after2 = readSample(run, "service.ts");
|
|
43410
|
+
const unchanged = readSample(run, "orders.ts");
|
|
43411
|
+
process.stderr.write(`
|
|
43412
|
+
${bold(color("WARNING \u2014 edit allowed (simulated)", "yellow"))}
|
|
43413
|
+
`);
|
|
43414
|
+
process.stderr.write(
|
|
43415
|
+
`Attempt: call fetch("/orders") directly.
|
|
43416
|
+
Decision (provisional sample): ${SAMPLE_DECISIONS[0].decision}
|
|
43417
|
+
Conflict: direct fetch bypasses consistent retries and request tracing.
|
|
43418
|
+
Outcome: this scenario surfaces the conflict and allows the edit.
|
|
43419
|
+
`
|
|
43420
|
+
);
|
|
43421
|
+
process.stderr.write(createPatch("service.ts", before2, after2));
|
|
43422
|
+
process.stderr.write(
|
|
43423
|
+
`Proof: service.ts ${before2 === after2 ? "already matches the shared client" : "changed, as shown above"}.
|
|
43424
|
+
Next: restore the shared HTTP client for consistent retries and tracing.
|
|
43425
|
+
`
|
|
43426
|
+
);
|
|
43427
|
+
narrateBlockedAttempt(unchanged);
|
|
43428
|
+
process.stderr.write(
|
|
43429
|
+
"\nChoose the shared repository correction, or retry direct storage.\nThese verdicts are scripted for this scenario. Live outcomes depend on Decision state and agent behavior; Claude may ask permission where other agents block.\n"
|
|
43430
|
+
);
|
|
43431
|
+
return {
|
|
43432
|
+
...resultFor2(run),
|
|
43433
|
+
decisions: SAMPLE_DECISIONS,
|
|
43434
|
+
evidence: {
|
|
43435
|
+
warning: { before: before2, after: after2 },
|
|
43436
|
+
block: {
|
|
43437
|
+
before: unchanged,
|
|
43438
|
+
proposed: BLOCKED_EDIT,
|
|
43439
|
+
after: readSample(run, "orders.ts")
|
|
43440
|
+
}
|
|
43441
|
+
}
|
|
43442
|
+
};
|
|
43443
|
+
}
|
|
43444
|
+
if (choice !== "repository" && choice !== "local-storage")
|
|
43445
|
+
throw new Error("choose repository or local-storage");
|
|
43446
|
+
if (choice === "local-storage") {
|
|
43447
|
+
const unchanged = readSample(run, "orders.ts");
|
|
43448
|
+
narrateBlockedAttempt(unchanged);
|
|
43449
|
+
return { ...resultFor2(run), evidence: { unchanged } };
|
|
43450
|
+
}
|
|
43451
|
+
const before = readSample(run, "service.ts");
|
|
43452
|
+
const ordersBefore = readSample(run, "orders.ts");
|
|
43453
|
+
writeSample(run, "service.ts", SAMPLE_FILES["service.ts"]);
|
|
43454
|
+
writeSample(run, "orders.ts", REPOSITORY_EDIT);
|
|
43455
|
+
const after = readSample(run, "service.ts");
|
|
43456
|
+
const orders = readSample(run, "orders.ts");
|
|
43457
|
+
process.stderr.write(createPatch("service.ts", before, after));
|
|
43458
|
+
process.stderr.write(createPatch("orders.ts", ordersBefore, orders));
|
|
43459
|
+
process.stderr.write(
|
|
43460
|
+
`${bold(color("PASS \u2014 compliant implementation written (simulated)", "green"))}
|
|
43461
|
+
Order saving now uses the shared repository. Service calls use the shared HTTP client.
|
|
43462
|
+
The requested change landed while preserving both sample Decisions.
|
|
43463
|
+
`
|
|
43464
|
+
);
|
|
43465
|
+
cleanSandbox(run);
|
|
43466
|
+
run.stage = "completed";
|
|
43467
|
+
saveRun(run);
|
|
43468
|
+
finishOnboarding("completed");
|
|
43469
|
+
narrateCompletion(run);
|
|
43470
|
+
return {
|
|
43471
|
+
...resultFor2(run),
|
|
43472
|
+
receipt: completionReceipt,
|
|
43473
|
+
evidence: {
|
|
43474
|
+
correction: { before, after },
|
|
43475
|
+
orders,
|
|
43476
|
+
orderCorrection: { before: ordersBefore, after: orders }
|
|
43477
|
+
}
|
|
43478
|
+
};
|
|
43479
|
+
} catch (error) {
|
|
43480
|
+
try {
|
|
43481
|
+
cleanSandbox(run);
|
|
43482
|
+
run.stage = "prepared";
|
|
43483
|
+
saveRun(run);
|
|
43484
|
+
} catch {
|
|
43485
|
+
}
|
|
43486
|
+
throw error;
|
|
42965
43487
|
}
|
|
42966
|
-
|
|
42967
|
-
|
|
42968
|
-
|
|
42969
|
-
|
|
42970
|
-
|
|
43488
|
+
});
|
|
43489
|
+
}
|
|
43490
|
+
function parseDemoAgent(value) {
|
|
43491
|
+
if (value === "claude") return "claude_code";
|
|
43492
|
+
if (value === void 0 || ["claude_code", "codex", "cursor", "hermes"].includes(value))
|
|
43493
|
+
return value;
|
|
43494
|
+
throw new Error("expected --agent claude, codex, cursor, or hermes");
|
|
43495
|
+
}
|
|
43496
|
+
function reportError(error) {
|
|
43497
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43498
|
+
process.stderr.write(`[prim] demo: ${message}
|
|
43499
|
+
`);
|
|
43500
|
+
printJson({ simulated: true, stage: "error", message });
|
|
43501
|
+
process.exitCode = 1;
|
|
43502
|
+
}
|
|
43503
|
+
function registerDemoCommands(program3) {
|
|
43504
|
+
const demo = program3.command("demo").description("Try a fictional, local Decision and enforcement walkthrough").option("--agent <agent>", "calling agent; requires hook acknowledgment before samples").action(async (options, command) => {
|
|
43505
|
+
try {
|
|
43506
|
+
const agent = parseDemoAgent(options.agent);
|
|
43507
|
+
const terminal = !agent && !isNonInteractive(command.optsWithGlobals()) && Boolean(process.stdin.isTTY && process.stderr.isTTY) && !process.env.CLAUDECODE && !process.env.CODEX_THREAD_ID && !process.env.CURSOR_AGENT && !process.env.HERMES_INTERACTIVE;
|
|
43508
|
+
const recovery = pendingRuns().map(
|
|
43509
|
+
(id) => lockRun(id, (run2) => ({ runId: id, skipAction: demoCommand(run2, "skip") }))
|
|
43510
|
+
);
|
|
43511
|
+
const run = prepareRun(agent, terminal);
|
|
43512
|
+
if (!terminal) {
|
|
43513
|
+
process.stderr.write(
|
|
43514
|
+
"[prim] Preparing the simulated tour. Run nextAction exactly, as a standalone shell command. No sample content is shown until session isolation is acknowledged.\n"
|
|
43515
|
+
);
|
|
43516
|
+
if (recovery.length)
|
|
43517
|
+
process.stderr.write(
|
|
43518
|
+
"[prim] Earlier unfinished tours are listed in recoverableRuns; use their skipAction to clean up.\n"
|
|
43519
|
+
);
|
|
43520
|
+
printJson({ ...resultFor2(run), recoverableRuns: recovery });
|
|
43521
|
+
return;
|
|
43522
|
+
}
|
|
43523
|
+
advanceDemo(run.id, "start");
|
|
43524
|
+
if (!await askConfirmation("Adopt this fictional Decision?", process.stderr)) {
|
|
43525
|
+
printJson(advanceDemo(run.id, "skip"));
|
|
43526
|
+
return;
|
|
43527
|
+
}
|
|
43528
|
+
advanceDemo(run.id, "confirm");
|
|
43529
|
+
if (await askConfirmation("Apply the shared repository correction?", process.stderr)) {
|
|
43530
|
+
printJson(advanceDemo(run.id, "resolve", "repository"));
|
|
43531
|
+
} else {
|
|
43532
|
+
printJson(advanceDemo(run.id, "skip"));
|
|
43533
|
+
}
|
|
43534
|
+
} catch (error) {
|
|
43535
|
+
reportError(error);
|
|
43536
|
+
}
|
|
43537
|
+
});
|
|
43538
|
+
for (const action of ["start", "confirm", "resolve", "skip"]) {
|
|
43539
|
+
const subcommand = demo.command(`${action} ${action === "skip" ? "[runId]" : "<runId>"}`);
|
|
43540
|
+
if (action === "resolve")
|
|
43541
|
+
subcommand.requiredOption("--choice <choice>", "repository or local-storage");
|
|
43542
|
+
subcommand.action((id, options) => {
|
|
43543
|
+
try {
|
|
43544
|
+
if (action === "skip" && !id) {
|
|
43545
|
+
finishOnboarding("skipped");
|
|
43546
|
+
printJson({
|
|
43547
|
+
simulated: true,
|
|
43548
|
+
stage: "skipped",
|
|
43549
|
+
message: "Tour skipped. Run prim welcome for real Decision seeding."
|
|
43550
|
+
});
|
|
43551
|
+
return;
|
|
43552
|
+
}
|
|
43553
|
+
if (action === "resolve" && options.choice !== "repository" && options.choice !== "local-storage") {
|
|
43554
|
+
throw new Error("choose repository or local-storage");
|
|
43555
|
+
}
|
|
43556
|
+
printJson(advanceDemo(id, action, options.choice));
|
|
43557
|
+
} catch (error) {
|
|
43558
|
+
reportError(error);
|
|
43559
|
+
}
|
|
42971
43560
|
});
|
|
42972
43561
|
}
|
|
42973
|
-
return out;
|
|
42974
|
-
}
|
|
42975
|
-
function pendingJournalStats() {
|
|
42976
|
-
const perKindBytes = Math.floor(JOURNAL_STATS_SAMPLE_BYTES / 2);
|
|
42977
|
-
const perKindFiles = Math.floor(PENDING_STATS_MAX_FILES / 2);
|
|
42978
|
-
const live = bucketStats({ sampleBytes: perKindBytes, maxFiles: perKindFiles });
|
|
42979
|
-
const stranded = listFlushing({ sampleBytes: perKindBytes, maxFiles: perKindFiles });
|
|
42980
|
-
const timestamps = [...live, ...stranded].map((entry) => entry.oldestCapturedAt).filter((value) => value !== void 0);
|
|
42981
|
-
const liveSampled = live.some((entry) => entry.sampled) || live.length >= perKindFiles;
|
|
42982
|
-
const strandedSampled = stranded.some((entry) => entry.sampled) || stranded.length >= perKindFiles;
|
|
42983
|
-
return {
|
|
42984
|
-
pendingCount: live.reduce((count, entry) => count + entry.lineCount, 0) + stranded.reduce((count, entry) => count + entry.lineCount, 0),
|
|
42985
|
-
oldestPendingAt: timestamps.length > 0 ? Math.min(...timestamps) : void 0,
|
|
42986
|
-
strandedCount: stranded.reduce((count, entry) => count + entry.lineCount, 0),
|
|
42987
|
-
strandedFileCount: stranded.length,
|
|
42988
|
-
sampled: liveSampled || strandedSampled,
|
|
42989
|
-
strandedSampled
|
|
42990
|
-
};
|
|
42991
43562
|
}
|
|
42992
43563
|
|
|
42993
|
-
// src/commands/
|
|
42994
|
-
import { existsSync as
|
|
42995
|
-
import { homedir as homedir9 } from "os";
|
|
42996
|
-
import { join as join22 } from "path";
|
|
43564
|
+
// src/commands/doctor.ts
|
|
43565
|
+
import { existsSync as existsSync18 } from "fs";
|
|
42997
43566
|
|
|
42998
|
-
//
|
|
42999
|
-
var
|
|
43000
|
-
var
|
|
43001
|
-
var
|
|
43002
|
-
|
|
43003
|
-
|
|
43004
|
-
var SEQ = /* @__PURE__ */ Symbol.for("yaml.seq");
|
|
43005
|
-
var NODE_TYPE = /* @__PURE__ */ Symbol.for("yaml.node.type");
|
|
43006
|
-
var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
|
|
43007
|
-
var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
|
|
43008
|
-
var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
|
|
43009
|
-
var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
|
|
43010
|
-
var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
|
|
43011
|
-
var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
|
|
43012
|
-
function isCollection(node) {
|
|
43013
|
-
if (node && typeof node === "object")
|
|
43014
|
-
switch (node[NODE_TYPE]) {
|
|
43015
|
-
case MAP:
|
|
43016
|
-
case SEQ:
|
|
43017
|
-
return true;
|
|
43018
|
-
}
|
|
43019
|
-
return false;
|
|
43567
|
+
// src/decisions/feedback.ts
|
|
43568
|
+
var FEEDBACK_PROTOCOL_VERSION = 2;
|
|
43569
|
+
var FEEDBACK_MIN_PROTOCOL_VERSION = 1;
|
|
43570
|
+
var STATUS_PATH = "/api/cli/decisions/feedback/status";
|
|
43571
|
+
function isRecord2(value) {
|
|
43572
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43020
43573
|
}
|
|
43021
|
-
function
|
|
43022
|
-
|
|
43023
|
-
switch (node[NODE_TYPE]) {
|
|
43024
|
-
case ALIAS:
|
|
43025
|
-
case MAP:
|
|
43026
|
-
case SCALAR:
|
|
43027
|
-
case SEQ:
|
|
43028
|
-
return true;
|
|
43029
|
-
}
|
|
43030
|
-
return false;
|
|
43574
|
+
function isSupportedProtocolVersion(value) {
|
|
43575
|
+
return Number.isSafeInteger(value) && Number(value) >= FEEDBACK_MIN_PROTOCOL_VERSION && Number(value) <= FEEDBACK_PROTOCOL_VERSION;
|
|
43031
43576
|
}
|
|
43032
|
-
|
|
43033
|
-
|
|
43034
|
-
|
|
43035
|
-
|
|
43036
|
-
|
|
43037
|
-
|
|
43577
|
+
function parseFeedbackCapability(value) {
|
|
43578
|
+
if (!isRecord2(value) || !isSupportedProtocolVersion(value.protocolVersion)) return void 0;
|
|
43579
|
+
if (value.status === "available") return { status: "available" };
|
|
43580
|
+
if (value.status === "unavailable" && value.reason === "organization_unbound") {
|
|
43581
|
+
return { status: "unavailable", reason: "organization_unbound" };
|
|
43582
|
+
}
|
|
43583
|
+
return void 0;
|
|
43584
|
+
}
|
|
43585
|
+
async function fetchFeedbackCapability(signal, client = getClient()) {
|
|
43586
|
+
const result = parseFeedbackCapability(await client.get(STATUS_PATH, { signal }));
|
|
43587
|
+
if (!result) throw new Error("server returned an unsupported decision-feedback contract");
|
|
43588
|
+
return result;
|
|
43589
|
+
}
|
|
43590
|
+
|
|
43591
|
+
// src/protocol/decision-lifecycle.ts
|
|
43592
|
+
var DECISION_LIFECYCLE_PROTOCOL_VERSION = 2;
|
|
43593
|
+
|
|
43594
|
+
// src/journal-organization.ts
|
|
43595
|
+
var ORGANIZATION_BINDING_VERSION = 1;
|
|
43596
|
+
var ORGANIZATION_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
43597
|
+
var UNBOUND_BUCKET = "_unbound";
|
|
43598
|
+
var InvalidJournalEnvelopeError = class extends Error {
|
|
43599
|
+
constructor() {
|
|
43600
|
+
super("Invalid locally journaled move");
|
|
43601
|
+
this.name = "InvalidJournalEnvelopeError";
|
|
43602
|
+
}
|
|
43603
|
+
};
|
|
43604
|
+
function safeOrganizationId(value) {
|
|
43605
|
+
return typeof value === "string" && ORGANIZATION_ID_RE.test(value);
|
|
43606
|
+
}
|
|
43607
|
+
function isCaptureAuthorityKind(value) {
|
|
43608
|
+
return value === "workos" || value === "service_token";
|
|
43609
|
+
}
|
|
43610
|
+
function parseOrganizationBinding(value) {
|
|
43611
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
43612
|
+
return { state: "server_contract_unavailable" };
|
|
43613
|
+
}
|
|
43614
|
+
const record3 = value;
|
|
43615
|
+
if (record3.authenticated !== true || record3.organizationBindingVersion !== ORGANIZATION_BINDING_VERSION || !isCaptureAuthorityKind(record3.captureAuthorityKind)) {
|
|
43616
|
+
return { state: "server_contract_unavailable" };
|
|
43617
|
+
}
|
|
43618
|
+
if (record3.organizationId === null && record3.workosOrganizationId === null) {
|
|
43619
|
+
return { state: "no_current_organization" };
|
|
43620
|
+
}
|
|
43621
|
+
if (safeOrganizationId(record3.organizationId) && record3.workosOrganizationId === null) {
|
|
43622
|
+
return { state: "organization_identity_unreconciled" };
|
|
43623
|
+
}
|
|
43624
|
+
if (!safeOrganizationId(record3.organizationId) || !safeOrganizationId(record3.workosOrganizationId)) {
|
|
43625
|
+
return { state: "server_contract_unavailable" };
|
|
43626
|
+
}
|
|
43627
|
+
return {
|
|
43628
|
+
state: "current",
|
|
43629
|
+
binding: {
|
|
43630
|
+
captureAuthorityKind: record3.captureAuthorityKind,
|
|
43631
|
+
organizationId: record3.organizationId,
|
|
43632
|
+
workosOrganizationId: record3.workosOrganizationId
|
|
43633
|
+
}
|
|
43634
|
+
};
|
|
43635
|
+
}
|
|
43636
|
+
function summarizeRetainedBuckets(retained) {
|
|
43637
|
+
const counts = /* @__PURE__ */ new Map();
|
|
43638
|
+
for (const item of retained) {
|
|
43639
|
+
counts.set(item.reason, (counts.get(item.reason) ?? 0) + 1);
|
|
43640
|
+
}
|
|
43641
|
+
return [...counts].sort(([left], [right]) => left.localeCompare(right)).map(([reason, count]) => `${reason}:${String(count)}`).join(", ");
|
|
43642
|
+
}
|
|
43643
|
+
function classifyJournalBuckets(buckets, binding) {
|
|
43644
|
+
const deliverableBuckets = /* @__PURE__ */ new Set();
|
|
43645
|
+
const retainedBuckets = [];
|
|
43646
|
+
for (const bucket of [...new Set(buckets)].sort()) {
|
|
43647
|
+
if (bucket === UNBOUND_BUCKET) {
|
|
43648
|
+
retainedBuckets.push({ bucket, reason: "unbound" });
|
|
43649
|
+
continue;
|
|
43650
|
+
}
|
|
43651
|
+
if (typeof binding === "string") {
|
|
43652
|
+
retainedBuckets.push({ bucket, reason: binding });
|
|
43653
|
+
continue;
|
|
43654
|
+
}
|
|
43655
|
+
if (bucket === binding.organizationId || bucket === binding.workosOrganizationId) {
|
|
43656
|
+
deliverableBuckets.add(bucket);
|
|
43657
|
+
} else {
|
|
43658
|
+
retainedBuckets.push({ bucket, reason: "organization_mismatch" });
|
|
43659
|
+
}
|
|
43660
|
+
}
|
|
43661
|
+
return { deliverableBuckets, retainedBuckets };
|
|
43662
|
+
}
|
|
43663
|
+
function buildOrganizationBoundMoveRequest(batch, binding) {
|
|
43664
|
+
const capturedOrganizationId = binding.captureAuthorityKind === "workos" ? binding.workosOrganizationId : binding.organizationId;
|
|
43665
|
+
const request2 = {
|
|
43666
|
+
batch: batch.map((move) => {
|
|
43667
|
+
if (typeof move !== "object" || move === null || Array.isArray(move)) {
|
|
43668
|
+
return move;
|
|
43669
|
+
}
|
|
43670
|
+
return {
|
|
43671
|
+
...move,
|
|
43672
|
+
envelopeVersion: 4,
|
|
43673
|
+
capturedOrganizationId,
|
|
43674
|
+
captureAuthorityKind: binding.captureAuthorityKind,
|
|
43675
|
+
decisionLifecycleProtocolVersion: DECISION_LIFECYCLE_PROTOCOL_VERSION
|
|
43676
|
+
};
|
|
43677
|
+
})
|
|
43678
|
+
};
|
|
43679
|
+
if (!isMoveIngestRequest(request2)) {
|
|
43680
|
+
throw new InvalidJournalEnvelopeError();
|
|
43681
|
+
}
|
|
43682
|
+
return request2;
|
|
43683
|
+
}
|
|
43684
|
+
async function inspectJournalDelivery(buckets, options = {}) {
|
|
43685
|
+
const bucketList = [...new Set(buckets)];
|
|
43686
|
+
let client;
|
|
43687
|
+
try {
|
|
43688
|
+
client = options.client ?? await (options.createClient ?? (() => getPinnedClient()))();
|
|
43689
|
+
} catch {
|
|
43690
|
+
return classifyJournalBuckets(bucketList, "identity_unavailable");
|
|
43691
|
+
}
|
|
43692
|
+
let parsed;
|
|
43693
|
+
try {
|
|
43694
|
+
parsed = parseOrganizationBinding(
|
|
43695
|
+
await client.get("/api/cli/auth/status", {
|
|
43696
|
+
signal: AbortSignal.timeout(1e4),
|
|
43697
|
+
quietRefresh: true
|
|
43698
|
+
})
|
|
43699
|
+
);
|
|
43700
|
+
} catch {
|
|
43701
|
+
return classifyJournalBuckets(bucketList, "identity_unavailable");
|
|
43702
|
+
}
|
|
43703
|
+
if (parsed.state !== "current") {
|
|
43704
|
+
return classifyJournalBuckets(bucketList, parsed.state);
|
|
43705
|
+
}
|
|
43706
|
+
return {
|
|
43707
|
+
client,
|
|
43708
|
+
binding: parsed.binding,
|
|
43709
|
+
...classifyJournalBuckets(bucketList, parsed.binding)
|
|
43710
|
+
};
|
|
43711
|
+
}
|
|
43712
|
+
|
|
43713
|
+
// src/journal.ts
|
|
43714
|
+
import {
|
|
43715
|
+
appendFileSync,
|
|
43716
|
+
closeSync as closeSync5,
|
|
43717
|
+
existsSync as existsSync16,
|
|
43718
|
+
fstatSync as fstatSync2,
|
|
43719
|
+
mkdirSync as mkdirSync11,
|
|
43720
|
+
openSync as openSync5,
|
|
43721
|
+
opendirSync,
|
|
43722
|
+
readFileSync as readFileSync19,
|
|
43723
|
+
readSync as readSync2,
|
|
43724
|
+
readdirSync as readdirSync8
|
|
43725
|
+
} from "fs";
|
|
43726
|
+
import { dirname as dirname13, join as join24 } from "path";
|
|
43727
|
+
|
|
43728
|
+
// src/drain-progress.ts
|
|
43729
|
+
import {
|
|
43730
|
+
chmodSync as chmodSync6,
|
|
43731
|
+
existsSync as existsSync15,
|
|
43732
|
+
readFileSync as readFileSync18,
|
|
43733
|
+
readdirSync as readdirSync7,
|
|
43734
|
+
rmSync as rmSync6,
|
|
43735
|
+
rmdirSync as rmdirSync2
|
|
43736
|
+
} from "fs";
|
|
43737
|
+
import { basename as basename5, dirname as dirname12, join as join23 } from "path";
|
|
43738
|
+
var DIRECTORY_MODE3 = 448;
|
|
43739
|
+
var FILE_MODE2 = 384;
|
|
43740
|
+
var DRAIN_PROGRESS_DIRNAME = "drain-progress";
|
|
43741
|
+
var CHECKPOINT_NAME = /^(.+)\.json(?:\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.tmp)?$/;
|
|
43742
|
+
function rotationIdentity(stat) {
|
|
43743
|
+
return { size: stat.size, ino: stat.ino, dev: stat.dev };
|
|
43744
|
+
}
|
|
43745
|
+
function drainProgressDirectory(flushingPath) {
|
|
43746
|
+
return join23(dirname12(flushingPath), DRAIN_PROGRESS_DIRNAME);
|
|
43747
|
+
}
|
|
43748
|
+
function drainProgressPath(flushingPath) {
|
|
43749
|
+
return join23(drainProgressDirectory(flushingPath), `${basename5(flushingPath)}.json`);
|
|
43750
|
+
}
|
|
43751
|
+
function isByteCount(value) {
|
|
43752
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
43753
|
+
}
|
|
43754
|
+
function drainResumeOffset(flushingPath, rotation) {
|
|
43755
|
+
let parsed;
|
|
43756
|
+
try {
|
|
43757
|
+
parsed = JSON.parse(readFileSync18(drainProgressPath(flushingPath), "utf8"));
|
|
43758
|
+
} catch {
|
|
43759
|
+
return 0;
|
|
43760
|
+
}
|
|
43761
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
43762
|
+
return 0;
|
|
43763
|
+
}
|
|
43764
|
+
const { v, offset, size, ino, dev } = parsed;
|
|
43765
|
+
if (v !== 2 || ino !== rotation.ino || dev !== rotation.dev || size !== rotation.size || !isByteCount(offset) || offset > rotation.size) {
|
|
43766
|
+
return 0;
|
|
43767
|
+
}
|
|
43768
|
+
return offset;
|
|
43769
|
+
}
|
|
43770
|
+
function writeDrainCheckpoint(flushingPath, checkpoint) {
|
|
43771
|
+
const directory = drainProgressDirectory(flushingPath);
|
|
43772
|
+
ensureDurableDirectory(directory, DIRECTORY_MODE3);
|
|
43773
|
+
chmodSync6(directory, DIRECTORY_MODE3);
|
|
43774
|
+
atomicWriteFile(drainProgressPath(flushingPath), `${JSON.stringify(checkpoint)}
|
|
43775
|
+
`, {
|
|
43776
|
+
mode: FILE_MODE2
|
|
43777
|
+
});
|
|
43778
|
+
}
|
|
43779
|
+
function removeEmptyDirectory(directory) {
|
|
43780
|
+
try {
|
|
43781
|
+
rmdirSync2(directory);
|
|
43782
|
+
} catch (error) {
|
|
43783
|
+
const code = error.code;
|
|
43784
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST") {
|
|
43785
|
+
throw error;
|
|
43786
|
+
}
|
|
43787
|
+
}
|
|
43788
|
+
}
|
|
43789
|
+
function removeDrainCheckpoint(flushingPath) {
|
|
43790
|
+
rmSync6(drainProgressPath(flushingPath), { force: true });
|
|
43791
|
+
removeEmptyDirectory(drainProgressDirectory(flushingPath));
|
|
43792
|
+
}
|
|
43793
|
+
function sweepOrphanedDrainCheckpoints(bucketDirectory) {
|
|
43794
|
+
const directory = join23(bucketDirectory, DRAIN_PROGRESS_DIRNAME);
|
|
43795
|
+
let names;
|
|
43796
|
+
try {
|
|
43797
|
+
names = readdirSync7(directory);
|
|
43798
|
+
} catch {
|
|
43799
|
+
return;
|
|
43800
|
+
}
|
|
43801
|
+
for (const name of names) {
|
|
43802
|
+
const rotation = CHECKPOINT_NAME.exec(name)?.[1];
|
|
43803
|
+
if (rotation === void 0 || existsSync15(join23(bucketDirectory, rotation))) {
|
|
43804
|
+
continue;
|
|
43805
|
+
}
|
|
43806
|
+
try {
|
|
43807
|
+
rmSync6(join23(directory, name), { force: true });
|
|
43808
|
+
} catch {
|
|
43809
|
+
}
|
|
43810
|
+
}
|
|
43811
|
+
try {
|
|
43812
|
+
removeEmptyDirectory(directory);
|
|
43813
|
+
} catch {
|
|
43814
|
+
}
|
|
43815
|
+
}
|
|
43816
|
+
|
|
43817
|
+
// src/journal.ts
|
|
43818
|
+
var JOURNAL_DIR = join24(primConfigDirectory(), "moves");
|
|
43819
|
+
var JOURNAL_BASENAME = "journal.ndjson";
|
|
43820
|
+
var JOURNAL_STATS_SAMPLE_BYTES = 64 * 1024;
|
|
43821
|
+
var PENDING_STATS_MAX_FILES = 128;
|
|
43822
|
+
function envSlug(apiUrl) {
|
|
43823
|
+
const slug = apiUrl.replace(/^https?:\/\//, "").replace(/[^a-zA-Z0-9._-]/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
|
|
43824
|
+
if (slug.length === 0 || slug === "." || slug === "..") {
|
|
43825
|
+
return "default";
|
|
43826
|
+
}
|
|
43827
|
+
return slug;
|
|
43828
|
+
}
|
|
43829
|
+
function currentEnvDir() {
|
|
43830
|
+
return join24(JOURNAL_DIR, envSlug(getSiteUrl()));
|
|
43831
|
+
}
|
|
43832
|
+
function parseMoves(content) {
|
|
43833
|
+
const moves = [];
|
|
43834
|
+
for (const line of content.split("\n")) {
|
|
43835
|
+
if (line.length === 0) {
|
|
43836
|
+
continue;
|
|
43837
|
+
}
|
|
43838
|
+
try {
|
|
43839
|
+
moves.push(JSON.parse(line));
|
|
43840
|
+
} catch {
|
|
43841
|
+
}
|
|
43842
|
+
}
|
|
43843
|
+
return moves;
|
|
43844
|
+
}
|
|
43845
|
+
function readMovesFromPath(path9) {
|
|
43846
|
+
if (!existsSync16(path9)) {
|
|
43847
|
+
return [];
|
|
43848
|
+
}
|
|
43849
|
+
return parseMoves(readFileSync19(path9, "utf-8"));
|
|
43850
|
+
}
|
|
43851
|
+
function listBuckets() {
|
|
43852
|
+
const out = [];
|
|
43853
|
+
const envDir = currentEnvDir();
|
|
43854
|
+
if (!existsSync16(envDir)) {
|
|
43855
|
+
return out;
|
|
43856
|
+
}
|
|
43857
|
+
for (const entry of readdirSync8(envDir, { withFileTypes: true })) {
|
|
43858
|
+
if (!entry.isDirectory()) {
|
|
43859
|
+
continue;
|
|
43860
|
+
}
|
|
43861
|
+
const path9 = join24(envDir, entry.name, JOURNAL_BASENAME);
|
|
43862
|
+
if (existsSync16(path9)) {
|
|
43863
|
+
out.push({ bucket: entry.name, path: path9 });
|
|
43864
|
+
}
|
|
43865
|
+
}
|
|
43866
|
+
return out;
|
|
43867
|
+
}
|
|
43868
|
+
var FLUSHING_PREFIX = `${JOURNAL_BASENAME}.flushing.`;
|
|
43869
|
+
function oldestCapturedAt(moves) {
|
|
43870
|
+
let oldest;
|
|
43871
|
+
for (const move of moves) {
|
|
43872
|
+
if (!Number.isFinite(move.capturedAt)) {
|
|
43873
|
+
continue;
|
|
43874
|
+
}
|
|
43875
|
+
oldest = oldest === void 0 ? move.capturedAt : Math.min(oldest, move.capturedAt);
|
|
43876
|
+
}
|
|
43877
|
+
return oldest;
|
|
43878
|
+
}
|
|
43879
|
+
function sampleJournalFile(path9, maxBytes = JOURNAL_STATS_SAMPLE_BYTES, options = {}) {
|
|
43880
|
+
const fd = openSync5(path9, "r");
|
|
43881
|
+
try {
|
|
43882
|
+
const initial = fstatSync2(fd);
|
|
43883
|
+
const start = options.fromDrainCheckpoint ? drainResumeOffset(path9, rotationIdentity(initial)) : 0;
|
|
43884
|
+
const target = Math.min(initial.size - start, Math.max(0, maxBytes));
|
|
43885
|
+
const buffer = Buffer.allocUnsafe(target);
|
|
43886
|
+
let sampledBytes = 0;
|
|
43887
|
+
while (sampledBytes < target) {
|
|
43888
|
+
const count = readSync2(fd, buffer, sampledBytes, target - sampledBytes, start + sampledBytes);
|
|
43889
|
+
if (count === 0) {
|
|
43890
|
+
break;
|
|
43891
|
+
}
|
|
43892
|
+
sampledBytes += count;
|
|
43893
|
+
}
|
|
43894
|
+
const stat = fstatSync2(fd);
|
|
43895
|
+
const sampled = stat.size - start > sampledBytes;
|
|
43896
|
+
let content = buffer.subarray(0, sampledBytes).toString("utf-8");
|
|
43897
|
+
if (sampled) {
|
|
43898
|
+
const lastNewline = content.lastIndexOf("\n");
|
|
43899
|
+
content = lastNewline === -1 ? "" : content.slice(0, lastNewline + 1);
|
|
43900
|
+
}
|
|
43901
|
+
const lines = content.split("\n").filter((line) => line.length > 0);
|
|
43902
|
+
const moves = parseMoves(content);
|
|
43903
|
+
return {
|
|
43904
|
+
sizeBytes: stat.size,
|
|
43905
|
+
pendingBytes: Math.max(0, stat.size - start),
|
|
43906
|
+
mtimeMs: stat.mtimeMs,
|
|
43907
|
+
lineCount: sampled && stat.size > 0 ? Math.max(1, lines.length) : lines.length,
|
|
43908
|
+
oldestCapturedAt: oldestCapturedAt(moves),
|
|
43909
|
+
sampled,
|
|
43910
|
+
sampledBytes
|
|
43911
|
+
};
|
|
43912
|
+
} finally {
|
|
43913
|
+
closeSync5(fd);
|
|
43914
|
+
}
|
|
43915
|
+
}
|
|
43916
|
+
function parseFlushingPid(name) {
|
|
43917
|
+
const segments = name.slice(FLUSHING_PREFIX.length).split(".");
|
|
43918
|
+
const last = segments.length >= 2 ? segments[segments.length - 1] : void 0;
|
|
43919
|
+
if (last === void 0 || !/^[0-9]+$/.test(last)) return void 0;
|
|
43920
|
+
const pid = Number(last);
|
|
43921
|
+
return Number.isSafeInteger(pid) && pid > 0 ? pid : void 0;
|
|
43922
|
+
}
|
|
43923
|
+
function listFlushingInDir(dir, bucket, options = {}) {
|
|
43924
|
+
if (!existsSync16(dir)) {
|
|
43925
|
+
return [];
|
|
43926
|
+
}
|
|
43927
|
+
const out = [];
|
|
43928
|
+
let remainingBytes = options.sampleBytes ?? JOURNAL_STATS_SAMPLE_BYTES;
|
|
43929
|
+
const maxFiles = options.maxFiles ?? Number.POSITIVE_INFINITY;
|
|
43930
|
+
const entries = opendirSync(dir);
|
|
43931
|
+
try {
|
|
43932
|
+
let entry = entries.readSync();
|
|
43933
|
+
while (entry && out.length < maxFiles) {
|
|
43934
|
+
if (!entry.isFile() || !entry.name.startsWith(FLUSHING_PREFIX)) {
|
|
43935
|
+
entry = entries.readSync();
|
|
43936
|
+
continue;
|
|
43937
|
+
}
|
|
43938
|
+
const path9 = join24(dir, entry.name);
|
|
43939
|
+
let sample;
|
|
43940
|
+
try {
|
|
43941
|
+
sample = sampleJournalFile(path9, remainingBytes, { fromDrainCheckpoint: true });
|
|
43942
|
+
} catch (err) {
|
|
43943
|
+
if (err.code === "ENOENT") {
|
|
43944
|
+
entry = entries.readSync();
|
|
43945
|
+
continue;
|
|
43946
|
+
}
|
|
43947
|
+
throw err;
|
|
43948
|
+
}
|
|
43949
|
+
remainingBytes = Math.max(0, remainingBytes - sample.sampledBytes);
|
|
43950
|
+
out.push({
|
|
43951
|
+
bucket,
|
|
43952
|
+
path: path9,
|
|
43953
|
+
pid: parseFlushingPid(entry.name),
|
|
43954
|
+
...sample
|
|
43955
|
+
});
|
|
43956
|
+
entry = entries.readSync();
|
|
43957
|
+
}
|
|
43958
|
+
} finally {
|
|
43959
|
+
entries.closeSync();
|
|
43960
|
+
}
|
|
43961
|
+
return out;
|
|
43962
|
+
}
|
|
43963
|
+
function listFlushing(options = {}) {
|
|
43964
|
+
const envDir = currentEnvDir();
|
|
43965
|
+
if (!existsSync16(envDir)) {
|
|
43966
|
+
return [];
|
|
43967
|
+
}
|
|
43968
|
+
const out = [];
|
|
43969
|
+
let remainingBytes = options.sampleBytes ?? JOURNAL_STATS_SAMPLE_BYTES;
|
|
43970
|
+
const maxFiles = options.maxFiles ?? Number.POSITIVE_INFINITY;
|
|
43971
|
+
for (const entry of readdirSync8(envDir, { withFileTypes: true })) {
|
|
43972
|
+
if (out.length >= maxFiles) {
|
|
43973
|
+
break;
|
|
43974
|
+
}
|
|
43975
|
+
if (entry.isDirectory()) {
|
|
43976
|
+
const found = listFlushingInDir(join24(envDir, entry.name), entry.name, {
|
|
43977
|
+
sampleBytes: remainingBytes,
|
|
43978
|
+
maxFiles: maxFiles - out.length
|
|
43979
|
+
});
|
|
43980
|
+
out.push(...found);
|
|
43981
|
+
remainingBytes = Math.max(
|
|
43982
|
+
0,
|
|
43983
|
+
remainingBytes - found.reduce((count, file) => count + file.sampledBytes, 0)
|
|
43984
|
+
);
|
|
43985
|
+
}
|
|
43986
|
+
}
|
|
43987
|
+
return out;
|
|
43988
|
+
}
|
|
43989
|
+
function sweepOrphanedDrainProgress() {
|
|
43990
|
+
const envDir = currentEnvDir();
|
|
43991
|
+
if (!existsSync16(envDir)) {
|
|
43992
|
+
return;
|
|
43993
|
+
}
|
|
43994
|
+
for (const entry of readdirSync8(envDir, { withFileTypes: true })) {
|
|
43995
|
+
if (entry.isDirectory()) {
|
|
43996
|
+
sweepOrphanedDrainCheckpoints(join24(envDir, entry.name));
|
|
43997
|
+
}
|
|
43998
|
+
}
|
|
43999
|
+
}
|
|
44000
|
+
function bucketStats(options = {}) {
|
|
44001
|
+
const out = [];
|
|
44002
|
+
let remainingBytes = options.sampleBytes ?? JOURNAL_STATS_SAMPLE_BYTES;
|
|
44003
|
+
const maxFiles = options.maxFiles ?? Number.POSITIVE_INFINITY;
|
|
44004
|
+
for (const { bucket, path: path9 } of listBuckets()) {
|
|
44005
|
+
if (out.length >= maxFiles) {
|
|
44006
|
+
break;
|
|
44007
|
+
}
|
|
44008
|
+
let sample;
|
|
44009
|
+
try {
|
|
44010
|
+
sample = sampleJournalFile(path9, remainingBytes);
|
|
44011
|
+
} catch (err) {
|
|
44012
|
+
if (err.code === "ENOENT") {
|
|
44013
|
+
continue;
|
|
44014
|
+
}
|
|
44015
|
+
throw err;
|
|
44016
|
+
}
|
|
44017
|
+
remainingBytes = Math.max(0, remainingBytes - sample.sampledBytes);
|
|
44018
|
+
out.push({
|
|
44019
|
+
bucket,
|
|
44020
|
+
path: path9,
|
|
44021
|
+
...sample
|
|
44022
|
+
});
|
|
44023
|
+
}
|
|
44024
|
+
return out;
|
|
44025
|
+
}
|
|
44026
|
+
function pendingJournalStats() {
|
|
44027
|
+
const perKindBytes = Math.floor(JOURNAL_STATS_SAMPLE_BYTES / 2);
|
|
44028
|
+
const perKindFiles = Math.floor(PENDING_STATS_MAX_FILES / 2);
|
|
44029
|
+
const live = bucketStats({ sampleBytes: perKindBytes, maxFiles: perKindFiles });
|
|
44030
|
+
const stranded = listFlushing({ sampleBytes: perKindBytes, maxFiles: perKindFiles });
|
|
44031
|
+
const timestamps = [...live, ...stranded].map((entry) => entry.oldestCapturedAt).filter((value) => value !== void 0);
|
|
44032
|
+
const liveSampled = live.some((entry) => entry.sampled) || live.length >= perKindFiles;
|
|
44033
|
+
const strandedSampled = stranded.some((entry) => entry.sampled) || stranded.length >= perKindFiles;
|
|
44034
|
+
return {
|
|
44035
|
+
pendingCount: live.reduce((count, entry) => count + entry.lineCount, 0) + stranded.reduce((count, entry) => count + entry.lineCount, 0),
|
|
44036
|
+
oldestPendingAt: timestamps.length > 0 ? Math.min(...timestamps) : void 0,
|
|
44037
|
+
strandedCount: stranded.reduce((count, entry) => count + entry.lineCount, 0),
|
|
44038
|
+
strandedFileCount: stranded.length,
|
|
44039
|
+
sampled: liveSampled || strandedSampled,
|
|
44040
|
+
strandedSampled
|
|
44041
|
+
};
|
|
44042
|
+
}
|
|
44043
|
+
|
|
44044
|
+
// src/commands/hermes-install.ts
|
|
44045
|
+
import { existsSync as existsSync17, readFileSync as readFileSync20, rmSync as rmSync7, statSync as statSync4 } from "fs";
|
|
44046
|
+
import { homedir as homedir9 } from "os";
|
|
44047
|
+
import { join as join25 } from "path";
|
|
44048
|
+
|
|
44049
|
+
// node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/browser/dist/nodes/identity.js
|
|
44050
|
+
var ALIAS = /* @__PURE__ */ Symbol.for("yaml.alias");
|
|
44051
|
+
var DOC = /* @__PURE__ */ Symbol.for("yaml.document");
|
|
44052
|
+
var MAP = /* @__PURE__ */ Symbol.for("yaml.map");
|
|
44053
|
+
var PAIR = /* @__PURE__ */ Symbol.for("yaml.pair");
|
|
44054
|
+
var SCALAR = /* @__PURE__ */ Symbol.for("yaml.scalar");
|
|
44055
|
+
var SEQ = /* @__PURE__ */ Symbol.for("yaml.seq");
|
|
44056
|
+
var NODE_TYPE = /* @__PURE__ */ Symbol.for("yaml.node.type");
|
|
44057
|
+
var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
|
|
44058
|
+
var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
|
|
44059
|
+
var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
|
|
44060
|
+
var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
|
|
44061
|
+
var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
|
|
44062
|
+
var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
|
|
44063
|
+
function isCollection(node) {
|
|
44064
|
+
if (node && typeof node === "object")
|
|
44065
|
+
switch (node[NODE_TYPE]) {
|
|
44066
|
+
case MAP:
|
|
44067
|
+
case SEQ:
|
|
44068
|
+
return true;
|
|
44069
|
+
}
|
|
44070
|
+
return false;
|
|
44071
|
+
}
|
|
44072
|
+
function isNode(node) {
|
|
44073
|
+
if (node && typeof node === "object")
|
|
44074
|
+
switch (node[NODE_TYPE]) {
|
|
44075
|
+
case ALIAS:
|
|
44076
|
+
case MAP:
|
|
44077
|
+
case SCALAR:
|
|
44078
|
+
case SEQ:
|
|
44079
|
+
return true;
|
|
44080
|
+
}
|
|
44081
|
+
return false;
|
|
44082
|
+
}
|
|
44083
|
+
var hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
44084
|
+
|
|
44085
|
+
// node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/browser/dist/visit.js
|
|
44086
|
+
var BREAK = /* @__PURE__ */ Symbol("break visit");
|
|
44087
|
+
var SKIP = /* @__PURE__ */ Symbol("skip children");
|
|
44088
|
+
var REMOVE = /* @__PURE__ */ Symbol("remove node");
|
|
43038
44089
|
function visit(node, visitor) {
|
|
43039
44090
|
const visitor_ = initVisitor(visitor);
|
|
43040
44091
|
if (isDocument(node)) {
|
|
@@ -48061,9 +49112,9 @@ var Lexer = class {
|
|
|
48061
49112
|
}
|
|
48062
49113
|
}
|
|
48063
49114
|
*parseQuotedScalar() {
|
|
48064
|
-
const
|
|
48065
|
-
let end = this.buffer.indexOf(
|
|
48066
|
-
if (
|
|
49115
|
+
const quote2 = this.charAt(0);
|
|
49116
|
+
let end = this.buffer.indexOf(quote2, this.pos + 1);
|
|
49117
|
+
if (quote2 === "'") {
|
|
48067
49118
|
while (end !== -1 && this.buffer[end + 1] === "'")
|
|
48068
49119
|
end = this.buffer.indexOf("'", end + 2);
|
|
48069
49120
|
} else {
|
|
@@ -49272,13 +50323,13 @@ var JSON_INDENT3 = 2;
|
|
|
49272
50323
|
var CONFIG_MODE = 384;
|
|
49273
50324
|
var PRIM_BINS4 = [CAPTURE_BIN4, GATE_BIN4, POST_TOOL_USE_BIN3, SESSION_START_BIN4, SESSION_END_BIN3];
|
|
49274
50325
|
function hermesHome() {
|
|
49275
|
-
return process.env.HERMES_HOME ??
|
|
50326
|
+
return process.env.HERMES_HOME ?? join25(homedir9(), ".hermes");
|
|
49276
50327
|
}
|
|
49277
50328
|
function configPath() {
|
|
49278
|
-
return
|
|
50329
|
+
return join25(hermesHome(), "config.yaml");
|
|
49279
50330
|
}
|
|
49280
50331
|
function legacyShimPath() {
|
|
49281
|
-
return
|
|
50332
|
+
return join25(hermesHome(), "agent-hooks", "prim-shim.sh");
|
|
49282
50333
|
}
|
|
49283
50334
|
function commandFor2(bin) {
|
|
49284
50335
|
return stableHookCommand(bin, HERMES_ARGS);
|
|
@@ -49392,8 +50443,8 @@ function hookRuntimeResolutions3(hooks) {
|
|
|
49392
50443
|
}
|
|
49393
50444
|
function inspectHookRuntimeResolutions4() {
|
|
49394
50445
|
const path9 = configPath();
|
|
49395
|
-
if (!
|
|
49396
|
-
return hookRuntimeResolutions3(readHooks(parseHermesDocument(
|
|
50446
|
+
if (!existsSync17(path9)) return [];
|
|
50447
|
+
return hookRuntimeResolutions3(readHooks(parseHermesDocument(readFileSync20(path9, "utf8"))));
|
|
49397
50448
|
}
|
|
49398
50449
|
function entryMatchesRegistration3(owned, registration) {
|
|
49399
50450
|
const expected = entryFor(registration);
|
|
@@ -49662,11 +50713,11 @@ function assertMergeValid(before, after, expectedHooks) {
|
|
|
49662
50713
|
}
|
|
49663
50714
|
}
|
|
49664
50715
|
function readConfigSnapshot(path9) {
|
|
49665
|
-
if (!
|
|
50716
|
+
if (!existsSync17(path9)) return { exists: false, mode: CONFIG_MODE, raw: "" };
|
|
49666
50717
|
return {
|
|
49667
50718
|
exists: true,
|
|
49668
50719
|
mode: statSync4(path9).mode & 511,
|
|
49669
|
-
raw:
|
|
50720
|
+
raw: readFileSync20(path9, "utf8")
|
|
49670
50721
|
};
|
|
49671
50722
|
}
|
|
49672
50723
|
var CONCURRENT_CONFIG_MESSAGE = "Hermes config changed during update; concurrent changes were preserved, retry the command";
|
|
@@ -49675,7 +50726,7 @@ function writeHermesConfigSnapshot(path9, before, after, expectedHooks) {
|
|
|
49675
50726
|
ensureParent: true,
|
|
49676
50727
|
mode: before.mode,
|
|
49677
50728
|
validate(temporaryPath) {
|
|
49678
|
-
const flushed =
|
|
50729
|
+
const flushed = readFileSync20(temporaryPath, "utf8");
|
|
49679
50730
|
if (!mergePreservesHermesSemantics(before.raw, flushed, expectedHooks)) {
|
|
49680
50731
|
throw new Error(INVALID_MERGE_MESSAGE);
|
|
49681
50732
|
}
|
|
@@ -49728,7 +50779,7 @@ function performInstall4(opts) {
|
|
|
49728
50779
|
}
|
|
49729
50780
|
function performUninstall4() {
|
|
49730
50781
|
const path9 = configPath();
|
|
49731
|
-
if (!
|
|
50782
|
+
if (!existsSync17(path9)) {
|
|
49732
50783
|
removeLegacyShim();
|
|
49733
50784
|
return { path: path9, gate: false, capture: false, autoAccept: false, changed: false };
|
|
49734
50785
|
}
|
|
@@ -49753,7 +50804,7 @@ function performUninstall4() {
|
|
|
49753
50804
|
}
|
|
49754
50805
|
function performStatus4() {
|
|
49755
50806
|
const path9 = configPath();
|
|
49756
|
-
const raw =
|
|
50807
|
+
const raw = existsSync17(path9) ? readFileSync20(path9, "utf8") : "";
|
|
49757
50808
|
const hooks = raw ? readHooks(parseHermesDocument(raw)) : {};
|
|
49758
50809
|
return {
|
|
49759
50810
|
path: path9,
|
|
@@ -49842,7 +50893,7 @@ function checkAuth() {
|
|
|
49842
50893
|
return classifyAuthCredential(
|
|
49843
50894
|
credential,
|
|
49844
50895
|
storedCredential ? getTokenExpiresAt() : void 0,
|
|
49845
|
-
storedCredential &&
|
|
50896
|
+
storedCredential && existsSync18(REFRESH_TOKEN_PATH)
|
|
49846
50897
|
);
|
|
49847
50898
|
}
|
|
49848
50899
|
function classifyDaemonHealth(snapshot, options = {}) {
|
|
@@ -50636,20 +51687,20 @@ function registerDoctorCommands(program3, dependencies = {}) {
|
|
|
50636
51687
|
}
|
|
50637
51688
|
|
|
50638
51689
|
// src/commands/moves.ts
|
|
50639
|
-
import { existsSync as
|
|
50640
|
-
import { join as
|
|
51690
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync13, unlinkSync as unlinkSync7, writeFileSync as writeFileSync9 } from "fs";
|
|
51691
|
+
import { join as join28 } from "path";
|
|
50641
51692
|
|
|
50642
51693
|
// src/flusher.ts
|
|
50643
|
-
import { createReadStream, renameSync as renameSync6, statSync as statSync5, unlinkSync as
|
|
50644
|
-
import { dirname as
|
|
51694
|
+
import { createReadStream, renameSync as renameSync6, statSync as statSync5, unlinkSync as unlinkSync6 } from "fs";
|
|
51695
|
+
import { dirname as dirname15, join as join27 } from "path";
|
|
50645
51696
|
|
|
50646
51697
|
// src/dead-letter.ts
|
|
50647
|
-
import { createHash as
|
|
51698
|
+
import { createHash as createHash10, randomBytes as randomBytes7 } from "crypto";
|
|
50648
51699
|
import {
|
|
50649
51700
|
constants as constants6,
|
|
50650
51701
|
chmodSync as chmodSync7,
|
|
50651
51702
|
closeSync as closeSync6,
|
|
50652
|
-
existsSync as
|
|
51703
|
+
existsSync as existsSync19,
|
|
50653
51704
|
fchmodSync as fchmodSync3,
|
|
50654
51705
|
fsyncSync as fsyncSync3,
|
|
50655
51706
|
mkdirSync as mkdirSync12,
|
|
@@ -50658,30 +51709,30 @@ import {
|
|
|
50658
51709
|
rmSync as rmSync8,
|
|
50659
51710
|
writeFileSync as writeFileSync8
|
|
50660
51711
|
} from "fs";
|
|
50661
|
-
import { dirname as
|
|
51712
|
+
import { dirname as dirname14, join as join26 } from "path";
|
|
50662
51713
|
var DIRECTORY_MODE4 = 448;
|
|
50663
51714
|
var FILE_MODE3 = 384;
|
|
50664
51715
|
var DEAD_LETTER_DIRNAME = "dead-letter";
|
|
50665
51716
|
function deadLetterDirectoryForRotation(flushingPath) {
|
|
50666
|
-
return
|
|
51717
|
+
return join26(dirname14(flushingPath), DEAD_LETTER_DIRNAME);
|
|
50667
51718
|
}
|
|
50668
51719
|
function deadLetterPathForRawLine(flushingPath, rawLine) {
|
|
50669
|
-
const quarantineId =
|
|
50670
|
-
return
|
|
51720
|
+
const quarantineId = createHash10("sha256").update(rawLine).digest("hex");
|
|
51721
|
+
return join26(deadLetterDirectoryForRotation(flushingPath), `raw-${quarantineId}.json`);
|
|
50671
51722
|
}
|
|
50672
51723
|
function ensureDeadLetterDirectory(flushingPath, persistDirectory) {
|
|
50673
51724
|
const directory = deadLetterDirectoryForRotation(flushingPath);
|
|
50674
51725
|
mkdirSync12(directory, { recursive: true, mode: DIRECTORY_MODE4 });
|
|
50675
51726
|
chmodSync7(directory, DIRECTORY_MODE4);
|
|
50676
|
-
persistDirectory(
|
|
51727
|
+
persistDirectory(dirname14(directory));
|
|
50677
51728
|
return directory;
|
|
50678
51729
|
}
|
|
50679
51730
|
function persistDeadLetter(directory, path9, quarantineId, record3, persistDirectory) {
|
|
50680
|
-
if (
|
|
51731
|
+
if (existsSync19(path9)) {
|
|
50681
51732
|
persistDirectory(directory);
|
|
50682
51733
|
return;
|
|
50683
51734
|
}
|
|
50684
|
-
const temporaryPath =
|
|
51735
|
+
const temporaryPath = join26(
|
|
50685
51736
|
directory,
|
|
50686
51737
|
`.${quarantineId}.${String(process.pid)}.${randomBytes7(8).toString("hex")}.tmp`
|
|
50687
51738
|
);
|
|
@@ -50708,12 +51759,12 @@ function quarantineMove(flushingPath, move, reason, now = Date.now, options = {}
|
|
|
50708
51759
|
const serializedMove = JSON.stringify(move);
|
|
50709
51760
|
const record3 = {
|
|
50710
51761
|
version: 1,
|
|
50711
|
-
quarantineId:
|
|
51762
|
+
quarantineId: createHash10("sha256").update(serializedMove).digest("hex"),
|
|
50712
51763
|
quarantinedAt: now(),
|
|
50713
51764
|
reason,
|
|
50714
51765
|
move
|
|
50715
51766
|
};
|
|
50716
|
-
const path9 =
|
|
51767
|
+
const path9 = join26(directory, `${record3.quarantineId}.json`);
|
|
50717
51768
|
persistDeadLetter(directory, path9, record3.quarantineId, record3, persistDirectory);
|
|
50718
51769
|
return record3;
|
|
50719
51770
|
}
|
|
@@ -50724,7 +51775,7 @@ function quarantineRawLine(flushingPath, rawLine, now = Date.now, options = {})
|
|
|
50724
51775
|
const record3 = {
|
|
50725
51776
|
version: 1,
|
|
50726
51777
|
recordKind: "raw_line_v1",
|
|
50727
|
-
quarantineId:
|
|
51778
|
+
quarantineId: createHash10("sha256").update(bytes).digest("hex"),
|
|
50728
51779
|
quarantinedAt: now(),
|
|
50729
51780
|
reason: "invalid_move",
|
|
50730
51781
|
rawLineEncoding: "base64",
|
|
@@ -50993,7 +52044,7 @@ async function drainFlushingPath(flushingPath, client, binding, options = {}) {
|
|
|
50993
52044
|
} finally {
|
|
50994
52045
|
input.destroy();
|
|
50995
52046
|
}
|
|
50996
|
-
|
|
52047
|
+
unlinkSync6(flushingPath);
|
|
50997
52048
|
try {
|
|
50998
52049
|
removeDrainCheckpoint(flushingPath);
|
|
50999
52050
|
} catch {
|
|
@@ -51137,7 +52188,7 @@ async function flushOnce() {
|
|
|
51137
52188
|
return inspection.retainedBuckets.length > 0 ? { flushed: total, quarantined, retained: inspection.retainedBuckets } : { flushed: total, quarantined };
|
|
51138
52189
|
}
|
|
51139
52190
|
var flushInFlight;
|
|
51140
|
-
var FLUSH_LOCK_PATH =
|
|
52191
|
+
var FLUSH_LOCK_PATH = join27(dirname15(JOURNAL_DIR), ".flush.lock");
|
|
51141
52192
|
var FLUSH_LOCK_TIMEOUT_MS = 250;
|
|
51142
52193
|
function isFlushLockContended(error) {
|
|
51143
52194
|
return error instanceof Error && error.message.startsWith("timed out waiting for file lock");
|
|
@@ -51269,23 +52320,23 @@ function registerMovesCommands(program3) {
|
|
|
51269
52320
|
}
|
|
51270
52321
|
});
|
|
51271
52322
|
moves.command("bind").description("Pin the current directory to an org via .prim/workspace.json").requiredOption("--orgId <orgId>", "Convex organization id").action((opts) => {
|
|
51272
|
-
const dir =
|
|
51273
|
-
if (!
|
|
52323
|
+
const dir = join28(process.cwd(), ".prim");
|
|
52324
|
+
if (!existsSync20(dir)) {
|
|
51274
52325
|
mkdirSync13(dir, { recursive: true, mode: DIR_MODE });
|
|
51275
52326
|
}
|
|
51276
|
-
const file =
|
|
52327
|
+
const file = join28(process.cwd(), WORKSPACE_FILE);
|
|
51277
52328
|
writeFileSync9(file, JSON.stringify({ orgId: opts.orgId, boundAt: Date.now() }, null, 2), {
|
|
51278
52329
|
mode: FILE_MODE4
|
|
51279
52330
|
});
|
|
51280
52331
|
console.log(`[prim] bound ${process.cwd()} to org ${opts.orgId}`);
|
|
51281
52332
|
});
|
|
51282
52333
|
moves.command("drop").description("Remove the .prim/workspace.json binding from the cwd").action(() => {
|
|
51283
|
-
const file =
|
|
51284
|
-
if (!
|
|
52334
|
+
const file = join28(process.cwd(), WORKSPACE_FILE);
|
|
52335
|
+
if (!existsSync20(file)) {
|
|
51285
52336
|
console.log("[prim] no workspace binding in cwd");
|
|
51286
52337
|
return;
|
|
51287
52338
|
}
|
|
51288
|
-
|
|
52339
|
+
unlinkSync7(file);
|
|
51289
52340
|
console.log(`[prim] dropped workspace binding from ${process.cwd()}`);
|
|
51290
52341
|
});
|
|
51291
52342
|
}
|
|
@@ -51411,31 +52462,31 @@ function registerReconcileCommands(program3) {
|
|
|
51411
52462
|
|
|
51412
52463
|
// src/commands/session.ts
|
|
51413
52464
|
import {
|
|
51414
|
-
existsSync as
|
|
52465
|
+
existsSync as existsSync22,
|
|
51415
52466
|
mkdirSync as mkdirSync14,
|
|
51416
|
-
readFileSync as
|
|
51417
|
-
readdirSync as
|
|
51418
|
-
unlinkSync as
|
|
52467
|
+
readFileSync as readFileSync22,
|
|
52468
|
+
readdirSync as readdirSync9,
|
|
52469
|
+
unlinkSync as unlinkSync8,
|
|
51419
52470
|
writeFileSync as writeFileSync10
|
|
51420
52471
|
} from "fs";
|
|
51421
|
-
import { join as
|
|
52472
|
+
import { join as join30 } from "path";
|
|
51422
52473
|
|
|
51423
52474
|
// src/binding.ts
|
|
51424
|
-
import { existsSync as
|
|
51425
|
-
import { dirname as
|
|
52475
|
+
import { existsSync as existsSync21, readFileSync as readFileSync21 } from "fs";
|
|
52476
|
+
import { dirname as dirname16, join as join29 } from "path";
|
|
51426
52477
|
var PRIM_CONFIG_DIR = primConfigDirectory();
|
|
51427
|
-
var SESSIONS_DIR =
|
|
52478
|
+
var SESSIONS_DIR = join29(PRIM_CONFIG_DIR, "sessions");
|
|
51428
52479
|
|
|
51429
52480
|
// src/commands/session.ts
|
|
51430
52481
|
var DIR_MODE2 = 448;
|
|
51431
52482
|
var FILE_MODE5 = 384;
|
|
51432
52483
|
function ensureDir() {
|
|
51433
|
-
if (!
|
|
52484
|
+
if (!existsSync22(SESSIONS_DIR)) {
|
|
51434
52485
|
mkdirSync14(SESSIONS_DIR, { recursive: true, mode: DIR_MODE2 });
|
|
51435
52486
|
}
|
|
51436
52487
|
}
|
|
51437
52488
|
function markerPath(sessionId) {
|
|
51438
|
-
return
|
|
52489
|
+
return join30(SESSIONS_DIR, `${sessionId}.json`);
|
|
51439
52490
|
}
|
|
51440
52491
|
function registerSessionCommands(program3) {
|
|
51441
52492
|
const session = program3.command("session").description("Decision Event Pipeline \u2014 session binding markers");
|
|
@@ -51451,11 +52502,11 @@ function registerSessionCommands(program3) {
|
|
|
51451
52502
|
console.log(`[prim] session ${sessionId} bound to org ${opts.orgId}`);
|
|
51452
52503
|
});
|
|
51453
52504
|
session.command("list").description("List active session markers").action(() => {
|
|
51454
|
-
if (!
|
|
52505
|
+
if (!existsSync22(SESSIONS_DIR)) {
|
|
51455
52506
|
console.log("[prim] no session markers");
|
|
51456
52507
|
return;
|
|
51457
52508
|
}
|
|
51458
|
-
const files =
|
|
52509
|
+
const files = readdirSync9(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
|
|
51459
52510
|
if (files.length === 0) {
|
|
51460
52511
|
console.log("[prim] no session markers");
|
|
51461
52512
|
return;
|
|
@@ -51463,7 +52514,7 @@ function registerSessionCommands(program3) {
|
|
|
51463
52514
|
for (const f of files) {
|
|
51464
52515
|
const sessionId = f.replace(/\.json$/, "");
|
|
51465
52516
|
try {
|
|
51466
|
-
const m = JSON.parse(
|
|
52517
|
+
const m = JSON.parse(readFileSync22(join30(SESSIONS_DIR, f), "utf-8"));
|
|
51467
52518
|
console.log(`${sessionId} org=${m.orgId}`);
|
|
51468
52519
|
} catch {
|
|
51469
52520
|
}
|
|
@@ -51471,19 +52522,19 @@ function registerSessionCommands(program3) {
|
|
|
51471
52522
|
});
|
|
51472
52523
|
session.command("drop <sessionId>").description("Remove a session marker").action((sessionId) => {
|
|
51473
52524
|
const p = markerPath(sessionId);
|
|
51474
|
-
if (!
|
|
52525
|
+
if (!existsSync22(p)) {
|
|
51475
52526
|
console.log(`[prim] no marker for session ${sessionId}`);
|
|
51476
52527
|
return;
|
|
51477
52528
|
}
|
|
51478
|
-
|
|
52529
|
+
unlinkSync8(p);
|
|
51479
52530
|
console.log(`[prim] dropped session marker ${sessionId}`);
|
|
51480
52531
|
});
|
|
51481
52532
|
}
|
|
51482
52533
|
|
|
51483
52534
|
// src/commands/setup.ts
|
|
51484
52535
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
51485
|
-
import { existsSync as
|
|
51486
|
-
import { join as
|
|
52536
|
+
import { existsSync as existsSync23, readFileSync as readFileSync23 } from "fs";
|
|
52537
|
+
import { join as join31 } from "path";
|
|
51487
52538
|
var EXIT_INCOMPLETE = 1;
|
|
51488
52539
|
var EXIT_USAGE3 = 2;
|
|
51489
52540
|
var SETUP_ORCHESTRATOR_ENV = "PRIM_SETUP_ORCHESTRATOR";
|
|
@@ -51524,831 +52575,357 @@ function planSetupSteps(opts) {
|
|
|
51524
52575
|
args: ["daemon", "start"],
|
|
51525
52576
|
required: true
|
|
51526
52577
|
});
|
|
51527
|
-
} else {
|
|
51528
|
-
steps.push({
|
|
51529
|
-
key: "daemon-opt-out",
|
|
51530
|
-
label: "Daemon opt-out",
|
|
51531
|
-
args: ["daemon", "stop"],
|
|
51532
|
-
required: true
|
|
51533
|
-
});
|
|
51534
|
-
}
|
|
51535
|
-
if (opts.scope === "project") {
|
|
51536
|
-
steps.push({ key: "hooks", label: "Git hooks", args: ["hooks", "install"], required: true });
|
|
51537
|
-
} else if (opts.globalHooksPath) {
|
|
51538
|
-
steps.push({
|
|
51539
|
-
key: "hooks",
|
|
51540
|
-
label: "Git hooks (global)",
|
|
51541
|
-
args: ["hooks", "install", "--scope", "user", "--global-hooks-path"],
|
|
51542
|
-
required: true
|
|
51543
|
-
});
|
|
51544
|
-
}
|
|
51545
|
-
const skillArgs = ["skill", "install", "--agent", opts.agent, ...scopeArgs];
|
|
51546
|
-
steps.push({ key: "skill", label: "Agent skill", args: skillArgs, required: true });
|
|
51547
|
-
steps.push({
|
|
51548
|
-
key: "enable",
|
|
51549
|
-
label: "Activate this repo",
|
|
51550
|
-
args: ["enable"],
|
|
51551
|
-
required: true
|
|
51552
|
-
});
|
|
51553
|
-
if (opts.daemon) {
|
|
51554
|
-
steps.push({
|
|
51555
|
-
key: "health",
|
|
51556
|
-
label: "Capture health",
|
|
51557
|
-
args: ["doctor", "--expect-backlog"],
|
|
51558
|
-
required: true
|
|
51559
|
-
});
|
|
51560
|
-
}
|
|
51561
|
-
return steps;
|
|
51562
|
-
}
|
|
51563
|
-
var CONFLICT_SESSION = "session";
|
|
51564
|
-
var CONFLICT_HOOKS = "hooks";
|
|
51565
|
-
var CONFLICT_SKILL = "skill";
|
|
51566
|
-
function planCleanupUninstalls(agent, conflicts) {
|
|
51567
|
-
const steps = [];
|
|
51568
|
-
if (conflicts.includes(CONFLICT_SESSION) && agent !== "hermes") {
|
|
51569
|
-
steps.push([agent, "uninstall", "--scope", "project"]);
|
|
51570
|
-
}
|
|
51571
|
-
if (conflicts.includes(CONFLICT_HOOKS)) steps.push(["hooks", "uninstall"]);
|
|
51572
|
-
if (conflicts.includes(CONFLICT_SKILL)) steps.push(["skill", "uninstall", "--agent", agent]);
|
|
51573
|
-
return steps;
|
|
51574
|
-
}
|
|
51575
|
-
function preCommitRunsPrim(content) {
|
|
51576
|
-
return content.includes("# >>> prim pre-commit hook >>>") || content.includes("prim-pre-commit");
|
|
51577
|
-
}
|
|
51578
|
-
function projectHooksConflict(globalHooksActive, preCommit) {
|
|
51579
|
-
return globalHooksActive && preCommit !== void 0 && preCommitRunsPrim(preCommit);
|
|
51580
|
-
}
|
|
51581
|
-
function enableWiresRepository(root) {
|
|
51582
|
-
if (!root) return void 0;
|
|
51583
|
-
try {
|
|
51584
|
-
if (gitHooksMode({ cwd: root }) === "manual") return void 0;
|
|
51585
|
-
return resolveEffectiveGitHook("post-commit", root).location !== "external";
|
|
51586
|
-
} catch {
|
|
51587
|
-
return void 0;
|
|
51588
|
-
}
|
|
51589
|
-
}
|
|
51590
|
-
function setupGitHooksNote(plan, wiresThisRepository) {
|
|
51591
|
-
if (wiresThisRepository === true && plan.action === "add_to_dir") {
|
|
51592
|
-
return `git hooks \xB7 Git runs this repository's hooks from inside it, so \`prim enable\` wires it; other repositories may run ${plan.global}, which prim edits only with --global-hooks-path, after asking the user`;
|
|
51593
|
-
}
|
|
51594
|
-
if (wiresThisRepository === true && plan.action === "system_declined") {
|
|
51595
|
-
return `git hooks \xB7 Git runs this repository's hooks from inside it, so \`prim enable\` wires it; other repositories may run the system hooks dir ${plan.system}, which prim never edits`;
|
|
51596
|
-
}
|
|
51597
|
-
switch (plan.action) {
|
|
51598
|
-
case "refresh":
|
|
51599
|
-
return "git hooks \xB7 prim's global hooks stay active; `prim enable` refreshes them";
|
|
51600
|
-
case "present_in_dir":
|
|
51601
|
-
return `git hooks \xB7 prim's hooks are already in your global hooks dir ${plan.global}`;
|
|
51602
|
-
case "add_to_dir":
|
|
51603
|
-
return `git hooks \xB7 your global core.hooksPath (${plan.global}) runs every repository's hooks, so \`prim enable\` cannot wire this repository without it; add prim there with --global-hooks-path, after asking the user`;
|
|
51604
|
-
case "system_declined":
|
|
51605
|
-
return `git hooks \xB7 the system core.hooksPath (${plan.system}) runs every repository's hooks, so \`prim enable\` cannot wire this repository: place \`prim hooks snippet <hook>\` there, or, after asking the user, run \`prim hooks install --scope user --global-hooks-path --force\` (its hooks stop firing)`;
|
|
51606
|
-
case "manual":
|
|
51607
|
-
return "git hooks \xB7 prim.gitHooks=manual: prim writes no hook files; wire them with `prim hooks snippet <hook>`";
|
|
51608
|
-
default:
|
|
51609
|
-
return "git hooks \xB7 wired per repository by `prim enable`; git's global hooks are untouched (opt in with --global-hooks-path)";
|
|
51610
|
-
}
|
|
51611
|
-
}
|
|
51612
|
-
function detectProjectConflicts(agent, run, globalHooksActive) {
|
|
51613
|
-
const conflicts = [];
|
|
51614
|
-
if (agent !== "hermes") {
|
|
51615
|
-
try {
|
|
51616
|
-
const parsed = JSON.parse(run([agent, "status"], true).stdout || "{}");
|
|
51617
|
-
if (parsed.project?.gate || parsed.project?.capture) conflicts.push(CONFLICT_SESSION);
|
|
51618
|
-
} catch {
|
|
51619
|
-
}
|
|
51620
|
-
}
|
|
51621
|
-
let preCommit;
|
|
51622
|
-
try {
|
|
51623
|
-
const root = gitToplevel();
|
|
51624
|
-
const path9 = root && join28(root, ".git", "hooks", "pre-commit");
|
|
51625
|
-
if (path9 && existsSync21(path9)) preCommit = readFileSync21(path9, "utf-8");
|
|
51626
|
-
} catch {
|
|
51627
|
-
}
|
|
51628
|
-
if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
|
|
51629
|
-
try {
|
|
51630
|
-
const parsed = JSON.parse(
|
|
51631
|
-
run(["skill", "status", "--agent", agent, "--json"], true).stdout || "{}"
|
|
51632
|
-
);
|
|
51633
|
-
if (parsed.installed) conflicts.push(CONFLICT_SKILL);
|
|
51634
|
-
} catch {
|
|
51635
|
-
}
|
|
51636
|
-
return conflicts;
|
|
51637
|
-
}
|
|
51638
|
-
function detectAgent(env4) {
|
|
51639
|
-
if (env4.HERMES_INTERACTIVE) {
|
|
51640
|
-
return "hermes";
|
|
51641
|
-
}
|
|
51642
|
-
if (env4.CURSOR_AGENT) {
|
|
51643
|
-
return "cursor";
|
|
51644
|
-
}
|
|
51645
|
-
return "claude";
|
|
51646
|
-
}
|
|
51647
|
-
function resolveAgent(agentFlag, env4) {
|
|
51648
|
-
if (agentFlag !== void 0) {
|
|
51649
|
-
return { agent: agentFlag, detected: false };
|
|
51650
|
-
}
|
|
51651
|
-
return { agent: detectAgent(env4), detected: true };
|
|
51652
|
-
}
|
|
51653
|
-
function parseSetupAuthStatus(result) {
|
|
51654
|
-
try {
|
|
51655
|
-
const parsed = JSON.parse(result.stdout || "{}");
|
|
51656
|
-
if (parsed.status === "valid" || parsed.authenticated === true) return "valid";
|
|
51657
|
-
if (parsed.status === "unreachable") return "unreachable";
|
|
51658
|
-
if (parsed.status === "invalid") return "invalid";
|
|
51659
|
-
} catch {
|
|
51660
|
-
}
|
|
51661
|
-
return result.code === EXIT_USAGE3 ? "unreachable" : "invalid";
|
|
51662
|
-
}
|
|
51663
|
-
function registerSetupCommand(program3, dependencies = {}) {
|
|
51664
|
-
program3.command("setup").description(
|
|
51665
|
-
"Install everything in one shot (auth, session + git hooks, daemon, skill, welcome)"
|
|
51666
|
-
).option("--agent <agent>", "claude, codex, cursor, or hermes (auto-detected when omitted)").option(
|
|
51667
|
-
"--scope <scope>",
|
|
51668
|
-
"user (default \u2014 agent integration and skill for every repo; git hooks per repo via enable) or project (this repo only)",
|
|
51669
|
-
"user"
|
|
51670
|
-
).option(
|
|
51671
|
-
"--global-hooks-path",
|
|
51672
|
-
"with the default user scope, also change git's global hooks so prim's hooks run in every repository"
|
|
51673
|
-
).option(
|
|
51674
|
-
"--migrate",
|
|
51675
|
-
"with the default user scope, remove any project-scoped prim config in this repo (else just warn)"
|
|
51676
|
-
).option("--no-daemon", "stop and disable the companion daemon").action((opts) => {
|
|
51677
|
-
const { agent: agentInput, detected } = resolveAgent(opts.agent, process.env);
|
|
51678
|
-
if (agentInput !== "claude" && agentInput !== "codex" && agentInput !== "cursor" && agentInput !== "hermes") {
|
|
51679
|
-
process.stderr.write(
|
|
51680
|
-
`[prim] unknown --agent "${agentInput}" (expected claude, codex, cursor, or hermes)
|
|
51681
|
-
`
|
|
51682
|
-
);
|
|
51683
|
-
(dependencies.exit ?? process.exit)(EXIT_USAGE3);
|
|
51684
|
-
return;
|
|
51685
|
-
}
|
|
51686
|
-
if (opts.scope !== "project" && opts.scope !== "user") {
|
|
51687
|
-
process.stderr.write(`[prim] unknown --scope "${opts.scope}" (expected project or user)
|
|
51688
|
-
`);
|
|
51689
|
-
(dependencies.exit ?? process.exit)(EXIT_USAGE3);
|
|
51690
|
-
return;
|
|
51691
|
-
}
|
|
51692
|
-
if (opts.globalHooksPath && opts.scope !== "user") {
|
|
51693
|
-
process.stderr.write("[prim] --global-hooks-path applies only with --scope user\n");
|
|
51694
|
-
(dependencies.exit ?? process.exit)(EXIT_USAGE3);
|
|
51695
|
-
return;
|
|
51696
|
-
}
|
|
51697
|
-
const agent = agentInput;
|
|
51698
|
-
const scope = opts.scope;
|
|
51699
|
-
const self = process.argv[1];
|
|
51700
|
-
const globals = program3.optsWithGlobals();
|
|
51701
|
-
const run = dependencies.run ?? ((args, capture = false) => {
|
|
51702
|
-
const r = spawnSync2(
|
|
51703
|
-
process.execPath,
|
|
51704
|
-
[self, ...args],
|
|
51705
|
-
setupStepSpawnOptions(capture, process.env, { startsDaemon: opts.daemon })
|
|
51706
|
-
);
|
|
51707
|
-
return { code: r.status ?? 1, stdout: capture ? r.stdout ?? "" : "" };
|
|
51708
|
-
});
|
|
51709
|
-
const results = {};
|
|
51710
|
-
const note = dependencies.note ?? ((msg) => {
|
|
51711
|
-
process.stderr.write(`[prim] ${msg}
|
|
51712
|
-
`);
|
|
51713
|
-
});
|
|
51714
|
-
const exit = dependencies.exit ?? process.exit;
|
|
51715
|
-
if (detected && agent !== "claude") {
|
|
51716
|
-
note(`agent \xB7 detected ${agent} session (override with --agent <agent>)`);
|
|
51717
|
-
}
|
|
51718
|
-
let authStatus = parseSetupAuthStatus(run(["auth", "status", "--json"], true));
|
|
51719
|
-
if (authStatus === "unreachable") {
|
|
51720
|
-
note("auth \xB7 verification unavailable; no setup changes were made");
|
|
51721
|
-
exit(EXIT_USAGE3);
|
|
51722
|
-
return;
|
|
51723
|
-
}
|
|
51724
|
-
if (authStatus === "invalid") {
|
|
51725
|
-
note("auth \xB7 opening browser to authenticate\u2026");
|
|
51726
|
-
const login = run(["auth", "login"]);
|
|
51727
|
-
if (login.code !== 0) {
|
|
51728
|
-
note("auth \xB7 login failed; no integration changes were made");
|
|
51729
|
-
exit(EXIT_INCOMPLETE);
|
|
51730
|
-
return;
|
|
51731
|
-
}
|
|
51732
|
-
authStatus = parseSetupAuthStatus(run(["auth", "status", "--json"], true));
|
|
51733
|
-
if (authStatus !== "valid") {
|
|
51734
|
-
note(
|
|
51735
|
-
authStatus === "unreachable" ? "auth \xB7 login completed but verification is unavailable; no integration changes were made" : "auth \xB7 login did not produce valid credentials; no integration changes were made"
|
|
51736
|
-
);
|
|
51737
|
-
exit(authStatus === "unreachable" ? EXIT_USAGE3 : EXIT_INCOMPLETE);
|
|
51738
|
-
return;
|
|
51739
|
-
}
|
|
51740
|
-
} else {
|
|
51741
|
-
note("auth \xB7 already authenticated");
|
|
51742
|
-
}
|
|
51743
|
-
results.auth = "ok";
|
|
51744
|
-
if (agent === "claude") {
|
|
51745
|
-
note("pre-authorize \xB7 writing prim allow-rule (user scope)\u2026");
|
|
51746
|
-
results.preauth = run(["claude", "preauth", "--scope", "user"]).code === 0 ? "ok" : "skipped";
|
|
51747
|
-
}
|
|
51748
|
-
const setupSteps = planSetupSteps({
|
|
51749
|
-
agent,
|
|
51750
|
-
daemon: opts.daemon,
|
|
51751
|
-
scope,
|
|
51752
|
-
globalHooksPath: opts.globalHooksPath === true
|
|
51753
|
-
});
|
|
51754
|
-
for (const step of setupSteps.filter(
|
|
51755
|
-
(candidate) => candidate.key !== "enable" && candidate.key !== "health"
|
|
51756
|
-
)) {
|
|
51757
|
-
note(`${step.label} \xB7 installing\u2026`);
|
|
51758
|
-
const { code } = run(step.args);
|
|
51759
|
-
results[step.key] = code === 0 ? "ok" : code === EXIT_GLOBAL_HOOKS_NOT_INSTALLED && step.key === "hooks" ? "skipped" : step.required ? "failed" : "skipped";
|
|
51760
|
-
}
|
|
51761
|
-
if (scope === "user" && !opts.globalHooksPath) {
|
|
51762
|
-
note(setupGitHooksNote(planGlobalHooks(), enableWiresRepository(gitToplevel())));
|
|
51763
|
-
}
|
|
51764
|
-
if (scope === "user") {
|
|
51765
|
-
const conflicts = detectProjectConflicts(agent, run, globalHooksPathIsPrims());
|
|
51766
|
-
if (conflicts.length > 0 && opts.migrate) {
|
|
51767
|
-
note(`migrate \xB7 removing project-scoped config (${conflicts.join(", ")})\u2026`);
|
|
51768
|
-
const ok = planCleanupUninstalls(agent, conflicts).map((args) => run(args).code === 0).every(Boolean);
|
|
51769
|
-
results.migrate = ok ? "ok" : "failed";
|
|
51770
|
-
} else if (conflicts.length > 0) {
|
|
51771
|
-
note(
|
|
51772
|
-
`migrate \xB7 project-scoped prim config present in this repo (${conflicts.join(", ")}) \u2014 it will double-fire with the user-scope install. Re-run \`prim setup --migrate\` to remove it.`
|
|
51773
|
-
);
|
|
51774
|
-
}
|
|
51775
|
-
}
|
|
51776
|
-
const enableStep = setupSteps.find((candidate) => candidate.key === "enable");
|
|
51777
|
-
if (enableStep) {
|
|
51778
|
-
note(`${enableStep.label} \xB7 installing\u2026`);
|
|
51779
|
-
const enableArgs = [
|
|
51780
|
-
...enableStep.args,
|
|
51781
|
-
...globals.yes ? ["--yes"] : [],
|
|
51782
|
-
...globals.nonInteractive ? ["--non-interactive"] : []
|
|
51783
|
-
];
|
|
51784
|
-
const { code } = run(enableArgs);
|
|
51785
|
-
results[enableStep.key] = code === 0 ? "ok" : enableStep.required ? "failed" : "skipped";
|
|
51786
|
-
}
|
|
51787
|
-
const healthStep = setupSteps.find((candidate) => candidate.key === "health");
|
|
51788
|
-
if (healthStep) {
|
|
51789
|
-
note(`${healthStep.label} \xB7 verifying\u2026`);
|
|
51790
|
-
const { code } = run(healthStep.args);
|
|
51791
|
-
results[healthStep.key] = code === 0 ? "ok" : healthStep.required ? "failed" : "skipped";
|
|
51792
|
-
}
|
|
51793
|
-
note("welcome");
|
|
51794
|
-
results.welcome = run(["welcome", "--agent", agent]).code === 0 ? "ok" : "failed";
|
|
51795
|
-
const failed = Object.entries(results).filter(([, v]) => v === "failed").map(([k]) => k);
|
|
51796
|
-
const trail = Object.entries(results).map(([k, v]) => `${k}:${v}`).join(" \xB7 ");
|
|
51797
|
-
note(
|
|
51798
|
-
`setup ${failed.length === 0 ? "complete" : `incomplete (failed: ${failed.join(", ")})`} \u2014 ${trail}`
|
|
51799
|
-
);
|
|
51800
|
-
exit(failed.length === 0 ? 0 : EXIT_INCOMPLETE);
|
|
51801
|
-
});
|
|
51802
|
-
}
|
|
51803
|
-
|
|
51804
|
-
// src/commands/skill.ts
|
|
51805
|
-
import { createHash as createHash11 } from "crypto";
|
|
51806
|
-
import {
|
|
51807
|
-
constants as constants8,
|
|
51808
|
-
closeSync as closeSync8,
|
|
51809
|
-
existsSync as existsSync23,
|
|
51810
|
-
fstatSync as fstatSync4,
|
|
51811
|
-
lstatSync as lstatSync9,
|
|
51812
|
-
openSync as openSync8,
|
|
51813
|
-
readFileSync as readFileSync23,
|
|
51814
|
-
readSync as readSync4,
|
|
51815
|
-
readdirSync as readdirSync9,
|
|
51816
|
-
rmdirSync as rmdirSync3,
|
|
51817
|
-
unlinkSync as unlinkSync8
|
|
51818
|
-
} from "fs";
|
|
51819
|
-
import { homedir as homedir11 } from "os";
|
|
51820
|
-
import { dirname as dirname17, join as join31, resolve as resolve9 } from "path";
|
|
51821
|
-
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
51822
|
-
|
|
51823
|
-
// node_modules/.pnpm/diff@5.2.2/node_modules/diff/lib/index.mjs
|
|
51824
|
-
function Diff() {
|
|
51825
|
-
}
|
|
51826
|
-
Diff.prototype = {
|
|
51827
|
-
diff: function diff(oldString, newString) {
|
|
51828
|
-
var _options$timeout;
|
|
51829
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
51830
|
-
var callback = options.callback;
|
|
51831
|
-
if (typeof options === "function") {
|
|
51832
|
-
callback = options;
|
|
51833
|
-
options = {};
|
|
51834
|
-
}
|
|
51835
|
-
this.options = options;
|
|
51836
|
-
var self = this;
|
|
51837
|
-
function done(value) {
|
|
51838
|
-
if (callback) {
|
|
51839
|
-
setTimeout(function() {
|
|
51840
|
-
callback(void 0, value);
|
|
51841
|
-
}, 0);
|
|
51842
|
-
return true;
|
|
51843
|
-
} else {
|
|
51844
|
-
return value;
|
|
51845
|
-
}
|
|
51846
|
-
}
|
|
51847
|
-
oldString = this.castInput(oldString);
|
|
51848
|
-
newString = this.castInput(newString);
|
|
51849
|
-
oldString = this.removeEmpty(this.tokenize(oldString));
|
|
51850
|
-
newString = this.removeEmpty(this.tokenize(newString));
|
|
51851
|
-
var newLen = newString.length, oldLen = oldString.length;
|
|
51852
|
-
var editLength = 1;
|
|
51853
|
-
var maxEditLength = newLen + oldLen;
|
|
51854
|
-
if (options.maxEditLength) {
|
|
51855
|
-
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
51856
|
-
}
|
|
51857
|
-
var maxExecutionTime = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : Infinity;
|
|
51858
|
-
var abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
51859
|
-
var bestPath = [{
|
|
51860
|
-
oldPos: -1,
|
|
51861
|
-
lastComponent: void 0
|
|
51862
|
-
}];
|
|
51863
|
-
var newPos = this.extractCommon(bestPath[0], newString, oldString, 0);
|
|
51864
|
-
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
51865
|
-
return done([{
|
|
51866
|
-
value: this.join(newString),
|
|
51867
|
-
count: newString.length
|
|
51868
|
-
}]);
|
|
51869
|
-
}
|
|
51870
|
-
var minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
51871
|
-
function execEditLength() {
|
|
51872
|
-
for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
51873
|
-
var basePath = void 0;
|
|
51874
|
-
var removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
51875
|
-
if (removePath) {
|
|
51876
|
-
bestPath[diagonalPath - 1] = void 0;
|
|
51877
|
-
}
|
|
51878
|
-
var canAdd = false;
|
|
51879
|
-
if (addPath) {
|
|
51880
|
-
var addPathNewPos = addPath.oldPos - diagonalPath;
|
|
51881
|
-
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
51882
|
-
}
|
|
51883
|
-
var canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
51884
|
-
if (!canAdd && !canRemove) {
|
|
51885
|
-
bestPath[diagonalPath] = void 0;
|
|
51886
|
-
continue;
|
|
51887
|
-
}
|
|
51888
|
-
if (!canRemove || canAdd && removePath.oldPos + 1 < addPath.oldPos) {
|
|
51889
|
-
basePath = self.addToPath(addPath, true, void 0, 0);
|
|
51890
|
-
} else {
|
|
51891
|
-
basePath = self.addToPath(removePath, void 0, true, 1);
|
|
51892
|
-
}
|
|
51893
|
-
newPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
|
|
51894
|
-
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
51895
|
-
return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken));
|
|
51896
|
-
} else {
|
|
51897
|
-
bestPath[diagonalPath] = basePath;
|
|
51898
|
-
if (basePath.oldPos + 1 >= oldLen) {
|
|
51899
|
-
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
51900
|
-
}
|
|
51901
|
-
if (newPos + 1 >= newLen) {
|
|
51902
|
-
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
51903
|
-
}
|
|
51904
|
-
}
|
|
51905
|
-
}
|
|
51906
|
-
editLength++;
|
|
51907
|
-
}
|
|
51908
|
-
if (callback) {
|
|
51909
|
-
(function exec2() {
|
|
51910
|
-
setTimeout(function() {
|
|
51911
|
-
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
51912
|
-
return callback();
|
|
51913
|
-
}
|
|
51914
|
-
if (!execEditLength()) {
|
|
51915
|
-
exec2();
|
|
51916
|
-
}
|
|
51917
|
-
}, 0);
|
|
51918
|
-
})();
|
|
51919
|
-
} else {
|
|
51920
|
-
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
51921
|
-
var ret = execEditLength();
|
|
51922
|
-
if (ret) {
|
|
51923
|
-
return ret;
|
|
51924
|
-
}
|
|
51925
|
-
}
|
|
51926
|
-
}
|
|
51927
|
-
},
|
|
51928
|
-
addToPath: function addToPath(path9, added, removed, oldPosInc) {
|
|
51929
|
-
var last = path9.lastComponent;
|
|
51930
|
-
if (last && last.added === added && last.removed === removed) {
|
|
51931
|
-
return {
|
|
51932
|
-
oldPos: path9.oldPos + oldPosInc,
|
|
51933
|
-
lastComponent: {
|
|
51934
|
-
count: last.count + 1,
|
|
51935
|
-
added,
|
|
51936
|
-
removed,
|
|
51937
|
-
previousComponent: last.previousComponent
|
|
51938
|
-
}
|
|
51939
|
-
};
|
|
51940
|
-
} else {
|
|
51941
|
-
return {
|
|
51942
|
-
oldPos: path9.oldPos + oldPosInc,
|
|
51943
|
-
lastComponent: {
|
|
51944
|
-
count: 1,
|
|
51945
|
-
added,
|
|
51946
|
-
removed,
|
|
51947
|
-
previousComponent: last
|
|
51948
|
-
}
|
|
51949
|
-
};
|
|
51950
|
-
}
|
|
51951
|
-
},
|
|
51952
|
-
extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
|
|
51953
|
-
var newLen = newString.length, oldLen = oldString.length, oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
51954
|
-
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
|
|
51955
|
-
newPos++;
|
|
51956
|
-
oldPos++;
|
|
51957
|
-
commonCount++;
|
|
51958
|
-
}
|
|
51959
|
-
if (commonCount) {
|
|
51960
|
-
basePath.lastComponent = {
|
|
51961
|
-
count: commonCount,
|
|
51962
|
-
previousComponent: basePath.lastComponent
|
|
51963
|
-
};
|
|
51964
|
-
}
|
|
51965
|
-
basePath.oldPos = oldPos;
|
|
51966
|
-
return newPos;
|
|
51967
|
-
},
|
|
51968
|
-
equals: function equals(left, right) {
|
|
51969
|
-
if (this.options.comparator) {
|
|
51970
|
-
return this.options.comparator(left, right);
|
|
51971
|
-
} else {
|
|
51972
|
-
return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
51973
|
-
}
|
|
51974
|
-
},
|
|
51975
|
-
removeEmpty: function removeEmpty(array) {
|
|
51976
|
-
var ret = [];
|
|
51977
|
-
for (var i = 0; i < array.length; i++) {
|
|
51978
|
-
if (array[i]) {
|
|
51979
|
-
ret.push(array[i]);
|
|
51980
|
-
}
|
|
51981
|
-
}
|
|
51982
|
-
return ret;
|
|
51983
|
-
},
|
|
51984
|
-
castInput: function castInput(value) {
|
|
51985
|
-
return value;
|
|
51986
|
-
},
|
|
51987
|
-
tokenize: function tokenize(value) {
|
|
51988
|
-
return value.split("");
|
|
51989
|
-
},
|
|
51990
|
-
join: function join29(chars) {
|
|
51991
|
-
return chars.join("");
|
|
51992
|
-
}
|
|
51993
|
-
};
|
|
51994
|
-
function buildValues(diff2, lastComponent, newString, oldString, useLongestToken) {
|
|
51995
|
-
var components = [];
|
|
51996
|
-
var nextComponent;
|
|
51997
|
-
while (lastComponent) {
|
|
51998
|
-
components.push(lastComponent);
|
|
51999
|
-
nextComponent = lastComponent.previousComponent;
|
|
52000
|
-
delete lastComponent.previousComponent;
|
|
52001
|
-
lastComponent = nextComponent;
|
|
52002
|
-
}
|
|
52003
|
-
components.reverse();
|
|
52004
|
-
var componentPos = 0, componentLen = components.length, newPos = 0, oldPos = 0;
|
|
52005
|
-
for (; componentPos < componentLen; componentPos++) {
|
|
52006
|
-
var component = components[componentPos];
|
|
52007
|
-
if (!component.removed) {
|
|
52008
|
-
if (!component.added && useLongestToken) {
|
|
52009
|
-
var value = newString.slice(newPos, newPos + component.count);
|
|
52010
|
-
value = value.map(function(value2, i) {
|
|
52011
|
-
var oldValue = oldString[oldPos + i];
|
|
52012
|
-
return oldValue.length > value2.length ? oldValue : value2;
|
|
52013
|
-
});
|
|
52014
|
-
component.value = diff2.join(value);
|
|
52015
|
-
} else {
|
|
52016
|
-
component.value = diff2.join(newString.slice(newPos, newPos + component.count));
|
|
52017
|
-
}
|
|
52018
|
-
newPos += component.count;
|
|
52019
|
-
if (!component.added) {
|
|
52020
|
-
oldPos += component.count;
|
|
52021
|
-
}
|
|
52022
|
-
} else {
|
|
52023
|
-
component.value = diff2.join(oldString.slice(oldPos, oldPos + component.count));
|
|
52024
|
-
oldPos += component.count;
|
|
52025
|
-
if (componentPos && components[componentPos - 1].added) {
|
|
52026
|
-
var tmp = components[componentPos - 1];
|
|
52027
|
-
components[componentPos - 1] = components[componentPos];
|
|
52028
|
-
components[componentPos] = tmp;
|
|
52029
|
-
}
|
|
52030
|
-
}
|
|
52031
|
-
}
|
|
52032
|
-
var finalComponent = components[componentLen - 1];
|
|
52033
|
-
if (componentLen > 1 && typeof finalComponent.value === "string" && (finalComponent.added || finalComponent.removed) && diff2.equals("", finalComponent.value)) {
|
|
52034
|
-
components[componentLen - 2].value += finalComponent.value;
|
|
52035
|
-
components.pop();
|
|
52036
|
-
}
|
|
52037
|
-
return components;
|
|
52038
|
-
}
|
|
52039
|
-
var characterDiff = new Diff();
|
|
52040
|
-
var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
|
|
52041
|
-
var reWhitespace = /\S/;
|
|
52042
|
-
var wordDiff = new Diff();
|
|
52043
|
-
wordDiff.equals = function(left, right) {
|
|
52044
|
-
if (this.options.ignoreCase) {
|
|
52045
|
-
left = left.toLowerCase();
|
|
52046
|
-
right = right.toLowerCase();
|
|
52047
|
-
}
|
|
52048
|
-
return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
|
|
52049
|
-
};
|
|
52050
|
-
wordDiff.tokenize = function(value) {
|
|
52051
|
-
var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/);
|
|
52052
|
-
for (var i = 0; i < tokens.length - 1; i++) {
|
|
52053
|
-
if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
|
|
52054
|
-
tokens[i] += tokens[i + 2];
|
|
52055
|
-
tokens.splice(i + 1, 2);
|
|
52056
|
-
i--;
|
|
52057
|
-
}
|
|
52058
|
-
}
|
|
52059
|
-
return tokens;
|
|
52060
|
-
};
|
|
52061
|
-
var lineDiff = new Diff();
|
|
52062
|
-
lineDiff.tokenize = function(value) {
|
|
52063
|
-
if (this.options.stripTrailingCr) {
|
|
52064
|
-
value = value.replace(/\r\n/g, "\n");
|
|
52578
|
+
} else {
|
|
52579
|
+
steps.push({
|
|
52580
|
+
key: "daemon-opt-out",
|
|
52581
|
+
label: "Daemon opt-out",
|
|
52582
|
+
args: ["daemon", "stop"],
|
|
52583
|
+
required: true
|
|
52584
|
+
});
|
|
52065
52585
|
}
|
|
52066
|
-
|
|
52067
|
-
|
|
52068
|
-
|
|
52586
|
+
if (opts.scope === "project") {
|
|
52587
|
+
steps.push({ key: "hooks", label: "Git hooks", args: ["hooks", "install"], required: true });
|
|
52588
|
+
} else if (opts.globalHooksPath) {
|
|
52589
|
+
steps.push({
|
|
52590
|
+
key: "hooks",
|
|
52591
|
+
label: "Git hooks (global)",
|
|
52592
|
+
args: ["hooks", "install", "--scope", "user", "--global-hooks-path"],
|
|
52593
|
+
required: true
|
|
52594
|
+
});
|
|
52069
52595
|
}
|
|
52070
|
-
|
|
52071
|
-
|
|
52072
|
-
|
|
52073
|
-
|
|
52074
|
-
|
|
52075
|
-
|
|
52076
|
-
|
|
52077
|
-
|
|
52078
|
-
|
|
52079
|
-
|
|
52596
|
+
const skillArgs = ["skill", "install", "--agent", opts.agent, ...scopeArgs];
|
|
52597
|
+
steps.push({ key: "skill", label: "Agent skill", args: skillArgs, required: true });
|
|
52598
|
+
steps.push({
|
|
52599
|
+
key: "enable",
|
|
52600
|
+
label: "Activate this repo",
|
|
52601
|
+
args: ["enable"],
|
|
52602
|
+
required: true
|
|
52603
|
+
});
|
|
52604
|
+
if (opts.daemon) {
|
|
52605
|
+
steps.push({
|
|
52606
|
+
key: "health",
|
|
52607
|
+
label: "Capture health",
|
|
52608
|
+
args: ["doctor", "--expect-backlog"],
|
|
52609
|
+
required: true
|
|
52610
|
+
});
|
|
52080
52611
|
}
|
|
52081
|
-
return
|
|
52082
|
-
};
|
|
52083
|
-
function diffLines(oldStr, newStr, callback) {
|
|
52084
|
-
return lineDiff.diff(oldStr, newStr, callback);
|
|
52612
|
+
return steps;
|
|
52085
52613
|
}
|
|
52086
|
-
var
|
|
52087
|
-
|
|
52088
|
-
|
|
52089
|
-
|
|
52090
|
-
|
|
52091
|
-
|
|
52092
|
-
|
|
52093
|
-
};
|
|
52094
|
-
function _typeof(obj) {
|
|
52095
|
-
"@babel/helpers - typeof";
|
|
52096
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
52097
|
-
_typeof = function(obj2) {
|
|
52098
|
-
return typeof obj2;
|
|
52099
|
-
};
|
|
52100
|
-
} else {
|
|
52101
|
-
_typeof = function(obj2) {
|
|
52102
|
-
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
52103
|
-
};
|
|
52614
|
+
var CONFLICT_SESSION = "session";
|
|
52615
|
+
var CONFLICT_HOOKS = "hooks";
|
|
52616
|
+
var CONFLICT_SKILL = "skill";
|
|
52617
|
+
function planCleanupUninstalls(agent, conflicts) {
|
|
52618
|
+
const steps = [];
|
|
52619
|
+
if (conflicts.includes(CONFLICT_SESSION) && agent !== "hermes") {
|
|
52620
|
+
steps.push([agent, "uninstall", "--scope", "project"]);
|
|
52104
52621
|
}
|
|
52105
|
-
|
|
52106
|
-
|
|
52107
|
-
|
|
52108
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
52109
|
-
}
|
|
52110
|
-
function _arrayWithoutHoles(arr) {
|
|
52111
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
52112
|
-
}
|
|
52113
|
-
function _iterableToArray(iter) {
|
|
52114
|
-
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
|
52622
|
+
if (conflicts.includes(CONFLICT_HOOKS)) steps.push(["hooks", "uninstall"]);
|
|
52623
|
+
if (conflicts.includes(CONFLICT_SKILL)) steps.push(["skill", "uninstall", "--agent", agent]);
|
|
52624
|
+
return steps;
|
|
52115
52625
|
}
|
|
52116
|
-
function
|
|
52117
|
-
|
|
52118
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
52119
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
52120
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
52121
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
52122
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
52626
|
+
function preCommitRunsPrim(content) {
|
|
52627
|
+
return content.includes("# >>> prim pre-commit hook >>>") || content.includes("prim-pre-commit");
|
|
52123
52628
|
}
|
|
52124
|
-
function
|
|
52125
|
-
|
|
52126
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
52127
|
-
return arr2;
|
|
52629
|
+
function projectHooksConflict(globalHooksActive, preCommit) {
|
|
52630
|
+
return globalHooksActive && preCommit !== void 0 && preCommitRunsPrim(preCommit);
|
|
52128
52631
|
}
|
|
52129
|
-
function
|
|
52130
|
-
|
|
52632
|
+
function enableWiresRepository(root) {
|
|
52633
|
+
if (!root) return void 0;
|
|
52634
|
+
try {
|
|
52635
|
+
if (gitHooksMode({ cwd: root }) === "manual") return void 0;
|
|
52636
|
+
return resolveEffectiveGitHook("post-commit", root).location !== "external";
|
|
52637
|
+
} catch {
|
|
52638
|
+
return void 0;
|
|
52639
|
+
}
|
|
52131
52640
|
}
|
|
52132
|
-
|
|
52133
|
-
|
|
52134
|
-
|
|
52135
|
-
jsonDiff.tokenize = lineDiff.tokenize;
|
|
52136
|
-
jsonDiff.castInput = function(value) {
|
|
52137
|
-
var _this$options = this.options, undefinedReplacement = _this$options.undefinedReplacement, _this$options$stringi = _this$options.stringifyReplacer, stringifyReplacer = _this$options$stringi === void 0 ? function(k, v) {
|
|
52138
|
-
return typeof v === "undefined" ? undefinedReplacement : v;
|
|
52139
|
-
} : _this$options$stringi;
|
|
52140
|
-
return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, " ");
|
|
52141
|
-
};
|
|
52142
|
-
jsonDiff.equals = function(left, right) {
|
|
52143
|
-
return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"));
|
|
52144
|
-
};
|
|
52145
|
-
function canonicalize(obj, stack, replacementStack, replacer, key) {
|
|
52146
|
-
stack = stack || [];
|
|
52147
|
-
replacementStack = replacementStack || [];
|
|
52148
|
-
if (replacer) {
|
|
52149
|
-
obj = replacer(key, obj);
|
|
52641
|
+
function setupGitHooksNote(plan, wiresThisRepository) {
|
|
52642
|
+
if (wiresThisRepository === true && plan.action === "add_to_dir") {
|
|
52643
|
+
return `git hooks \xB7 Git runs this repository's hooks from inside it, so \`prim enable\` wires it; other repositories may run ${plan.global}, which prim edits only with --global-hooks-path, after asking the user`;
|
|
52150
52644
|
}
|
|
52151
|
-
|
|
52152
|
-
|
|
52153
|
-
if (stack[i] === obj) {
|
|
52154
|
-
return replacementStack[i];
|
|
52155
|
-
}
|
|
52645
|
+
if (wiresThisRepository === true && plan.action === "system_declined") {
|
|
52646
|
+
return `git hooks \xB7 Git runs this repository's hooks from inside it, so \`prim enable\` wires it; other repositories may run the system hooks dir ${plan.system}, which prim never edits`;
|
|
52156
52647
|
}
|
|
52157
|
-
|
|
52158
|
-
|
|
52159
|
-
|
|
52160
|
-
|
|
52161
|
-
|
|
52162
|
-
|
|
52163
|
-
|
|
52648
|
+
switch (plan.action) {
|
|
52649
|
+
case "refresh":
|
|
52650
|
+
return "git hooks \xB7 prim's global hooks stay active; `prim enable` refreshes them";
|
|
52651
|
+
case "present_in_dir":
|
|
52652
|
+
return `git hooks \xB7 prim's hooks are already in your global hooks dir ${plan.global}`;
|
|
52653
|
+
case "add_to_dir":
|
|
52654
|
+
return `git hooks \xB7 your global core.hooksPath (${plan.global}) runs every repository's hooks, so \`prim enable\` cannot wire this repository without it; add prim there with --global-hooks-path, after asking the user`;
|
|
52655
|
+
case "system_declined":
|
|
52656
|
+
return `git hooks \xB7 the system core.hooksPath (${plan.system}) runs every repository's hooks, so \`prim enable\` cannot wire this repository: place \`prim hooks snippet <hook>\` there, or, after asking the user, run \`prim hooks install --scope user --global-hooks-path --force\` (its hooks stop firing)`;
|
|
52657
|
+
case "manual":
|
|
52658
|
+
return "git hooks \xB7 prim.gitHooks=manual: prim writes no hook files; wire them with `prim hooks snippet <hook>`";
|
|
52659
|
+
default:
|
|
52660
|
+
return "git hooks \xB7 wired per repository by `prim enable`; git's global hooks are untouched (opt in with --global-hooks-path)";
|
|
52661
|
+
}
|
|
52662
|
+
}
|
|
52663
|
+
function detectProjectConflicts(agent, run, globalHooksActive) {
|
|
52664
|
+
const conflicts = [];
|
|
52665
|
+
if (agent !== "hermes") {
|
|
52666
|
+
try {
|
|
52667
|
+
const parsed = JSON.parse(run([agent, "status"], true).stdout || "{}");
|
|
52668
|
+
if (parsed.project?.gate || parsed.project?.capture) conflicts.push(CONFLICT_SESSION);
|
|
52669
|
+
} catch {
|
|
52164
52670
|
}
|
|
52165
|
-
stack.pop();
|
|
52166
|
-
replacementStack.pop();
|
|
52167
|
-
return canonicalizedObj;
|
|
52168
52671
|
}
|
|
52169
|
-
|
|
52170
|
-
|
|
52672
|
+
let preCommit;
|
|
52673
|
+
try {
|
|
52674
|
+
const root = gitToplevel();
|
|
52675
|
+
const path9 = root && join31(root, ".git", "hooks", "pre-commit");
|
|
52676
|
+
if (path9 && existsSync23(path9)) preCommit = readFileSync23(path9, "utf-8");
|
|
52677
|
+
} catch {
|
|
52171
52678
|
}
|
|
52172
|
-
if (
|
|
52173
|
-
|
|
52174
|
-
|
|
52175
|
-
|
|
52176
|
-
|
|
52177
|
-
|
|
52178
|
-
|
|
52179
|
-
sortedKeys.push(_key);
|
|
52180
|
-
}
|
|
52181
|
-
}
|
|
52182
|
-
sortedKeys.sort();
|
|
52183
|
-
for (i = 0; i < sortedKeys.length; i += 1) {
|
|
52184
|
-
_key = sortedKeys[i];
|
|
52185
|
-
canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
|
|
52186
|
-
}
|
|
52187
|
-
stack.pop();
|
|
52188
|
-
replacementStack.pop();
|
|
52189
|
-
} else {
|
|
52190
|
-
canonicalizedObj = obj;
|
|
52679
|
+
if (projectHooksConflict(globalHooksActive, preCommit)) conflicts.push(CONFLICT_HOOKS);
|
|
52680
|
+
try {
|
|
52681
|
+
const parsed = JSON.parse(
|
|
52682
|
+
run(["skill", "status", "--agent", agent, "--json"], true).stdout || "{}"
|
|
52683
|
+
);
|
|
52684
|
+
if (parsed.installed) conflicts.push(CONFLICT_SKILL);
|
|
52685
|
+
} catch {
|
|
52191
52686
|
}
|
|
52192
|
-
return
|
|
52687
|
+
return conflicts;
|
|
52193
52688
|
}
|
|
52194
|
-
|
|
52195
|
-
|
|
52196
|
-
|
|
52197
|
-
};
|
|
52198
|
-
arrayDiff.join = arrayDiff.removeEmpty = function(value) {
|
|
52199
|
-
return value;
|
|
52200
|
-
};
|
|
52201
|
-
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
52202
|
-
if (!options) {
|
|
52203
|
-
options = {};
|
|
52689
|
+
function detectAgent(env4) {
|
|
52690
|
+
if (env4.HERMES_INTERACTIVE) {
|
|
52691
|
+
return "hermes";
|
|
52204
52692
|
}
|
|
52205
|
-
if (
|
|
52206
|
-
|
|
52693
|
+
if (env4.CURSOR_AGENT) {
|
|
52694
|
+
return "cursor";
|
|
52207
52695
|
}
|
|
52208
|
-
|
|
52209
|
-
|
|
52210
|
-
|
|
52696
|
+
return "claude";
|
|
52697
|
+
}
|
|
52698
|
+
function resolveAgent(agentFlag, env4) {
|
|
52699
|
+
if (agentFlag !== void 0) {
|
|
52700
|
+
return { agent: agentFlag, detected: false };
|
|
52211
52701
|
}
|
|
52212
|
-
|
|
52213
|
-
|
|
52214
|
-
|
|
52215
|
-
|
|
52216
|
-
|
|
52217
|
-
|
|
52218
|
-
|
|
52219
|
-
|
|
52702
|
+
return { agent: detectAgent(env4), detected: true };
|
|
52703
|
+
}
|
|
52704
|
+
function parseSetupAuthStatus(result) {
|
|
52705
|
+
try {
|
|
52706
|
+
const parsed = JSON.parse(result.stdout || "{}");
|
|
52707
|
+
if (parsed.status === "valid" || parsed.authenticated === true) return "valid";
|
|
52708
|
+
if (parsed.status === "unreachable") return "unreachable";
|
|
52709
|
+
if (parsed.status === "invalid") return "invalid";
|
|
52710
|
+
} catch {
|
|
52220
52711
|
}
|
|
52221
|
-
|
|
52222
|
-
|
|
52223
|
-
|
|
52224
|
-
|
|
52225
|
-
|
|
52226
|
-
|
|
52227
|
-
|
|
52228
|
-
|
|
52229
|
-
|
|
52230
|
-
|
|
52231
|
-
|
|
52232
|
-
|
|
52233
|
-
|
|
52234
|
-
|
|
52235
|
-
|
|
52236
|
-
|
|
52712
|
+
return result.code === EXIT_USAGE3 ? "unreachable" : "invalid";
|
|
52713
|
+
}
|
|
52714
|
+
function registerSetupCommand(program3, dependencies = {}) {
|
|
52715
|
+
program3.command("setup").description(
|
|
52716
|
+
"Install everything in one shot (auth, session + git hooks, daemon, skill, welcome)"
|
|
52717
|
+
).option("--agent <agent>", "claude, codex, cursor, or hermes (auto-detected when omitted)").option(
|
|
52718
|
+
"--scope <scope>",
|
|
52719
|
+
"user (default \u2014 agent integration and skill for every repo; git hooks per repo via enable) or project (this repo only)",
|
|
52720
|
+
"user"
|
|
52721
|
+
).option(
|
|
52722
|
+
"--global-hooks-path",
|
|
52723
|
+
"with the default user scope, also change git's global hooks so prim's hooks run in every repository"
|
|
52724
|
+
).option(
|
|
52725
|
+
"--migrate",
|
|
52726
|
+
"with the default user scope, remove any project-scoped prim config in this repo (else just warn)"
|
|
52727
|
+
).option("--no-daemon", "stop and disable the companion daemon").option("--skip-demo", "skip the local onboarding tour and remember that choice").action((opts) => {
|
|
52728
|
+
const { agent: agentInput, detected } = resolveAgent(opts.agent, process.env);
|
|
52729
|
+
if (agentInput !== "claude" && agentInput !== "codex" && agentInput !== "cursor" && agentInput !== "hermes") {
|
|
52730
|
+
process.stderr.write(
|
|
52731
|
+
`[prim] unknown --agent "${agentInput}" (expected claude, codex, cursor, or hermes)
|
|
52732
|
+
`
|
|
52733
|
+
);
|
|
52734
|
+
(dependencies.exit ?? process.exit)(EXIT_USAGE3);
|
|
52735
|
+
return;
|
|
52736
|
+
}
|
|
52737
|
+
if (opts.scope !== "project" && opts.scope !== "user") {
|
|
52738
|
+
process.stderr.write(`[prim] unknown --scope "${opts.scope}" (expected project or user)
|
|
52739
|
+
`);
|
|
52740
|
+
(dependencies.exit ?? process.exit)(EXIT_USAGE3);
|
|
52741
|
+
return;
|
|
52742
|
+
}
|
|
52743
|
+
if (opts.globalHooksPath && opts.scope !== "user") {
|
|
52744
|
+
process.stderr.write("[prim] --global-hooks-path applies only with --scope user\n");
|
|
52745
|
+
(dependencies.exit ?? process.exit)(EXIT_USAGE3);
|
|
52746
|
+
return;
|
|
52747
|
+
}
|
|
52748
|
+
const agent = agentInput;
|
|
52749
|
+
const scope = opts.scope;
|
|
52750
|
+
const self = process.argv[1];
|
|
52751
|
+
const globals = program3.optsWithGlobals();
|
|
52752
|
+
const run = dependencies.run ?? ((args, capture = false) => {
|
|
52753
|
+
const r = spawnSync2(
|
|
52754
|
+
process.execPath,
|
|
52755
|
+
[self, ...args],
|
|
52756
|
+
setupStepSpawnOptions(capture, process.env, { startsDaemon: opts.daemon })
|
|
52757
|
+
);
|
|
52758
|
+
return { code: r.status ?? 1, stdout: capture ? r.stdout ?? "" : "" };
|
|
52759
|
+
});
|
|
52760
|
+
const results = {};
|
|
52761
|
+
const note = dependencies.note ?? ((msg) => {
|
|
52762
|
+
process.stderr.write(`[prim] ${msg}
|
|
52763
|
+
`);
|
|
52764
|
+
});
|
|
52765
|
+
const exit = dependencies.exit ?? process.exit;
|
|
52766
|
+
if (detected && agent !== "claude") {
|
|
52767
|
+
note(`agent \xB7 detected ${agent} session (override with --agent <agent>)`);
|
|
52768
|
+
}
|
|
52769
|
+
let authStatus = parseSetupAuthStatus(run(["auth", "status", "--json"], true));
|
|
52770
|
+
if (authStatus === "unreachable") {
|
|
52771
|
+
note("auth \xB7 verification unavailable; no setup changes were made");
|
|
52772
|
+
exit(EXIT_USAGE3);
|
|
52773
|
+
return;
|
|
52774
|
+
}
|
|
52775
|
+
if (authStatus === "invalid") {
|
|
52776
|
+
note("auth \xB7 opening browser to authenticate\u2026");
|
|
52777
|
+
const login = run(["auth", "login"]);
|
|
52778
|
+
if (login.code !== 0) {
|
|
52779
|
+
note("auth \xB7 login failed; no integration changes were made");
|
|
52780
|
+
exit(EXIT_INCOMPLETE);
|
|
52781
|
+
return;
|
|
52237
52782
|
}
|
|
52238
|
-
|
|
52239
|
-
|
|
52240
|
-
|
|
52241
|
-
|
|
52242
|
-
|
|
52243
|
-
|
|
52244
|
-
|
|
52783
|
+
authStatus = parseSetupAuthStatus(run(["auth", "status", "--json"], true));
|
|
52784
|
+
if (authStatus !== "valid") {
|
|
52785
|
+
note(
|
|
52786
|
+
authStatus === "unreachable" ? "auth \xB7 login completed but verification is unavailable; no integration changes were made" : "auth \xB7 login did not produce valid credentials; no integration changes were made"
|
|
52787
|
+
);
|
|
52788
|
+
exit(authStatus === "unreachable" ? EXIT_USAGE3 : EXIT_INCOMPLETE);
|
|
52789
|
+
return;
|
|
52245
52790
|
}
|
|
52246
52791
|
} else {
|
|
52247
|
-
|
|
52248
|
-
|
|
52249
|
-
|
|
52250
|
-
|
|
52251
|
-
|
|
52252
|
-
|
|
52253
|
-
|
|
52254
|
-
|
|
52255
|
-
|
|
52256
|
-
|
|
52257
|
-
|
|
52258
|
-
|
|
52259
|
-
|
|
52260
|
-
|
|
52261
|
-
|
|
52262
|
-
|
|
52263
|
-
|
|
52264
|
-
|
|
52265
|
-
|
|
52266
|
-
|
|
52267
|
-
|
|
52268
|
-
|
|
52269
|
-
|
|
52270
|
-
|
|
52271
|
-
|
|
52272
|
-
|
|
52273
|
-
|
|
52274
|
-
|
|
52275
|
-
|
|
52276
|
-
|
|
52277
|
-
|
|
52792
|
+
note("auth \xB7 already authenticated");
|
|
52793
|
+
}
|
|
52794
|
+
results.auth = "ok";
|
|
52795
|
+
if (agent === "claude") {
|
|
52796
|
+
note("pre-authorize \xB7 writing prim allow-rule (user scope)\u2026");
|
|
52797
|
+
results.preauth = run(["claude", "preauth", "--scope", "user"]).code === 0 ? "ok" : "skipped";
|
|
52798
|
+
}
|
|
52799
|
+
const setupSteps = planSetupSteps({
|
|
52800
|
+
agent,
|
|
52801
|
+
daemon: opts.daemon,
|
|
52802
|
+
scope,
|
|
52803
|
+
globalHooksPath: opts.globalHooksPath === true
|
|
52804
|
+
});
|
|
52805
|
+
for (const step of setupSteps.filter(
|
|
52806
|
+
(candidate) => candidate.key !== "enable" && candidate.key !== "health"
|
|
52807
|
+
)) {
|
|
52808
|
+
note(`${step.label} \xB7 installing\u2026`);
|
|
52809
|
+
const { code } = run(step.args);
|
|
52810
|
+
results[step.key] = code === 0 ? "ok" : code === EXIT_GLOBAL_HOOKS_NOT_INSTALLED && step.key === "hooks" ? "skipped" : step.required ? "failed" : "skipped";
|
|
52811
|
+
}
|
|
52812
|
+
if (scope === "user" && !opts.globalHooksPath) {
|
|
52813
|
+
note(setupGitHooksNote(planGlobalHooks(), enableWiresRepository(gitToplevel())));
|
|
52814
|
+
}
|
|
52815
|
+
if (scope === "user") {
|
|
52816
|
+
const conflicts = detectProjectConflicts(agent, run, globalHooksPathIsPrims());
|
|
52817
|
+
if (conflicts.length > 0 && opts.migrate) {
|
|
52818
|
+
note(`migrate \xB7 removing project-scoped config (${conflicts.join(", ")})\u2026`);
|
|
52819
|
+
const ok = planCleanupUninstalls(agent, conflicts).map((args) => run(args).code === 0).every(Boolean);
|
|
52820
|
+
results.migrate = ok ? "ok" : "failed";
|
|
52821
|
+
} else if (conflicts.length > 0) {
|
|
52822
|
+
note(
|
|
52823
|
+
`migrate \xB7 project-scoped prim config present in this repo (${conflicts.join(", ")}) \u2014 it will double-fire with the user-scope install. Re-run \`prim setup --migrate\` to remove it.`
|
|
52824
|
+
);
|
|
52278
52825
|
}
|
|
52279
|
-
oldLine += lines.length;
|
|
52280
|
-
newLine += lines.length;
|
|
52281
52826
|
}
|
|
52282
|
-
|
|
52283
|
-
|
|
52284
|
-
|
|
52285
|
-
|
|
52286
|
-
|
|
52287
|
-
|
|
52288
|
-
|
|
52289
|
-
|
|
52290
|
-
|
|
52291
|
-
|
|
52292
|
-
};
|
|
52293
|
-
}
|
|
52294
|
-
function formatPatch(diff2) {
|
|
52295
|
-
if (Array.isArray(diff2)) {
|
|
52296
|
-
return diff2.map(formatPatch).join("\n");
|
|
52297
|
-
}
|
|
52298
|
-
var ret = [];
|
|
52299
|
-
if (diff2.oldFileName == diff2.newFileName) {
|
|
52300
|
-
ret.push("Index: " + diff2.oldFileName);
|
|
52301
|
-
}
|
|
52302
|
-
ret.push("===================================================================");
|
|
52303
|
-
ret.push("--- " + diff2.oldFileName + (typeof diff2.oldHeader === "undefined" ? "" : " " + diff2.oldHeader));
|
|
52304
|
-
ret.push("+++ " + diff2.newFileName + (typeof diff2.newHeader === "undefined" ? "" : " " + diff2.newHeader));
|
|
52305
|
-
for (var i = 0; i < diff2.hunks.length; i++) {
|
|
52306
|
-
var hunk = diff2.hunks[i];
|
|
52307
|
-
if (hunk.oldLines === 0) {
|
|
52308
|
-
hunk.oldStart -= 1;
|
|
52827
|
+
const enableStep = setupSteps.find((candidate) => candidate.key === "enable");
|
|
52828
|
+
if (enableStep) {
|
|
52829
|
+
note(`${enableStep.label} \xB7 installing\u2026`);
|
|
52830
|
+
const enableArgs = [
|
|
52831
|
+
...enableStep.args,
|
|
52832
|
+
...globals.yes ? ["--yes"] : [],
|
|
52833
|
+
...globals.nonInteractive ? ["--non-interactive"] : []
|
|
52834
|
+
];
|
|
52835
|
+
const { code } = run(enableArgs);
|
|
52836
|
+
results[enableStep.key] = code === 0 ? "ok" : enableStep.required ? "failed" : "skipped";
|
|
52309
52837
|
}
|
|
52310
|
-
|
|
52311
|
-
|
|
52838
|
+
const healthStep = setupSteps.find((candidate) => candidate.key === "health");
|
|
52839
|
+
if (healthStep) {
|
|
52840
|
+
note(`${healthStep.label} \xB7 verifying\u2026`);
|
|
52841
|
+
const { code } = run(healthStep.args);
|
|
52842
|
+
results[healthStep.key] = code === 0 ? "ok" : healthStep.required ? "failed" : "skipped";
|
|
52312
52843
|
}
|
|
52313
|
-
|
|
52314
|
-
|
|
52315
|
-
|
|
52316
|
-
|
|
52317
|
-
|
|
52318
|
-
|
|
52319
|
-
|
|
52320
|
-
|
|
52321
|
-
|
|
52322
|
-
|
|
52844
|
+
const installationSucceeded = !Object.values(results).includes("failed");
|
|
52845
|
+
let tourDue = false;
|
|
52846
|
+
if (installationSucceeded && !opts.skipDemo) {
|
|
52847
|
+
try {
|
|
52848
|
+
tourDue = !onboardingFinished();
|
|
52849
|
+
} catch (error) {
|
|
52850
|
+
tourDue = true;
|
|
52851
|
+
note(
|
|
52852
|
+
`demo \xB7 cannot read onboarding state: ${error instanceof Error ? error.message : String(error)}; use prim demo to retry`
|
|
52853
|
+
);
|
|
52854
|
+
}
|
|
52855
|
+
}
|
|
52856
|
+
if (installationSucceeded && opts.skipDemo) {
|
|
52857
|
+
if (run(["demo", "skip"]).code !== 0)
|
|
52858
|
+
note("demo \xB7 could not remember skip; installation remains configured");
|
|
52859
|
+
}
|
|
52860
|
+
note("welcome");
|
|
52861
|
+
results.welcome = run(["welcome", "--agent", agent, ...tourDue ? ["--defer-seeding"] : []]).code === 0 ? "ok" : "failed";
|
|
52862
|
+
const failed = Object.entries(results).filter(([, v]) => v === "failed").map(([k]) => k);
|
|
52863
|
+
const trail = Object.entries(results).map(([k, v]) => `${k}:${v}`).join(" \xB7 ");
|
|
52864
|
+
note(
|
|
52865
|
+
`setup ${failed.length === 0 ? "complete" : `incomplete (failed: ${failed.join(", ")})`} \u2014 ${trail}`
|
|
52866
|
+
);
|
|
52867
|
+
if (failed.length === 0 && tourDue) {
|
|
52868
|
+
const agentDriven = Boolean(
|
|
52869
|
+
opts.agent || !process.stdin.isTTY || !process.stderr.isTTY || process.env.CLAUDECODE || process.env.CODEX_THREAD_ID || process.env.CURSOR_AGENT || process.env.HERMES_INTERACTIVE
|
|
52870
|
+
);
|
|
52871
|
+
const demoResult = run([
|
|
52872
|
+
...globals.nonInteractive ? ["--non-interactive"] : [],
|
|
52873
|
+
"demo",
|
|
52874
|
+
...agentDriven ? ["--agent", agent] : []
|
|
52875
|
+
]);
|
|
52876
|
+
if (demoResult.code !== 0)
|
|
52877
|
+
note("demo \xB7 pending after an error; setup succeeded. Run prim demo to retry");
|
|
52878
|
+
}
|
|
52879
|
+
exit(failed.length === 0 ? 0 : EXIT_INCOMPLETE);
|
|
52880
|
+
});
|
|
52323
52881
|
}
|
|
52324
52882
|
|
|
52883
|
+
// src/commands/skill.ts
|
|
52884
|
+
import { createHash as createHash12 } from "crypto";
|
|
52885
|
+
import {
|
|
52886
|
+
constants as constants8,
|
|
52887
|
+
closeSync as closeSync8,
|
|
52888
|
+
existsSync as existsSync25,
|
|
52889
|
+
fstatSync as fstatSync4,
|
|
52890
|
+
lstatSync as lstatSync11,
|
|
52891
|
+
openSync as openSync8,
|
|
52892
|
+
readFileSync as readFileSync25,
|
|
52893
|
+
readSync as readSync4,
|
|
52894
|
+
readdirSync as readdirSync11,
|
|
52895
|
+
rmdirSync as rmdirSync4,
|
|
52896
|
+
unlinkSync as unlinkSync9
|
|
52897
|
+
} from "fs";
|
|
52898
|
+
import { homedir as homedir11 } from "os";
|
|
52899
|
+
import { dirname as dirname18, join as join33, resolve as resolve10 } from "path";
|
|
52900
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
52901
|
+
|
|
52325
52902
|
// src/commands/claude-plugin.ts
|
|
52326
|
-
import { createHash as
|
|
52903
|
+
import { createHash as createHash11 } from "crypto";
|
|
52327
52904
|
import {
|
|
52328
52905
|
constants as constants7,
|
|
52329
52906
|
closeSync as closeSync7,
|
|
52330
|
-
existsSync as
|
|
52907
|
+
existsSync as existsSync24,
|
|
52331
52908
|
fstatSync as fstatSync3,
|
|
52332
|
-
lstatSync as
|
|
52909
|
+
lstatSync as lstatSync10,
|
|
52333
52910
|
mkdirSync as mkdirSync15,
|
|
52334
52911
|
openSync as openSync7,
|
|
52335
|
-
readFileSync as
|
|
52912
|
+
readFileSync as readFileSync24,
|
|
52336
52913
|
readSync as readSync3,
|
|
52337
|
-
readdirSync as
|
|
52338
|
-
realpathSync as
|
|
52914
|
+
readdirSync as readdirSync10,
|
|
52915
|
+
realpathSync as realpathSync6,
|
|
52339
52916
|
rmSync as rmSync9,
|
|
52340
|
-
rmdirSync as
|
|
52917
|
+
rmdirSync as rmdirSync3
|
|
52341
52918
|
} from "fs";
|
|
52342
52919
|
import { homedir as homedir10 } from "os";
|
|
52343
|
-
import { dirname as
|
|
52920
|
+
import { dirname as dirname17, isAbsolute as isAbsolute9, join as join32, relative as relative3, resolve as resolve9, sep as sep3 } from "path";
|
|
52344
52921
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
52345
|
-
var __dirname4 =
|
|
52922
|
+
var __dirname4 = dirname17(fileURLToPath4(import.meta.url));
|
|
52346
52923
|
var PLUGIN_DESCRIPTION = "Primitive decision-graph guidance for the prim CLI \u2014 a model-invoked skill installed by prim skill install.";
|
|
52347
52924
|
var MAX_MANIFEST_BYTES2 = 64 * 1024;
|
|
52348
52925
|
var MAX_SKILL_BYTES = 1024 * 1024;
|
|
52349
52926
|
function pluginDirFor(cwd, scope) {
|
|
52350
|
-
const base = scope === "user" ?
|
|
52351
|
-
return
|
|
52927
|
+
const base = scope === "user" ? join32(homedir10(), ".claude") : join32(gitToplevel(cwd) ?? cwd, ".claude");
|
|
52928
|
+
return join32(base, "skills", "prim");
|
|
52352
52929
|
}
|
|
52353
52930
|
function resolvePluginDir(cwd, scope) {
|
|
52354
52931
|
if (scope && scope !== "user" && scope !== "project") {
|
|
@@ -52359,10 +52936,10 @@ function resolvePluginDir(cwd, scope) {
|
|
|
52359
52936
|
}
|
|
52360
52937
|
function packageVersion2() {
|
|
52361
52938
|
let dir = __dirname4;
|
|
52362
|
-
while (dir !==
|
|
52363
|
-
const p =
|
|
52364
|
-
if (
|
|
52365
|
-
dir =
|
|
52939
|
+
while (dir !== dirname17(dir)) {
|
|
52940
|
+
const p = resolve9(dir, "package.json");
|
|
52941
|
+
if (existsSync24(p)) return JSON.parse(readFileSync24(p, "utf-8")).version;
|
|
52942
|
+
dir = dirname17(dir);
|
|
52366
52943
|
}
|
|
52367
52944
|
return "0.0.0";
|
|
52368
52945
|
}
|
|
@@ -52376,12 +52953,12 @@ function renderClaudePlugin() {
|
|
|
52376
52953
|
return { manifest: pluginManifest(version), skill: loadSkill(), version };
|
|
52377
52954
|
}
|
|
52378
52955
|
function removeDirIfEmpty(dir) {
|
|
52379
|
-
if (
|
|
52956
|
+
if (existsSync24(dir) && readdirSync10(dir).length === 0) rmdirSync3(dir);
|
|
52380
52957
|
}
|
|
52381
52958
|
function pluginPaths(dir) {
|
|
52382
52959
|
return {
|
|
52383
|
-
manifestPath:
|
|
52384
|
-
skillPath:
|
|
52960
|
+
manifestPath: join32(dir, ".claude-plugin", "plugin.json"),
|
|
52961
|
+
skillPath: join32(dir, "SKILL.md")
|
|
52385
52962
|
};
|
|
52386
52963
|
}
|
|
52387
52964
|
function installClaudePlugin(cwd, opts) {
|
|
@@ -52389,8 +52966,8 @@ function installClaudePlugin(cwd, opts) {
|
|
|
52389
52966
|
if (dir === null) return 1;
|
|
52390
52967
|
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
52391
52968
|
const { manifest, skill } = renderClaudePlugin();
|
|
52392
|
-
const manifestCurrent =
|
|
52393
|
-
const skillCurrent =
|
|
52969
|
+
const manifestCurrent = existsSync24(manifestPath) ? readFileSync24(manifestPath, "utf-8") : null;
|
|
52970
|
+
const skillCurrent = existsSync24(skillPath) ? readFileSync24(skillPath, "utf-8") : null;
|
|
52394
52971
|
if (manifestCurrent === manifest && skillCurrent === skill) {
|
|
52395
52972
|
console.log("No changes \u2014 prim skill plugin already up to date.");
|
|
52396
52973
|
return 0;
|
|
@@ -52399,7 +52976,7 @@ function installClaudePlugin(cwd, opts) {
|
|
|
52399
52976
|
console.log(`Would write plugin to ${dir} (.claude-plugin/plugin.json + SKILL.md)`);
|
|
52400
52977
|
return 0;
|
|
52401
52978
|
}
|
|
52402
|
-
mkdirSync15(
|
|
52979
|
+
mkdirSync15(join32(dir, ".claude-plugin"), { recursive: true });
|
|
52403
52980
|
atomicWrite5(manifestPath, manifest);
|
|
52404
52981
|
atomicWrite5(skillPath, skill);
|
|
52405
52982
|
console.log(`Installed prim skill plugin at ${dir}`);
|
|
@@ -52413,13 +52990,13 @@ function uninstallClaudePlugin(cwd, opts) {
|
|
|
52413
52990
|
const dir = resolvePluginDir(cwd, opts.scope);
|
|
52414
52991
|
if (dir === null) return 1;
|
|
52415
52992
|
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
52416
|
-
if (!
|
|
52993
|
+
if (!existsSync24(manifestPath) && !existsSync24(skillPath)) {
|
|
52417
52994
|
console.log(`prim skill plugin not present at ${dir}`);
|
|
52418
52995
|
return 0;
|
|
52419
52996
|
}
|
|
52420
52997
|
rmSync9(manifestPath, { force: true });
|
|
52421
52998
|
rmSync9(skillPath, { force: true });
|
|
52422
|
-
removeDirIfEmpty(
|
|
52999
|
+
removeDirIfEmpty(join32(dir, ".claude-plugin"));
|
|
52423
53000
|
removeDirIfEmpty(dir);
|
|
52424
53001
|
console.log(`Removed prim skill plugin from ${dir}`);
|
|
52425
53002
|
return 0;
|
|
@@ -52428,7 +53005,7 @@ function statusClaudePlugin(cwd, opts) {
|
|
|
52428
53005
|
const dir = resolvePluginDir(cwd, opts.scope);
|
|
52429
53006
|
if (dir === null) return 1;
|
|
52430
53007
|
const { skillPath } = pluginPaths(dir);
|
|
52431
|
-
const installed =
|
|
53008
|
+
const installed = existsSync24(skillPath);
|
|
52432
53009
|
if (opts.json) {
|
|
52433
53010
|
printJson({ installed, target: dir });
|
|
52434
53011
|
return installed ? 0 : 1;
|
|
@@ -52442,7 +53019,7 @@ function statusClaudePlugin(cwd, opts) {
|
|
|
52442
53019
|
}
|
|
52443
53020
|
|
|
52444
53021
|
// src/commands/skill.ts
|
|
52445
|
-
var __dirname5 =
|
|
53022
|
+
var __dirname5 = dirname18(fileURLToPath5(import.meta.url));
|
|
52446
53023
|
var SKILL_BEGIN = "<!-- BEGIN PRIM SKILL v1 -->";
|
|
52447
53024
|
var SKILL_END = "<!-- END PRIM SKILL v1 -->";
|
|
52448
53025
|
var CODEX_GUIDANCE_LIMIT_BYTES = 1024 * 1024;
|
|
@@ -52466,23 +53043,23 @@ var AGENT_TARGET = {
|
|
|
52466
53043
|
var CURSOR_SKILL_OWNER = "@primitive.ai/prim";
|
|
52467
53044
|
var CURSOR_SKILL_MANIFEST = ".prim-owned.json";
|
|
52468
53045
|
function sha2563(content) {
|
|
52469
|
-
return
|
|
53046
|
+
return createHash12("sha256").update(content).digest("hex");
|
|
52470
53047
|
}
|
|
52471
53048
|
function cursorSkillDirectory(cwd, scope) {
|
|
52472
53049
|
const base = scope === "user" ? cursorConfigDirectory() : gitToplevel(cwd) ?? cwd;
|
|
52473
|
-
return
|
|
53050
|
+
return join33(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
|
|
52474
53051
|
}
|
|
52475
53052
|
function cursorSkillPaths(cwd, scope) {
|
|
52476
53053
|
const directory = cursorSkillDirectory(cwd, scope);
|
|
52477
53054
|
return {
|
|
52478
53055
|
directory,
|
|
52479
|
-
skill:
|
|
52480
|
-
manifest:
|
|
53056
|
+
skill: join33(directory, "SKILL.md"),
|
|
53057
|
+
manifest: join33(directory, CURSOR_SKILL_MANIFEST)
|
|
52481
53058
|
};
|
|
52482
53059
|
}
|
|
52483
53060
|
function readCursorSkillManifest(path9) {
|
|
52484
53061
|
try {
|
|
52485
|
-
const value = JSON.parse(
|
|
53062
|
+
const value = JSON.parse(readFileSync25(path9, "utf8"));
|
|
52486
53063
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
52487
53064
|
const record3 = value;
|
|
52488
53065
|
if (record3.version !== 1 || record3.owner !== CURSOR_SKILL_OWNER || typeof record3.contentSha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record3.contentSha256)) {
|
|
@@ -52496,7 +53073,7 @@ function readCursorSkillManifest(path9) {
|
|
|
52496
53073
|
function cursorSkillStatus(cwd, scope) {
|
|
52497
53074
|
const paths = cursorSkillPaths(cwd, scope);
|
|
52498
53075
|
const manifest = readCursorSkillManifest(paths.manifest);
|
|
52499
|
-
const content =
|
|
53076
|
+
const content = existsSync25(paths.skill) ? readFileSync25(paths.skill, "utf8") : void 0;
|
|
52500
53077
|
const owned = manifest !== void 0;
|
|
52501
53078
|
const installed = owned && content !== void 0 && sha2563(content) === manifest.contentSha256;
|
|
52502
53079
|
return {
|
|
@@ -52514,8 +53091,8 @@ function validCursorSkillScope(scope) {
|
|
|
52514
53091
|
function installCursorSkill(cwd, opts) {
|
|
52515
53092
|
const paths = cursorSkillPaths(cwd, opts.scope);
|
|
52516
53093
|
const status = cursorSkillStatus(cwd, opts.scope);
|
|
52517
|
-
const manifestExists =
|
|
52518
|
-
const skillExists =
|
|
53094
|
+
const manifestExists = existsSync25(paths.manifest);
|
|
53095
|
+
const skillExists = existsSync25(paths.skill);
|
|
52519
53096
|
if (manifestExists && !status.owned || !manifestExists && skillExists || status.edited) {
|
|
52520
53097
|
console.error(`Refusing to overwrite a foreign or edited Cursor skill at ${paths.skill}`);
|
|
52521
53098
|
return 1;
|
|
@@ -52526,12 +53103,12 @@ function installCursorSkill(cwd, opts) {
|
|
|
52526
53103
|
owner: CURSOR_SKILL_OWNER,
|
|
52527
53104
|
contentSha256: sha2563(content)
|
|
52528
53105
|
};
|
|
52529
|
-
if (status.installed &&
|
|
53106
|
+
if (status.installed && readFileSync25(paths.skill, "utf8") === content) {
|
|
52530
53107
|
console.log(`No changes \u2014 Cursor skill already up to date at ${paths.skill}`);
|
|
52531
53108
|
return 0;
|
|
52532
53109
|
}
|
|
52533
53110
|
if (opts.dryRun) {
|
|
52534
|
-
const existing = skillExists ?
|
|
53111
|
+
const existing = skillExists ? readFileSync25(paths.skill, "utf8") : "";
|
|
52535
53112
|
process.stdout.write(createPatch(paths.skill, existing, content, "current", "proposed"));
|
|
52536
53113
|
return 0;
|
|
52537
53114
|
}
|
|
@@ -52552,34 +53129,34 @@ function uninstallCursorSkill(cwd, scope) {
|
|
|
52552
53129
|
console.error(`Refusing to remove an edited Cursor skill at ${paths.skill}`);
|
|
52553
53130
|
return 1;
|
|
52554
53131
|
}
|
|
52555
|
-
if (
|
|
52556
|
-
if (
|
|
53132
|
+
if (existsSync25(paths.skill)) unlinkSync9(paths.skill);
|
|
53133
|
+
if (existsSync25(paths.manifest)) unlinkSync9(paths.manifest);
|
|
52557
53134
|
try {
|
|
52558
|
-
if (
|
|
53135
|
+
if (readdirSync11(paths.directory).length === 0) rmdirSync4(paths.directory);
|
|
52559
53136
|
} catch {
|
|
52560
53137
|
}
|
|
52561
53138
|
console.log(`Removed Primitive-owned Cursor skill from ${paths.skill}`);
|
|
52562
53139
|
return 0;
|
|
52563
53140
|
}
|
|
52564
53141
|
function userTargetFor(agent) {
|
|
52565
|
-
if (agent === "claude") return
|
|
52566
|
-
if (agent === "codex") return
|
|
53142
|
+
if (agent === "claude") return join33(homedir11(), ".claude", "CLAUDE.md");
|
|
53143
|
+
if (agent === "codex") return join33(homedir11(), ".codex", "AGENTS.md");
|
|
52567
53144
|
if (agent === "hermes") {
|
|
52568
|
-
return
|
|
53145
|
+
return join33(process.env.HERMES_HOME ?? join33(homedir11(), ".hermes"), ".hermes.md");
|
|
52569
53146
|
}
|
|
52570
53147
|
return null;
|
|
52571
53148
|
}
|
|
52572
53149
|
function loadSkill() {
|
|
52573
53150
|
let dir = __dirname5;
|
|
52574
|
-
while (dir !==
|
|
52575
|
-
const p =
|
|
52576
|
-
if (
|
|
52577
|
-
dir =
|
|
53151
|
+
while (dir !== dirname18(dir)) {
|
|
53152
|
+
const p = resolve10(dir, "SKILL.md");
|
|
53153
|
+
if (existsSync25(p)) return readFileSync25(p, "utf-8");
|
|
53154
|
+
dir = dirname18(dir);
|
|
52578
53155
|
}
|
|
52579
53156
|
throw new Error("SKILL.md not found in package");
|
|
52580
53157
|
}
|
|
52581
53158
|
function detectTargets(cwd) {
|
|
52582
|
-
return TARGET_CANDIDATES.filter((p) =>
|
|
53159
|
+
return TARGET_CANDIDATES.filter((p) => existsSync25(resolve10(cwd, p)));
|
|
52583
53160
|
}
|
|
52584
53161
|
function detectNewline(content) {
|
|
52585
53162
|
return content.includes("\r\n") ? "\r\n" : "\n";
|
|
@@ -52613,7 +53190,7 @@ function resolveTarget(cwd, opts) {
|
|
|
52613
53190
|
console.error(`Unknown --scope "${opts.scope}" (expected user or project)`);
|
|
52614
53191
|
return null;
|
|
52615
53192
|
}
|
|
52616
|
-
if (opts.target) return
|
|
53193
|
+
if (opts.target) return resolve10(cwd, opts.target);
|
|
52617
53194
|
if (opts.scope === "user") {
|
|
52618
53195
|
if (!opts.agent) {
|
|
52619
53196
|
console.error("--scope user requires --agent (claude, codex, cursor, or hermes)");
|
|
@@ -52626,13 +53203,13 @@ function resolveTarget(cwd, opts) {
|
|
|
52626
53203
|
}
|
|
52627
53204
|
if (opts.agent) {
|
|
52628
53205
|
const mapped = AGENT_TARGET[opts.agent];
|
|
52629
|
-
if (typeof mapped === "string") return
|
|
53206
|
+
if (typeof mapped === "string") return resolve10(cwd, mapped);
|
|
52630
53207
|
console.error(`Unknown --agent "${opts.agent}" (expected claude, codex, cursor, or hermes)`);
|
|
52631
53208
|
return null;
|
|
52632
53209
|
}
|
|
52633
53210
|
const matches = detectTargets(cwd);
|
|
52634
|
-
if (matches.length === 0) return
|
|
52635
|
-
if (matches.length === 1) return
|
|
53211
|
+
if (matches.length === 0) return resolve10(cwd, DEFAULT_TARGET);
|
|
53212
|
+
if (matches.length === 1) return resolve10(cwd, matches[0]);
|
|
52636
53213
|
console.error("Multiple rules files detected. Use --target to disambiguate:");
|
|
52637
53214
|
for (const m of matches) console.error(` ${m}`);
|
|
52638
53215
|
return null;
|
|
@@ -52645,7 +53222,7 @@ function runInstall(cwd, opts) {
|
|
|
52645
53222
|
}
|
|
52646
53223
|
const target = resolveTarget(cwd, opts);
|
|
52647
53224
|
if (target === null) return 1;
|
|
52648
|
-
const existing =
|
|
53225
|
+
const existing = existsSync25(target) ? readFileSync25(target, "utf-8") : "";
|
|
52649
53226
|
const eol = existing ? detectNewline(existing) : "\n";
|
|
52650
53227
|
const block = composeBlock(loadSkill(), eol);
|
|
52651
53228
|
const next = applyBlock(existing, block, eol);
|
|
@@ -52669,11 +53246,11 @@ function runUninstall(cwd, opts) {
|
|
|
52669
53246
|
}
|
|
52670
53247
|
const target = resolveTarget(cwd, opts);
|
|
52671
53248
|
if (target === null) return 1;
|
|
52672
|
-
if (!
|
|
53249
|
+
if (!existsSync25(target)) {
|
|
52673
53250
|
console.log(`Skill block not present at ${target}`);
|
|
52674
53251
|
return 0;
|
|
52675
53252
|
}
|
|
52676
|
-
const existing =
|
|
53253
|
+
const existing = readFileSync25(target, "utf-8");
|
|
52677
53254
|
const next = removeBlock(existing);
|
|
52678
53255
|
if (next === null) {
|
|
52679
53256
|
console.log(`Skill block not present at ${target}`);
|
|
@@ -52697,10 +53274,10 @@ function runStatus(cwd, opts) {
|
|
|
52697
53274
|
}
|
|
52698
53275
|
const target = resolveTarget(cwd, opts);
|
|
52699
53276
|
if (target === null) return 1;
|
|
52700
|
-
const fileExists =
|
|
53277
|
+
const fileExists = existsSync25(target);
|
|
52701
53278
|
let installed = false;
|
|
52702
53279
|
if (fileExists) {
|
|
52703
|
-
const content =
|
|
53280
|
+
const content = readFileSync25(target, "utf-8");
|
|
52704
53281
|
installed = content.includes(SKILL_BEGIN) && content.includes(SKILL_END);
|
|
52705
53282
|
}
|
|
52706
53283
|
if (opts.json) {
|
|
@@ -52737,23 +53314,23 @@ function registerSkillCommands(program3) {
|
|
|
52737
53314
|
}
|
|
52738
53315
|
|
|
52739
53316
|
// src/commands/statusline.ts
|
|
52740
|
-
import { readFileSync as
|
|
52741
|
-
import { dirname as
|
|
53317
|
+
import { readFileSync as readFileSync26 } from "fs";
|
|
53318
|
+
import { dirname as dirname19, resolve as resolve11 } from "path";
|
|
52742
53319
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
52743
53320
|
var STATUSLINE_TIMEOUT_MS = 200;
|
|
52744
53321
|
function readPackageVersion() {
|
|
52745
53322
|
try {
|
|
52746
|
-
const here =
|
|
53323
|
+
const here = dirname19(fileURLToPath6(import.meta.url));
|
|
52747
53324
|
const candidates = [
|
|
52748
53325
|
// Schema-v2 runtimes staged a manifest beside this standalone bundle.
|
|
52749
53326
|
// Keep resolving it while those legacy launchers transition to schema v3.
|
|
52750
|
-
|
|
52751
|
-
|
|
52752
|
-
|
|
53327
|
+
resolve11(here, "manifest.json"),
|
|
53328
|
+
resolve11(here, "../../package.json"),
|
|
53329
|
+
resolve11(here, "../package.json")
|
|
52753
53330
|
];
|
|
52754
53331
|
for (const path9 of candidates) {
|
|
52755
53332
|
try {
|
|
52756
|
-
const pkg2 = JSON.parse(
|
|
53333
|
+
const pkg2 = JSON.parse(readFileSync26(path9, "utf-8"));
|
|
52757
53334
|
if (pkg2.version) {
|
|
52758
53335
|
return pkg2.version;
|
|
52759
53336
|
}
|
|
@@ -53066,10 +53643,11 @@ var GUIDANCE_PASSIVE = {
|
|
|
53066
53643
|
hermes: "Otherwise, once you approve the prim hooks when Hermes prompts, Primitive passively captures decisions in the background while you work.",
|
|
53067
53644
|
generic: "Otherwise, once your agent's prim hooks are active, Primitive passively captures decisions in the background while you work."
|
|
53068
53645
|
};
|
|
53069
|
-
|
|
53646
|
+
var EXCLUDED_CAPTURE = "Passive capture is excluded for this onboarding session. Start a new session for normal capture; explicitly approved real Decisions can still be created.";
|
|
53647
|
+
function seedGuidanceFor(agent, captureExcluded = false) {
|
|
53070
53648
|
return [
|
|
53071
53649
|
"You can tell your agent to add any decision to your Primitive decision graph at any time.",
|
|
53072
|
-
GUIDANCE_PASSIVE[agent ?? "generic"],
|
|
53650
|
+
captureExcluded ? EXCLUDED_CAPTURE : GUIDANCE_PASSIVE[agent ?? "generic"],
|
|
53073
53651
|
"To capture decisions in other repositories, enable Primitive there too: run `prim enable` in each one."
|
|
53074
53652
|
].join(" ");
|
|
53075
53653
|
}
|
|
@@ -53084,7 +53662,7 @@ function welcomeStateFromRecent(result) {
|
|
|
53084
53662
|
}
|
|
53085
53663
|
return { org: "active", recent };
|
|
53086
53664
|
}
|
|
53087
|
-
function formatWelcome(state, agent) {
|
|
53665
|
+
function formatWelcome(state, agent, captureExcluded = false) {
|
|
53088
53666
|
const cmd = (command, desc) => ` ${dim(command.padEnd(CMD_GUTTER))}${desc}`;
|
|
53089
53667
|
const bullet = (text) => ` ${color("\u2022", "green")} ${text}`;
|
|
53090
53668
|
const asBullet = ([first, ...rest]) => [
|
|
@@ -53099,7 +53677,7 @@ function formatWelcome(state, agent) {
|
|
|
53099
53677
|
"shared graph \u2014 automatically, as you work.",
|
|
53100
53678
|
"",
|
|
53101
53679
|
bold("How it works"),
|
|
53102
|
-
...asBullet(CAPTURE_LINES[copyKey]),
|
|
53680
|
+
...asBullet(captureExcluded ? [EXCLUDED_CAPTURE] : CAPTURE_LINES[copyKey]),
|
|
53103
53681
|
bullet("Conflict Gates can warn, ask, or block edits that conflict"),
|
|
53104
53682
|
" with a load-bearing decision when Enforcement is enabled.",
|
|
53105
53683
|
bullet('Occasional yes/no prompts confirm the "why" behind a decision \u2014'),
|
|
@@ -53129,7 +53707,7 @@ function formatWelcome(state, agent) {
|
|
|
53129
53707
|
"",
|
|
53130
53708
|
bold("From here on"),
|
|
53131
53709
|
bullet("Tell your agent to add any decision to Primitive, any time."),
|
|
53132
|
-
...asBullet(PASSIVE_LINES[copyKey]),
|
|
53710
|
+
...asBullet(captureExcluded ? [EXCLUDED_CAPTURE] : PASSIVE_LINES[copyKey]),
|
|
53133
53711
|
bullet("Run `prim enable` in each additional repo you want captured.")
|
|
53134
53712
|
];
|
|
53135
53713
|
} else {
|
|
@@ -53142,7 +53720,7 @@ function formatWelcome(state, agent) {
|
|
|
53142
53720
|
}
|
|
53143
53721
|
return [...head, ...body, "", dim("App: https://app.getprimitive.ai")].join("\n");
|
|
53144
53722
|
}
|
|
53145
|
-
function welcomeJson(state, agent) {
|
|
53723
|
+
function welcomeJson(state, agent, captureExcluded = false) {
|
|
53146
53724
|
if (state.org === "active") {
|
|
53147
53725
|
return { welcomed: true, org: "active", recent: state.recent };
|
|
53148
53726
|
}
|
|
@@ -53150,21 +53728,30 @@ function welcomeJson(state, agent) {
|
|
|
53150
53728
|
return {
|
|
53151
53729
|
welcomed: true,
|
|
53152
53730
|
org: "seed",
|
|
53153
|
-
seedGuidance: seedGuidanceFor(agent),
|
|
53731
|
+
seedGuidance: seedGuidanceFor(agent, captureExcluded),
|
|
53154
53732
|
recent: state.recent
|
|
53155
53733
|
};
|
|
53156
53734
|
}
|
|
53157
53735
|
return { welcomed: true, org: "unknown" };
|
|
53158
53736
|
}
|
|
53159
53737
|
function registerWelcomeCommand(program3, deps = { getClient }) {
|
|
53160
|
-
program3.command("welcome").description("Print a brief orientation to Primitive's decision graph").option("--agent <agent>", "claude, codex, cursor, or hermes \u2014 tailors the capture guidance").
|
|
53161
|
-
|
|
53162
|
-
|
|
53163
|
-
|
|
53164
|
-
|
|
53738
|
+
program3.command("welcome").description("Print a brief orientation to Primitive's decision graph").option("--agent <agent>", "claude, codex, cursor, or hermes \u2014 tailors the capture guidance").option("--defer-seeding", "let setup's local tour finish before proposing real Decisions").option("--capture-excluded", "explain the demo session's passive capture exclusion").action(
|
|
53739
|
+
async (options) => {
|
|
53740
|
+
const agent = resolveWelcomeAgent(options.agent, process.env);
|
|
53741
|
+
if (options.deferSeeding) {
|
|
53742
|
+
process.stderr.write(
|
|
53743
|
+
"Welcome to Primitive. Setup is complete; the optional simulated tour comes before real Decision seeding.\n"
|
|
53744
|
+
);
|
|
53745
|
+
printJson({ welcomed: true, onboarding: "demo", seedingDeferred: true });
|
|
53746
|
+
return;
|
|
53747
|
+
}
|
|
53748
|
+
const result = await fetchRecent({ limit: RECENT_LIMIT }, deps);
|
|
53749
|
+
const state = welcomeStateFromRecent(result);
|
|
53750
|
+
process.stderr.write(`${formatWelcome(state, agent, options.captureExcluded)}
|
|
53165
53751
|
`);
|
|
53166
|
-
|
|
53167
|
-
|
|
53752
|
+
printJson(welcomeJson(state, agent, options.captureExcluded));
|
|
53753
|
+
}
|
|
53754
|
+
);
|
|
53168
53755
|
}
|
|
53169
53756
|
|
|
53170
53757
|
// src/daemon/self-heal.ts
|
|
@@ -53297,13 +53884,13 @@ function healDaemonDrift(options = {}) {
|
|
|
53297
53884
|
|
|
53298
53885
|
// src/lib/background-flush.ts
|
|
53299
53886
|
import { spawn as spawn5 } from "child_process";
|
|
53300
|
-
import { readFileSync as
|
|
53887
|
+
import { readFileSync as readFileSync27 } from "fs";
|
|
53301
53888
|
|
|
53302
53889
|
// src/daemon/health.ts
|
|
53303
|
-
import { chmodSync as chmodSync8, existsSync as
|
|
53304
|
-
import { dirname as
|
|
53890
|
+
import { chmodSync as chmodSync8, existsSync as existsSync26, mkdirSync as mkdirSync16, renameSync as renameSync7, writeFileSync as writeFileSync11 } from "fs";
|
|
53891
|
+
import { dirname as dirname20, join as join34 } from "path";
|
|
53305
53892
|
var HEARTBEAT_FRESH_MS = 9e4;
|
|
53306
|
-
var DAEMON_HEALTH_PATH =
|
|
53893
|
+
var DAEMON_HEALTH_PATH = join34(primConfigDirectory(), "daemon-health.json");
|
|
53307
53894
|
|
|
53308
53895
|
// src/lib/background-flush.ts
|
|
53309
53896
|
function record2(value) {
|
|
@@ -53314,7 +53901,7 @@ function daemonOwnsDrain(options = {}) {
|
|
|
53314
53901
|
const expectedVersion = options.expectedVersion === void 0 ? packageVersion() : options.expectedVersion;
|
|
53315
53902
|
if (!expectedVersion) return false;
|
|
53316
53903
|
const health = record2(
|
|
53317
|
-
JSON.parse(
|
|
53904
|
+
JSON.parse(readFileSync27(options.healthPath ?? DAEMON_HEALTH_PATH, "utf8"))
|
|
53318
53905
|
);
|
|
53319
53906
|
const heartbeat = record2(health?.heartbeat);
|
|
53320
53907
|
const ingestion = record2(health?.ingestion);
|
|
@@ -53422,7 +54009,7 @@ function runStartupBackgroundWork(argv, env4, work) {
|
|
|
53422
54009
|
const args = commandArguments(argv);
|
|
53423
54010
|
const [command, subcommand] = args;
|
|
53424
54011
|
const uninstall = command === "uninstall" || env4[UNINSTALL_ORCHESTRATOR_ENV] === "1";
|
|
53425
|
-
if (uninstall) return;
|
|
54012
|
+
if (uninstall || command === "demo") return;
|
|
53426
54013
|
work.notify();
|
|
53427
54014
|
const setupDaemonDrains = command === "setup" && !args.includes("--no-daemon") || env4[SETUP_DAEMON_DRAINS_ENV] === "1";
|
|
53428
54015
|
if (!setupDaemonDrains && (command !== "moves" || subcommand !== "flush")) work.flush();
|
|
@@ -53430,8 +54017,8 @@ function runStartupBackgroundWork(argv, env4, work) {
|
|
|
53430
54017
|
}
|
|
53431
54018
|
|
|
53432
54019
|
// src/index.ts
|
|
53433
|
-
var __dirname6 =
|
|
53434
|
-
var pkg = JSON.parse(
|
|
54020
|
+
var __dirname6 = dirname21(fileURLToPath7(import.meta.url));
|
|
54021
|
+
var pkg = JSON.parse(readFileSync28(resolve12(__dirname6, "../package.json"), "utf-8"));
|
|
53435
54022
|
runStartupBackgroundWork(process.argv.slice(2), process.env, {
|
|
53436
54023
|
notify: () => updateNotifier({ pkg }).notify(),
|
|
53437
54024
|
flush: () => startBackgroundFlush(),
|
|
@@ -53449,6 +54036,7 @@ registerSkillCommands(program2);
|
|
|
53449
54036
|
registerMovesCommands(program2);
|
|
53450
54037
|
registerSessionCommands(program2);
|
|
53451
54038
|
registerDecisionsCommands(program2);
|
|
54039
|
+
registerDemoCommands(program2);
|
|
53452
54040
|
registerClaudeCommands(program2);
|
|
53453
54041
|
registerCodexCommands(program2);
|
|
53454
54042
|
registerCursorCommands(program2);
|