cruo-agent 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/VERSION +1 -1
- package/dist/cli.js +58 -21
- package/dist/index.js +3 -2
- package/package.json +1 -1
package/dist/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.13
|
package/dist/cli.js
CHANGED
|
@@ -36895,12 +36895,13 @@ async function delegatedSessionFor(config3, principal) {
|
|
|
36895
36895
|
workspaceName: principal.workspaceName
|
|
36896
36896
|
};
|
|
36897
36897
|
}
|
|
36898
|
-
async function fetchDelegatedSession(endpoint, token) {
|
|
36898
|
+
async function fetchDelegatedSession(endpoint, token, options2 = {}) {
|
|
36899
36899
|
let response;
|
|
36900
36900
|
try {
|
|
36901
36901
|
response = await fetch(endpoint, {
|
|
36902
36902
|
method: "POST",
|
|
36903
|
-
headers: { authorization: `Bearer ${token}`, accept: "application/json" }
|
|
36903
|
+
headers: { authorization: `Bearer ${token}`, accept: "application/json" },
|
|
36904
|
+
signal: options2.signal
|
|
36904
36905
|
});
|
|
36905
36906
|
} catch (error51) {
|
|
36906
36907
|
throw new Error(`Could not reach ${endpoint}: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
@@ -46116,6 +46117,22 @@ function entryKindOf(token) {
|
|
|
46116
46117
|
if (!OWN_PACKAGE_MARKERS.some((marker) => normalised.includes(marker))) return null;
|
|
46117
46118
|
return isCliFile ? "cli" : "supervisor";
|
|
46118
46119
|
}
|
|
46120
|
+
function entryPosition(tokens) {
|
|
46121
|
+
const first = tokens[0];
|
|
46122
|
+
if (!first) return null;
|
|
46123
|
+
const direct = entryKindOf(first);
|
|
46124
|
+
if (direct) return { at: 0, kind: direct };
|
|
46125
|
+
const normalised = first.replace(/\\/g, "/");
|
|
46126
|
+
const program = normalised.slice(normalised.lastIndexOf("/") + 1);
|
|
46127
|
+
if (!/^(node|nodejs)(\d+)?$/.test(program)) return null;
|
|
46128
|
+
let i = 1;
|
|
46129
|
+
while (i < tokens.length && tokens[i].startsWith("-")) {
|
|
46130
|
+
i += NODE_FLAGS_WITH_VALUE.has(tokens[i]) ? 2 : 1;
|
|
46131
|
+
}
|
|
46132
|
+
const script = tokens[i];
|
|
46133
|
+
const kind = script ? entryKindOf(script) : null;
|
|
46134
|
+
return kind ? { at: i, kind } : null;
|
|
46135
|
+
}
|
|
46119
46136
|
function parsePsLine(line) {
|
|
46120
46137
|
const m = /^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(line);
|
|
46121
46138
|
return m ? { pid: Number(m[1]), uid: Number(m[2]), args: m[3] } : null;
|
|
@@ -46148,16 +46165,9 @@ async function findSupervisorProcesses() {
|
|
|
46148
46165
|
const parsed = parsePsLine(line);
|
|
46149
46166
|
if (!parsed || parsed.uid !== uid || parsed.pid === process.pid) continue;
|
|
46150
46167
|
const tokens = parsed.args.trim().split(/\s+/).filter(Boolean);
|
|
46151
|
-
|
|
46152
|
-
|
|
46153
|
-
|
|
46154
|
-
kind = entryKindOf(tokens[i]);
|
|
46155
|
-
if (kind) {
|
|
46156
|
-
scriptAt = i;
|
|
46157
|
-
break;
|
|
46158
|
-
}
|
|
46159
|
-
}
|
|
46160
|
-
if (!kind) continue;
|
|
46168
|
+
const entry = entryPosition(tokens);
|
|
46169
|
+
if (!entry) continue;
|
|
46170
|
+
const { at: scriptAt, kind } = entry;
|
|
46161
46171
|
if (kind === "cli") {
|
|
46162
46172
|
const next = tokens[scriptAt + 1];
|
|
46163
46173
|
const isSubcommand = next !== void 0 && !next.startsWith("-") && NON_LOOPING_CLI_COMMANDS.includes(next);
|
|
@@ -46198,7 +46208,7 @@ function since(iso) {
|
|
|
46198
46208
|
if (ms2 < 864e5) return `${Math.round(ms2 / 36e5)}h`;
|
|
46199
46209
|
return `${Math.round(ms2 / 864e5)}d`;
|
|
46200
46210
|
}
|
|
46201
|
-
var exec, runDir, logDir, recordPath, CLI_BIN_NAMES, SUPERVISOR_BIN_NAMES, OWN_PACKAGE_MARKERS, NON_LOOPING_CLI_COMMANDS, SIGNALS;
|
|
46211
|
+
var exec, runDir, logDir, recordPath, CLI_BIN_NAMES, SUPERVISOR_BIN_NAMES, OWN_PACKAGE_MARKERS, NON_LOOPING_CLI_COMMANDS, NODE_FLAGS_WITH_VALUE, SIGNALS;
|
|
46202
46212
|
var init_process = __esm({
|
|
46203
46213
|
"src/process.ts"() {
|
|
46204
46214
|
"use strict";
|
|
@@ -46211,6 +46221,7 @@ var init_process = __esm({
|
|
|
46211
46221
|
SUPERVISOR_BIN_NAMES = /* @__PURE__ */ new Set(["cruo-supervisor"]);
|
|
46212
46222
|
OWN_PACKAGE_MARKERS = ["@cruo/mcp", "cruo-agent", "apps/mcp", "packages/cli"];
|
|
46213
46223
|
NON_LOOPING_CLI_COMMANDS = CRUO_COMMANDS.filter((c) => c !== "run");
|
|
46224
|
+
NODE_FLAGS_WITH_VALUE = /* @__PURE__ */ new Set(["--import", "--require", "-r", "--loader", "--experimental-loader"]);
|
|
46214
46225
|
SIGNALS = {
|
|
46215
46226
|
stop: "SIGTERM",
|
|
46216
46227
|
pause: "SIGUSR1",
|
|
@@ -48180,15 +48191,21 @@ async function writeConfig(config3) {
|
|
|
48180
48191
|
await writeFile3(CONFIG_PATH, JSON.stringify(config3, null, 2) + "\n", { mode: 384 });
|
|
48181
48192
|
await chmod(CONFIG_PATH, 384);
|
|
48182
48193
|
}
|
|
48183
|
-
async function
|
|
48194
|
+
async function lookup(token, timeoutMs = 5e3) {
|
|
48184
48195
|
const endpoint = process.env.CRUO_SESSION_URL?.trim() || CRUO_CLOUD.sessionUrl;
|
|
48185
48196
|
try {
|
|
48186
|
-
const session = await fetchDelegatedSession(endpoint, token
|
|
48187
|
-
|
|
48188
|
-
|
|
48189
|
-
return
|
|
48197
|
+
const session = await fetchDelegatedSession(endpoint, token, {
|
|
48198
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
48199
|
+
});
|
|
48200
|
+
return { state: "known", who: { email: session.email, workspace: session.workspaceName } };
|
|
48201
|
+
} catch (error51) {
|
|
48202
|
+
return error51 instanceof TokenRefused ? { state: "refused" } : { state: "unreachable" };
|
|
48190
48203
|
}
|
|
48191
48204
|
}
|
|
48205
|
+
async function identify2(token) {
|
|
48206
|
+
const found = await lookup(token);
|
|
48207
|
+
return found.state === "known" ? found.who : null;
|
|
48208
|
+
}
|
|
48192
48209
|
async function login(token, as) {
|
|
48193
48210
|
if (!token.startsWith("cruo_pat_")) {
|
|
48194
48211
|
console.error(`
|
|
@@ -48196,7 +48213,7 @@ That does not look like a Cruo token \u2014 they begin "cruo_pat_".
|
|
|
48196
48213
|
`);
|
|
48197
48214
|
process.exit(2);
|
|
48198
48215
|
}
|
|
48199
|
-
const who =
|
|
48216
|
+
const who = await identify2(token);
|
|
48200
48217
|
const name = as ?? (who ? nameFromEmail(who.email) : null);
|
|
48201
48218
|
if (!name) {
|
|
48202
48219
|
console.error(
|
|
@@ -48294,12 +48311,32 @@ No tokens stored. \`cruo login <token>\` to add one.
|
|
|
48294
48311
|
`);
|
|
48295
48312
|
return;
|
|
48296
48313
|
}
|
|
48314
|
+
const found = await Promise.all(names.map((n2) => lookup(config3.agents[n2].token)));
|
|
48315
|
+
let changed = false;
|
|
48316
|
+
found.forEach((f, i) => {
|
|
48317
|
+
if (f.state !== "known") return;
|
|
48318
|
+
const a = config3.agents[names[i]];
|
|
48319
|
+
if (a.email !== f.who.email || a.workspace !== f.who.workspace) {
|
|
48320
|
+
a.email = f.who.email;
|
|
48321
|
+
a.workspace = f.who.workspace;
|
|
48322
|
+
changed = true;
|
|
48323
|
+
}
|
|
48324
|
+
});
|
|
48325
|
+
if (changed) await writeConfig(config3);
|
|
48297
48326
|
console.log("");
|
|
48298
|
-
|
|
48327
|
+
names.forEach((name, i) => {
|
|
48299
48328
|
const a = config3.agents[name];
|
|
48300
48329
|
const mark = config3.default === name ? "*" : " ";
|
|
48301
48330
|
const who = a.email ? ` \u2014 ${a.email}${a.workspace ? ` in ${a.workspace}` : ""}` : "";
|
|
48302
|
-
|
|
48331
|
+
const note = found[i].state === "refused" ? " (token refused \u2014 revoked? `cruo login` a new one)" : "";
|
|
48332
|
+
console.log(` ${mark} ${name}${who}${note}`);
|
|
48333
|
+
});
|
|
48334
|
+
const unchecked = found.filter((f) => f.state === "unreachable").length;
|
|
48335
|
+
if (unchecked > 0) {
|
|
48336
|
+
console.log(
|
|
48337
|
+
`
|
|
48338
|
+
(${unchecked === names.length ? "Could not reach Cruo" : `${unchecked} could not be checked`} just now \u2014 showing what was stored.)`
|
|
48339
|
+
);
|
|
48303
48340
|
}
|
|
48304
48341
|
console.log(`
|
|
48305
48342
|
* is what \`cruo run\` runs. Use \`--as <name>\` for another.
|
package/dist/index.js
CHANGED
|
@@ -43087,12 +43087,13 @@ async function sessionFor(config3, principal) {
|
|
|
43087
43087
|
return attempt;
|
|
43088
43088
|
}
|
|
43089
43089
|
var DELEGATED_SESSION_ENV = "CRUO_SESSION";
|
|
43090
|
-
async function fetchDelegatedSession(endpoint, token) {
|
|
43090
|
+
async function fetchDelegatedSession(endpoint, token, options = {}) {
|
|
43091
43091
|
let response;
|
|
43092
43092
|
try {
|
|
43093
43093
|
response = await fetch(endpoint, {
|
|
43094
43094
|
method: "POST",
|
|
43095
|
-
headers: { authorization: `Bearer ${token}`, accept: "application/json" }
|
|
43095
|
+
headers: { authorization: `Bearer ${token}`, accept: "application/json" },
|
|
43096
|
+
signal: options.signal
|
|
43096
43097
|
});
|
|
43097
43098
|
} catch (error51) {
|
|
43098
43099
|
throw new Error(`Could not reach ${endpoint}: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
package/package.json
CHANGED