oneie 4.0.2 → 4.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/README.md +78 -1
- package/dist/package.json +4 -4
- package/dist/src/agent.d.ts +73 -0
- package/dist/src/agent.js +486 -53
- package/dist/src/auth.js +3 -4
- package/dist/src/broadcast.d.ts +2 -0
- package/dist/src/broadcast.js +24 -0
- package/dist/src/compiler.js +27 -3
- package/dist/src/doctor.js +61 -6
- package/dist/src/eval.js +1 -0
- package/dist/src/fn.js +5 -8
- package/dist/src/index.js +8 -1
- package/dist/src/init.js +33 -3
- package/dist/src/lib/agent-env.js +7 -0
- package/dist/src/lib/client.js +16 -7
- package/dist/src/lib/keyfile.d.ts +130 -0
- package/dist/src/lib/keyfile.js +381 -0
- package/dist/src/lib/paths.d.ts +33 -0
- package/dist/src/lib/paths.js +77 -0
- package/dist/src/lib/tasks-digest.d.ts +66 -0
- package/dist/src/lib/tasks-digest.js +200 -0
- package/dist/src/lib/tasks-graph.d.ts +78 -0
- package/dist/src/lib/tasks-graph.js +425 -0
- package/dist/src/lib/vaultfile.d.ts +73 -0
- package/dist/src/lib/vaultfile.js +184 -0
- package/dist/src/media.d.ts +2 -0
- package/dist/src/media.js +256 -0
- package/dist/src/plugin.js +10 -1
- package/dist/src/skill.js +128 -12
- package/dist/src/tasks.d.ts +2 -0
- package/dist/src/tasks.js +424 -0
- package/dist/src/templates.js +8 -0
- package/dist/src/wallet.d.ts +9 -0
- package/dist/src/wallet.js +259 -1
- package/dist/src/workflow.d.ts +2 -0
- package/dist/src/workflow.js +144 -0
- package/package.json +4 -4
package/dist/src/auth.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { CONFIG_DIR } from './lib/paths.js';
|
|
2
3
|
import { writeFileSync, readFileSync, existsSync, mkdirSync, chmodSync, unlinkSync, renameSync, } from 'node:fs';
|
|
3
4
|
import { resolve, join } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
5
|
import { requestDeviceCode, openBrowser, pollForToken } from './device-flow.js';
|
|
6
|
-
const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
|
|
7
6
|
const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
8
7
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
9
8
|
const CLI_CLIENT_ID = 'oneie-cli';
|
|
@@ -12,7 +11,7 @@ const CLI_SCOPE = 'read write';
|
|
|
12
11
|
* Command shape, same action, registered under two parents (contract #11). */
|
|
13
12
|
export function buildLoginCommand() {
|
|
14
13
|
const cmd = new Command('login')
|
|
15
|
-
.description('Sign in via browser and persist token to ~/.config/
|
|
14
|
+
.description('Sign in via browser and persist token to ~/.config/one/key')
|
|
16
15
|
.option('--key <key>', 'Skip browser flow — store API key directly (or set ONEIE_API_KEY)')
|
|
17
16
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
18
17
|
.action(async (opts) => {
|
|
@@ -39,7 +38,7 @@ export function buildLoginCommand() {
|
|
|
39
38
|
// (c) Poll until token or expiry
|
|
40
39
|
process.stderr.write(`Waiting for sign-in (expires in ${dc.expires_in}s)…\n`);
|
|
41
40
|
const token = await pollForToken(base, CLI_CLIENT_ID, dc.device_code, dc.interval, dc.expires_in);
|
|
42
|
-
// (d) Write token to ~/.config/
|
|
41
|
+
// (d) Write token to ~/.config/one/key mode 0600
|
|
43
42
|
writeKey(token.access_token);
|
|
44
43
|
// (e) Print success — emit userId if server returned it
|
|
45
44
|
const userId = token.userId ?? 'unknown';
|
package/dist/src/broadcast.d.ts
CHANGED
|
@@ -2,5 +2,7 @@ import { Command } from 'commander';
|
|
|
2
2
|
/** `one broadcast` — operate newsletters from the terminal.
|
|
3
3
|
* Two verbs: list + send. Both hit broadcast:* receivers via ask(); no new route. */
|
|
4
4
|
export declare function broadcastCmd(): Command;
|
|
5
|
+
/** `one segment` — read-only v1: list + preview audience segments from the terminal. */
|
|
6
|
+
export declare function segmentCmd(): Command;
|
|
5
7
|
/** `one newsletter` — pull/push newsletter block trees from the terminal. */
|
|
6
8
|
export declare function newsletterCmd(): Command;
|
package/dist/src/broadcast.js
CHANGED
|
@@ -38,6 +38,30 @@ export function broadcastCmd() {
|
|
|
38
38
|
});
|
|
39
39
|
return cmd;
|
|
40
40
|
}
|
|
41
|
+
/** `one segment` — read-only v1: list + preview audience segments from the terminal. */
|
|
42
|
+
export function segmentCmd() {
|
|
43
|
+
const cmd = new Command('segment').description('List and preview audience segments');
|
|
44
|
+
cmd
|
|
45
|
+
.command('list')
|
|
46
|
+
.description('List audience segments for the workspace')
|
|
47
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
48
|
+
.action(async (opts) => {
|
|
49
|
+
out(await ask(opts.api, 'segment:list', {}));
|
|
50
|
+
});
|
|
51
|
+
cmd
|
|
52
|
+
.command('preview <id>')
|
|
53
|
+
.description('Preview an audience segment by id — live count + up to 10 sample addresses')
|
|
54
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
55
|
+
.action(async (id, opts) => {
|
|
56
|
+
const got = await ask(opts.api, 'segment:get', { id });
|
|
57
|
+
if (!got.segment) {
|
|
58
|
+
process.stderr.write(`segment:get returned no segment for id=${id}\n`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
out(await ask(opts.api, 'segment:preview', { definition: got.segment.definition }));
|
|
62
|
+
});
|
|
63
|
+
return cmd;
|
|
64
|
+
}
|
|
41
65
|
// ---------------------------------------------------------------------------
|
|
42
66
|
// Inline block serialization — mirrors serialize.ts; no Zod dep (CLI rule)
|
|
43
67
|
// ---------------------------------------------------------------------------
|
package/dist/src/compiler.js
CHANGED
|
@@ -180,7 +180,10 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
180
180
|
errors.push({ path: f, message: String(e) });
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
// ai/skills/*/SKILL.md → world:create-thing (skill
|
|
183
|
+
// ai/skills/*/SKILL.md → world:create-thing (catalog listing) + skill:save (runnable
|
|
184
|
+
// body in the workspace R2 catalog — the store skill:run reads, bare name). Without
|
|
185
|
+
// the second item a pushed skill exists only as a world_things row and skill:run
|
|
186
|
+
// returns skill_not_found (verified live 2026-07-12).
|
|
184
187
|
for (const f of walk(join(dir, 'ai', 'skills'), 'SKILL.md')) {
|
|
185
188
|
try {
|
|
186
189
|
const md = readFileSync(f, 'utf8');
|
|
@@ -190,6 +193,7 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
190
193
|
continue;
|
|
191
194
|
}
|
|
192
195
|
compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'skill', md } });
|
|
196
|
+
compiled.push({ path: f, receiver: 'skill:save', payload: { slug: safeSlug(agencySlug), name: safeSlug(fm.name), content: md } });
|
|
193
197
|
}
|
|
194
198
|
catch (e) {
|
|
195
199
|
errors.push({ path: f, message: String(e) });
|
|
@@ -251,7 +255,18 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
251
255
|
// human bits {id,label,tags,description,[[stages]]}; the rest is derived deterministically:
|
|
252
256
|
// stage.slot numeric order (the wall loads ORDER BY slot) → the stage index
|
|
253
257
|
// stage.tag full namespaced tag lifecycle:<id>:<stageId> (LifecycleStage.tag)
|
|
254
|
-
// stage.subSteps
|
|
258
|
+
// stage.subSteps always empty — TOML has no sub-step authoring surface
|
|
259
|
+
// stage.enter_when optional TOML field, straight through (null when absent) — the
|
|
260
|
+
// C7 rule engine grammar (an exact event name or a conversion-stage
|
|
261
|
+
// category, e.g. "purchase"/"intent"); the compiler does not validate
|
|
262
|
+
// it against event-vocabulary.ts (that package isn't a CLI dependency),
|
|
263
|
+
// so an author who wants the stage to self-populate from real traffic
|
|
264
|
+
// must use a value the web app's isValidEnterWhen() accepts — a bad
|
|
265
|
+
// value just leaves the stage manual-only (evaluate() never matches it).
|
|
266
|
+
// stage.goal / principle / band plain string fields, straight through if present
|
|
267
|
+
// stage.levers parseToml has no nested array-of-tables, so a lever is one string per
|
|
268
|
+
// entry in a bracket list: levers = ["page:/pricing", "agent:one"] —
|
|
269
|
+
// "<kind>:<id>", kind ∈ page|workflow|agent|human (LeverKind)
|
|
255
270
|
for (const f of walk(join(dir, 'data', 'lifecycles'), '.toml')) {
|
|
256
271
|
try {
|
|
257
272
|
const toml = parseToml(readFileSync(f, 'utf8'));
|
|
@@ -259,13 +274,22 @@ export async function compileNode(dir, agencySlug, opts) {
|
|
|
259
274
|
const rawStages = Array.isArray(toml.stages) ? toml.stages : [];
|
|
260
275
|
const stages = rawStages.map((s, i) => {
|
|
261
276
|
const stageId = String(s.id ?? '');
|
|
277
|
+
const rawLevers = Array.isArray(s.levers) ? s.levers : [];
|
|
278
|
+
const levers = rawLevers.map((l) => {
|
|
279
|
+
const [kind, ...rest] = l.split(':');
|
|
280
|
+
return { kind, id: rest.join(':') };
|
|
281
|
+
}).filter((l) => l.kind && l.id);
|
|
262
282
|
return {
|
|
263
283
|
id: stageId,
|
|
264
284
|
label: String(s.label ?? stageId),
|
|
265
285
|
tag: `lifecycle:${id}:${stageId}`,
|
|
266
286
|
slot: i,
|
|
267
287
|
subSteps: [],
|
|
268
|
-
enter_when: null,
|
|
288
|
+
enter_when: s.enter_when ? String(s.enter_when) : null,
|
|
289
|
+
...(s.goal ? { goal: String(s.goal) } : {}),
|
|
290
|
+
...(s.principle ? { principle: String(s.principle) } : {}),
|
|
291
|
+
...(s.band ? { band: String(s.band) } : {}),
|
|
292
|
+
...(levers.length > 0 ? { levers } : {}),
|
|
269
293
|
};
|
|
270
294
|
});
|
|
271
295
|
const def = { id, name: String(toml.label ?? id), version: 1, stages, transitions: [], arcs: [], monotonic: true };
|
package/dist/src/doctor.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
3
|
import { mergeEnv } from './env.js';
|
|
6
4
|
import { resolveBase, resolveKey, authHeaders } from './lib/client.js';
|
|
5
|
+
import { readKeyFolder, keyFolderStatus } from './lib/keyfile.js';
|
|
6
|
+
import { KEY_FILE } from './lib/paths.js';
|
|
7
7
|
import { askPath } from './lib/api-path.js';
|
|
8
|
-
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
9
8
|
/** api.one.ie (the gateway) answers `GET /health`; one.ie/web has no /health
|
|
10
9
|
* route, so a HEAD / 200 is the reachability signal there — same host split
|
|
11
10
|
* askPath() already makes for /ask. */
|
|
@@ -34,14 +33,70 @@ export async function runDoctor(dir, opts = {}) {
|
|
|
34
33
|
const keyFile = opts.keyFile ?? KEY_FILE;
|
|
35
34
|
const env = mergeEnv(dir);
|
|
36
35
|
const checks = [];
|
|
37
|
-
|
|
36
|
+
// A folder key outranks the machine key, the same order resolveKey uses — so
|
|
37
|
+
// doctor reports the credential the commands will actually send.
|
|
38
|
+
const folder = readKeyFolder(dir);
|
|
39
|
+
// A REFUSED folder key must be explained, not silently skipped. `foreign` means
|
|
40
|
+
// a .oneie/agent.key exists here but was minted for another directory — the
|
|
41
|
+
// credential-confusion guard. Silence would leave the operator staring at a key
|
|
42
|
+
// on disk that nothing uses, with no way to tell that from a bug.
|
|
43
|
+
const folderState = keyFolderStatus(dir);
|
|
44
|
+
if (folderState === 'foreign' || folderState === 'unsafe' || folderState === 'unreadable') {
|
|
45
|
+
checks.push({
|
|
46
|
+
name: 'folder-key',
|
|
47
|
+
ok: false,
|
|
48
|
+
detail: folderState === 'foreign'
|
|
49
|
+
? 'a .oneie/agent.key here was minted for a DIFFERENT directory or machine — ignored. Run `one init --dir .` to mint one for this project.'
|
|
50
|
+
: folderState === 'unsafe'
|
|
51
|
+
? 'a .oneie/agent.key here is a symlink, group/world-readable, or owned by another user — ignored. Delete it and re-mint.'
|
|
52
|
+
: 'a .oneie/agent.key here is empty or unreadable — ignored.',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const hasConfig = Boolean(folder) || existsSync(keyFile) || Boolean(env.ONE_API_KEY) || Boolean(env.ONEIE_API_KEY);
|
|
38
56
|
checks.push({
|
|
39
57
|
name: 'config',
|
|
40
58
|
ok: hasConfig,
|
|
41
|
-
detail:
|
|
59
|
+
detail: folder
|
|
60
|
+
? `${dir}/.oneie/agent.key (0600, project)`
|
|
61
|
+
: hasConfig
|
|
62
|
+
? `${keyFile} (0600)`
|
|
63
|
+
: `${keyFile} missing — run \`one setup\` or \`one login\``,
|
|
42
64
|
});
|
|
43
|
-
const key = env.ONE_API_KEY ||
|
|
65
|
+
const key = env.ONE_API_KEY ||
|
|
66
|
+
env.ONEIE_API_KEY ||
|
|
67
|
+
folder?.apiKey ||
|
|
68
|
+
(existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
44
69
|
checks.push({ name: 'key', ok: Boolean(key), detail: key ? `${key.slice(0, 4)}***…` : 'no key found' });
|
|
70
|
+
// EXPIRY. Keys minted by the anonymous provision door carry a 90-day
|
|
71
|
+
// valid_to, and verifyWorldKey enforces it in SQL — so an unwatched folder
|
|
72
|
+
// key stops working one day with a bare 401, which `packages/cli/CLAUDE.md`
|
|
73
|
+
// documents as indistinguishable from a WRONG key. The metadata already
|
|
74
|
+
// records the date; reading it is what turns a scheduled outage into a
|
|
75
|
+
// warning. An absent expiresAt means a permanent key, not an unknown one, so
|
|
76
|
+
// it reports ok and says so rather than inventing a doubt.
|
|
77
|
+
const expiresAt = folder?.meta.expiresAt;
|
|
78
|
+
if (typeof expiresAt === 'string') {
|
|
79
|
+
const ms = Date.parse(expiresAt);
|
|
80
|
+
if (Number.isNaN(ms)) {
|
|
81
|
+
checks.push({ name: 'key-expiry', ok: false, detail: `unreadable expiresAt: ${expiresAt}` });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const days = Math.floor((ms - Date.now()) / 86_400_000);
|
|
85
|
+
checks.push({
|
|
86
|
+
name: 'key-expiry',
|
|
87
|
+
// Expired is a failure; expiring is not, or doctor cries wolf for 83 days.
|
|
88
|
+
ok: days > 0,
|
|
89
|
+
detail: days > 14
|
|
90
|
+
? `expires in ${days} days`
|
|
91
|
+
: days > 0
|
|
92
|
+
? `expires in ${days} days — renew with \`one init --dir .\``
|
|
93
|
+
: `EXPIRED ${-days} days ago — renew with \`one init --dir .\``,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (folder) {
|
|
98
|
+
checks.push({ name: 'key-expiry', ok: true, detail: 'no expiry recorded (permanent key)' });
|
|
99
|
+
}
|
|
45
100
|
const base = resolveBase({ api: opts.api });
|
|
46
101
|
const reach = await checkReachability(base);
|
|
47
102
|
checks.push({ name: 'substrate', ok: reach.ok, detail: `${base} ${reach.ms}ms` });
|
package/dist/src/eval.js
CHANGED
|
@@ -18,6 +18,7 @@ export function evalCmd() {
|
|
|
18
18
|
channelsUrl: opts.channels.replace(/\/$/, ''),
|
|
19
19
|
eventsUrl: opts.events.replace(/\/$/, ''),
|
|
20
20
|
groqApiKey: process.env.GROQ_API_KEY,
|
|
21
|
+
typesafeApiKey: process.env.TYPESAFE_API_KEY,
|
|
21
22
|
});
|
|
22
23
|
const failed = results.filter((r) => r.failed > 0).length;
|
|
23
24
|
out({ ok: failed === 0, total: results.length, passed: results.length - failed, results });
|
package/dist/src/fn.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { FN_MAP, FN_MAP_VERSION } from '@oneie/sdk/generated/fn-map';
|
|
3
|
+
// The allowlist is ONE source (`@oneie/sdk/fn-allowlist`) shared by web, MCP, CLI
|
|
4
|
+
// and channels — never a literal copied per surface.
|
|
5
|
+
import { FN_ALLOWLIST, isAllowedFn } from '@oneie/sdk/fn-allowlist';
|
|
3
6
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
4
|
-
const ALLOWLIST = new Set([
|
|
5
|
-
'actionable_hypotheses', 'active_frontiers', 'active_objectives',
|
|
6
|
-
'actor_classification', 'actors_by_kind', 'actors_by_tag', 'actors_for',
|
|
7
|
-
'attractive_tasks', 'blocked_tasks', 'cheapest_provider', 'exploratory_tasks',
|
|
8
|
-
'highways', 'optimal_route', 'promising_frontiers', 'suggest_route', 'total_contribution',
|
|
9
|
-
]);
|
|
10
7
|
function apiKey() {
|
|
11
8
|
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
12
9
|
}
|
|
@@ -32,7 +29,7 @@ export function fnCmd() {
|
|
|
32
29
|
.command('list')
|
|
33
30
|
.description('List all allowlisted functions')
|
|
34
31
|
.action(() => {
|
|
35
|
-
const rows =
|
|
32
|
+
const rows = FN_ALLOWLIST.map((name) => {
|
|
36
33
|
const entry = FN_MAP[name];
|
|
37
34
|
const params = entry?.params.map((p) => p.name).join(', ') ?? '';
|
|
38
35
|
return ` ${name.padEnd(28)}${params ? `(${params})` : '()'} → ${entry?.returnKind ?? '?'}`;
|
|
@@ -46,7 +43,7 @@ export function fnCmd() {
|
|
|
46
43
|
.option('--workspace <slug>', 'Workspace slug')
|
|
47
44
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
48
45
|
.action(async (name, opts) => {
|
|
49
|
-
if (!
|
|
46
|
+
if (!isAllowedFn(name)) {
|
|
50
47
|
process.stderr.write(`error: '${name}' is not in the allowlist. Run 'one fn list' to see available functions.\n`);
|
|
51
48
|
process.exit(1);
|
|
52
49
|
}
|
package/dist/src/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { devCmd } from './dev.js';
|
|
|
10
10
|
import { groupCmd } from './group.js';
|
|
11
11
|
import { socialCmd } from './social.js';
|
|
12
12
|
import { connectCmd } from './connect.js';
|
|
13
|
-
import { broadcastCmd, newsletterCmd } from './broadcast.js';
|
|
13
|
+
import { broadcastCmd, newsletterCmd, segmentCmd } from './broadcast.js';
|
|
14
14
|
import { chatCmd } from './chat.js';
|
|
15
15
|
import { linksCmd } from './links.js';
|
|
16
16
|
import { staffCmd } from './staff.js';
|
|
@@ -32,6 +32,9 @@ import { trailCmd } from './trail.js';
|
|
|
32
32
|
import { initCmd } from './init.js';
|
|
33
33
|
import { onboardCmd } from './onboard.js';
|
|
34
34
|
import { pluginCmd } from './plugin.js';
|
|
35
|
+
import { workflowCmd } from './workflow.js';
|
|
36
|
+
import { tasksCmd } from './tasks.js';
|
|
37
|
+
import { mediaCmd } from './media.js';
|
|
35
38
|
import { readFileSync } from 'node:fs';
|
|
36
39
|
import { fileURLToPath } from 'node:url';
|
|
37
40
|
import { resolve, dirname } from 'node:path';
|
|
@@ -50,6 +53,7 @@ program.addCommand(groupCmd());
|
|
|
50
53
|
program.addCommand(socialCmd());
|
|
51
54
|
program.addCommand(connectCmd());
|
|
52
55
|
program.addCommand(broadcastCmd());
|
|
56
|
+
program.addCommand(segmentCmd());
|
|
53
57
|
program.addCommand(chatCmd());
|
|
54
58
|
program.addCommand(newsletterCmd());
|
|
55
59
|
program.addCommand(linksCmd());
|
|
@@ -75,6 +79,9 @@ program.addCommand(trailCmd());
|
|
|
75
79
|
program.addCommand(initCmd());
|
|
76
80
|
program.addCommand(onboardCmd());
|
|
77
81
|
program.addCommand(pluginCmd());
|
|
82
|
+
program.addCommand(workflowCmd());
|
|
83
|
+
program.addCommand(tasksCmd());
|
|
84
|
+
program.addCommand(mediaCmd());
|
|
78
85
|
// Bare `oneie` (no args, no --help/--version): route the audience to its
|
|
79
86
|
// journey instead of commander's default help dump. Never an interactive
|
|
80
87
|
// prompt — agent env and human TTY both get a printed block (contract #10).
|
package/dist/src/init.js
CHANGED
|
@@ -14,6 +14,7 @@ import { homedir } from 'node:os';
|
|
|
14
14
|
import { renameSync, chmodSync } from 'node:fs';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
16
|
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
17
|
+
import { writeKeyFolder } from './lib/keyfile.js';
|
|
17
18
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
18
19
|
const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
|
|
19
20
|
const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
@@ -66,6 +67,8 @@ export function initCmd() {
|
|
|
66
67
|
.option('--no-content', 'Skip generating a starter agent.md')
|
|
67
68
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
68
69
|
.option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory')
|
|
70
|
+
.option('--dir <path>', 'Write the key into THIS project folder (.oneie/agent.key, 0600, gitignored) instead of the machine-wide ~/.config/oneie/key')
|
|
71
|
+
.option('--ttl-days <n>', 'Key lifetime in days (default 90, max 365)')
|
|
69
72
|
.action(async (opts) => {
|
|
70
73
|
const dir = process.cwd();
|
|
71
74
|
if (opts.writeEnv) {
|
|
@@ -85,6 +88,8 @@ export function initCmd() {
|
|
|
85
88
|
body.skills = skills;
|
|
86
89
|
if (opts.email)
|
|
87
90
|
body.invite = { email: opts.email, role: 'owner' };
|
|
91
|
+
if (opts.ttlDays)
|
|
92
|
+
body.ttlDays = Number(opts.ttlDays);
|
|
88
93
|
let res;
|
|
89
94
|
try {
|
|
90
95
|
res = await fetch(`${opts.api.replace(/\/$/, '')}/api/provision/agent`, {
|
|
@@ -102,8 +107,32 @@ export function initCmd() {
|
|
|
102
107
|
out(cmd, { ok: false, ...json });
|
|
103
108
|
return;
|
|
104
109
|
}
|
|
105
|
-
const { workspace, apiKey, inviteUrl } = json;
|
|
106
|
-
|
|
110
|
+
const { workspace, apiKey, regKey, uid, expiresAt, inviteUrl } = json;
|
|
111
|
+
// --dir writes the credential INTO the project, which is narrower than the
|
|
112
|
+
// machine-wide default: one project's key, revocable alone, gone when the
|
|
113
|
+
// folder is. The ceremony writes the ignore entry BEFORE the key and
|
|
114
|
+
// refuses to write a key at all if it cannot — see lib/keyfile.ts.
|
|
115
|
+
let keyLocation;
|
|
116
|
+
if (opts.dir) {
|
|
117
|
+
const res = writeKeyFolder({
|
|
118
|
+
dir: opts.dir,
|
|
119
|
+
apiKey,
|
|
120
|
+
regKey,
|
|
121
|
+
workspace,
|
|
122
|
+
uid,
|
|
123
|
+
api: opts.api,
|
|
124
|
+
expiresAt,
|
|
125
|
+
});
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
out(cmd, { ok: false, error: res.error ?? 'could not write key folder' });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
keyLocation = `${res.keyPath} (0600, ignored via ${res.ignorePath})`;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
writeKey(apiKey);
|
|
134
|
+
keyLocation = `${KEY_FILE} (0600)`;
|
|
135
|
+
}
|
|
107
136
|
if (opts.writeEnv) {
|
|
108
137
|
writeEnvLocal(dir, { ONE_API_KEY: apiKey, ONE_API_URL: opts.api });
|
|
109
138
|
}
|
|
@@ -111,7 +140,8 @@ export function initCmd() {
|
|
|
111
140
|
ok: true,
|
|
112
141
|
workspace,
|
|
113
142
|
url: `${opts.api.replace(/\/$/, '')}/u/${workspace}`,
|
|
114
|
-
key:
|
|
143
|
+
key: keyLocation,
|
|
144
|
+
...(expiresAt ? { expires: new Date(expiresAt * 1000).toISOString() } : {}),
|
|
115
145
|
...(opts.writeEnv ? { env: `${dir}/.env.local`, mcp: 'export ONE_API_KEY before launching Claude Code — MCP reads the shell env, not .env.local directly' } : {}),
|
|
116
146
|
...(inviteUrl ? { invite: inviteUrl } : {}),
|
|
117
147
|
...(skills.length ? { skills: skills.join(', ') } : {}),
|
|
@@ -7,6 +7,13 @@ const AGENT_ENV_MARKERS = {
|
|
|
7
7
|
CURSOR_TRACE_ID: 'cursor',
|
|
8
8
|
WINDSURF: 'windsurf',
|
|
9
9
|
GITHUB_COPILOT_CLI: 'copilot',
|
|
10
|
+
// Codex sets CODEX_SANDBOX (to "seatbelt" on macOS) for the child processes of
|
|
11
|
+
// its sandboxed tool calls. UNDOCUMENTED, and absent when sandboxing is off —
|
|
12
|
+
// so this NAMES a Codex shell when it can and never gates on it. The gate is
|
|
13
|
+
// still the TTY check below, which already answered true for every Codex shell;
|
|
14
|
+
// what was missing was `agentType()` being able to say WHICH agent, which is
|
|
15
|
+
// what the front door routes on.
|
|
16
|
+
CODEX_SANDBOX: 'codex',
|
|
10
17
|
};
|
|
11
18
|
/** The specific coding agent driving this shell, if env vars name one. */
|
|
12
19
|
export function agentType(env = process.env) {
|
package/dist/src/lib/client.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { resolve } from 'node:path';
|
|
1
|
+
import { readKeyFolder } from './keyfile.js';
|
|
2
|
+
import { readMachineKey } from './paths.js';
|
|
4
3
|
// Every command resolves base URL, key, and --json the same way — this module
|
|
5
4
|
// is the one place that knows the env contract. Composes askPath() from
|
|
6
5
|
// ./api-path.js for the gateway-vs-web path split; does not replace it.
|
|
7
|
-
|
|
6
|
+
// Path canon lives in lib/paths.ts — six modules used to each carry their own.
|
|
8
7
|
/** --api flag > ONE_API_URL (canonical) > ONEIE_BASE_URL (legacy) > fallback. ONE_BASE_URL is retired. */
|
|
9
8
|
export function resolveBase(opts = {}, fallback = 'https://one.ie') {
|
|
10
9
|
const base = opts.api ?? process.env.ONE_API_URL ?? process.env.ONEIE_BASE_URL ?? fallback;
|
|
@@ -18,9 +17,19 @@ export function resolveKey(opts = {}) {
|
|
|
18
17
|
return process.env.ONE_API_KEY;
|
|
19
18
|
if (process.env.ONEIE_API_KEY)
|
|
20
19
|
return process.env.ONEIE_API_KEY;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
// The PROJECT's key outranks the machine's. A folder that carries its own
|
|
21
|
+
// credential is saying "use mine", and `one init --dir .` wrote it there to
|
|
22
|
+
// narrow the blast radius — falling through to ~/.config/oneie/key would hand
|
|
23
|
+
// the command the machine-wide key instead and quietly undo that.
|
|
24
|
+
//
|
|
25
|
+
// Below the env vars on purpose: an explicit ONE_API_KEY in the shell is a
|
|
26
|
+
// deliberate override, and CI sets it that way.
|
|
27
|
+
const folder = readKeyFolder(process.cwd());
|
|
28
|
+
if (folder)
|
|
29
|
+
return folder.apiKey;
|
|
30
|
+
// readMachineKey tries ~/.config/one/key then the pre-rename ~/.config/oneie/key,
|
|
31
|
+
// so an upgrade does not silently log anyone out.
|
|
32
|
+
return readMachineKey();
|
|
24
33
|
}
|
|
25
34
|
export function authHeaders(opts = {}) {
|
|
26
35
|
const h = { 'Content-Type': 'application/json' };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** The per-project directory holding the key, the vault and their metadata. */
|
|
2
|
+
export declare const KEY_DIR_NAME = ".one";
|
|
3
|
+
/**
|
|
4
|
+
* The pre-rename project directory. READ-ONLY — a folder minted before the
|
|
5
|
+
* rename keeps working; nothing is ever written here again. Same fallback shape
|
|
6
|
+
* as `paths.ts` uses for ~/.config, and for the same reason: a rename must not
|
|
7
|
+
* present as "my key stopped working".
|
|
8
|
+
*/
|
|
9
|
+
export declare const LEGACY_KEY_DIR_NAME = ".oneie";
|
|
10
|
+
/** `*.key` is already covered by the scaffold's root .gitignore. */
|
|
11
|
+
export declare const KEY_FILE_NAME = "agent.key";
|
|
12
|
+
export declare const META_FILE_NAME = "agent.json";
|
|
13
|
+
export interface KeyFolderInput {
|
|
14
|
+
/** Project root. The key lands at <dir>/.oneie/agent.key */
|
|
15
|
+
dir: string;
|
|
16
|
+
/** The workspace-scoped key — authenticates as the workspace actor. */
|
|
17
|
+
apiKey: string;
|
|
18
|
+
/** The uid-bound registration key. Distinct from apiKey; see the note below. */
|
|
19
|
+
regKey?: string;
|
|
20
|
+
workspace: string;
|
|
21
|
+
uid?: string;
|
|
22
|
+
api: string;
|
|
23
|
+
/** Unix seconds at which the key stops verifying, when the server set one. */
|
|
24
|
+
expiresAt?: number;
|
|
25
|
+
/** The spend ceiling the server reports for this actor, in USD. */
|
|
26
|
+
spendLimitUsd?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface KeyFolderResult {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
keyPath?: string;
|
|
31
|
+
metaPath?: string;
|
|
32
|
+
ignorePath?: string;
|
|
33
|
+
/** Set when the ceremony refused — the key was NOT written. */
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* True when `.gitignore` already ignores the key directory.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately a literal scan, not a `git check-ignore` shell-out: the folder
|
|
40
|
+
* may not be a git repo yet (that is the common case — `npx oneie` runs before
|
|
41
|
+
* `git init`), and a check that silently passes on "not a repo" would be the
|
|
42
|
+
* false green this whole module exists to avoid.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ignoresKeyDir(ignoreText: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Ensure `<dir>/.gitignore` ignores the key directory. Returns the path on
|
|
47
|
+
* success, or null when it could not be written — in which case the caller must
|
|
48
|
+
* NOT write a key.
|
|
49
|
+
*/
|
|
50
|
+
export declare function ensureIgnored(dir: string): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Canonical absolute path — symlinks resolved.
|
|
53
|
+
*
|
|
54
|
+
* `resolve()` alone is NOT enough for the path binding. On macOS `/tmp` is a
|
|
55
|
+
* symlink to `/private/tmp` and `/var` to `/private/var`, so a key minted at the
|
|
56
|
+
* path the user typed and read back after a `chdir` compares unequal and a
|
|
57
|
+
* legitimate credential is refused. Home directories and network mounts are
|
|
58
|
+
* symlinked on plenty of real machines too. Compare the REAL path on both sides
|
|
59
|
+
* or the check fails open on attackers and closed on users — the worst pairing.
|
|
60
|
+
*
|
|
61
|
+
* Falls back to `resolve()` when the path does not exist yet (realpath throws).
|
|
62
|
+
*/
|
|
63
|
+
export declare function canonicalDir(p: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* A stable, secret-ish id for THIS machine.
|
|
66
|
+
*
|
|
67
|
+
* The path binding alone is not enough where the path is predictable. A repo
|
|
68
|
+
* that ships `.oneie/agent.json` recording `dir:
|
|
69
|
+
* "/home/runner/work/<repo>/<repo>"` matches that path on EVERY GitHub Actions
|
|
70
|
+
* checkout of it — so the clone attack the binding closes for a laptop reopens
|
|
71
|
+
* for CI, which is exactly where nobody is watching. The machine id is a value
|
|
72
|
+
* the attacker cannot guess and cannot read from the victim's repo, so a key
|
|
73
|
+
* must be BOTH at the right path AND on the right machine.
|
|
74
|
+
*
|
|
75
|
+
* Stored 0600 beside the machine-wide key. Not a secret in the cryptographic
|
|
76
|
+
* sense — it authorises nothing on its own — so a read-only or unwritable home
|
|
77
|
+
* degrades to path-only binding rather than refusing all work.
|
|
78
|
+
*/
|
|
79
|
+
export declare function machineId(): string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Write `data` to `path` at 0600, refusing to follow a symlink.
|
|
82
|
+
*
|
|
83
|
+
* `writeFileSync` FOLLOWS symlinks. An attacker who can pre-plant
|
|
84
|
+
* `.oneie/agent.key.tmp` as a link to a file they control gets our chmod(0600)
|
|
85
|
+
* and our credential written to their target — the classic pre-plant, and the
|
|
86
|
+
* 0700 directory does not help because the link is created before we ever run.
|
|
87
|
+
* `O_NOFOLLOW` makes the kernel refuse, and `O_EXCL` means we never write onto
|
|
88
|
+
* an existing file at all.
|
|
89
|
+
*/
|
|
90
|
+
export declare function writeSecret(path: string, data: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Write the key folder: ignore entry FIRST, then 0700 dir, then 0600 key via
|
|
93
|
+
* tmp+rename so a reader never observes a partial or world-readable file.
|
|
94
|
+
*
|
|
95
|
+
* Refuses (and writes nothing) when the ignore entry cannot be established.
|
|
96
|
+
*/
|
|
97
|
+
export declare function writeKeyFolder(input: KeyFolderInput): KeyFolderResult;
|
|
98
|
+
/**
|
|
99
|
+
* Read a folder key back, or null when the folder has none — or when the key
|
|
100
|
+
* found there was minted for a DIFFERENT directory.
|
|
101
|
+
*
|
|
102
|
+
* THE PATH BINDING IS A SECURITY CONTROL, not bookkeeping. `resolveKey` consults
|
|
103
|
+
* the current working directory, so without this check any directory you `cd`
|
|
104
|
+
* into can supply your credentials: clone a repo that ships a `.oneie/agent.key`,
|
|
105
|
+
* run one `one` command inside it, and you are authenticated as WHOEVER MINTED
|
|
106
|
+
* THAT KEY. The damage is not that your key leaks — it is that your next
|
|
107
|
+
* `one push` writes your agents and skills into THEIR workspace, and your next
|
|
108
|
+
* `one trade` spends against their ledger. That is a credential-confusion
|
|
109
|
+
* exfiltration, and the folder-key rung introduced it.
|
|
110
|
+
*
|
|
111
|
+
* `agent.json` records the absolute path the key was minted for, so a key that
|
|
112
|
+
* travelled — by clone, copy, or archive — refuses rather than authenticates.
|
|
113
|
+
* This is the same shape as git's `safe.directory`, decided per key instead of
|
|
114
|
+
* per user.
|
|
115
|
+
*
|
|
116
|
+
* A key with NO recorded `dir` is pre-binding and also refused: the whole point
|
|
117
|
+
* is that an unbound credential is the untrustworthy case, and treating a
|
|
118
|
+
* missing field as permission is how the check gets bypassed by simply deleting
|
|
119
|
+
* a line.
|
|
120
|
+
*/
|
|
121
|
+
export declare function readKeyFolder(dir: string): {
|
|
122
|
+
apiKey: string;
|
|
123
|
+
meta: Record<string, unknown>;
|
|
124
|
+
} | null;
|
|
125
|
+
/**
|
|
126
|
+
* Why a folder key present on disk was not used. Separate from `readKeyFolder`
|
|
127
|
+
* so a refusal can be EXPLAINED without the reader having to hold a credential:
|
|
128
|
+
* a silent null is right for `resolveKey` and useless for `doctor`.
|
|
129
|
+
*/
|
|
130
|
+
export declare function keyFolderStatus(dir: string): 'none' | 'ok' | 'foreign' | 'unsafe' | 'unreadable';
|