cruo-agent 0.1.11 → 0.1.12
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 +37 -10
- package/dist/index.js +3 -2
- package/package.json +1 -1
package/dist/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.12
|
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)}`);
|
|
@@ -48180,15 +48181,21 @@ async function writeConfig(config3) {
|
|
|
48180
48181
|
await writeFile3(CONFIG_PATH, JSON.stringify(config3, null, 2) + "\n", { mode: 384 });
|
|
48181
48182
|
await chmod(CONFIG_PATH, 384);
|
|
48182
48183
|
}
|
|
48183
|
-
async function
|
|
48184
|
+
async function lookup(token, timeoutMs = 5e3) {
|
|
48184
48185
|
const endpoint = process.env.CRUO_SESSION_URL?.trim() || CRUO_CLOUD.sessionUrl;
|
|
48185
48186
|
try {
|
|
48186
|
-
const session = await fetchDelegatedSession(endpoint, token
|
|
48187
|
-
|
|
48188
|
-
|
|
48189
|
-
return
|
|
48187
|
+
const session = await fetchDelegatedSession(endpoint, token, {
|
|
48188
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
48189
|
+
});
|
|
48190
|
+
return { state: "known", who: { email: session.email, workspace: session.workspaceName } };
|
|
48191
|
+
} catch (error51) {
|
|
48192
|
+
return error51 instanceof TokenRefused ? { state: "refused" } : { state: "unreachable" };
|
|
48190
48193
|
}
|
|
48191
48194
|
}
|
|
48195
|
+
async function identify2(token) {
|
|
48196
|
+
const found = await lookup(token);
|
|
48197
|
+
return found.state === "known" ? found.who : null;
|
|
48198
|
+
}
|
|
48192
48199
|
async function login(token, as) {
|
|
48193
48200
|
if (!token.startsWith("cruo_pat_")) {
|
|
48194
48201
|
console.error(`
|
|
@@ -48196,7 +48203,7 @@ That does not look like a Cruo token \u2014 they begin "cruo_pat_".
|
|
|
48196
48203
|
`);
|
|
48197
48204
|
process.exit(2);
|
|
48198
48205
|
}
|
|
48199
|
-
const who =
|
|
48206
|
+
const who = await identify2(token);
|
|
48200
48207
|
const name = as ?? (who ? nameFromEmail(who.email) : null);
|
|
48201
48208
|
if (!name) {
|
|
48202
48209
|
console.error(
|
|
@@ -48294,12 +48301,32 @@ No tokens stored. \`cruo login <token>\` to add one.
|
|
|
48294
48301
|
`);
|
|
48295
48302
|
return;
|
|
48296
48303
|
}
|
|
48304
|
+
const found = await Promise.all(names.map((n2) => lookup(config3.agents[n2].token)));
|
|
48305
|
+
let changed = false;
|
|
48306
|
+
found.forEach((f, i) => {
|
|
48307
|
+
if (f.state !== "known") return;
|
|
48308
|
+
const a = config3.agents[names[i]];
|
|
48309
|
+
if (a.email !== f.who.email || a.workspace !== f.who.workspace) {
|
|
48310
|
+
a.email = f.who.email;
|
|
48311
|
+
a.workspace = f.who.workspace;
|
|
48312
|
+
changed = true;
|
|
48313
|
+
}
|
|
48314
|
+
});
|
|
48315
|
+
if (changed) await writeConfig(config3);
|
|
48297
48316
|
console.log("");
|
|
48298
|
-
|
|
48317
|
+
names.forEach((name, i) => {
|
|
48299
48318
|
const a = config3.agents[name];
|
|
48300
48319
|
const mark = config3.default === name ? "*" : " ";
|
|
48301
48320
|
const who = a.email ? ` \u2014 ${a.email}${a.workspace ? ` in ${a.workspace}` : ""}` : "";
|
|
48302
|
-
|
|
48321
|
+
const note = found[i].state === "refused" ? " (token refused \u2014 revoked? `cruo login` a new one)" : "";
|
|
48322
|
+
console.log(` ${mark} ${name}${who}${note}`);
|
|
48323
|
+
});
|
|
48324
|
+
const unchecked = found.filter((f) => f.state === "unreachable").length;
|
|
48325
|
+
if (unchecked > 0) {
|
|
48326
|
+
console.log(
|
|
48327
|
+
`
|
|
48328
|
+
(${unchecked === names.length ? "Could not reach Cruo" : `${unchecked} could not be checked`} just now \u2014 showing what was stored.)`
|
|
48329
|
+
);
|
|
48303
48330
|
}
|
|
48304
48331
|
console.log(`
|
|
48305
48332
|
* 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