@0gfoundation/0g-agentdna 0.0.0-stage → 0.2.0
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/GUIDE.md +975 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +84 -0
- package/MIGRATION.zh.md +70 -0
- package/PROVIDERS.md +273 -0
- package/PROVIDERS.zh.md +234 -0
- package/README.md +334 -2
- package/dist/AgentClient.d.ts +312 -0
- package/dist/AgentClient.d.ts.map +1 -0
- package/dist/AgentClient.js +715 -0
- package/dist/AgentClient.js.map +1 -0
- package/dist/AgenticID.d.ts +823 -0
- package/dist/AgenticID.d.ts.map +1 -0
- package/dist/AgenticID.js +1188 -0
- package/dist/AgenticID.js.map +1 -0
- package/dist/AgenticIDClient.d.ts +68 -0
- package/dist/AgenticIDClient.d.ts.map +1 -0
- package/dist/AgenticIDClient.js +198 -0
- package/dist/AgenticIDClient.js.map +1 -0
- package/dist/AttestorClient.d.ts +465 -0
- package/dist/AttestorClient.d.ts.map +1 -0
- package/dist/AttestorClient.js +1030 -0
- package/dist/AttestorClient.js.map +1 -0
- package/dist/Providers.d.ts +72 -0
- package/dist/Providers.d.ts.map +1 -0
- package/dist/Providers.js +182 -0
- package/dist/Providers.js.map +1 -0
- package/dist/ReputationClient.d.ts +213 -0
- package/dist/ReputationClient.d.ts.map +1 -0
- package/dist/ReputationClient.js +708 -0
- package/dist/ReputationClient.js.map +1 -0
- package/dist/SandboxClient.d.ts +107 -0
- package/dist/SandboxClient.d.ts.map +1 -0
- package/dist/SandboxClient.js +200 -0
- package/dist/SandboxClient.js.map +1 -0
- package/dist/ServeProof.d.ts +161 -0
- package/dist/ServeProof.d.ts.map +1 -0
- package/dist/ServeProof.js +230 -0
- package/dist/ServeProof.js.map +1 -0
- package/dist/ServeSession.d.ts +180 -0
- package/dist/ServeSession.d.ts.map +1 -0
- package/dist/ServeSession.js +336 -0
- package/dist/ServeSession.js.map +1 -0
- package/dist/Settings.d.ts +179 -0
- package/dist/Settings.d.ts.map +1 -0
- package/dist/Settings.js +247 -0
- package/dist/Settings.js.map +1 -0
- package/dist/abi.d.ts +2216 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +1248 -0
- package/dist/abi.js.map +1 -0
- package/dist/cli/commands/cells.d.ts +34 -0
- package/dist/cli/commands/cells.d.ts.map +1 -0
- package/dist/cli/commands/cells.js +66 -0
- package/dist/cli/commands/cells.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +15 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +236 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/interactive.d.ts +107 -0
- package/dist/cli/commands/interactive.d.ts.map +1 -0
- package/dist/cli/commands/interactive.js +3034 -0
- package/dist/cli/commands/interactive.js.map +1 -0
- package/dist/cli/commands/list.d.ts +31 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +115 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/providers.d.ts +3 -0
- package/dist/cli/commands/providers.d.ts.map +1 -0
- package/dist/cli/commands/providers.js +21 -0
- package/dist/cli/commands/providers.js.map +1 -0
- package/dist/cli/commands/settings.d.ts +22 -0
- package/dist/cli/commands/settings.d.ts.map +1 -0
- package/dist/cli/commands/settings.js +188 -0
- package/dist/cli/commands/settings.js.map +1 -0
- package/dist/cli/commands/status.d.ts +16 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +148 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/update.d.ts +21 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +95 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/config.d.ts +73 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +239 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/env.d.ts +36 -0
- package/dist/cli/env.d.ts.map +1 -0
- package/dist/cli/env.js +74 -0
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/envelope.d.ts +33 -0
- package/dist/cli/envelope.d.ts.map +1 -0
- package/dist/cli/envelope.js +62 -0
- package/dist/cli/envelope.js.map +1 -0
- package/dist/cli/errors.d.ts +48 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/errors.js +81 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/inference.d.ts +21 -0
- package/dist/cli/inference.d.ts.map +1 -0
- package/dist/cli/inference.js +60 -0
- package/dist/cli/inference.js.map +1 -0
- package/dist/cli/logo.d.ts +21 -0
- package/dist/cli/logo.d.ts.map +1 -0
- package/dist/cli/logo.js +131 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/main.d.ts +14 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +223 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/proofs.d.ts +67 -0
- package/dist/cli/proofs.d.ts.map +1 -0
- package/dist/cli/proofs.js +133 -0
- package/dist/cli/proofs.js.map +1 -0
- package/dist/cli/ref.d.ts +39 -0
- package/dist/cli/ref.d.ts.map +1 -0
- package/dist/cli/ref.js +48 -0
- package/dist/cli/ref.js.map +1 -0
- package/dist/cli/sdk.d.ts +24 -0
- package/dist/cli/sdk.d.ts.map +1 -0
- package/dist/cli/sdk.js +65 -0
- package/dist/cli/sdk.js.map +1 -0
- package/dist/cli/settings.d.ts +66 -0
- package/dist/cli/settings.d.ts.map +1 -0
- package/dist/cli/settings.js +137 -0
- package/dist/cli/settings.js.map +1 -0
- package/dist/cli/tokenize.d.ts +61 -0
- package/dist/cli/tokenize.d.ts.map +1 -0
- package/dist/cli/tokenize.js +157 -0
- package/dist/cli/tokenize.js.map +1 -0
- package/dist/cli/types.d.ts +25 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +8 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/constants.d.ts +107 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +74 -0
- package/dist/constants.js.map +1 -0
- package/dist/context.d.ts +108 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +64 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-catalog.json +23 -0
- package/dist/seal.d.ts +47 -0
- package/dist/seal.d.ts.map +1 -0
- package/dist/seal.js +145 -0
- package/dist/seal.js.map +1 -0
- package/dist/secretEnv.d.ts +119 -0
- package/dist/secretEnv.d.ts.map +1 -0
- package/dist/secretEnv.js +199 -0
- package/dist/secretEnv.js.map +1 -0
- package/dist/taskHash.d.ts +39 -0
- package/dist/taskHash.d.ts.map +1 -0
- package/dist/taskHash.js +119 -0
- package/dist/taskHash.js.map +1 -0
- package/dist/types.d.ts +336 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -4
- package/scripts/sync-providers.cjs +8 -0
- package/src/AgentClient.ts +897 -0
- package/src/AgenticID.ts +1382 -0
- package/src/AgenticIDClient.ts +238 -0
- package/src/AttestorClient.ts +1306 -0
- package/src/Providers.ts +176 -0
- package/src/ReputationClient.ts +821 -0
- package/src/SandboxClient.ts +227 -0
- package/src/ServeProof.ts +290 -0
- package/src/ServeSession.ts +421 -0
- package/src/Settings.ts +296 -0
- package/src/abi.ts +1282 -0
- package/src/cli/commands/cells.ts +61 -0
- package/src/cli/commands/doctor.ts +235 -0
- package/src/cli/commands/interactive.ts +2715 -0
- package/src/cli/commands/list.ts +117 -0
- package/src/cli/commands/providers.ts +16 -0
- package/src/cli/commands/settings.ts +197 -0
- package/src/cli/commands/status.ts +170 -0
- package/src/cli/commands/update.ts +86 -0
- package/src/cli/config.ts +225 -0
- package/src/cli/env.ts +90 -0
- package/src/cli/envelope.ts +57 -0
- package/src/cli/errors.ts +114 -0
- package/src/cli/inference.ts +57 -0
- package/src/cli/logo.ts +125 -0
- package/src/cli/main.ts +235 -0
- package/src/cli/proofs.ts +160 -0
- package/src/cli/ref.ts +58 -0
- package/src/cli/sdk.ts +65 -0
- package/src/cli/settings.ts +153 -0
- package/src/cli/tokenize.ts +131 -0
- package/src/cli/types.ts +27 -0
- package/src/constants.ts +106 -0
- package/src/context.ts +161 -0
- package/src/index.ts +129 -0
- package/src/provider-catalog.json +23 -0
- package/src/seal.ts +163 -0
- package/src/secretEnv.ts +250 -0
- package/src/taskHash.ts +100 -0
- package/src/types.ts +357 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file proofs.ts
|
|
4
|
+
* @description The proof jar: locally saved serve-proofs ("tickets") captured
|
|
5
|
+
* from agent interactions, so `rate` can spend a ticket from an interaction
|
|
6
|
+
* that already happened — including rating an agent that has since gone
|
|
7
|
+
* offline. Physics of a ticket: expires one hour after issuance (the sealed
|
|
8
|
+
* proxy sets the deadline; the chain enforces it), single-use (signature is
|
|
9
|
+
* the nonce), and redeemable ONLY by the wallet named in `submitter` — so a
|
|
10
|
+
* jar entry leaking is harmless to anyone else.
|
|
11
|
+
*
|
|
12
|
+
* Stored next to the CLI config (`proofs.json`, 0600 out of caution). Each
|
|
13
|
+
* entry carries the proof AND the task-receipt materials (method/uri/body
|
|
14
|
+
* hashes/status) captured from the same interaction, so submission can open
|
|
15
|
+
* the taskHash commitment on-chain (TEE-verified endpoint).
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.saveProof = saveProof;
|
|
19
|
+
exports.listProofs = listProofs;
|
|
20
|
+
exports.removeProof = removeProof;
|
|
21
|
+
exports.ticketRedeemable = ticketRedeemable;
|
|
22
|
+
exports.ticketDisposition = ticketDisposition;
|
|
23
|
+
exports.toServeProof = toServeProof;
|
|
24
|
+
const node_fs_1 = require("node:fs");
|
|
25
|
+
const node_path_1 = require("node:path");
|
|
26
|
+
const config_1 = require("./config");
|
|
27
|
+
function jarPath() {
|
|
28
|
+
return (0, node_path_1.join)((0, config_1.configPaths)().dir, 'proofs.json');
|
|
29
|
+
}
|
|
30
|
+
function loadJar() {
|
|
31
|
+
const p = jarPath();
|
|
32
|
+
if (!(0, node_fs_1.existsSync)(p))
|
|
33
|
+
return [];
|
|
34
|
+
try {
|
|
35
|
+
const all = JSON.parse((0, node_fs_1.readFileSync)(p, 'utf8'));
|
|
36
|
+
const now = Math.floor(Date.now() / 1000);
|
|
37
|
+
return all.filter((e) => e.deadline > now); // prune expired on load
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function writeJar(entries) {
|
|
44
|
+
(0, node_fs_1.mkdirSync)((0, config_1.configPaths)().dir, { recursive: true });
|
|
45
|
+
(0, node_fs_1.writeFileSync)(jarPath(), `${JSON.stringify(entries, null, 2)}\n`, { mode: 0o600 });
|
|
46
|
+
}
|
|
47
|
+
/** Tickets kept per (agentId, submitter). Proofs expire in ~1h anyway, so
|
|
48
|
+
* the cap only bounds the file against pathological call loops. */
|
|
49
|
+
const MAX_TICKETS_PER_PAIR = 5;
|
|
50
|
+
/** Bank a ticket (append — one proof backs one rating, several interactions
|
|
51
|
+
* with one agent yield several independently spendable tickets). */
|
|
52
|
+
function saveProof(proof, task, endpoint) {
|
|
53
|
+
const entry = {
|
|
54
|
+
agentId: proof.agentId.toString(),
|
|
55
|
+
submitter: proof.submitter,
|
|
56
|
+
endpoint,
|
|
57
|
+
capturedAt: Math.floor(Date.now() / 1000),
|
|
58
|
+
deadline: Number(proof.deadline),
|
|
59
|
+
proof: {
|
|
60
|
+
agentId: proof.agentId.toString(),
|
|
61
|
+
submitter: proof.submitter,
|
|
62
|
+
timestamp: proof.timestamp.toString(),
|
|
63
|
+
deadline: proof.deadline.toString(),
|
|
64
|
+
taskHash: proof.taskHash,
|
|
65
|
+
dataHashes: proof.dataHashes,
|
|
66
|
+
frameworkHash: proof.frameworkHash,
|
|
67
|
+
signature: proof.signature,
|
|
68
|
+
...(proof.validator ? { validator: proof.validator } : {}),
|
|
69
|
+
},
|
|
70
|
+
task,
|
|
71
|
+
};
|
|
72
|
+
const all = loadJar();
|
|
73
|
+
const mine = all.filter((e) => e.agentId === entry.agentId && e.submitter.toLowerCase() === entry.submitter.toLowerCase());
|
|
74
|
+
const others = all.filter((e) => !mine.includes(e));
|
|
75
|
+
// newest kept; oldest dropped past the cap
|
|
76
|
+
const kept = [...mine, entry]
|
|
77
|
+
.sort((a, b) => b.capturedAt - a.capturedAt)
|
|
78
|
+
.slice(0, MAX_TICKETS_PER_PAIR);
|
|
79
|
+
writeJar([...others, ...kept]);
|
|
80
|
+
}
|
|
81
|
+
/** All unexpired tickets for (agentId, wallet), newest first — with a
|
|
82
|
+
* mining-time margin so a ticket seconds from expiry isn't offered. */
|
|
83
|
+
function listProofs(agentId, wallet, marginSeconds = 120) {
|
|
84
|
+
const now = Math.floor(Date.now() / 1000);
|
|
85
|
+
return loadJar()
|
|
86
|
+
.filter((e) => e.agentId === agentId.toString() &&
|
|
87
|
+
e.submitter.toLowerCase() === wallet.toLowerCase() &&
|
|
88
|
+
e.deadline > now + marginSeconds)
|
|
89
|
+
.sort((a, b) => b.capturedAt - a.capturedAt);
|
|
90
|
+
}
|
|
91
|
+
/** Burn ONE spent (or refused) ticket, identified by its unique signature. */
|
|
92
|
+
function removeProof(signature) {
|
|
93
|
+
writeJar(loadJar().filter((e) => e.proof.signature !== signature));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether the registry would redeem this ticket, judged on exactly what
|
|
97
|
+
* VerifiedFeedbackRegistry checks: not expired, and a signature that verifies
|
|
98
|
+
* against the registry configured here. `dataOnChain` is NOT one of them —
|
|
99
|
+
* the registry never compares a proof's dataHashes with the agent's current
|
|
100
|
+
* iData (it records them as the version that served), so a ticket whose
|
|
101
|
+
* agent has since committed new state still redeems. `rate` shows that case
|
|
102
|
+
* as an informational note, not a failure.
|
|
103
|
+
*/
|
|
104
|
+
function ticketRedeemable(v) {
|
|
105
|
+
return v.notExpired && v.registryMatches && v.signerMatches;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* What `rate` does with a ticket that is not `ticketRedeemable`.
|
|
109
|
+
* `'burn'` only on a defect of the ticket itself — expired, or a signature
|
|
110
|
+
* that does not verify against the registry it names. `'keep'` when the
|
|
111
|
+
* failure is this side's configuration (no registry configured, or the
|
|
112
|
+
* ticket names a different one): the ticket may still redeem once that is
|
|
113
|
+
* fixed. `dataOnChain` never burns a ticket (see `ticketRedeemable`).
|
|
114
|
+
*/
|
|
115
|
+
function ticketDisposition(v) {
|
|
116
|
+
const defect = !v.notExpired || (v.registryMatches && !v.signerMatches);
|
|
117
|
+
return defect ? 'burn' : 'keep';
|
|
118
|
+
}
|
|
119
|
+
/** Rehydrate the bigint fields for SDK submission. */
|
|
120
|
+
function toServeProof(e) {
|
|
121
|
+
return {
|
|
122
|
+
agentId: BigInt(e.proof.agentId),
|
|
123
|
+
submitter: e.proof.submitter,
|
|
124
|
+
timestamp: BigInt(e.proof.timestamp),
|
|
125
|
+
deadline: BigInt(e.proof.deadline),
|
|
126
|
+
taskHash: e.proof.taskHash,
|
|
127
|
+
dataHashes: e.proof.dataHashes,
|
|
128
|
+
frameworkHash: e.proof.frameworkHash,
|
|
129
|
+
signature: e.proof.signature,
|
|
130
|
+
...(e.proof.validator ? { validator: e.proof.validator } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=proofs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proofs.js","sourceRoot":"","sources":["../../src/cli/proofs.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAmDH,8BA8BC;AAID,gCAUC;AAGD,kCAEC;AAWD,4CAIC;AAUD,8CAK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C,CAAC,eAAe,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,sDAAsD;AACtD,SAAgB,YAAY,CAAC,CAAa;IACxC,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QAChC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS;QAC5B,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;QACpC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;QAClC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ;QAC1B,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU;QAC9B,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa;QACpC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS;QAC5B,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ref.ts
|
|
3
|
+
* @description The unified `<agent>` reference parser — a pure function, no
|
|
4
|
+
* I/O — shared by every command that takes an agent argument (spec v0.03
|
|
5
|
+
* §3.2). One positional accepts either coordinate; the CLI converts between
|
|
6
|
+
* them so callers never juggle the protocol's ID system:
|
|
7
|
+
*
|
|
8
|
+
* - decimal string → agentId (ERC-721 tokenId, exists only after mint)
|
|
9
|
+
* - 0x + 64 hex → sealId (attestor deployment key, exists from accept)
|
|
10
|
+
*
|
|
11
|
+
* Chain resolution (agentId ⇄ sealId) lives in the commands — this module
|
|
12
|
+
* only classifies the input, so it is trivially unit-testable.
|
|
13
|
+
*/
|
|
14
|
+
/** A classified agent reference. */
|
|
15
|
+
export type AgentRef = {
|
|
16
|
+
kind: 'agentId';
|
|
17
|
+
agentId: bigint;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'sealId';
|
|
20
|
+
sealId: `0x${string}`;
|
|
21
|
+
}
|
|
22
|
+
/** A truncated sealId (0x + 8..63 hex) — resolved against a listing by
|
|
23
|
+
* unique prefix. Lets the abbreviated ids shown by `list` be pasted back
|
|
24
|
+
* into commands (unminted rows have no agentId, so their sealId is the
|
|
25
|
+
* only handle). */
|
|
26
|
+
| {
|
|
27
|
+
kind: 'sealPrefix';
|
|
28
|
+
prefix: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Classify a raw `<agent>` argument. Throws `BAD_AGENT_REF` (exit 2) for
|
|
32
|
+
* anything that is neither a decimal agentId nor a 0x… (8..64)-hex sealId
|
|
33
|
+
* (shorter than 64 = prefix, matched uniquely against the listing).
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseAgentRef(input: string | undefined): AgentRef;
|
|
36
|
+
/** Does `sealId` match this ref? (exact id or unique-prefix candidates —
|
|
37
|
+
* prefix uniqueness is the caller's job, this is the per-row predicate.) */
|
|
38
|
+
export declare function refMatchesSeal(ref: AgentRef, sealId: string): boolean;
|
|
39
|
+
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/cli/ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,oCAAoC;AACpC,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE;AAC3C;;;oBAGoB;GAClB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAiBjE;AAED;6EAC6E;AAC7E,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAKrE"}
|
package/dist/cli/ref.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file ref.ts
|
|
4
|
+
* @description The unified `<agent>` reference parser — a pure function, no
|
|
5
|
+
* I/O — shared by every command that takes an agent argument (spec v0.03
|
|
6
|
+
* §3.2). One positional accepts either coordinate; the CLI converts between
|
|
7
|
+
* them so callers never juggle the protocol's ID system:
|
|
8
|
+
*
|
|
9
|
+
* - decimal string → agentId (ERC-721 tokenId, exists only after mint)
|
|
10
|
+
* - 0x + 64 hex → sealId (attestor deployment key, exists from accept)
|
|
11
|
+
*
|
|
12
|
+
* Chain resolution (agentId ⇄ sealId) lives in the commands — this module
|
|
13
|
+
* only classifies the input, so it is trivially unit-testable.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.parseAgentRef = parseAgentRef;
|
|
17
|
+
exports.refMatchesSeal = refMatchesSeal;
|
|
18
|
+
const errors_1 = require("./errors");
|
|
19
|
+
/**
|
|
20
|
+
* Classify a raw `<agent>` argument. Throws `BAD_AGENT_REF` (exit 2) for
|
|
21
|
+
* anything that is neither a decimal agentId nor a 0x… (8..64)-hex sealId
|
|
22
|
+
* (shorter than 64 = prefix, matched uniquely against the listing).
|
|
23
|
+
*/
|
|
24
|
+
function parseAgentRef(input) {
|
|
25
|
+
if (input && /^\d+$/.test(input)) {
|
|
26
|
+
return { kind: 'agentId', agentId: BigInt(input) };
|
|
27
|
+
}
|
|
28
|
+
if (input && /^0x[0-9a-fA-F]{64}$/.test(input)) {
|
|
29
|
+
return { kind: 'sealId', sealId: input };
|
|
30
|
+
}
|
|
31
|
+
if (input && /^0x[0-9a-fA-F]{8,63}$/.test(input)) {
|
|
32
|
+
return { kind: 'sealPrefix', prefix: input.toLowerCase() };
|
|
33
|
+
}
|
|
34
|
+
throw new errors_1.CliError('BAD_AGENT_REF', input
|
|
35
|
+
? `not an agent reference: "${input}" (expected a decimal agentId or a 0x… 64-hex sealId; ≥8 hex chars work as a unique prefix)`
|
|
36
|
+
: 'missing <agent> argument (a decimal agentId or a 0x… 64-hex sealId)', { remedy: '0g-agentdna status 33 | 0g-agentdna status 0x<64-hex sealId>' });
|
|
37
|
+
}
|
|
38
|
+
/** Does `sealId` match this ref? (exact id or unique-prefix candidates —
|
|
39
|
+
* prefix uniqueness is the caller's job, this is the per-row predicate.) */
|
|
40
|
+
function refMatchesSeal(ref, sealId) {
|
|
41
|
+
const s = sealId.toLowerCase();
|
|
42
|
+
if (ref.kind === 'sealId')
|
|
43
|
+
return s === ref.sealId.toLowerCase();
|
|
44
|
+
if (ref.kind === 'sealPrefix')
|
|
45
|
+
return s.startsWith(ref.prefix);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/cli/ref.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAmBH,sCAiBC;AAID,wCAKC;AA3CD,qCAAoC;AAYpC;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAAyB;IACrD,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACrD,CAAC;IACD,IAAI,KAAK,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAsB,EAAE,CAAC;IAC5D,CAAC;IACD,IAAI,KAAK,IAAI,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;IAC7D,CAAC;IACD,MAAM,IAAI,iBAAQ,CAChB,eAAe,EACf,KAAK;QACH,CAAC,CAAC,4BAA4B,KAAK,6FAA6F;QAChI,CAAC,CAAC,qEAAqE,EACzE,EAAE,MAAM,EAAE,kEAAkE,EAAE,CAC/E,CAAC;AACJ,CAAC;AAED;6EAC6E;AAC7E,SAAgB,cAAc,CAAC,GAAa,EAAE,MAAc;IAC1D,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAC/B,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IACjE,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file sdk.ts
|
|
3
|
+
* @description Shared bootstrap: CliEnv → AgenticID facade. The single place
|
|
4
|
+
* the CLI constructs the SDK client — doctor/status/list all reuse it, so the
|
|
5
|
+
* env→client semantics can never drift between commands (this is the shared
|
|
6
|
+
* artifact that made B/C/D "parallel with a hidden shared piece"; it lands in
|
|
7
|
+
* B and the others consume it).
|
|
8
|
+
*/
|
|
9
|
+
import { AgenticID } from '../AgenticID';
|
|
10
|
+
import { type CliEnv } from './env';
|
|
11
|
+
/**
|
|
12
|
+
* Build an SDK facade from the CLI environment.
|
|
13
|
+
*
|
|
14
|
+
* - Attestor URL is always required (one URL selects the environment).
|
|
15
|
+
* - The private key is strictly validated when the caller REQUIRES a wallet
|
|
16
|
+
* (`withWallet` — owner-signed surfaces fail loudly with exit 3 + remedy).
|
|
17
|
+
* Read-only callers proceed walletless on a malformed key (the caller is
|
|
18
|
+
* expected to warn) — public surfaces must not be hostage to a bad env var.
|
|
19
|
+
* - `AGENTIC_RPC_URL` overrides the attestor-advertised RPC (explicit-wins).
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildClient(env: CliEnv, opts?: {
|
|
22
|
+
withWallet?: boolean;
|
|
23
|
+
}): Promise<AgenticID>;
|
|
24
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/cli/sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAyC,KAAK,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAwCtG"}
|
package/dist/cli/sdk.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file sdk.ts
|
|
4
|
+
* @description Shared bootstrap: CliEnv → AgenticID facade. The single place
|
|
5
|
+
* the CLI constructs the SDK client — doctor/status/list all reuse it, so the
|
|
6
|
+
* env→client semantics can never drift between commands (this is the shared
|
|
7
|
+
* artifact that made B/C/D "parallel with a hidden shared piece"; it lands in
|
|
8
|
+
* B and the others consume it).
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.buildClient = buildClient;
|
|
12
|
+
const AgenticID_1 = require("../AgenticID");
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const config_1 = require("./config");
|
|
15
|
+
const env_1 = require("./env");
|
|
16
|
+
/**
|
|
17
|
+
* Build an SDK facade from the CLI environment.
|
|
18
|
+
*
|
|
19
|
+
* - Attestor URL is always required (one URL selects the environment).
|
|
20
|
+
* - The private key is strictly validated when the caller REQUIRES a wallet
|
|
21
|
+
* (`withWallet` — owner-signed surfaces fail loudly with exit 3 + remedy).
|
|
22
|
+
* Read-only callers proceed walletless on a malformed key (the caller is
|
|
23
|
+
* expected to warn) — public surfaces must not be hostage to a bad env var.
|
|
24
|
+
* - `AGENTIC_RPC_URL` overrides the attestor-advertised RPC (explicit-wins).
|
|
25
|
+
*/
|
|
26
|
+
async function buildClient(env, opts = {}) {
|
|
27
|
+
const attestorUrl = (0, env_1.requireAttestorUrl)(env);
|
|
28
|
+
// Wallet-requiring callers get the strict check (named error + remedy).
|
|
29
|
+
// Read-only callers proceed WALLETLESS on a malformed key instead of dying —
|
|
30
|
+
// public surfaces like `list`/`hello` must not be hostage to a bad env var.
|
|
31
|
+
const account = opts.withWallet
|
|
32
|
+
? (0, env_1.requirePrivateKey)(env)
|
|
33
|
+
: env.privateKey && /^0x[0-9a-fA-F]{64}$/.test(env.privateKey)
|
|
34
|
+
? env.privateKey
|
|
35
|
+
: undefined;
|
|
36
|
+
try {
|
|
37
|
+
// Address overrides for environments whose attestor /config doesn't (yet)
|
|
38
|
+
// advertise the reputation pair — explicit env wins over discovery. The
|
|
39
|
+
// registry must equal the one the sealed proxy signs serve-proofs for
|
|
40
|
+
// (EIP-191 v0x00 intended validator), or every proof fails verification.
|
|
41
|
+
const vf = process.env.AGENTIC_VERIFIED_FEEDBACK_ADDR?.trim();
|
|
42
|
+
const fbb = process.env.AGENTIC_FEEDBACK_BATCHER_ADDR?.trim();
|
|
43
|
+
const overrides = {
|
|
44
|
+
...(vf ? { verifiedFeedback: vf } : {}),
|
|
45
|
+
...(fbb ? { feedbackBatcher: fbb } : {}),
|
|
46
|
+
};
|
|
47
|
+
return await AgenticID_1.AgenticID.fromAttestor(attestorUrl, {
|
|
48
|
+
...(account ? { account } : {}),
|
|
49
|
+
...(env.rpcUrl ? { rpcUrl: env.rpcUrl } : {}),
|
|
50
|
+
...(Object.keys(overrides).length ? { overrides } : {}),
|
|
51
|
+
// Once this machine has seen an attestor advertise secret_env_scheme,
|
|
52
|
+
// its absence is tampering, not a downgrade (issue #166).
|
|
53
|
+
secretEnvPin: {
|
|
54
|
+
seen: (url) => !!(0, config_1.loadSecretEnvPins)()[url],
|
|
55
|
+
record: (url) => (0, config_1.recordSecretEnvPin)(url),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
if (e instanceof errors_1.CliError)
|
|
61
|
+
throw e;
|
|
62
|
+
throw new errors_1.CliError('ATTESTOR_UNREACHABLE', `could not bootstrap from ${attestorUrl}/config: ${e.message}`, { remedy: 'verify AGENTIC_ATTESTOR_URL points at a reachable attestor, then retry' });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/cli/sdk.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAiBH,kCAwCC;AAvDD,4CAAyC;AACzC,qCAAoC;AACpC,qCAAiE;AACjE,+BAA2E;AAE3E;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,GAAW,EAAE,OAAiC,EAAE;IAChF,MAAM,WAAW,GAAG,IAAA,wBAAkB,EAAC,GAAG,CAAC,CAAC;IAC5C,wEAAwE;IACxE,6EAA6E;IAC7E,4EAA4E;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU;QAC7B,CAAC,CAAC,IAAA,uBAAiB,EAAC,GAAG,CAA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G,EAAE,EAAE,CAAC,IAAA,2BAAkB,EAAC,GAAG,CAAC;aACzC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,iBAAQ;YAAE,MAAM,CAAC,CAAC;QACnC,MAAM,IAAI,iBAAQ,CAChB,sBAAsB,EACtB,4BAA4B,WAAW,YAAa,CAAW,CAAC,OAAO,EAAE,EACzE,EAAE,MAAM,EAAE,wEAAwE,EAAE,CACrF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file settings.ts
|
|
3
|
+
* @description Shared pieces of the CLI's settings surface — the `key=value`
|
|
4
|
+
* grammar, the merge, and the rendering. Used by the `settings` command and
|
|
5
|
+
* by both REPL levels, so the three can never drift apart.
|
|
6
|
+
*
|
|
7
|
+
* The grammar is deliberately tiny, because the document is:
|
|
8
|
+
*
|
|
9
|
+
* settings <agent> show the current document
|
|
10
|
+
* settings <agent> model=0gm-1.0-35b-a3b change one field
|
|
11
|
+
* settings <agent> thinking= clear one field
|
|
12
|
+
* settings <agent> others='{"a": 1}' the framework's own opaque knobs
|
|
13
|
+
*
|
|
14
|
+
* Assignments MERGE into the stored document — the owner is editing one
|
|
15
|
+
* field, not re-authoring the whole thing. The wire write is still a whole
|
|
16
|
+
* document; the merge happens here.
|
|
17
|
+
*
|
|
18
|
+
* Quoting works at both layers: a shell hands `others='{"a": 1}'` over as
|
|
19
|
+
* one argument, and the REPL's own splitter (`cli/tokenize.ts`) honours the
|
|
20
|
+
* same quotes rather than breaking the JSON on its spaces.
|
|
21
|
+
*/
|
|
22
|
+
import { type SettingsDoc, type ThinkingLevel } from '../Settings';
|
|
23
|
+
/** The document's named fields. `others` is opaque JSON; the rest are
|
|
24
|
+
* strings. Anything else a container understands is writable through the
|
|
25
|
+
* SDK, but not through this grammar — the CLI refuses keys it cannot
|
|
26
|
+
* describe, so a typo can never become a stored field. */
|
|
27
|
+
export declare const SETTINGS_KEYS: readonly ["provider", "model", "thinking", "others"];
|
|
28
|
+
export type SettingsKey = (typeof SETTINGS_KEYS)[number];
|
|
29
|
+
/** One `key=value`. `value === undefined` means "clear this field". */
|
|
30
|
+
export interface Assignment {
|
|
31
|
+
key: SettingsKey;
|
|
32
|
+
value: string | ThinkingLevel | unknown | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse `key=value` positionals. Throws `BAD_FLAG` (exit 2) on an unknown
|
|
36
|
+
* key, a bad thinking level, or an `others=` value that is not JSON — all
|
|
37
|
+
* usage errors worth failing on before any network work.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseAssignments(args: string[]): Assignment[];
|
|
40
|
+
/** Merge assignments onto the stored document, producing the document to write. */
|
|
41
|
+
export declare function applyAssignments(base: SettingsDoc | null, assignments: Assignment[]): SettingsDoc;
|
|
42
|
+
/**
|
|
43
|
+
* Refuse a document with no model, before anything is signed.
|
|
44
|
+
*
|
|
45
|
+
* A blank model is the ONE state the container treats as fatal (two adapters
|
|
46
|
+
* hard-fail Start without a pin), and it is also the one state the
|
|
47
|
+
* last-known-good fallback cannot rescue: an agent that predates this channel
|
|
48
|
+
* has no stored document and no confirmed one, so a first partial edit
|
|
49
|
+
* (`settings 286 thinking=high`) would merge onto nothing, write
|
|
50
|
+
* `{"thinking":"high"}`, and take the agent down on its next boot with
|
|
51
|
+
* nothing to fall back to. That is a foot-gun, not a choice worth honouring —
|
|
52
|
+
* so name the missing field and the fix.
|
|
53
|
+
*
|
|
54
|
+
* `hadStored` distinguishes the two ways to get here, because the fix differs:
|
|
55
|
+
* with no stored document the user has to say which model to pin, while
|
|
56
|
+
* clearing `model=` out of an existing one is simply not a thing to do.
|
|
57
|
+
*/
|
|
58
|
+
export declare function assertModelPresent(next: SettingsDoc, hadStored: boolean): void;
|
|
59
|
+
/**
|
|
60
|
+
* Human rendering: aligned `field value` lines. Named fields first, then any
|
|
61
|
+
* field this build does not know about — showing them is the point, since
|
|
62
|
+
* the container owns the vocabulary and the CLI must not pretend a newer
|
|
63
|
+
* setting is not there.
|
|
64
|
+
*/
|
|
65
|
+
export declare function renderSettings(doc: SettingsDoc | null): string[];
|
|
66
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/cli/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAoC,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAErG;;;2DAG2D;AAC3D,eAAO,MAAM,aAAa,sDAAkB,CAAC;AAC7C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,uEAAuE;AACvE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,WAAW,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,SAAS,CAAC;CACrD;AAQD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAyC7D;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,WAAW,CAQjG;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAe9E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,GAAG,MAAM,EAAE,CAUhE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file settings.ts
|
|
4
|
+
* @description Shared pieces of the CLI's settings surface — the `key=value`
|
|
5
|
+
* grammar, the merge, and the rendering. Used by the `settings` command and
|
|
6
|
+
* by both REPL levels, so the three can never drift apart.
|
|
7
|
+
*
|
|
8
|
+
* The grammar is deliberately tiny, because the document is:
|
|
9
|
+
*
|
|
10
|
+
* settings <agent> show the current document
|
|
11
|
+
* settings <agent> model=0gm-1.0-35b-a3b change one field
|
|
12
|
+
* settings <agent> thinking= clear one field
|
|
13
|
+
* settings <agent> others='{"a": 1}' the framework's own opaque knobs
|
|
14
|
+
*
|
|
15
|
+
* Assignments MERGE into the stored document — the owner is editing one
|
|
16
|
+
* field, not re-authoring the whole thing. The wire write is still a whole
|
|
17
|
+
* document; the merge happens here.
|
|
18
|
+
*
|
|
19
|
+
* Quoting works at both layers: a shell hands `others='{"a": 1}'` over as
|
|
20
|
+
* one argument, and the REPL's own splitter (`cli/tokenize.ts`) honours the
|
|
21
|
+
* same quotes rather than breaking the JSON on its spaces.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.SETTINGS_KEYS = void 0;
|
|
25
|
+
exports.parseAssignments = parseAssignments;
|
|
26
|
+
exports.applyAssignments = applyAssignments;
|
|
27
|
+
exports.assertModelPresent = assertModelPresent;
|
|
28
|
+
exports.renderSettings = renderSettings;
|
|
29
|
+
const errors_1 = require("./errors");
|
|
30
|
+
const Settings_1 = require("../Settings");
|
|
31
|
+
/** The document's named fields. `others` is opaque JSON; the rest are
|
|
32
|
+
* strings. Anything else a container understands is writable through the
|
|
33
|
+
* SDK, but not through this grammar — the CLI refuses keys it cannot
|
|
34
|
+
* describe, so a typo can never become a stored field. */
|
|
35
|
+
exports.SETTINGS_KEYS = Settings_1.SETTINGS_FIELDS;
|
|
36
|
+
const USAGE = '0g-agentdna settings <agent> [provider=… model=… thinking=low|high|max others=<json>]';
|
|
37
|
+
/** How to quote a JSON value, in either place it can be typed. */
|
|
38
|
+
const FRAMEWORK_QUOTING = `settings <agent> others='{"key": "value"}' # quote it — inside the REPL too`;
|
|
39
|
+
/**
|
|
40
|
+
* Parse `key=value` positionals. Throws `BAD_FLAG` (exit 2) on an unknown
|
|
41
|
+
* key, a bad thinking level, or an `others=` value that is not JSON — all
|
|
42
|
+
* usage errors worth failing on before any network work.
|
|
43
|
+
*/
|
|
44
|
+
function parseAssignments(args) {
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const arg of args) {
|
|
47
|
+
const eq = arg.indexOf('=');
|
|
48
|
+
if (eq < 1) {
|
|
49
|
+
throw new errors_1.CliError('BAD_FLAG', `not a setting assignment: "${arg}" (expected key=value)`, { remedy: USAGE });
|
|
50
|
+
}
|
|
51
|
+
const key = arg.slice(0, eq);
|
|
52
|
+
const raw = arg.slice(eq + 1);
|
|
53
|
+
if (!exports.SETTINGS_KEYS.includes(key)) {
|
|
54
|
+
throw new errors_1.CliError('BAD_FLAG', `unknown setting "${key}" — the platform's named fields are ${exports.SETTINGS_KEYS.join(', ')} ` +
|
|
55
|
+
'(anything framework-specific goes inside others=<json>)', { remedy: USAGE });
|
|
56
|
+
}
|
|
57
|
+
if (raw === '') {
|
|
58
|
+
out.push({ key: key, value: undefined });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (key === 'thinking' && !Settings_1.THINKING_LEVELS.includes(raw)) {
|
|
62
|
+
throw new errors_1.CliError('BAD_FLAG', `thinking must be one of ${Settings_1.THINKING_LEVELS.join('|')}, got "${raw}"`, {
|
|
63
|
+
remedy: USAGE,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (key === 'others') {
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = JSON.parse(raw);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
throw new errors_1.CliError('BAD_FLAG', `others= must be JSON: ${e.message}`, {
|
|
73
|
+
remedy: FRAMEWORK_QUOTING,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
out.push({ key, value: parsed });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
out.push({ key: key, value: raw });
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/** Merge assignments onto the stored document, producing the document to write. */
|
|
84
|
+
function applyAssignments(base, assignments) {
|
|
85
|
+
const doc = { ...(base ?? {}) };
|
|
86
|
+
for (const a of assignments) {
|
|
87
|
+
if (a.value === undefined)
|
|
88
|
+
delete doc[a.key];
|
|
89
|
+
else if (a.key === 'others')
|
|
90
|
+
doc.others = a.value;
|
|
91
|
+
else
|
|
92
|
+
doc[a.key] = a.value;
|
|
93
|
+
}
|
|
94
|
+
return doc;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Refuse a document with no model, before anything is signed.
|
|
98
|
+
*
|
|
99
|
+
* A blank model is the ONE state the container treats as fatal (two adapters
|
|
100
|
+
* hard-fail Start without a pin), and it is also the one state the
|
|
101
|
+
* last-known-good fallback cannot rescue: an agent that predates this channel
|
|
102
|
+
* has no stored document and no confirmed one, so a first partial edit
|
|
103
|
+
* (`settings 286 thinking=high`) would merge onto nothing, write
|
|
104
|
+
* `{"thinking":"high"}`, and take the agent down on its next boot with
|
|
105
|
+
* nothing to fall back to. That is a foot-gun, not a choice worth honouring —
|
|
106
|
+
* so name the missing field and the fix.
|
|
107
|
+
*
|
|
108
|
+
* `hadStored` distinguishes the two ways to get here, because the fix differs:
|
|
109
|
+
* with no stored document the user has to say which model to pin, while
|
|
110
|
+
* clearing `model=` out of an existing one is simply not a thing to do.
|
|
111
|
+
*/
|
|
112
|
+
function assertModelPresent(next, hadStored) {
|
|
113
|
+
if (next.model?.trim())
|
|
114
|
+
return;
|
|
115
|
+
throw new errors_1.CliError('BAD_FLAG', hadStored
|
|
116
|
+
? 'refusing to write a document with no model — two framework adapters hard-fail startup without a model pin'
|
|
117
|
+
: 'this agent has no stored settings document yet, so a partial edit would write one with no model — ' +
|
|
118
|
+
'and two framework adapters hard-fail startup without a model pin', {
|
|
119
|
+
remedy: 'include the model in the same command, e.g. ' +
|
|
120
|
+
'`settings <agent> model=0gm-1.0-35b-a3b thinking=high` (the agent\'s current model is whatever its ' +
|
|
121
|
+
'image was built or last configured with — `hello <agent>` and `/agentlog` show what it is running)',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Human rendering: aligned `field value` lines. Named fields first, then any
|
|
126
|
+
* field this build does not know about — showing them is the point, since
|
|
127
|
+
* the container owns the vocabulary and the CLI must not pretend a newer
|
|
128
|
+
* setting is not there.
|
|
129
|
+
*/
|
|
130
|
+
function renderSettings(doc) {
|
|
131
|
+
if (!doc || Object.keys(doc).length === 0)
|
|
132
|
+
return ['(not configured — the agent boots on its framework defaults)'];
|
|
133
|
+
const show = (v) => v === undefined || v === null ? '—' : typeof v === 'string' ? v : JSON.stringify(v);
|
|
134
|
+
const extra = Object.keys(doc).filter((k) => !exports.SETTINGS_KEYS.includes(k) && doc[k] !== undefined);
|
|
135
|
+
return [...exports.SETTINGS_KEYS.filter((k) => doc[k] !== undefined), ...extra].map((k) => `${k.padEnd(11)}${show(doc[k])}`);
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/cli/settings.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA6BH,4CAyCC;AAGD,4CAQC;AAkBD,gDAeC;AAQD,wCAUC;AAlID,qCAAoC;AACpC,0CAAqG;AAErG;;;2DAG2D;AAC9C,QAAA,aAAa,GAAG,0BAAe,CAAC;AAS7C,MAAM,KAAK,GAAG,uFAAuF,CAAC;AAEtG,kEAAkE;AAClE,MAAM,iBAAiB,GACrB,+EAA+E,CAAC;AAElF;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAc;IAC7C,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,GAAG,IAAI,IA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GAAqG;YACrG,oGAAoG;KACvG,CACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,GAAuB;IACpD,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,8DAA8D,CAAC,CAAC;IACnH,MAAM,IAAI,GAAG,CAAC,CAAU,EAAU,EAAE,CAClC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACtF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CACnC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,qBAAmC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CACjF,CAAC;IACF,OAAO,CAAC,GAAG,qBAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,CACzE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file tokenize.ts
|
|
3
|
+
* @description Splitting a REPL line into arguments, the way a shell does.
|
|
4
|
+
*
|
|
5
|
+
* Outside the REPL the user's shell does this and the CLI never sees quotes.
|
|
6
|
+
* Inside it, a bare `line.split(/\s+/)` made every value containing a space
|
|
7
|
+
* unreachable — `others={"tools": {"bash": true}}` arrived as four
|
|
8
|
+
* arguments, and the error message helpfully suggested quoting, which the
|
|
9
|
+
* splitter then handed through as literal `'` characters. Quoting has to
|
|
10
|
+
* actually work, or the advice is a dead end.
|
|
11
|
+
*
|
|
12
|
+
* The grammar is the small familiar one, and deliberately no larger:
|
|
13
|
+
*
|
|
14
|
+
* 'single' everything literal up to the next single quote
|
|
15
|
+
* "double" literal too, except `\"` and `\\`
|
|
16
|
+
* \x outside quotes, the next character verbatim (so `\ ` is a space)
|
|
17
|
+
* {…} […] a JSON literal WHERE A VALUE STARTS — copied through exactly as
|
|
18
|
+
* typed, to its matching close: spaces, nesting and quotes alike
|
|
19
|
+
*
|
|
20
|
+
* That last rule is what keeps a shell splitter honest about JSON. Quote
|
|
21
|
+
* characters are how a shell protects a value, but they are also what JSON is
|
|
22
|
+
* MADE of, so stripping them turns `others={"a":1}` — the unquoted form the
|
|
23
|
+
* help and the GUIDE print — into `others={a:1}`, which parses as nothing.
|
|
24
|
+
* A literal opening where a value begins (the start of a token, or right after
|
|
25
|
+
* an `=`) is therefore data: copied, not interpreted. Elsewhere a bracket is
|
|
26
|
+
* an ordinary character, so `/api/x[0]` is still one plain token.
|
|
27
|
+
*
|
|
28
|
+
* No variable expansion, no globbing, no operators — a REPL argument is data,
|
|
29
|
+
* and a splitter that interprets it would be a surprise, not a convenience.
|
|
30
|
+
* Adjacent pieces join into one token (`others='{"a": 1}'` is one word),
|
|
31
|
+
* which is the whole point.
|
|
32
|
+
*
|
|
33
|
+
* A command whose LAST argument is free-form text rather than a value in a
|
|
34
|
+
* list — `call <id> <path> <json-body>` — should not be run through this at
|
|
35
|
+
* all: see {@link splitHead}.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Split a command line into tokens. An unterminated quote is NOT an error:
|
|
39
|
+
* the user is mid-thought at an interactive prompt, so the run of text is
|
|
40
|
+
* taken as written and the caller's own grammar check reports whatever is
|
|
41
|
+
* wrong with it — a parse error about quoting would just be noise on top.
|
|
42
|
+
*/
|
|
43
|
+
export declare function tokenize(line: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Split off the first `n` tokens and hand the REST OF THE LINE back verbatim.
|
|
46
|
+
*
|
|
47
|
+
* The shell-style splitter is the wrong tool for an argument that is free-form
|
|
48
|
+
* text. `call 42 /api/x {"a": 1}` has a fixed head — command, agent, path —
|
|
49
|
+
* and then a body that is whatever the user typed, quotes and inner spacing
|
|
50
|
+
* included, on its way to an agent that will parse it. Tokenizing that and
|
|
51
|
+
* re-joining the pieces with a single space is a guess about what was typed;
|
|
52
|
+
* taking the remainder of the line is not a guess.
|
|
53
|
+
*
|
|
54
|
+
* `rest` has no leading whitespace, and is '' when the line holds no more
|
|
55
|
+
* than `n` tokens.
|
|
56
|
+
*/
|
|
57
|
+
export declare function splitHead(line: string, n: number): {
|
|
58
|
+
head: string[];
|
|
59
|
+
rest: string;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=tokenize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../src/cli/tokenize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAE/C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAEnF"}
|