@actario/cli 0.1.1 → 0.1.2
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 +8 -4
- package/dist/actario.js +446 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,22 +11,26 @@ land in an inbox for you to confirm before any other agent can see them.
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
npx @actario/cli
|
|
14
|
+
npx @actario/cli login
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Or install it for real:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
npm install -g @actario/cli
|
|
21
|
-
actario
|
|
21
|
+
actario login
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
`
|
|
25
|
-
|
|
24
|
+
`login` opens your browser at Actario: sign in with your own account, pick a
|
|
25
|
+
workspace and approve. This machine is then linked -- no token to copy. On a
|
|
26
|
+
machine without a browser (SSH, a container), `actario login --device` prints
|
|
27
|
+
a URL and a short code to approve from any device. `actario init` still takes
|
|
28
|
+
a pasted capture token if you prefer.
|
|
26
29
|
|
|
27
30
|
## Commands
|
|
28
31
|
|
|
29
32
|
```
|
|
33
|
+
actario login link this machine by signing in with the browser
|
|
30
34
|
actario capture capture, redact and upload new sessions
|
|
31
35
|
actario analyze analyse the captured batch here, on your own subscription
|
|
32
36
|
actario status local capture state, or one upload's progress
|
package/dist/actario.js
CHANGED
|
@@ -564,7 +564,7 @@ var flagBool = (a, k) => a.flags[k] === true || a.flags[k] === "true";
|
|
|
564
564
|
var flagList = (a, k) => (flagString(a, k) ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
565
565
|
|
|
566
566
|
// ../../apps/cli/src/version.ts
|
|
567
|
-
var CLI_VERSION = "0.1.
|
|
567
|
+
var CLI_VERSION = "0.1.2";
|
|
568
568
|
|
|
569
569
|
// ../../apps/cli/src/print.ts
|
|
570
570
|
var useColour = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
@@ -4718,7 +4718,7 @@ ${dim("is safe to paste into a report as-is.")}
|
|
|
4718
4718
|
|
|
4719
4719
|
// ../../apps/cli/src/commands/init.ts
|
|
4720
4720
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
4721
|
-
import { join as
|
|
4721
|
+
import { join as join22 } from "node:path";
|
|
4722
4722
|
|
|
4723
4723
|
// ../../apps/cli/src/core/link.ts
|
|
4724
4724
|
import { hostname } from "node:os";
|
|
@@ -4776,6 +4776,335 @@ async function linkMachine(opts) {
|
|
|
4776
4776
|
return { config, identity, source, sourceCreated, sources };
|
|
4777
4777
|
}
|
|
4778
4778
|
|
|
4779
|
+
// ../../apps/cli/src/commands/login.ts
|
|
4780
|
+
import { join as join21 } from "node:path";
|
|
4781
|
+
|
|
4782
|
+
// ../../apps/cli/src/core/device-login.ts
|
|
4783
|
+
import { spawn } from "node:child_process";
|
|
4784
|
+
import { createServer } from "node:http";
|
|
4785
|
+
import { hostname as hostname2 } from "node:os";
|
|
4786
|
+
var DEFAULT_API_URL = "https://distill-web-ten.vercel.app";
|
|
4787
|
+
function defaultApiUrl() {
|
|
4788
|
+
return (readConfig().api_url ?? actarioEnv("API_URL") ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
4789
|
+
}
|
|
4790
|
+
async function post(base, path, body) {
|
|
4791
|
+
let res;
|
|
4792
|
+
try {
|
|
4793
|
+
res = await fetch(new URL(path, base), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
|
|
4794
|
+
} catch (e) {
|
|
4795
|
+
return { ok: false, status: 0, code: "network", message: e.message };
|
|
4796
|
+
}
|
|
4797
|
+
const json = await res.json().catch(() => null);
|
|
4798
|
+
if (res.ok && json) return { ok: true, data: json };
|
|
4799
|
+
return { ok: false, status: res.status, code: json?.error?.code ?? `http_${res.status}`, message: json?.error?.message ?? `${res.status} ${res.statusText}` };
|
|
4800
|
+
}
|
|
4801
|
+
function canOpenBrowser() {
|
|
4802
|
+
if (process.platform === "win32" || process.platform === "darwin") return true;
|
|
4803
|
+
return Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
|
4804
|
+
}
|
|
4805
|
+
async function openInBrowser(url) {
|
|
4806
|
+
let u;
|
|
4807
|
+
try {
|
|
4808
|
+
u = new URL(url);
|
|
4809
|
+
} catch {
|
|
4810
|
+
return false;
|
|
4811
|
+
}
|
|
4812
|
+
if (u.protocol !== "https:" && u.protocol !== "http:" || !u.hostname || /[\s"'`]/.test(url)) return false;
|
|
4813
|
+
if (!canOpenBrowser()) return false;
|
|
4814
|
+
const plat = process.platform;
|
|
4815
|
+
const [cmd, args] = plat === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", u.href]] : plat === "darwin" ? ["open", [u.href]] : ["xdg-open", [u.href]];
|
|
4816
|
+
return new Promise((resolve4) => {
|
|
4817
|
+
try {
|
|
4818
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true, windowsHide: true });
|
|
4819
|
+
child.once("error", () => resolve4(false));
|
|
4820
|
+
child.once("spawn", () => {
|
|
4821
|
+
child.unref();
|
|
4822
|
+
resolve4(true);
|
|
4823
|
+
});
|
|
4824
|
+
} catch {
|
|
4825
|
+
resolve4(false);
|
|
4826
|
+
}
|
|
4827
|
+
});
|
|
4828
|
+
}
|
|
4829
|
+
var escapeHtml = (s) => s.replace(/[&<>"']/g, (c2) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c2]);
|
|
4830
|
+
function resultPage(title, body, ok2) {
|
|
4831
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
4832
|
+
<title>Actario \xB7 ${escapeHtml(title)}</title>
|
|
4833
|
+
<style>
|
|
4834
|
+
:root{color-scheme:light dark;--bg:#fafafa;--ink:#18181b;--muted:#52525b;--line:#e4e4e7;--mark:${ok2 ? "#15803d" : "#b91c1c"}}
|
|
4835
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0f0f10;--ink:#f4f4f5;--muted:#a1a1aa;--line:#27272a;--mark:${ok2 ? "#4ade80" : "#f87171"}}}
|
|
4836
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif;display:grid;place-items:center;min-height:100vh;padding:16px;box-sizing:border-box}
|
|
4837
|
+
main{max-width:460px;border:1px solid var(--line);border-radius:12px;padding:24px 26px}
|
|
4838
|
+
h1{font-size:19px;margin:0 0 8px;display:flex;gap:10px;align-items:center}
|
|
4839
|
+
h1::before{content:"";width:10px;height:10px;border-radius:50%;background:var(--mark)}
|
|
4840
|
+
p{margin:0;color:var(--muted)}
|
|
4841
|
+
</style></head><body><main><h1>${escapeHtml(title)}</h1><p>${escapeHtml(body)}</p></main></body></html>`;
|
|
4842
|
+
}
|
|
4843
|
+
async function listenLoopback() {
|
|
4844
|
+
const server = createServer();
|
|
4845
|
+
await new Promise((resolve4, reject) => {
|
|
4846
|
+
server.once("error", reject);
|
|
4847
|
+
server.listen(0, "127.0.0.1", () => resolve4());
|
|
4848
|
+
});
|
|
4849
|
+
const addr = server.address();
|
|
4850
|
+
if (!addr || typeof addr === "string") throw new Error("no port");
|
|
4851
|
+
return { server, port: addr.port };
|
|
4852
|
+
}
|
|
4853
|
+
var MAX_INTERVAL_MS = 3e4;
|
|
4854
|
+
async function startDeviceLogin(opts = {}) {
|
|
4855
|
+
const apiUrl = (opts.apiUrl ?? defaultApiUrl()).replace(/\/+$/, "");
|
|
4856
|
+
if (!/^https?:\/\//.test(apiUrl)) throw new DistillError("invalid_request", "api_url must start with http:// or https://");
|
|
4857
|
+
const launch = opts.launch ?? openInBrowser;
|
|
4858
|
+
const wantBrowser = opts.openBrowser ?? !actarioEnv("NO_BROWSER");
|
|
4859
|
+
const canLaunch = wantBrowser && (opts.launch ? true : canOpenBrowser());
|
|
4860
|
+
const requestCode = async (redirect) => {
|
|
4861
|
+
const r = await post(apiUrl, "/api/v1/device/code", {
|
|
4862
|
+
client_name: opts.clientName ?? "Actario CLI",
|
|
4863
|
+
client_host: opts.label ?? hostname2(),
|
|
4864
|
+
...redirect ? { redirect_uri: redirect } : {}
|
|
4865
|
+
});
|
|
4866
|
+
if (r.ok) return r.data;
|
|
4867
|
+
if (r.status === 404 || r.status === 405) {
|
|
4868
|
+
throw new DistillError(
|
|
4869
|
+
"not_found",
|
|
4870
|
+
`${apiUrl} does not support signing in from Claude yet (no /api/v1/device/code). Link with a token from Settings \u2192 Access tokens instead.`
|
|
4871
|
+
);
|
|
4872
|
+
}
|
|
4873
|
+
if (r.code === "network") throw new DistillError("internal", `Could not reach ${apiUrl}: ${r.message}`, void 0, 502);
|
|
4874
|
+
throw new DistillError(r.code, r.message, void 0, r.status);
|
|
4875
|
+
};
|
|
4876
|
+
let local = null;
|
|
4877
|
+
if (opts.loopback !== false && canLaunch) {
|
|
4878
|
+
try {
|
|
4879
|
+
local = await listenLoopback();
|
|
4880
|
+
} catch {
|
|
4881
|
+
local = null;
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
let s;
|
|
4885
|
+
try {
|
|
4886
|
+
s = await requestCode(local ? `http://127.0.0.1:${local.port}/callback` : null);
|
|
4887
|
+
} catch (e) {
|
|
4888
|
+
local?.server.close();
|
|
4889
|
+
throw e;
|
|
4890
|
+
}
|
|
4891
|
+
const launched = canLaunch ? await launch(s.verification_uri_complete) : false;
|
|
4892
|
+
if (local && !launched) {
|
|
4893
|
+
local.server.close();
|
|
4894
|
+
local = null;
|
|
4895
|
+
s = await requestCode(null);
|
|
4896
|
+
}
|
|
4897
|
+
const prompt = {
|
|
4898
|
+
verification_uri: s.verification_uri,
|
|
4899
|
+
verification_uri_complete: s.verification_uri_complete,
|
|
4900
|
+
user_code: s.user_code,
|
|
4901
|
+
expires_in: s.expires_in,
|
|
4902
|
+
browser_opened: launched,
|
|
4903
|
+
loopback: local !== null
|
|
4904
|
+
};
|
|
4905
|
+
let cancelled = false;
|
|
4906
|
+
let approvalCode = null;
|
|
4907
|
+
let wake = null;
|
|
4908
|
+
let state = { status: "waiting" };
|
|
4909
|
+
const deadline = Date.now() + s.expires_in * 1e3;
|
|
4910
|
+
let interval = Math.max(1, s.interval) * 1e3;
|
|
4911
|
+
const sleep = (ms) => new Promise((resolve4) => {
|
|
4912
|
+
const t = setTimeout(() => {
|
|
4913
|
+
wake = null;
|
|
4914
|
+
resolve4();
|
|
4915
|
+
}, ms);
|
|
4916
|
+
wake = () => {
|
|
4917
|
+
clearTimeout(t);
|
|
4918
|
+
wake = null;
|
|
4919
|
+
resolve4();
|
|
4920
|
+
};
|
|
4921
|
+
});
|
|
4922
|
+
const poll = async () => {
|
|
4923
|
+
for (; ; ) {
|
|
4924
|
+
if (cancelled) throw new DistillError("expired_token", "Sign-in was cancelled.");
|
|
4925
|
+
if (Date.now() > deadline) throw new DistillError("expired_token", "The sign-in code expired before it was approved. Start again.");
|
|
4926
|
+
const r = await post(apiUrl, "/api/v1/device/token", {
|
|
4927
|
+
device_code: s.device_code,
|
|
4928
|
+
...approvalCode ? { approval_code: approvalCode } : {}
|
|
4929
|
+
});
|
|
4930
|
+
if (r.ok) return r.data;
|
|
4931
|
+
if (r.code === "authorization_pending" || r.code === "network" || r.status >= 500) {
|
|
4932
|
+
await sleep(interval);
|
|
4933
|
+
continue;
|
|
4934
|
+
}
|
|
4935
|
+
if (r.code === "slow_down") {
|
|
4936
|
+
interval = Math.min(MAX_INTERVAL_MS, interval + 5e3);
|
|
4937
|
+
await sleep(interval);
|
|
4938
|
+
continue;
|
|
4939
|
+
}
|
|
4940
|
+
if (r.code === "access_denied") throw new DistillError("access_denied", "The sign-in was declined in the browser. Nothing was linked.", void 0, 403);
|
|
4941
|
+
throw new DistillError(r.code ?? "expired_token", r.message, void 0, r.status);
|
|
4942
|
+
}
|
|
4943
|
+
};
|
|
4944
|
+
const revoke = async (tok) => {
|
|
4945
|
+
if (!tok.token_id) return;
|
|
4946
|
+
await fetch(new URL(`/api/v1/tokens/${tok.token_id}`, apiUrl), {
|
|
4947
|
+
method: "DELETE",
|
|
4948
|
+
headers: { authorization: `Bearer ${tok.access_token}` }
|
|
4949
|
+
}).catch(() => void 0);
|
|
4950
|
+
};
|
|
4951
|
+
const done = (async () => {
|
|
4952
|
+
const tok = await poll();
|
|
4953
|
+
if (cancelled) {
|
|
4954
|
+
await revoke(tok);
|
|
4955
|
+
throw new DistillError("expired_token", "Sign-in was cancelled.");
|
|
4956
|
+
}
|
|
4957
|
+
let lastErr;
|
|
4958
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
4959
|
+
try {
|
|
4960
|
+
const linked = await linkMachine({
|
|
4961
|
+
apiUrl,
|
|
4962
|
+
token: tok.access_token,
|
|
4963
|
+
...opts.label ? { label: opts.label } : {},
|
|
4964
|
+
...opts.profile ? { profile: opts.profile } : {}
|
|
4965
|
+
});
|
|
4966
|
+
return { ...linked, email: tok.email, workspace_name: tok.workspace.name, api_url: apiUrl };
|
|
4967
|
+
} catch (e) {
|
|
4968
|
+
lastErr = e;
|
|
4969
|
+
if (e.code !== "internal") break;
|
|
4970
|
+
await new Promise((r) => setTimeout(r, 1e3 * (attempt + 1)));
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4973
|
+
await revoke(tok);
|
|
4974
|
+
const m = lastErr?.message ?? String(lastErr);
|
|
4975
|
+
throw new DistillError(
|
|
4976
|
+
lastErr?.code ?? "internal",
|
|
4977
|
+
`Signed in, but registering this machine failed (${m}). The new key was revoked; run the sign-in again.`
|
|
4978
|
+
);
|
|
4979
|
+
})();
|
|
4980
|
+
done.then(
|
|
4981
|
+
() => {
|
|
4982
|
+
state = { status: "linked" };
|
|
4983
|
+
},
|
|
4984
|
+
(e) => {
|
|
4985
|
+
const err = e;
|
|
4986
|
+
state = { status: "failed", error: { code: err.code ?? "internal", message: err.message } };
|
|
4987
|
+
}
|
|
4988
|
+
);
|
|
4989
|
+
if (local) {
|
|
4990
|
+
const expectedHost = `127.0.0.1:${local.port}`;
|
|
4991
|
+
local.server.on("request", (req, res) => {
|
|
4992
|
+
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
4993
|
+
if (url.pathname !== "/callback" || req.method !== "GET" || req.headers.host !== expectedHost) {
|
|
4994
|
+
res.writeHead(404, { "content-type": "text/plain" }).end("Not found");
|
|
4995
|
+
return;
|
|
4996
|
+
}
|
|
4997
|
+
const status = url.searchParams.get("status");
|
|
4998
|
+
const code = url.searchParams.get("code");
|
|
4999
|
+
if (status === "approved" && code && /^[0-9a-f]{64}$/.test(code)) approvalCode ??= code;
|
|
5000
|
+
else if (status !== "denied") {
|
|
5001
|
+
res.writeHead(400, { "content-type": "text/plain" }).end("Bad request");
|
|
5002
|
+
return;
|
|
5003
|
+
}
|
|
5004
|
+
wake?.();
|
|
5005
|
+
const settled = Promise.race([
|
|
5006
|
+
done.then((r) => ({ ok: true, r }), (e) => ({ ok: false, e })),
|
|
5007
|
+
new Promise((resolve4) => setTimeout(() => resolve4(null), 15e3))
|
|
5008
|
+
]);
|
|
5009
|
+
void settled.then((out) => {
|
|
5010
|
+
const html = out === null ? resultPage("Almost there", "Approved. Actario is finishing the link on this machine; go back to Claude, it will confirm there.", true) : out.ok ? resultPage("Linked", `This machine is linked to ${out.r.workspace_name ?? "your workspace"}${out.r.email ? ` as ${out.r.email}` : ""}. You can close this tab and go back to Claude.`, true) : resultPage(out.e.code === "access_denied" ? "Declined" : "Not linked", out.e.message, false);
|
|
5011
|
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store", "referrer-policy": "no-referrer" }).end(html);
|
|
5012
|
+
});
|
|
5013
|
+
});
|
|
5014
|
+
const server = local.server;
|
|
5015
|
+
const closeLocal = () => setTimeout(() => {
|
|
5016
|
+
server.close();
|
|
5017
|
+
server.closeAllConnections?.();
|
|
5018
|
+
}, 2e4).unref();
|
|
5019
|
+
done.then(closeLocal, closeLocal);
|
|
5020
|
+
server.unref();
|
|
5021
|
+
}
|
|
5022
|
+
return {
|
|
5023
|
+
prompt,
|
|
5024
|
+
done,
|
|
5025
|
+
state: () => state,
|
|
5026
|
+
cancel: () => {
|
|
5027
|
+
cancelled = true;
|
|
5028
|
+
wake?.();
|
|
5029
|
+
}
|
|
5030
|
+
};
|
|
5031
|
+
}
|
|
5032
|
+
|
|
5033
|
+
// ../../apps/cli/src/commands/login.ts
|
|
5034
|
+
async function loginCommand(args) {
|
|
5035
|
+
const device = flagBool(args, "device");
|
|
5036
|
+
const profile = flagString(args, "profile");
|
|
5037
|
+
process.stdout.write(heading("Sign in to Actario"));
|
|
5038
|
+
let login;
|
|
5039
|
+
try {
|
|
5040
|
+
login = await startDeviceLogin({
|
|
5041
|
+
...flagString(args, "api-url") ? { apiUrl: flagString(args, "api-url") } : {},
|
|
5042
|
+
clientName: "Actario CLI",
|
|
5043
|
+
...flagString(args, "label") ? { label: flagString(args, "label") } : {},
|
|
5044
|
+
...profile === "medical" || profile === "general" ? { profile } : {},
|
|
5045
|
+
...device || flagBool(args, "no-browser") ? { loopback: false, openBrowser: false } : {}
|
|
5046
|
+
});
|
|
5047
|
+
} catch (e) {
|
|
5048
|
+
process.stderr.write(`${red("Could not start the sign-in.")} ${e.message}
|
|
5049
|
+
`);
|
|
5050
|
+
return 1;
|
|
5051
|
+
}
|
|
5052
|
+
const p = login.prompt;
|
|
5053
|
+
if (p.browser_opened) {
|
|
5054
|
+
process.stdout.write(`A browser tab should have opened. If it didn't, open this on THIS machine:
|
|
5055
|
+
|
|
5056
|
+
${bold(p.verification_uri_complete)}
|
|
5057
|
+
|
|
5058
|
+
${dim(`If approving ends on a "can't connect" page, press Ctrl-C and run ${bold("actario login --device")} instead.`)}
|
|
5059
|
+
`);
|
|
5060
|
+
} else {
|
|
5061
|
+
process.stdout.write(`On any device, open
|
|
5062
|
+
|
|
5063
|
+
${bold(p.verification_uri)}
|
|
5064
|
+
|
|
5065
|
+
and enter the code
|
|
5066
|
+
|
|
5067
|
+
${bold(p.user_code)}
|
|
5068
|
+
|
|
5069
|
+
`);
|
|
5070
|
+
}
|
|
5071
|
+
process.stdout.write(`${dim(`Check the page shows ${p.user_code}. The code expires in ${Math.round(p.expires_in / 60)} minutes.`)}
|
|
5072
|
+
`);
|
|
5073
|
+
process.stdout.write(`${dim("Waiting for approval\u2026")}
|
|
5074
|
+
`);
|
|
5075
|
+
const onInt = () => login.cancel();
|
|
5076
|
+
process.once("SIGINT", onInt);
|
|
5077
|
+
try {
|
|
5078
|
+
const r = await login.done;
|
|
5079
|
+
process.stdout.write(
|
|
5080
|
+
`
|
|
5081
|
+
${green("Linked")}${r.email ? ` as ${r.email}` : ""} to ${bold(r.workspace_name ?? r.identity.workspace_id ?? "your workspace")}
|
|
5082
|
+
source ${r.source.id}${"label" in r.source && r.source.label ? dim(` (${r.source.label}${r.sourceCreated ? ", created" : ""})`) : ""}
|
|
5083
|
+
saved ${dim(join21(actarioDir(), "config.json"))}
|
|
5084
|
+
${dim('The key is listed under Settings \u2192 Access tokens as "Claude \xB7 <this machine>"; revoke it there.')}
|
|
5085
|
+
`
|
|
5086
|
+
);
|
|
5087
|
+
process.stdout.write(heading("Sources on this machine"));
|
|
5088
|
+
for (const s of r.sources) {
|
|
5089
|
+
const mark = s.found ? green("found") : yellow("not found");
|
|
5090
|
+
process.stdout.write(` ${s.id.padEnd(24)} ${mark} ${s.found ? dim(`~${s.approxUnits} unit(s)`) : dim(s.note ?? "")}
|
|
5091
|
+
`);
|
|
5092
|
+
}
|
|
5093
|
+
process.stdout.write(`
|
|
5094
|
+
Next: ${bold("actario capture --dry-run")} to see what would be uploaded.
|
|
5095
|
+
`);
|
|
5096
|
+
return 0;
|
|
5097
|
+
} catch (e) {
|
|
5098
|
+
const err = e;
|
|
5099
|
+
process.stderr.write(`
|
|
5100
|
+
${red(err.code === "access_denied" ? "Declined." : "Not linked.")} ${err.message}
|
|
5101
|
+
`);
|
|
5102
|
+
return 1;
|
|
5103
|
+
} finally {
|
|
5104
|
+
process.off("SIGINT", onInt);
|
|
5105
|
+
}
|
|
5106
|
+
}
|
|
5107
|
+
|
|
4779
5108
|
// ../../apps/cli/src/commands/init.ts
|
|
4780
5109
|
async function initCommand(args) {
|
|
4781
5110
|
const cfg = readConfig();
|
|
@@ -4789,10 +5118,14 @@ async function initCommand(args) {
|
|
|
4789
5118
|
try {
|
|
4790
5119
|
process.stdout.write(heading("Actario setup"));
|
|
4791
5120
|
const apiUrl = flagString(args, "api-url") ?? await ask("API URL", cfg.api_url ?? "http://localhost:3000");
|
|
4792
|
-
const token = flagString(args, "token") ?? await ask("Capture token (
|
|
5121
|
+
const token = flagString(args, "token") ?? await ask("Capture token (empty = sign in with the browser instead)", cfg.token);
|
|
4793
5122
|
const profile = flagString(args, "profile") ?? await ask("Redaction profile (medical|general)", cfg.redaction_profile);
|
|
5123
|
+
if (apiUrl && !token && interactive) {
|
|
5124
|
+
rl?.close();
|
|
5125
|
+
return loginCommand({ ...args, flags: { ...args.flags, "api-url": apiUrl, ...profile ? { profile } : {} } });
|
|
5126
|
+
}
|
|
4794
5127
|
if (!apiUrl || !token) {
|
|
4795
|
-
process.stderr.write(`${red("Both an API URL and a token are needed.")}
|
|
5128
|
+
process.stderr.write(`${red("Both an API URL and a token are needed.")} Or run ${bold("actario login")} to sign in with the browser.
|
|
4796
5129
|
`);
|
|
4797
5130
|
return 1;
|
|
4798
5131
|
}
|
|
@@ -4831,8 +5164,8 @@ Nothing was written.
|
|
|
4831
5164
|
`
|
|
4832
5165
|
${green("Linked")} as ${dim(r.identity.user_id ?? "user")} to workspace ${dim(r.identity.workspace_id ?? "(first membership)")}
|
|
4833
5166
|
source ${r.source.id}${"label" in r.source && r.source.label ? dim(` (${r.source.label}${r.sourceCreated ? ", created" : ""})`) : ""}
|
|
4834
|
-
saved ${dim(
|
|
4835
|
-
${dim(`Pseudonym salt at ${
|
|
5167
|
+
saved ${dim(join22(dir, "config.json"))}
|
|
5168
|
+
${dim(`Pseudonym salt at ${join22(dir, "salt")} -- never uploaded, back it up if you care about cross-capture linking.`)}
|
|
4836
5169
|
`
|
|
4837
5170
|
);
|
|
4838
5171
|
process.stdout.write(heading("Sources on this machine"));
|
|
@@ -4891,12 +5224,12 @@ function apiFromConfig() {
|
|
|
4891
5224
|
}
|
|
4892
5225
|
async function writeGuard() {
|
|
4893
5226
|
const api = apiFromConfig();
|
|
4894
|
-
if (!api) return fail("not_linked", "This machine is not linked to a workspace. Call `link` with
|
|
5227
|
+
if (!api) return fail("not_linked", "This machine is not linked to a workspace. Call `link` first (with no arguments it signs the user in through the browser).");
|
|
4895
5228
|
let me;
|
|
4896
5229
|
try {
|
|
4897
5230
|
me = await whoami(api);
|
|
4898
5231
|
} catch (e) {
|
|
4899
|
-
if (e instanceof DistillError && e.code === "unauthorized") return fail("unauthorized", "The configured token was rejected by the server.
|
|
5232
|
+
if (e instanceof DistillError && e.code === "unauthorized") return fail("unauthorized", "The configured token was rejected by the server (revoked?). Call `link` again to sign in.");
|
|
4900
5233
|
const msg = e instanceof Error ? e.message : String(e);
|
|
4901
5234
|
return fail("internal", `Could not verify the token against ${api.baseUrl} (${msg}). Nothing was captured; retry when the API is reachable.`);
|
|
4902
5235
|
}
|
|
@@ -4906,26 +5239,100 @@ async function writeGuard() {
|
|
|
4906
5239
|
}
|
|
4907
5240
|
function buildServer() {
|
|
4908
5241
|
const server = new McpServer({ name: "actario-capture", version: CLI_VERSION });
|
|
5242
|
+
let pending = null;
|
|
5243
|
+
let starting = null;
|
|
5244
|
+
const linkedBody = (r, via) => ({
|
|
5245
|
+
linked: true,
|
|
5246
|
+
via,
|
|
5247
|
+
...r.email ? { account: r.email } : {},
|
|
5248
|
+
workspace_id: r.identity.workspace_id,
|
|
5249
|
+
...r.workspace_name ? { workspace_name: r.workspace_name } : {},
|
|
5250
|
+
source: { id: r.source.id, label: "label" in r.source ? r.source.label : null, created: r.sourceCreated },
|
|
5251
|
+
config_path: `${actarioDir()}/config.json`,
|
|
5252
|
+
sources_on_this_machine: r.sources,
|
|
5253
|
+
next: "Call `capture` (optionally with a `record` of this conversation), then `list_runs`, `read_run`, and `submit_daf`."
|
|
5254
|
+
});
|
|
5255
|
+
const awaitPending = async (seconds) => {
|
|
5256
|
+
if (!pending) return fail("not_found", "No sign-in is in progress. Call `link` to start one.");
|
|
5257
|
+
const p = pending;
|
|
5258
|
+
const out = await Promise.race([
|
|
5259
|
+
p.login.done.then((r) => ({ r }), (e) => ({ e })),
|
|
5260
|
+
new Promise((resolve4) => setTimeout(() => resolve4(null), Math.max(0, seconds) * 1e3))
|
|
5261
|
+
]);
|
|
5262
|
+
if (out === null) {
|
|
5263
|
+
const left = Math.max(0, Math.round(p.login.prompt.expires_in - (Date.now() - p.startedAt) / 1e3));
|
|
5264
|
+
return ok({
|
|
5265
|
+
linked: false,
|
|
5266
|
+
status: "waiting_for_approval",
|
|
5267
|
+
verification_uri: p.login.prompt.verification_uri,
|
|
5268
|
+
verification_uri_complete: p.login.prompt.verification_uri_complete,
|
|
5269
|
+
user_code: p.login.prompt.user_code,
|
|
5270
|
+
browser_opened: p.login.prompt.browser_opened,
|
|
5271
|
+
expires_in_seconds: left,
|
|
5272
|
+
server: new URL(p.login.prompt.verification_uri).host,
|
|
5273
|
+
tell_the_user: p.login.prompt.browser_opened ? `A browser tab opened at the Actario sign-in page (${new URL(p.login.prompt.verification_uri).host}). Sign in, check the code is ${p.login.prompt.user_code}, pick a workspace and click Approve. (If no tab appeared, open ${p.login.prompt.verification_uri_complete}.)` : `Open ${p.login.prompt.verification_uri} on any device, sign in, and enter the code ${p.login.prompt.user_code}. Then pick a workspace and click Approve.`,
|
|
5274
|
+
next: 'Show the user the URL and code above, then call `link_status` to wait for their approval (it waits up to ~45 s per call; call again if still waiting). If a browser tab opened but approving there fails to come back ("can\'t connect"), call `link` with method: "code".'
|
|
5275
|
+
});
|
|
5276
|
+
}
|
|
5277
|
+
if (pending === p) pending = null;
|
|
5278
|
+
if ("e" in out) return fail(out.e.code ?? "internal", out.e.message);
|
|
5279
|
+
return ok(linkedBody(out.r, "browser"));
|
|
5280
|
+
};
|
|
4909
5281
|
server.registerTool("link", {
|
|
4910
|
-
title: "Link this machine to an Actario
|
|
4911
|
-
description: "
|
|
5282
|
+
title: "Link this machine to an Actario account",
|
|
5283
|
+
description: "Connect this machine to the user's Actario workspace so `capture` can upload. With no token (recommended): starts a browser sign-in -- a tab opens on the user's machine where they log in to their own Actario account and approve; if no browser can open, returns a URL and a short code to show the user (they can approve from any device). With a token: validates a capture token pasted from Settings instead. Either way it registers this machine as a source and saves the config. Refuses agent tokens and tokens without the capture scope. Nothing is written until the link succeeds.",
|
|
4912
5284
|
inputSchema: {
|
|
4913
|
-
api_url: z9.string().url().describe(
|
|
4914
|
-
token: z9.string().min(8).describe("
|
|
5285
|
+
api_url: z9.string().url().optional().describe(`Actario base URL. Defaults to the one already configured, else ACTARIO_API_URL, else ${DEFAULT_API_URL}`),
|
|
5286
|
+
token: z9.string().min(8).optional().describe("Only if the user pasted one: a personal access token with the capture scope. Omit to sign in through the browser."),
|
|
4915
5287
|
label: z9.string().min(1).max(80).optional().describe("Name for this machine on the Sources page. Defaults to the hostname."),
|
|
4916
|
-
profile: z9.enum(["general", "medical"]).optional().describe("Redaction profile. medical is one-way and excludes this source from the corpus for good.")
|
|
5288
|
+
profile: z9.enum(["general", "medical"]).optional().describe("Redaction profile. medical is one-way and excludes this source from the corpus for good."),
|
|
5289
|
+
method: z9.enum(["auto", "code"]).optional().describe("Browser sign-in only. auto (default): open a browser on this machine if there is one (it comes back through localhost), else fall back to a code. code: skip the browser; just return a URL + code for the user to approve on any device."),
|
|
5290
|
+
wait_seconds: z9.number().int().min(0).max(55).optional().describe("Browser sign-in only: how long to wait for approval before returning the URL and code. Default 45 if a browser opened, else 0."),
|
|
5291
|
+
switch_server: z9.boolean().optional().describe("Required (true) to link to a different Actario server than the one this machine is linked to now. Only set it after the user confirmed the new URL.")
|
|
4917
5292
|
}
|
|
4918
5293
|
}, guarded(async (a) => {
|
|
4919
|
-
const
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
5294
|
+
const cfg = readConfig();
|
|
5295
|
+
const target = (a.api_url ?? defaultApiUrl()).replace(/\/+$/, "");
|
|
5296
|
+
if (cfg.api_url && cfg.token && cfg.api_url.replace(/\/+$/, "") !== target && !a.switch_server) {
|
|
5297
|
+
return fail(
|
|
5298
|
+
"confirm_required",
|
|
5299
|
+
`This machine is linked to ${cfg.api_url}. Linking to ${target} instead would send future captures there. Ask the user to confirm that URL, then call \`link\` again with switch_server: true.`
|
|
5300
|
+
);
|
|
5301
|
+
}
|
|
5302
|
+
if (a.token) {
|
|
5303
|
+
pending?.login.cancel();
|
|
5304
|
+
pending = null;
|
|
5305
|
+
const r = await linkMachine({ apiUrl: target, token: a.token, ...a.label ? { label: a.label } : {}, ...a.profile ? { profile: a.profile } : {} });
|
|
5306
|
+
return ok(linkedBody(r, "token"));
|
|
5307
|
+
}
|
|
5308
|
+
const key = JSON.stringify([target, a.method ?? "auto", a.label ?? null, a.profile ?? null]);
|
|
5309
|
+
while (starting) await starting.catch(() => void 0);
|
|
5310
|
+
if (!pending || pending.key !== key || pending.login.state().status !== "waiting") {
|
|
5311
|
+
pending?.login.cancel();
|
|
5312
|
+
pending = null;
|
|
5313
|
+
const p = startDeviceLogin({
|
|
5314
|
+
apiUrl: target,
|
|
5315
|
+
clientName: "Claude (Actario MCP)",
|
|
5316
|
+
...a.label ? { label: a.label } : {},
|
|
5317
|
+
...a.profile ? { profile: a.profile } : {},
|
|
5318
|
+
...a.method === "code" ? { loopback: false, openBrowser: false } : {}
|
|
5319
|
+
});
|
|
5320
|
+
starting = p;
|
|
5321
|
+
try {
|
|
5322
|
+
pending = { login: await p, startedAt: Date.now(), key };
|
|
5323
|
+
} finally {
|
|
5324
|
+
starting = null;
|
|
5325
|
+
}
|
|
5326
|
+
}
|
|
5327
|
+
return awaitPending(a.wait_seconds ?? (pending.login.prompt.browser_opened ? 45 : 0));
|
|
4928
5328
|
}));
|
|
5329
|
+
server.registerTool("link_status", {
|
|
5330
|
+
title: "Finish a browser sign-in",
|
|
5331
|
+
description: "After `link` returned a URL and code: wait for the user to approve in the browser, then finish linking. Returns linked:true when done, or the same URL/code if they have not approved yet (call again).",
|
|
5332
|
+
inputSchema: {
|
|
5333
|
+
wait_seconds: z9.number().int().min(0).max(55).optional().describe("How long to wait for approval in this call. Default 45.")
|
|
5334
|
+
}
|
|
5335
|
+
}, guarded(async (a) => awaitPending(a.wait_seconds ?? 45)));
|
|
4929
5336
|
server.registerTool("capture", {
|
|
4930
5337
|
title: "Capture sessions and upload them",
|
|
4931
5338
|
description: "Run the capture pipeline on this machine: scan sources, redact, score, pack, upload, and keep the bundle locally for analysis. Pass `record` to capture THIS conversation: a distill.chat/v1 record (turns as said, no summarising, no redacting -- the pipeline redacts, with rules no flag reaches). Without `record`, scans the installed adapters. `dry_run` reports without uploading or changing state. Redaction cannot be disabled here.",
|
|
@@ -5162,7 +5569,7 @@ async function mcpCommand(_args) {
|
|
|
5162
5569
|
}
|
|
5163
5570
|
|
|
5164
5571
|
// ../../apps/cli/src/commands/reset-state.ts
|
|
5165
|
-
import { join as
|
|
5572
|
+
import { join as join23 } from "node:path";
|
|
5166
5573
|
async function resetStateCommand(args) {
|
|
5167
5574
|
const sources = flagList(args, "sources");
|
|
5168
5575
|
const state = readState();
|
|
@@ -5195,7 +5602,7 @@ async function resetStateCommand(args) {
|
|
|
5195
5602
|
`
|
|
5196
5603
|
${green("Done.")} The next ${bold("actario capture")} will re-read everything from these sources.
|
|
5197
5604
|
${dim("The server deduplicates by content hash, so nothing is uploaded twice.")}
|
|
5198
|
-
${dim(`State file: ${
|
|
5605
|
+
${dim(`State file: ${join23(actarioDir(), "state.json")}`)}
|
|
5199
5606
|
`
|
|
5200
5607
|
);
|
|
5201
5608
|
return 0;
|
|
@@ -5254,7 +5661,7 @@ async function statusCommand(args) {
|
|
|
5254
5661
|
|
|
5255
5662
|
// ../../apps/cli/src/commands/unmask.ts
|
|
5256
5663
|
import { existsSync as existsSync8, mkdirSync as mkdirSync7, readFileSync as readFileSync5, readdirSync, statSync, writeFileSync as writeFileSync7 } from "node:fs";
|
|
5257
|
-
import { basename as basename2, dirname as dirname4, join as
|
|
5664
|
+
import { basename as basename2, dirname as dirname4, join as join24, relative, resolve as resolve2, sep } from "node:path";
|
|
5258
5665
|
async function unmaskCommand(args) {
|
|
5259
5666
|
const input = args.positional[0];
|
|
5260
5667
|
if (!input) {
|
|
@@ -5269,8 +5676,8 @@ async function unmaskCommand(args) {
|
|
|
5269
5676
|
return 1;
|
|
5270
5677
|
}
|
|
5271
5678
|
const home = actarioDir();
|
|
5272
|
-
const saltPath =
|
|
5273
|
-
const mapPath =
|
|
5679
|
+
const saltPath = join24(home, "salt");
|
|
5680
|
+
const mapPath = join24(home, "redaction_map.json.enc");
|
|
5274
5681
|
if (!existsSync8(saltPath) || !existsSync8(mapPath)) {
|
|
5275
5682
|
process.stderr.write(
|
|
5276
5683
|
`${red("No redaction map on this machine.")} ${dim(`(${mapPath})`)}
|
|
@@ -5304,11 +5711,11 @@ ${dim("Pass --out to choose another.")}
|
|
|
5304
5711
|
const members = isDir ? readDir(inputPath) : readZip(readFileSync5(inputPath)).map((m) => ({ name: m.name, data: m.data() }));
|
|
5305
5712
|
const { members: out, report } = unmaskMembers(members, reverse);
|
|
5306
5713
|
for (const m of out) {
|
|
5307
|
-
const target =
|
|
5714
|
+
const target = join24(outDir, ...m.name.split("/"));
|
|
5308
5715
|
mkdirSync7(dirname4(target), { recursive: true });
|
|
5309
5716
|
writeFileSync7(target, m.data);
|
|
5310
5717
|
}
|
|
5311
|
-
writeFileSync7(
|
|
5718
|
+
writeFileSync7(join24(outDir, UNMASK_MARKER_NAME), UNMASK_MARKER_TEXT, { mode: 384 });
|
|
5312
5719
|
const total = Object.values(report.replaced).reduce((a, b) => a + b, 0);
|
|
5313
5720
|
process.stdout.write(heading(`Unmasked ${out.length} file(s) \u2192 ${outDir}`));
|
|
5314
5721
|
if (total === 0) process.stdout.write(` ${dim("No pseudonyms from this machine were found.")}
|
|
@@ -5331,13 +5738,13 @@ ${dim("Pass --out to choose another.")}
|
|
|
5331
5738
|
function defaultOut(inputPath, isDir) {
|
|
5332
5739
|
const base = basename2(inputPath);
|
|
5333
5740
|
const stem = !isDir && base.toLowerCase().endsWith(".zip") ? base.slice(0, -4) : base;
|
|
5334
|
-
return
|
|
5741
|
+
return join24(dirname4(inputPath), `${stem}.unmasked`);
|
|
5335
5742
|
}
|
|
5336
5743
|
function readDir(root) {
|
|
5337
5744
|
const out = [];
|
|
5338
5745
|
const walk = (dir) => {
|
|
5339
5746
|
for (const name of readdirSync(dir)) {
|
|
5340
|
-
const p =
|
|
5747
|
+
const p = join24(dir, name);
|
|
5341
5748
|
if (statSync(p).isDirectory()) walk(p);
|
|
5342
5749
|
else out.push({ name: relative(root, p).split(sep).join("/"), data: readFileSync5(p) });
|
|
5343
5750
|
}
|
|
@@ -5354,7 +5761,8 @@ var USAGE = `${bold("actario")} ${dim(`v${CLI_VERSION}`)}
|
|
|
5354
5761
|
${dim("(separate from capture on purpose: a model failure never costs a capture)")}
|
|
5355
5762
|
actario status [upload_id] local capture state, or one upload's progress
|
|
5356
5763
|
actario doctor [--schema] diagnose sources and report format changes
|
|
5357
|
-
actario
|
|
5764
|
+
actario login [options] link this machine by signing in with the browser
|
|
5765
|
+
actario init [options] link this machine with a pasted token
|
|
5358
5766
|
actario reset-state forget the high-water mark and re-read everything
|
|
5359
5767
|
${dim("(needed after resetting a development database)")}
|
|
5360
5768
|
actario unmask <zip|dir> reverse pseudonyms in a downloaded export, locally
|
|
@@ -5390,6 +5798,11 @@ ${bold("init options")}
|
|
|
5390
5798
|
--api-url URL --token TOKEN --profile medical|general --label NAME
|
|
5391
5799
|
${dim("the token is validated first; this machine is registered as a source (--source-id to reuse one)")}
|
|
5392
5800
|
|
|
5801
|
+
${bold("login options")}
|
|
5802
|
+
--device no browser: print a URL + code to approve on any device
|
|
5803
|
+
--no-browser same as --device
|
|
5804
|
+
--api-url URL --label NAME --profile medical|general
|
|
5805
|
+
|
|
5393
5806
|
${bold("unmask options")}
|
|
5394
5807
|
--out DIR write here instead of <name>.unmasked/ next to the input
|
|
5395
5808
|
|
|
@@ -5420,6 +5833,7 @@ async function main(argv) {
|
|
|
5420
5833
|
status: () => statusCommand(args),
|
|
5421
5834
|
doctor: () => doctorCommand(args),
|
|
5422
5835
|
init: () => initCommand(args),
|
|
5836
|
+
login: () => loginCommand(args),
|
|
5423
5837
|
"reset-state": () => resetStateCommand(args),
|
|
5424
5838
|
unmask: () => unmaskCommand(args),
|
|
5425
5839
|
mcp: () => mcpCommand(args)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actario/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Capture, redact and distil your AI coding sessions into decisions, facts and open questions. Runs on your machine; redaction happens before anything is uploaded.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|