@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.60
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/CHANGELOG.md +77 -0
- package/README.md +188 -106
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/chatgpt-plan.d.ts +4 -2
- package/dist/chatgpt-plan.js +13 -3
- package/dist/claude-login-token.d.ts +5 -0
- package/dist/claude-login-token.js +8 -0
- package/dist/claude-login.d.ts +49 -3
- package/dist/claude-login.js +140 -10
- package/dist/cli-learning/connections.js +1 -1
- package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +2 -2
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-table.d.ts +4 -0
- package/dist/harness-table.js +4 -0
- package/dist/harness.js +6 -2
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +9 -0
- package/dist/import.js +11 -1
- package/dist/key-refusal.d.ts +5 -0
- package/dist/key-refusal.js +25 -15
- package/dist/learn/audit.d.ts +20 -22
- package/dist/learn/audit.js +72 -55
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +4 -4
- package/dist/learn/compile.js +6 -7
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +40 -66
- package/dist/learn/promote.js +69 -207
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/openapi.js +89 -29
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +33 -11
- package/dist/place.js +61 -26
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +19 -4
- package/dist/redact/match.js +123 -30
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +6 -5
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-run-spec.js +11 -20
- package/dist/runner/audit.d.ts +2 -4
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +8 -14
- package/dist/runner/compare-end.d.ts +0 -2
- package/dist/runner/compare-end.js +6 -2
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +2 -3
- package/dist/runner/held.d.ts +0 -10
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +1 -1
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +3 -3
- package/dist/runner/learning-end.d.ts +12 -16
- package/dist/runner/learning-end.js +41 -75
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/native-loop.js +2 -3
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/run-child-host.d.ts +1 -9
- package/dist/runner/run-child-host.js +11 -67
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +2 -4
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +20 -7
- package/dist/sdk/runs.js +105 -68
- package/dist/secrets.d.ts +4 -0
- package/dist/secrets.js +44 -10
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +6 -0
- package/dist/server-keys.js +12 -0
- package/dist/server.d.ts +15 -15
- package/dist/server.js +214 -164
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/schema.d.ts +28 -2
- package/dist/store/schema.js +81 -5
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/store.d.ts +7 -1
- package/dist/store/sqlite/store.js +84 -18
- package/dist/store/store.d.ts +219 -6
- package/dist/store/store.js +13 -0
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +18 -22
- package/dist/store-reads/learning.js +35 -26
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +40 -11
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/tool-plane.d.ts +4 -2
- package/dist/tool-plane.js +9 -2
- package/dist/web-holds.d.ts +2 -0
- package/dist/web-holds.js +5 -2
- package/dist/web-run.js +2 -1
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-deps.js +5 -3
- package/dist/workspace/computer-providers.d.ts +11 -1
- package/dist/workspace/computer-providers.js +29 -2
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/workspace.d.ts +1 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -13
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/index-LwNL4L9q.js +0 -619
- package/dist/console/assets/styles-DQo8rzY-.css +0 -1
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/claude-login.js
CHANGED
|
@@ -13,15 +13,17 @@
|
|
|
13
13
|
// for a server one person runs: it is refused where more than one person can start runs, `on` included, and the owner
|
|
14
14
|
// confirms they alone run agents here. It runs only in a runner place, on the machine the owner turned it on for.
|
|
15
15
|
import { createHash, randomBytes } from "node:crypto";
|
|
16
|
-
import { accessSync, chmodSync, closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readlinkSync, readSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { accessSync, chmodSync, closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readlinkSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
17
17
|
import { homedir, userInfo } from "node:os";
|
|
18
|
-
import { delimiter, dirname, isAbsolute, join } from "node:path";
|
|
19
|
-
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
20
|
-
import { registerSecretWrite } from "./secret-writes.js";
|
|
18
|
+
import { basename, delimiter, dirname, isAbsolute, join } from "node:path";
|
|
19
|
+
import { facts as claudeFacts, loginRefresh } from "@parcha/agentrun-harness-claude/facts";
|
|
20
|
+
import { registerSecretPage, registerSecretWrite } from "./secret-writes.js";
|
|
21
|
+
import { copyEnv } from "./secrets.js";
|
|
21
22
|
// Every operation here is the owner's session's alone (secret-writes.ts): no answer holds a credential, but turning a
|
|
22
23
|
// person's plan on for this server's runs, and starting its sign-in, are the owner's to do.
|
|
23
|
-
for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin"])
|
|
24
|
+
for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin", "signOutClaudeLogin"])
|
|
24
25
|
registerSecretWrite(operation, () => true);
|
|
26
|
+
registerSecretPage("signOutClaudeLogin", "/#/settings/keys");
|
|
25
27
|
/** The switch: `off` (or 0, false, no) turns the mode off on this server, `on` (or 1, true, yes) leaves it there past
|
|
26
28
|
* loopback; unset, the listen address decides (claudeLoginSwitchedOff). */
|
|
27
29
|
export const CLAUDE_LOGIN_ENV = "AGENTRUN_CLAUDE_CODE_LOGIN";
|
|
@@ -435,15 +437,17 @@ export function loginRefused(place, env, uid = process.geteuid?.()) {
|
|
|
435
437
|
* runs on a copy of the account file (the harness's claudeLoginStatus). Every login carries the person's home as
|
|
436
438
|
* `userHome`, read here once (homeOf), so the status check, the sign-in and a run on macOS all run in that one home
|
|
437
439
|
* whatever reads it later (the harness's personHome), and `homeApart` where the env's HOME was not that home (homeOf's
|
|
438
|
-
* `apart`). The home and the folders the env gives are the real paths the walk ended in. */
|
|
440
|
+
* `apart`). AgentRun's carries `own`. The home and the folders the env gives are the real paths the walk ended in. */
|
|
439
441
|
export function loginAt(place, data, env = process.env, uid = process.geteuid?.()) {
|
|
440
442
|
const checked = homeOf(env, uid);
|
|
441
443
|
if (checked.refused !== undefined)
|
|
442
444
|
return { refused: checked.refused };
|
|
443
445
|
const { home, apart } = checked;
|
|
444
446
|
const homeAt = { userHome: home, ...(apart ? { homeApart: true } : {}) };
|
|
447
|
+
// `own`: no CLI of the person's uses AgentRun's folder, so the harness may delete the Keychain item a sign-in left
|
|
448
|
+
// there under "unknown" (its dropUnknownItem).
|
|
445
449
|
if (place === "agentrun")
|
|
446
|
-
return { login: { dir: agentRunLoginDir(data), profiles: join(agentRunLoginDir(data), "anthropic"), ...homeAt }, toMake: [] };
|
|
450
|
+
return { login: { dir: agentRunLoginDir(data), profiles: join(agentRunLoginDir(data), "anthropic"), ...homeAt, own: true }, toMake: [] };
|
|
447
451
|
const real = new Map();
|
|
448
452
|
const toMake = [];
|
|
449
453
|
for (const [name, folder] of envFolders(env)) {
|
|
@@ -497,11 +501,12 @@ export function withClaudeLogin(env, login) {
|
|
|
497
501
|
return env;
|
|
498
502
|
}
|
|
499
503
|
/** `env` as a run at `place` reads it: a runner place keeps the login; any other place (a sandbox) gets a copy without it,
|
|
500
|
-
* so a revision's checks there ask for a key, as its run will.
|
|
504
|
+
* so a revision's checks there ask for a key, as its run will. The copy is copyEnv's, which keeps withSecrets' keys
|
|
505
|
+
* (read by name, never enumerated), where a spread would keep none. */
|
|
501
506
|
export function envAtPlace(env, place) {
|
|
502
507
|
if (place?.mode === "runner" || env[LOGIN] === undefined)
|
|
503
508
|
return env;
|
|
504
|
-
return withClaudeLogin(
|
|
509
|
+
return withClaudeLogin(copyEnv(env), undefined);
|
|
505
510
|
}
|
|
506
511
|
/** The login `env` carries, unless the switch is off. */
|
|
507
512
|
export function claudeLoginOf(env) {
|
|
@@ -589,7 +594,7 @@ export async function loginForRun(settings, data, env, harness, place, uid = pro
|
|
|
589
594
|
return loginOf(await claudeLoginSetting(settings), data, env, uid);
|
|
590
595
|
}
|
|
591
596
|
/** The routes here (server.ts): every one answers 404, by its name, while the mode is off (`why`). */
|
|
592
|
-
export const CLAUDE_LOGIN_ROUTES = new Set(["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin"]);
|
|
597
|
+
export const CLAUDE_LOGIN_ROUTES = new Set(["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin", "signOutClaudeLogin"]);
|
|
593
598
|
/** Whether the claude-login routes answer here, the one rule the routes and capabilities' `features.claude_login` both
|
|
594
599
|
* read: none while the mode is switched off (`off`, claudeLoginSwitchedOff's reason), and none on an API-only server
|
|
595
600
|
* (`apiOnly`), whose route list holds none of them, so it refuses them before routing (server.ts). */
|
|
@@ -668,6 +673,20 @@ export async function claudeLoginView(deps) {
|
|
|
668
673
|
return { state: "unknown", ...base };
|
|
669
674
|
}
|
|
670
675
|
}
|
|
676
|
+
/** What AgentRun's own login folder (`<data>/claude-login`) leads to where it is a link (the link's text); else
|
|
677
|
+
* undefined, a folder or nothing there. */
|
|
678
|
+
function loginFolderLink(data) {
|
|
679
|
+
const dir = agentRunLoginDir(data);
|
|
680
|
+
try {
|
|
681
|
+
return lstatSync(dir, { throwIfNoEntry: false })?.isSymbolicLink() ? readlinkSync(dir) : undefined;
|
|
682
|
+
}
|
|
683
|
+
catch {
|
|
684
|
+
return undefined;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
/** Why a turn-on is refused where AgentRun's own login folder (`dir`) is a link (to `to`). A sign-out removes that folder
|
|
688
|
+
* whole, so it is one AgentRun keeps itself, and no link leads a sign-out into a folder elsewhere. */
|
|
689
|
+
export const loginFolderIsLink = (dir, to) => `AgentRun's own Claude login folder ${dir} is a link (to ${to}). AgentRun keeps its login in a folder of its own, which a sign-out removes whole, so it never follows a link there: remove the link, then turn it on again.`;
|
|
671
690
|
/** PUT /settings/claude-login: turned on, refused in one line where more than one person can start runs. A turn-on that
|
|
672
691
|
* moves the login to another place first ends a sign-in this server started that still waits: its CLI signs in at the
|
|
673
692
|
* old place, which the login no longer reads. One at the same place leaves it waiting, as it still signs in there. */
|
|
@@ -703,6 +722,9 @@ export async function turnOnClaudeLogin(deps, body) {
|
|
|
703
722
|
const at = loginAt(asked.place, deps.data, deps.env, deps.uid);
|
|
704
723
|
if (at.refused !== undefined)
|
|
705
724
|
throw new ClaudeLoginRefused("forbidden", at.refused);
|
|
725
|
+
const linked = asked.place === "agentrun" ? loginFolderLink(deps.data) : undefined;
|
|
726
|
+
if (linked !== undefined)
|
|
727
|
+
throw new ClaudeLoginRefused("forbidden", loginFolderIsLink(agentRunLoginDir(deps.data), linked));
|
|
706
728
|
// Its folders still to make are made here (madeLogin), so a sign-in from the line shown finds them made 0700.
|
|
707
729
|
const login = madeLogin(at, asked.place, deps);
|
|
708
730
|
const setting = settingFor(asked.place, deps.data);
|
|
@@ -724,6 +746,114 @@ export async function turnOffClaudeLogin(deps) {
|
|
|
724
746
|
await deps.changed();
|
|
725
747
|
return claudeLoginView(deps);
|
|
726
748
|
}
|
|
749
|
+
/** What may remain where the CLI didn't confirm its own sign-out (`why`, the CLI's step as it went). */
|
|
750
|
+
const keychainMayRemain = (why) => `${why}, so on macOS its Keychain item for this login may remain: remove it in Keychain Access (its name starts with "Claude Code-credentials").`;
|
|
751
|
+
const KEYCHAIN_MAY_REMAIN = keychainMayRemain("Claude Code's own sign-out didn't confirm");
|
|
752
|
+
/** The Keychain's words where the CLI's step threw before the CLI ran (`failed`, the error's words), else where it didn't confirm. */
|
|
753
|
+
const keychainWords = (failed) => failed === undefined ? KEYCHAIN_MAY_REMAIN : keychainMayRemain(`Claude Code's own sign-out could not run (${failed})`);
|
|
754
|
+
/** What a sign-out answers beside `confirmed: false`: the login is gone here, and the CLI said nothing of its own copy. */
|
|
755
|
+
export const LOGIN_SIGN_OUT_UNCONFIRMED = `Signed out here: AgentRun's copy of the login is removed. ${KEYCHAIN_MAY_REMAIN}`;
|
|
756
|
+
/** What a sign-out answers beside `confirmed: false` where the CLI's step threw (`failed`, the error's words): the login is
|
|
757
|
+
* gone here all the same, and the CLI's own copy may remain. */
|
|
758
|
+
export const signOutCliFailed = (failed) => `Signed out here: AgentRun's copy of the login is removed. ${keychainWords(failed)}`;
|
|
759
|
+
/** What a sign-out answers beside `confirmed: false` where some of the login is still there (`left`: each thing, its path
|
|
760
|
+
* and why), and the Keychain's words too where the CLI didn't confirm its own sign-out (`keychain`), naming the CLI
|
|
761
|
+
* step's failure where it threw (`failed`). */
|
|
762
|
+
export const signOutLeft = (left, keychain, failed) => `Signed out here, and the mode is off, but some of AgentRun's copy of the login remains: ${left.join("; ")}. Remove it by hand before turning the mode on again.${keychain ? ` ${keychainWords(failed)}` : ""}`;
|
|
763
|
+
/** Why a sign-out of this machine's own login (`folder`, the person's `~/.claude` or CLAUDE_CONFIG_DIR) is refused. */
|
|
764
|
+
export const machineSignOutRefused = (folder) => `This is your own Claude Code login on this machine (${folder}), which AgentRun only uses: it never signs it out. Run \`claude auth logout\` in a terminal there to sign it out, or turn the mode off here.`;
|
|
765
|
+
/** POST /settings/claude-login/sign-out: AgentRun's own login (`<data>/claude-login`) signed out and removed, so the next
|
|
766
|
+
* turn-on finds none and the person signs in fresh, to the same account or another. In one turn on the sign-ins' queue
|
|
767
|
+
* (no sign-in or turn-on lands in between): a sign-in this server started that still waits is ended; the mode is turned
|
|
768
|
+
* off, so no new run goes on the login while it goes; the pinned CLI's own sign-out (the harness's claudeLogout) runs on
|
|
769
|
+
* the folder, so it removes its credentials file and, on macOS, the Keychain item named from the folder. It runs where
|
|
770
|
+
* the folder is gone too: a retry after a sign-out the CLI didn't confirm finds no folder, and the Keychain item may
|
|
771
|
+
* remain, so the answer is confirmed only where the CLI confirms. Then the folder is removed whatever the CLI said (a
|
|
772
|
+
* folder the CLI made as it signed out too) (credentials, account, profiles, the CLI's refresh lock, and
|
|
773
|
+
* the CLI's older lock beside it), with the login's signed-in note (noteAnswer) and this process's token reader of it
|
|
774
|
+
* (claude-login-token.ts forgetLoginTokens). Each removal stands alone: one that fails is named in the answer
|
|
775
|
+
* (signOutLeft, `confirmed` false), and the others, the reader's drop and the server's reread of the keys still happen.
|
|
776
|
+
* So with the CLI's step: a throw finding the CLI or loading the harness is named in the answer (signOutCliFailed), and
|
|
777
|
+
* every removal still runs.
|
|
778
|
+
* Where the folder is a link (put there after the turn-on, which refuses one), the link alone is removed, with the
|
|
779
|
+
* login's signed-in note: no CLI runs through it, nothing it leads to is touched, and the answer names it. Runs already going are left as a turn-off
|
|
780
|
+
* leaves them: each keeps the token its CLI holds, and fails in
|
|
781
|
+
* LOGIN_SIGNED_OUT's words at its next read of the login; one claimed on it and started while the mode is off is refused
|
|
782
|
+
* at its start (claude-login-token.ts LOGIN_CHANGED_SINCE_CLAIM). That check is of the folder, not the account, so one
|
|
783
|
+
* started after a turn-on and a new sign-in runs on that sign-in. A run whose CLI reads the folder itself (in the
|
|
784
|
+
* runner's process) holds the refresh token and may write a renewed pair back after the folder goes; nothing here
|
|
785
|
+
* removes it again. A login on this machine's own folder (`machine`) is the person's:
|
|
786
|
+
* refused (machineSignOutRefused), with nothing touched. */
|
|
787
|
+
export async function signOutClaudeLogin(deps) {
|
|
788
|
+
let off = false;
|
|
789
|
+
let signedOut = true;
|
|
790
|
+
let cliFailed;
|
|
791
|
+
const left = [];
|
|
792
|
+
const remove = (what, path, options) => {
|
|
793
|
+
try {
|
|
794
|
+
rmSync(path, options);
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
left.push(`${what} ${path} (${error.code ?? String(error)})`);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
try {
|
|
801
|
+
await deps.signIns.serial(async (turn) => {
|
|
802
|
+
if ((await claudeLoginSetting(deps.settings))?.place === "machine")
|
|
803
|
+
throw new ClaudeLoginRefused("forbidden", machineSignOutRefused(machineFolder(deps.env, deps.uid).folder));
|
|
804
|
+
await turn.stop();
|
|
805
|
+
await deps.settings.remove(CLAUDE_LOGIN_SETTING);
|
|
806
|
+
deps.saved(undefined);
|
|
807
|
+
off = true;
|
|
808
|
+
const dir = agentRunLoginDir(deps.data);
|
|
809
|
+
const linked = loginFolderLink(deps.data);
|
|
810
|
+
const note = answerFile(deps.data, { dir, profiles: join(dir, "anthropic") });
|
|
811
|
+
try {
|
|
812
|
+
if (linked !== undefined) {
|
|
813
|
+
// A link put there after the turn-on (which refuses one, loginFolderIsLink): the link alone goes, no CLI runs
|
|
814
|
+
// through it, and nothing it leads to is touched. The login's signed-in note, in the data folder, goes too.
|
|
815
|
+
signedOut = false;
|
|
816
|
+
remove("the link", dir, { force: true });
|
|
817
|
+
remove("the login's signed-in note", note, { force: true });
|
|
818
|
+
left.push(`${linked}, where the link ${dir} led, left as it was`);
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
// The CLI's step in its own try: a throw finding the CLI or loading the harness skips no removal below, and the
|
|
822
|
+
// answer names it.
|
|
823
|
+
try {
|
|
824
|
+
const { login } = loginAt("agentrun", deps.data, deps.env, deps.uid);
|
|
825
|
+
const cli = loginCli(await deps.pinned(), deps.env);
|
|
826
|
+
signedOut = login && cli ? await (await deps.claude()).claudeLogout(cli, login, pathOf(deps.env)) : false;
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
signedOut = false;
|
|
830
|
+
cliFailed = error instanceof Error ? error.message : String(error);
|
|
831
|
+
}
|
|
832
|
+
// The older lock sits beside the folder in the data folder's real path. The folder's own real path is never
|
|
833
|
+
// followed: a link swapped in during the CLI's await would lead the lock's removal outside the data folder.
|
|
834
|
+
let beside = dir;
|
|
835
|
+
try {
|
|
836
|
+
beside = join(realpathSync(dirname(dir)), basename(dir));
|
|
837
|
+
}
|
|
838
|
+
catch {
|
|
839
|
+
// The folder as named.
|
|
840
|
+
}
|
|
841
|
+
remove("the login's folder", dir, { recursive: true, force: true });
|
|
842
|
+
remove("the CLI's older lock", `${beside}${loginRefresh.legacyLockSuffix}`, { recursive: true, force: true });
|
|
843
|
+
remove("the login's signed-in note", note, { force: true });
|
|
844
|
+
}
|
|
845
|
+
finally {
|
|
846
|
+
(await import("./claude-login-token.js")).forgetLoginTokens(dir);
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
finally {
|
|
851
|
+
if (off)
|
|
852
|
+
await deps.changed();
|
|
853
|
+
}
|
|
854
|
+
const message = left.length > 0 ? signOutLeft(left, !signedOut, cliFailed) : signedOut ? undefined : cliFailed !== undefined ? signOutCliFailed(cliFailed) : LOGIN_SIGN_OUT_UNCONFIRMED;
|
|
855
|
+
return { confirmed: message === undefined, ...(message ? { message } : {}), login: await claudeLoginView(deps) };
|
|
856
|
+
}
|
|
727
857
|
/** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
|
|
728
858
|
* shown line's own variables (the harness's signInEnv), so it signs in where the status reads. A sign-in that
|
|
729
859
|
* still waits is ended first (deps.signIns). The browser code goes to the CLI, never here; the answer is the view as it
|
|
@@ -32,7 +32,7 @@ export class CliLearningConnections {
|
|
|
32
32
|
const native = await launchNative({ ...target, connected: true });
|
|
33
33
|
const id = createHash('sha256').update(`${target.runtime}\0${target.machine_id}\0${target.project}`).digest('hex').slice(0, 32);
|
|
34
34
|
const agentId = `cli-${id}`;
|
|
35
|
-
// Agent creation is deterministic. Concurrent enrollments keep the winner's revision and learning
|
|
35
|
+
// Agent creation is deterministic. Concurrent enrollments keep the winner's revision and learning.
|
|
36
36
|
if (!await getAgent(this.store, agentId))
|
|
37
37
|
try {
|
|
38
38
|
await createAgent(this.store, { definition: { id: agentId, name: typeof body.name === 'string' ? body.name : `${basename(target.project)} (${target.runtime})`, instructions: '', tools: [], learning: true, cli_learning: { runtime: target.runtime, connection_id: id, project: target.project } } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as It,D as Yn}from"./index-
|
|
1
|
+
import{d as It,D as Yn}from"./index-DZi-muIj.js";import{az as bt}from"./styles-CcceGcu2.js";const we=t=>({type:"boolean",description:t}),Yt={type:"object",required:["name","pageCount","pages","text"],properties:{name:{type:"string"},pageCount:{type:"integer"},pages:{type:"array"},text:{type:"string"}}},Jn={type:"object",required:["status","text"],properties:{status:{type:"integer"},url:{type:"string"},title:{type:"string"},text:{type:"string"}}},vt={type:"object"},Ke={type:"object",additionalProperties:!1,required:["altered","seal","signature","legible"],properties:{altered:we("Does the page show signs of digital alteration: mismatched fonts, misaligned lines, pasted regions or an edited date?"),seal:we("Is a state seal or a filing stamp visible on the page?"),signature:we("Is the certificate signed by a state official?"),legible:we("Is the entity's full legal name legible on the page?")}},mt={v:2,name:"coi-batch-review",schemas:{Input:{type:"object",required:["documents"],properties:{documents:{type:"array",items:{type:"string"},minItems:1,maxItems:50}}},DocChecks:Ke,Pages:Yt,Report:vt},input:{schemaId:"Input"},output:{schemaId:"Report",path:"report"},root:{node:"chain",steps:[{node:"map",label:"each-document",itemsPath:"documents",as:"rows",maxConcurrency:4,onItemFailure:"collect",failedAs:"failed",body:{node:"chain",steps:[{node:"call",label:"render-pages",via:"tool",tool:"pdf_pages",args:{path:"{item}",maxPages:2},out:"Pages",as:"pages",deadline_s:60},{node:"judge",label:"inspect-certificate",provider:"jev",state:{document:"{item}",page:"<page1>",text:"{pages.text}"},images:{"<page1>":"{pages.pages.0.image}"},out:"DocChecks",as:"checks"},{node:"code",label:"grade",code:"(s) => ({ document: s.item, verdict: s.checks.altered || !s.checks.seal || !s.checks.legible ? 'doubtful' : 'valid', checks: s.checks })",as:"row"}]}},{node:"code",label:"batch-report",code:"(s) => ({ valid: s.rows.filter((r) => r && r.verdict === 'valid').length, doubtful: s.rows.filter((r) => r && r.verdict === 'doubtful').map((r) => r.document), failed: s.failed })",as:"report"}]}},xe={v:2,name:"kyb-onboarding",schemas:{Pages:Yt,Result:vt,Input:{type:"object",required:["company","state","registration_number","documents"],properties:{company:{type:"string"},state:{type:"string"},registration_number:{type:"string"},documents:{type:"array",items:{type:"string"}}}},Registry:{type:"object",additionalProperties:!1,required:["registered","active","name_matches"],properties:{registered:we("Is a company with this exact registration number on file with the named state's business registry?"),active:we("Is that registration currently active (in good standing, not dissolved, forfeited or revoked)?"),name_matches:we("Does the registry's legal name match the applicant's name, ignoring punctuation and suffix style?")}},CertLook:{type:"object",additionalProperties:!1,required:["altered","seal","legible"],properties:{altered:Ke.properties.altered,seal:Ke.properties.seal,legible:Ke.properties.legible}},CrossCheck:{type:"object",additionalProperties:!1,required:["same_entity","same_state","dates_consistent"],properties:{same_entity:we("Do the registry record and the certificate name the same legal entity?"),same_state:we("Do they name the same state of incorporation?"),dates_consistent:we("Is the certificate's filing date consistent with the registry's formation date (within 3 days)?")}}},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"render-certificate",via:"tool",tool:"pdf_pages",args:{path:"{documents.0}",maxPages:1},out:"Pages",as:"cert",deadline_s:60},{node:"parallel",label:"checks",branches:[{node:"judge",label:"registry-lookup",provider:"parallel",model:"standard",state:{company:"{company}",state:"{state}",registration_number:"{registration_number}"},out:"Registry",as:"registry"},{node:"judge",label:"certificate-look",provider:"jev",state:{page:"<cert>",text:"{cert.text}"},images:{"<cert>":"{cert.pages.0.image}"},out:"CertLook",as:"look"}]},{node:"judge",label:"cross-check",provider:"jev",state:{applicant:{company:"{company}",state:"{state}"},registry:"{registry$answers}",certificate_text:"{cert.text}"},out:"CrossCheck",as:"cross"},{node:"route",label:"decide",provider:"jev",state:{registry:"{registry}",look:"{look}",cross:"{cross}"},instructions:"Decide the onboarding outcome for this business from the registry check, the certificate's look and the cross-check.",branches:{approve:{criteria:"Registered, active, the certificate looks genuine, and every cross-check agrees.",body:{node:"code",label:"record-approval",code:"(s) => ({ outcome: 'approved' })",as:"outcome"}},review:{criteria:"Mostly consistent, but one check is doubtful or the evidence disagrees on a detail.",body:{node:"code",label:"open-review-case",code:"(s) => ({ outcome: 'review', reasons: s.cross })",as:"outcome"}},reject:{criteria:"Not registered, dissolved, or the certificate is altered.",body:{node:"code",label:"record-rejection",code:"(s) => ({ outcome: 'rejected' })",as:"outcome"}}},unsure:{branch:"review",gte:.75}}]},output:{schemaId:"Result",path:"outcome"}},Vn={type:"object",additionalProperties:!1,required:["prohibited"],properties:{prohibited:we("Does this merchant sell goods the card networks prohibit: weapons, controlled substances, counterfeit goods, or unlicensed nicotine products?")}},Ve=(t,s,o)=>({node:"judge",label:t,provider:s,...o?{model:o}:{},state:{merchant:"{merchant}",url:"{url}",page_text:"{page.text}"},out:"Prohibited",as:t.replace(/-/g,"_")}),Ze={v:2,name:"prohibited-goods-jury",schemas:{Page:Jn,Result:vt,Input:{type:"object",required:["merchant","url"],properties:{merchant:{type:"string"},url:{type:"string"}}},Prohibited:Vn},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"fetch-storefront",via:"tool",tool:"web_fetch",args:{url:"{url}"},out:"Page",as:"page",deadline_s:30},{node:"parallel",label:"jury",branches:[Ve("jev","jev"),Ve("pplx-decider","openrouter","perplexity/pplx-decider-v1.2"),Ve("liquid-d1","openrouter","liquid/d1"),Ve("clef","openrouter","cloudflare/clef")]},{node:"code",label:"aggregate",code:"(s) => { const p = [s.jev$answers, s.pplx_decider$answers, s.liquid_d1$answers, s.clef$answers].map((a) => a.answers.prohibited.noul); const mean = p.reduce((x, y) => x + y, 0) / p.length; const spread = Math.max(...p) - Math.min(...p); return { mean, spread, outcome: spread > 0.3 ? 'disagree' : 'agree' }; }",as:"agreement"},{node:"route",label:"agreement",valuePath:"agreement.outcome",branches:{agree:{body:{node:"code",label:"auto-decide",code:"(s) => ({ decision: s.agreement.mean >= 0.5 ? 'decline' : 'approve' })",as:"decision"}},disagree:{body:{node:"code",label:"human-review",code:"(s) => ({ decision: 'review', spread: s.agreement.spread })",as:"decision"}}}}]},output:{schemaId:"Result",path:"decision"}},re=6e4,le=60*re,W=24*le,se={default:"anthropic/claude-sonnet-5-5",fast:"openai/gpt-6-luna",strong:"anthropic/claude-opus-5-5",codex:"openai/gpt-6.1-sol"},Qn={v:2,name:"ticket-triage",schemas:{Ticket:{type:"object",required:["subject","body"],properties:{subject:{type:"string"},body:{type:"string"}}},Triage:{type:"object",required:["queue","urgency"],properties:{queue:{type:"string"},urgency:{type:"integer"}}}},input:{schemaId:"Ticket"},output:{schemaId:"Triage",path:"triage"},root:{node:"chain",steps:[{node:"call",label:"read the playbook",tool:"read",args:{path:"playbooks/triage.md"},as:"playbook"},{node:"pick",label:"which queue",from:"playbook.queues",instructions:"Which queue does this ticket belong to, by what the buyer or seller asks for?",as:"queue",none:"hand back"},{node:"code",label:"score the urgency",as:"triage"}]}},Zn=`# ticket-triage
|
|
2
2
|
|
|
3
3
|
Files a ticket under its queue (billing, shipping, account, merchant, abuse) and scores its urgency from the playbook: a chargeback, a locked account or a safety problem is 4 or more.
|
|
4
4
|
|