@notis_ai/cli 0.2.29 → 0.2.30
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 +25 -8
- package/dist/agent-hooks/notis-agent-hook.mjs +1030 -610
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +11 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/references/release.md +6 -5
- package/dist/base-skills/notis-spaces/references/sdk.md +82 -17
- package/dist/sdk/src/hooks/useThreadItem.ts +56 -0
- package/dist/sdk/src/index.ts +6 -1
- package/dist/sdk/src/runtime.ts +8 -1
- package/dist/sdk/src/space.ts +230 -0
- package/dist/skill-sync-worker.mjs +185 -30
- package/dist/space-harness/host.js +237 -93
- package/dist/space-sdk/dist/{chunk-BFGB6XXC.js → chunk-6GJ2BS7B.js} +1 -3
- package/dist/space-sdk/dist/index.js +4 -2
- package/dist/space-sdk/dist/ui.js +18 -13
- package/dist/space-sdk/src/hooks/useThreadItem.d.ts +28 -0
- package/dist/space-sdk/src/index.d.ts +3 -1
- package/dist/space-sdk/src/runtime.d.ts +8 -1
- package/dist/space-sdk/src/space.ts +230 -0
- package/dist/space-sdk/src/tailwind-candidates.d.ts +492 -14
- package/dist/space-sdk/src/ui/actions/useToast.d.ts +2 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +56 -10
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +16 -7
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +59 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +5 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +103 -8
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +37 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +119 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +75 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +147 -15
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +24 -8
- package/dist/space-sdk/src/ui/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +6 -1
- package/dist/space-sdk/src/ui/overlay/Tooltip.d.ts +8 -2
- package/dist/space-sdk/src/ui/styles.d.ts +27 -5
- package/dist/view-renderer/dist/host.js +307 -163
- package/dist/view-renderer/src/host.tsx +6 -3
- package/dist/view-renderer/src/renderer.js +25 -2
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -1
- package/skills/notis-spaces/cli.md +8 -8
- package/src/cli.js +10 -2
- package/src/command-specs/computer.js +21 -1
- package/src/command-specs/profile.js +12 -5
- package/src/command-specs/spaces.js +30 -16
- package/src/runtime/agent-identity.js +187 -0
- package/src/runtime/api-hosts.js +92 -0
- package/src/runtime/channel.js +3 -7
- package/src/runtime/oauth.js +95 -4
- package/src/runtime/profiles.js +200 -41
- package/src/runtime/skill-sync-service.js +4 -5
- package/src/runtime/space-platform.js +2 -0
- package/src/runtime/space-source.js +66 -1
- package/src/runtime/space-test-server.js +20 -4
- package/src/runtime/space-verification.js +5 -1
- package/src/runtime/telemetry.js +14 -1
- package/src/runtime/transport.js +12 -0
- package/src/runtime/upsell.js +3 -6
- package/src/runtime/view-render.js +3 -1
- package/src/skill-sync-worker.js +13 -2
- package/src/space-harness-host.ts +6 -3
|
@@ -20,7 +20,7 @@ import * as NotisSDKUI from '../../sdk/src/ui/index';
|
|
|
20
20
|
// The toolkit stylesheet the host adopts into every Space shadow root (esbuild text import).
|
|
21
21
|
import toolkitCss from '../../sdk/src/ui/toolkit.css' with { type: 'text' };
|
|
22
22
|
|
|
23
|
-
const state = { mounted: false, pending: 0, blocked: [] as string[], lastActivity: performance.now(), failed: false };
|
|
23
|
+
const state = { mounted: false, pending: 0, blocked: [] as string[], lastActivity: performance.now(), failed: false, failure: '' };
|
|
24
24
|
// The Space runtime contract (packages/sdk/src/runtimeModules.ts): bundles import React and the SDK from these.
|
|
25
25
|
Object.assign(window, { __notisRenderState: state, React, ReactDOM, ReactDOMClient, __ReactJSXRuntime: JSXRuntime,
|
|
26
26
|
__NotisSDK: NotisSDK, __NotisSDKUI: NotisSDKUI });
|
|
@@ -228,7 +228,8 @@ async function start() {
|
|
|
228
228
|
const host = document.createElement('div'); host.style.cssText = 'height:100vh;min-height:100vh';
|
|
229
229
|
const shadow = host.attachShadow({ mode: 'open' });
|
|
230
230
|
const styles = document.createElement('style'); styles.textContent = (snapshot.hostCss || '') + '\n' + snapshot.css; shadow.appendChild(styles);
|
|
231
|
-
|
|
231
|
+
// A Tailwind 3 Space keeps the toolkit unlayered, so its unlayered preflight does not reset toolkit pieces.
|
|
232
|
+
NotisSDKUI.adoptToolkitStyles(shadow, { cascade: NotisSDKUI.toolkitCascadeFor(snapshot.css) });
|
|
232
233
|
const mount = document.createElement('div'); mount.style.cssText = 'height:100%;min-height:0'; shadow.appendChild(mount);
|
|
233
234
|
document.body.appendChild(host);
|
|
234
235
|
const controller = document.createElement('div'); document.body.appendChild(controller);
|
|
@@ -250,4 +251,6 @@ async function start() {
|
|
|
250
251
|
onProtocolError={error => { if ((error as any)?.code === 'notis_sdk_query:actionUnavailable') return; state.blocked.push('render_read_only'); changed(); }}
|
|
251
252
|
onCommit={mounted => { frame(); state.mounted = mounted; changed(); }} />);
|
|
252
253
|
}
|
|
253
|
-
|
|
254
|
+
// Why the view never started (most often its module did not load), for `spaces verify` to show; the render
|
|
255
|
+
// service never returns it.
|
|
256
|
+
void start().catch(error => { state.failed = true; state.failure = String(error?.message ?? error).slice(0, 300) || 'The view did not start.'; });
|
|
@@ -91,12 +91,21 @@ async function capturePage(page, sliceHeight, maxBytes, maxHeight, maxPixels) {
|
|
|
91
91
|
return stitcher.finish();
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
function viewFailure(reason) {
|
|
95
|
+
const failure = new ViewRenderError('render_view_failed', "This view's code failed before it showed anything. Run notis spaces verify on its source to see why.", 422);
|
|
96
|
+
// What the browser said (a module that did not load), for `spaces verify` on the author's own source only: it is
|
|
97
|
+
// not enumerable, and the render service returns only the code.
|
|
98
|
+
if (reason) Object.defineProperty(failure, 'reason', { value: String(reason).slice(0, 300) });
|
|
99
|
+
return failure;
|
|
100
|
+
}
|
|
101
|
+
|
|
94
102
|
function diagnosticFailure(error, stage, fallback = 'render_failed') {
|
|
95
103
|
const failure = error instanceof ViewRenderError
|
|
96
104
|
? new ViewRenderError(error.code, error.message, error.status) : renderFailure(fallback);
|
|
97
105
|
// Private in-process diagnostics only. Public JSON/error projections cannot
|
|
98
106
|
// enumerate a browser exception, which may contain source or request data.
|
|
99
107
|
Object.defineProperties(failure, { cause: { value: error }, stage: { value: stage } });
|
|
108
|
+
if (error instanceof ViewRenderError && error.reason) Object.defineProperty(failure, 'reason', { value: error.reason });
|
|
100
109
|
// A view that was not ready in time keeps the screenshot of what it showed, released after the final authority check.
|
|
101
110
|
if (error instanceof ViewRenderError && error.screenshot) {
|
|
102
111
|
Object.defineProperties(failure, { screenshot: { value: error.screenshot }, mounted: { value: error.mounted === true },
|
|
@@ -237,7 +246,13 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
237
246
|
Object.defineProperty(failure, 'cause', { value: transientFailure });
|
|
238
247
|
throw failure;
|
|
239
248
|
}
|
|
240
|
-
|
|
249
|
+
const host = await page.evaluate(() => ({ failed: Boolean(window.__notisRenderState?.failed),
|
|
250
|
+
mounted: Boolean(window.__notisRenderState?.mounted), failure: String(window.__notisRenderState?.failure || '') }));
|
|
251
|
+
// The view's code did not start (a module that does not load, an import this host does not provide; the
|
|
252
|
+
// host records why in `failure`): rendering again cannot help, and it is not about access. A view that
|
|
253
|
+
// threw while rendering keeps the outcome it had, since that may depend on the data it read.
|
|
254
|
+
if (!authorityLost && !cancellation.aborted && host.failed && !host.mounted && host.failure) throw viewFailure(host.failure);
|
|
255
|
+
if (authorityLost || cancellation.aborted || host.failed) {
|
|
241
256
|
const failure = renderFailure('render_access_changed');
|
|
242
257
|
if (authorityFailure) Object.defineProperty(failure, 'cause', { value: authorityFailure });
|
|
243
258
|
throw failure;
|
|
@@ -285,11 +300,19 @@ export async function renderView({ broker, outputs, width, timeoutMs, signal, po
|
|
|
285
300
|
}
|
|
286
301
|
stage = 'host_ready';
|
|
287
302
|
const ready = () => window.__notisRenderState?.mounted && window.__notisRenderState.pending === 0 && performance.now() - window.__notisRenderState.lastActivity > 100;
|
|
303
|
+
// A view whose code did not start has nothing left to wait for: stop at once instead of waiting out the
|
|
304
|
+
// render timeout. Any other failure still waits for the reads in flight, whose outcome decides the error.
|
|
305
|
+
// (Each function runs in the page on its own, so this one cannot call ready.)
|
|
306
|
+
const readyOrFailed = () => Boolean(window.__notisRenderState?.failure) || (window.__notisRenderState?.mounted
|
|
307
|
+
&& window.__notisRenderState.pending === 0 && performance.now() - window.__notisRenderState.lastActivity > 100);
|
|
288
308
|
// The bounded wait also leaves the capture and the final authority check room before the render deadline.
|
|
289
309
|
const readyWait = readyTimeoutMs === undefined ? config.timeoutMs
|
|
290
310
|
: Math.max(1, Math.min(readyTimeoutMs, deadlineAt - Date.now() - CAPTURE_MARGIN_MS));
|
|
291
311
|
const readyStarted = Date.now();
|
|
292
|
-
try {
|
|
312
|
+
try {
|
|
313
|
+
await page.waitForFunction(readyOrFailed, undefined, { timeout: readyWait });
|
|
314
|
+
if (await page.evaluate(() => Boolean(window.__notisRenderState?.failure))) await complete();
|
|
315
|
+
}
|
|
293
316
|
catch (error) {
|
|
294
317
|
if (readyTimeoutMs === undefined || cancellation.aborted || error?.name !== 'TimeoutError') throw error;
|
|
295
318
|
stage = 'not_ready_capture';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notis_ai/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30",
|
|
4
4
|
"description": "Agent-first Notis CLI for Spaces, Skills and generic tool execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"react-dom": "19.3.0"
|
|
53
53
|
},
|
|
54
54
|
"notisRelease": {
|
|
55
|
-
"sourceSha": "
|
|
55
|
+
"sourceSha": "c85c7d62766a6561de18ec338247843d089cadae",
|
|
56
56
|
"channel": "stable"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "c85c7d62766a6561de18ec338247843d089cadae"
|
|
59
59
|
}
|
|
@@ -37,7 +37,7 @@ Call these with `notis tools exec <TOOL>` (add `--get-schema` first when you nee
|
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
"name": "LOCAL_NOTIS_SEARCH_THREADS",
|
|
40
|
-
"description": "Find the current user's earlier conversations across channels, including voice calls. Search by title/latest inbound user-message preview and filter by channel, source, status, failure cause or date. A failed conversation has status 'failed' and names its saved cause in failure_cause. This is not full-transcript search: broaden a missed keyword query or list recent threads, then inspect likely matches with LOCAL_NOTIS_LOAD_CONVERSATION_HISTORY using the returned thread_id. Returns up to 50 summaries."
|
|
40
|
+
"description": "Find the current user's earlier conversations across channels, including voice calls. Search by title/latest inbound user-message preview and filter by channel, source, status, failure cause or date. A failed conversation has status 'failed' and names its saved cause in failure_cause. This is not full-transcript search: broaden a missed keyword query or list recent threads, then inspect likely matches with LOCAL_NOTIS_LOAD_CONVERSATION_HISTORY using the returned thread_id. summary_line is the last reply's bold opening line. Returns up to 50 summaries."
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"name": "LOCAL_NOTIS_SEARCH_MEMORIES",
|
|
@@ -86,6 +86,7 @@ Call these with `notis tools exec <TOOL>` (add `--get-schema` first when you nee
|
|
|
86
86
|
|
|
87
87
|
- Cold discovery can exceed 30 seconds. Use `--timeout-ms 90000` for discovery calls when needed; after `network_timeout`, retry the exact command once with that timeout instead of looping.
|
|
88
88
|
- Before writing a Notion or native database row, read the schema and relevant property descriptions.
|
|
89
|
+
- Before writing for the user (comments, rows), declare yourself once per session with a fresh lowercase imaginary rock-band name: `export NOTIS_AGENT_NAME="fred-and-the-machine"` (or `--agent-name`; lowercase letters and digits in at least two words joined by hyphens, 3 to 60 characters). The CLI keeps one id per name on this computer, so set `NOTIS_AGENT_ID` only to override it. Where the user has unified comments on, the write then shows your name, never reads as the user's own, and never wakes you, and a comment written through the CLI without a name is refused (`agent_name_required`); elsewhere the name is ignored.
|
|
89
90
|
- When answering about meetings or availability, check every connected calendar.
|
|
90
91
|
- Use `notis doctor` before concluding that authentication or API reachability is broken.
|
|
91
92
|
- Keep credentials and other secrets out of tool arguments and search queries unless the target tool explicitly requires them.
|
|
@@ -261,8 +261,8 @@ Render one frozen Space with offline fixtures and validate its current action au
|
|
|
261
261
|
When to use: Check immutable build bytes and authoring compatibility without executing actions or publishing.
|
|
262
262
|
|
|
263
263
|
Options:
|
|
264
|
-
- `--space <key>` — Exact source key from the workspace index.
|
|
265
|
-
- `--space-id <id>` — Exact existing destination Space.
|
|
264
|
+
- `--space <key>` — Exact source key from the workspace index. Optional when the workspace holds one Space.
|
|
265
|
+
- `--space-id <id>` — Exact existing destination Space. Optional in a pulled workspace: the Space it was pulled from.
|
|
266
266
|
- `--reuse-grants <json>` — Explicit action-key to saved-grant-ID map. Otherwise your own connections are used.
|
|
267
267
|
- `--reuse-grants-only` — Never authorize new actions. Reuse only the supplied saved grants; other declarations remain unavailable. Requires existing bound databases.
|
|
268
268
|
|
|
@@ -276,8 +276,8 @@ Seal a checked unpublished revision of the same Space and return its authenticat
|
|
|
276
276
|
When to use: Review a checked candidate using current Editor access without changing live source or cloning the Space.
|
|
277
277
|
|
|
278
278
|
Options:
|
|
279
|
-
- `--space <key>` — Exact source key from the workspace index.
|
|
280
|
-
- `--space-id <id>` — Exact existing destination Space.
|
|
279
|
+
- `--space <key>` — Exact source key from the workspace index. Optional when the workspace holds one Space.
|
|
280
|
+
- `--space-id <id>` — Exact existing destination Space. Optional in a pulled workspace: the Space it was pulled from.
|
|
281
281
|
- `--reuse-grants <json>` — Explicit action-key to saved-grant-ID map. Otherwise your own connections are used.
|
|
282
282
|
- `--reuse-grants-only` — Never authorize new actions. Reuse only the supplied saved grants; other declarations remain unavailable. Requires existing bound databases.
|
|
283
283
|
- `--request-id <key>` — Stable intent key. Reuse after timeouts or lost replies.
|
|
@@ -293,8 +293,8 @@ Publish one built Space with a retry-safe, independent source revision.
|
|
|
293
293
|
When to use: Update only the selected existing Space; this does not publish to the Store or change siblings.
|
|
294
294
|
|
|
295
295
|
Options:
|
|
296
|
-
- `--space <key>` — Exact source key from the workspace index.
|
|
297
|
-
- `--space-id <id>` — Exact existing destination Space.
|
|
296
|
+
- `--space <key>` — Exact source key from the workspace index. Optional when the workspace holds one Space.
|
|
297
|
+
- `--space-id <id>` — Exact existing destination Space. Optional in a pulled workspace: the Space it was pulled from.
|
|
298
298
|
- `--reuse-grants <json>` — Explicit action-key to saved-grant-ID map. Otherwise your own connections are used.
|
|
299
299
|
- `--reuse-grants-only` — Never authorize new actions. Reuse only the supplied saved grants; other declarations remain unavailable. Requires existing bound databases.
|
|
300
300
|
- `--request-id <key>` — Stable intent key. Reuse after timeouts or lost replies.
|
|
@@ -528,7 +528,7 @@ Build one independent Space and save its frozen source/artifact snapshot.
|
|
|
528
528
|
When to use: Prepare a selected Space for verification without publishing it or changing siblings.
|
|
529
529
|
|
|
530
530
|
Options:
|
|
531
|
-
- `--space <key>` — Exact source key from the workspace Space index.
|
|
531
|
+
- `--space <key>` — Exact source key from the workspace Space index. Optional when the workspace holds one Space.
|
|
532
532
|
|
|
533
533
|
Examples:
|
|
534
534
|
- `npx --package @notis_ai/cli@latest -- notis spaces build . --space overview`
|
|
@@ -540,7 +540,7 @@ Inspect one local Space definition and its declared capabilities.
|
|
|
540
540
|
When to use: Read the selected source definition without loading sibling definitions or account resources.
|
|
541
541
|
|
|
542
542
|
Options:
|
|
543
|
-
- `--space <key>` — Exact source key from the workspace Space index.
|
|
543
|
+
- `--space <key>` — Exact source key from the workspace Space index. Optional when the workspace holds one Space.
|
|
544
544
|
|
|
545
545
|
Examples:
|
|
546
546
|
- `npx --package @notis_ai/cli@latest -- notis spaces inspect . --space overview`
|
package/src/cli.js
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
resolveOutputMode,
|
|
24
24
|
resolveRuntimeProfile,
|
|
25
25
|
resolveWorktreeRuntime,
|
|
26
|
+
routingProfile,
|
|
26
27
|
workspacePath,
|
|
27
28
|
} from './runtime/profiles.js';
|
|
28
29
|
|
|
@@ -236,6 +237,11 @@ export function createProgram(launchContext = {}) {
|
|
|
236
237
|
.option('--timeout-ms <n>', 'Time limit in milliseconds for each call, automatic retries included')
|
|
237
238
|
.option('--idempotency-key <key>', 'Override the generated idempotency key for mutating commands')
|
|
238
239
|
.option('--no-retry', 'Turn off automatic retries of interrupted calls that are safe to repeat (or set NOTIS_NO_RETRY=1)')
|
|
240
|
+
// Any agent using the CLI declares itself, so what it writes is its own (a comment's Author), not the person's.
|
|
241
|
+
// A comment written through the CLI needs the name (agent-identity.js).
|
|
242
|
+
.option('--agent-name <name>', 'The agent making this call, a lowercase band name such as fred-and-the-machine, shown as the Author of what it writes; required to write comments (or set NOTIS_AGENT_NAME)')
|
|
243
|
+
.option('--agent-id <id>', 'Override the id this computer keeps for the agent name (generated on first use) (or set NOTIS_AGENT_ID)')
|
|
244
|
+
.option('--agent-thread <thread>', 'The thread or session the agent runs in: a Notis thread id or link of yours gets the replies (or set NOTIS_AGENT_THREAD)')
|
|
239
245
|
.addOption(new Option('--notis-managed-agent-hook').hideHelp());
|
|
240
246
|
|
|
241
247
|
const parentMap = new Map([['', program]]);
|
|
@@ -283,7 +289,7 @@ export function channelProfileForArgs(
|
|
|
283
289
|
const config = suppliedConfig || loadConfig();
|
|
284
290
|
const explicitProfile = profileName || env.NOTIS_PROFILE;
|
|
285
291
|
if (explicitProfile) {
|
|
286
|
-
return getProfile(config, explicitProfile);
|
|
292
|
+
return routingProfile(getProfile(config, explicitProfile), env);
|
|
287
293
|
}
|
|
288
294
|
const resolvedWorktree = suppliedWorktreeRuntime === undefined
|
|
289
295
|
? resolveWorktreeRuntime()
|
|
@@ -299,7 +305,9 @@ export function channelProfileForArgs(
|
|
|
299
305
|
}
|
|
300
306
|
// NOTIS_JWT replaces the credential, not the route. Unless NOTIS_API_BASE
|
|
301
307
|
// was explicit above, the selected/current profile still owns the channel.
|
|
302
|
-
|
|
308
|
+
// A signed-out profile's channel is a leftover (routingProfile): it runs on
|
|
309
|
+
// this build, and the next login pins the account's own channel.
|
|
310
|
+
return routingProfile(getProfile(config, config.current_profile || DEFAULT_PROFILE), env);
|
|
303
311
|
}
|
|
304
312
|
|
|
305
313
|
function interruptedExitCode(signal) {
|
|
@@ -173,8 +173,28 @@ const STATUS_LINES = {
|
|
|
173
173
|
none: 'You have no Cloud Computer yet. It starts the first time Notis needs it.',
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
+
// boat's own word (machine_state) on a live read while it starts or stops. The status only knows Notis's own work,
|
|
177
|
+
// so it reads "stopped" for a machine awake in its idle tail: boat's awake wins over that (bx_yaqe7sjj, 2026-11-12).
|
|
178
|
+
const MACHINE_LINES = {
|
|
179
|
+
starting: 'Your Cloud Computer is starting.',
|
|
180
|
+
stopping: 'Your Cloud Computer is finishing a stop. It starts again when Notis has work to do.',
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const AWAKE_IDLE = 'Your Cloud Computer is awake, with nothing to do. It goes to sleep after its sleep time.';
|
|
184
|
+
const AWAKE_ALWAYS_ON = 'Your Cloud Computer is awake, with nothing to do. It stays on: always on is set.';
|
|
185
|
+
|
|
186
|
+
function liveLine(computer) {
|
|
187
|
+
if (computer.status === 'stopped' && computer.machine_state === 'awake') {
|
|
188
|
+
// sleep.after_seconds is null when always on: that machine never goes to sleep.
|
|
189
|
+
return computer.sleep && computer.sleep.after_seconds === null ? AWAKE_ALWAYS_ON : AWAKE_IDLE;
|
|
190
|
+
}
|
|
191
|
+
return ['running', 'stopped'].includes(computer.status) ? MACHINE_LINES[computer.machine_state] : null;
|
|
192
|
+
}
|
|
193
|
+
|
|
176
194
|
function statusText(computer) {
|
|
177
|
-
if (computer.status !== 'not_responding')
|
|
195
|
+
if (computer.status !== 'not_responding') {
|
|
196
|
+
return liveLine(computer) || STATUS_LINES[computer.status] || STATUS_LINES.none;
|
|
197
|
+
}
|
|
178
198
|
const reason = computer.status_reason ? ` Reason: ${computer.status_reason}.` : '';
|
|
179
199
|
const saved = computer.last_saved_at ? ` Last saved ${computer.last_saved_at}.` : '';
|
|
180
200
|
return `Your Cloud Computer is not responding.${reason}${saved} Restart it with: notis computer restart`;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { isLiveApiOrigin } from '../runtime/api-hosts.js';
|
|
2
3
|
import { CHANNEL_SWITCH_ENV } from '../runtime/channel.js';
|
|
3
4
|
import { CliError, EXIT_CODES } from '../runtime/errors.js';
|
|
4
5
|
import { quoteShellArgument } from '../runtime/auth-recovery.js';
|
|
@@ -9,6 +10,8 @@ import {
|
|
|
9
10
|
loadConfig,
|
|
10
11
|
normalizeConfig,
|
|
11
12
|
profileHasCredential,
|
|
13
|
+
oauthGrantOnRetiredAddress,
|
|
14
|
+
profileIsSignedIn,
|
|
12
15
|
profileExists,
|
|
13
16
|
resolveWorktreeRuntime,
|
|
14
17
|
updateConfig,
|
|
@@ -116,8 +119,6 @@ async function listHandler(ctx) {
|
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
const SKILL_SYNC_API_BASE_PATTERN = /^https:\/\/api(?:-beta)?\.notis\.ai\/?$/;
|
|
120
|
-
|
|
121
122
|
// Overrides that belong to this `profile use` run. Inherited, a NOTIS_JWT would
|
|
122
123
|
// sync its own account into the agent folders under the named profile.
|
|
123
124
|
const RELINK_DROPPED_ENV = ['NOTIS_JWT', 'NOTIS_API_BASE', 'NOTIS_PROFILE', CHANNEL_SWITCH_ENV];
|
|
@@ -134,7 +135,10 @@ export function relinkSkillsInBackground(name, profile, {
|
|
|
134
135
|
// Never from a test run: a detached sync would outlive it and reach the real API.
|
|
135
136
|
if (env.NODE_ENV === 'test' || env.NODE_TEST_CONTEXT || !argv[1]) return false;
|
|
136
137
|
if (!profile?.oauth_access_token && !profile?.oauth_refresh_token) return false;
|
|
137
|
-
|
|
138
|
+
// A grant minted for a retired API name is signed out (CLI-038).
|
|
139
|
+
if (oauthGrantOnRetiredAddress(profile)) return false;
|
|
140
|
+
// Every live Notis API, nightly's current name included (CLI-039).
|
|
141
|
+
if (!isLiveApiOrigin(profile.api_base)) return false;
|
|
138
142
|
// Like the automatic sync, the relink runs as the named profile alone: its
|
|
139
143
|
// credential, its endpoint and the CLI build for its channel.
|
|
140
144
|
const childEnv = { ...env };
|
|
@@ -171,7 +175,8 @@ async function useHandler(ctx) {
|
|
|
171
175
|
const profile = getProfile(next, requested);
|
|
172
176
|
const worktreeOverride = Boolean(worktreeRuntime);
|
|
173
177
|
const worktreeBlocked = Boolean(worktreeUnavailable);
|
|
174
|
-
|
|
178
|
+
// A dead grant (CLI-035) reads as signed out, as `profile list` shows it.
|
|
179
|
+
const authenticated = profileIsSignedIn(profile);
|
|
175
180
|
if (authenticated) relinkSkillsInBackground(requested, profile);
|
|
176
181
|
|
|
177
182
|
return ctx.output.emitSuccess({
|
|
@@ -193,7 +198,9 @@ async function useHandler(ctx) {
|
|
|
193
198
|
? `Saved profile "${requested}" as the default outside this worktree; this checkout still uses "${worktreeRuntime.profile}" unless --profile is explicit.`
|
|
194
199
|
: authenticated
|
|
195
200
|
? `Switched to profile "${requested}".`
|
|
196
|
-
:
|
|
201
|
+
: profileHasCredential(profile)
|
|
202
|
+
? `Switched to profile "${requested}", whose sign-in has ended; sign in again.`
|
|
203
|
+
: `Switched to profile "${requested}", which has no credential yet.`,
|
|
197
204
|
hints: worktreeBlocked
|
|
198
205
|
? [
|
|
199
206
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scaffoldSpaceCollection } from '../runtime/space-collection-scaffold.js';
|
|
2
|
-
import { appFilesDigest, clearSpaceScreenshots, pullAppSource, resolveProjectDir, saveSpacePendingScreenshots, saveSpaceScreenshots, saveSpaceVerification, spacePublicationIntent, syncSpaceSdk } from '../runtime/app-platform.js';
|
|
2
|
+
import { appFilesDigest, clearSpaceScreenshots, loadAppConfig, pullAppSource, resolveProjectDir, saveSpacePendingScreenshots, saveSpaceScreenshots, saveSpaceVerification, spacePublicationIntent, syncSpaceSdk } from '../runtime/app-platform.js';
|
|
3
3
|
import { buildSpaceArtifact, prepareSpaceRelease, requireSpaceIcon } from '../runtime/space-platform.js';
|
|
4
4
|
import { verifySpaceRelease } from '../runtime/space-verification.js';
|
|
5
5
|
import { loadSelectedSpace } from '../runtime/space-source.js';
|
|
@@ -16,10 +16,24 @@ import { unifiedDiffSummary, versionName } from './version-history.js';
|
|
|
16
16
|
import { createHash } from 'node:crypto';
|
|
17
17
|
import { viewRenderCommandSpec } from './views.js';
|
|
18
18
|
|
|
19
|
-
function selected(ctx) {
|
|
20
|
-
if (!ctx.options.space) throw usageError('Choose the independent Space with --space <key>.');
|
|
19
|
+
async function selected(ctx) {
|
|
21
20
|
// build, verify, preview, deploy and inspect write or stage inside this folder.
|
|
22
|
-
|
|
21
|
+
const directory = assertSourceRoot(resolveProjectDir(ctx.args.dir || '.'));
|
|
22
|
+
if (ctx.options.space) return { directory, key: ctx.options.space };
|
|
23
|
+
// A folder that holds one Space (a pulled Space always does) needs no --space.
|
|
24
|
+
const workspace = await loadAppConfig(directory);
|
|
25
|
+
const keys = workspace && typeof workspace.spaces === 'object' && workspace.spaces ? Object.keys(workspace.spaces) : [];
|
|
26
|
+
if (keys.length === 1) return { directory, key: keys[0] };
|
|
27
|
+
throw usageError(keys.length ? `Choose the Space with --space <key>: this workspace declares ${keys.join(', ')}.`
|
|
28
|
+
: 'Choose the independent Space with --space <key>.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** --space-id, else the Space this folder was pulled from on the same API (its lock file). */
|
|
32
|
+
function destinationSpaceId(ctx, directory) {
|
|
33
|
+
if (ctx.options.spaceId) return ctx.options.spaceId;
|
|
34
|
+
const lock = readSpaceLock(directory);
|
|
35
|
+
if (lock && lock.api_base === ctx.runtime.apiBase.replace(/\/$/, '')) return lock.space_id;
|
|
36
|
+
throw usageError('Pass --space-id <id> for the existing Space.');
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
function requestId(ctx) {
|
|
@@ -168,8 +182,8 @@ function sameVerification(verification, body, sourceDigest) {
|
|
|
168
182
|
}
|
|
169
183
|
|
|
170
184
|
async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
171
|
-
const { directory, key } = selected(ctx);
|
|
172
|
-
|
|
185
|
+
const { directory, key } = await selected(ctx);
|
|
186
|
+
const spaceId = destinationSpaceId(ctx, directory);
|
|
173
187
|
const intentKey = publish ? requestId(ctx) : null;
|
|
174
188
|
// A verify that stops at any point (a build older than its source, a refused source check, a cancelled render), or
|
|
175
189
|
// a release without a loading skeleton, leaves no image of an older build.
|
|
@@ -177,11 +191,11 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
177
191
|
const release = await prepareSpaceRelease(directory, key);
|
|
178
192
|
try {
|
|
179
193
|
if (publish) requireSpaceIcon(release.manifest, key);
|
|
180
|
-
const identity = [ctx.runtime.apiBase.replace(/\/$/, ''), ctx.runtime.profileName, key,
|
|
194
|
+
const identity = [ctx.runtime.apiBase.replace(/\/$/, ''), ctx.runtime.profileName, key, spaceId, intentKey];
|
|
181
195
|
let verification = publish && !ctx.options.dryRun ? spacePublicationIntent(directory, identity) : null;
|
|
182
|
-
const local = intentChanges(directory,
|
|
183
|
-
localSpaceChanges(directory,
|
|
184
|
-
const body = { space_id:
|
|
196
|
+
const local = intentChanges(directory, spaceId, release.manifest,
|
|
197
|
+
localSpaceChanges(directory, spaceId, release.manifest), verification);
|
|
198
|
+
const body = { space_id: spaceId, manifest: release.manifest, source_files: release.sourceFiles,
|
|
185
199
|
artifact_files: release.files, reuse_grants: object(ctx.options.reuseGrants || '{}', '--reuse-grants'),
|
|
186
200
|
...(ctx.options.reuseGrantsOnly ? { authorization_mode: 'reuse_only' } : {}),
|
|
187
201
|
...(local.changes ? { changes: local.changes } : {}) };
|
|
@@ -691,8 +705,8 @@ export const spacesCommandSpecs = [
|
|
|
691
705
|
: operation === 'preview' ? 'Review a checked candidate using current Editor access without changing live source or cloning the Space.'
|
|
692
706
|
: 'Update only the selected existing Space; this does not publish to the Store or change siblings.',
|
|
693
707
|
args_schema: { arguments: [{ token: '[dir]', key: 'dir', description: 'Source workspace (default current directory).' }],
|
|
694
|
-
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace index.' },
|
|
695
|
-
{ flags: '--space-id <id>', description: 'Exact existing destination Space.' },
|
|
708
|
+
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace index. Optional when the workspace holds one Space.' },
|
|
709
|
+
{ flags: '--space-id <id>', description: 'Exact existing destination Space. Optional in a pulled workspace: the Space it was pulled from.' },
|
|
696
710
|
{ flags: '--reuse-grants <json>', description: 'Explicit action-key to saved-grant-ID map. Otherwise your own connections are used.' },
|
|
697
711
|
{ flags: '--reuse-grants-only', description: 'Never authorize new actions. Reuse only the supplied saved grants; other declarations remain unavailable. Requires existing bound databases.' },
|
|
698
712
|
...(operation !== 'verify' ? [requestOption, { flags: '--dry-run', description: 'Validate without uploading or publishing.' }] : [])] },
|
|
@@ -906,12 +920,12 @@ export const spacesCommandSpecs = [
|
|
|
906
920
|
summary: 'Build one independent Space and save its frozen source/artifact snapshot.',
|
|
907
921
|
when_to_use: 'Prepare a selected Space for verification without publishing it or changing siblings.',
|
|
908
922
|
args_schema: { arguments: [{ token: '[dir]', key: 'dir', description: 'Source workspace (default current directory).' }],
|
|
909
|
-
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace Space index.' }] },
|
|
923
|
+
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace Space index. Optional when the workspace holds one Space.' }] },
|
|
910
924
|
examples: ['notis spaces build . --space overview'],
|
|
911
925
|
mutates: true, idempotent: true, require_auth: false,
|
|
912
926
|
backend_call: { type: 'local', name: 'space_build' },
|
|
913
927
|
async handler(ctx) {
|
|
914
|
-
const { directory, key } = selected(ctx);
|
|
928
|
+
const { directory, key } = await selected(ctx);
|
|
915
929
|
const result = await buildSpaceArtifact(directory, key, { stdio: ctx.output.isMachineMode() ? 'pipe' : 'inherit' });
|
|
916
930
|
return ctx.output.emitSuccess({ command: 'spaces build', data: result, humanSummary: `Built ${key}; no Space was published.` });
|
|
917
931
|
},
|
|
@@ -921,12 +935,12 @@ export const spacesCommandSpecs = [
|
|
|
921
935
|
summary: 'Inspect one local Space definition and its declared capabilities.',
|
|
922
936
|
when_to_use: 'Read the selected source definition without loading sibling definitions or account resources.',
|
|
923
937
|
args_schema: { arguments: [{ token: '[dir]', key: 'dir', description: 'Source workspace (default current directory).' }],
|
|
924
|
-
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace Space index.' }] },
|
|
938
|
+
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace Space index. Optional when the workspace holds one Space.' }] },
|
|
925
939
|
examples: ['notis spaces inspect . --space overview'],
|
|
926
940
|
mutates: false, idempotent: true, require_auth: false,
|
|
927
941
|
backend_call: { type: 'local', name: 'space_source_inspect' },
|
|
928
942
|
async handler(ctx) {
|
|
929
|
-
const { directory, key } = selected(ctx);
|
|
943
|
+
const { directory, key } = await selected(ctx);
|
|
930
944
|
const selection = await loadSelectedSpace(directory, key);
|
|
931
945
|
return ctx.output.emitSuccess({ command: 'spaces inspect', data: { key, definition: selection.definition, definition_path: selection.definitionPath },
|
|
932
946
|
humanSummary: `${selection.definition.name} (${key})` });
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { resolveCliConfigFile, withConfigFileWriteLock } from './config-lock.js';
|
|
6
|
+
import { usageError } from './errors.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An agent's declared identity, sent on every backend call.
|
|
10
|
+
*
|
|
11
|
+
* Any agent driving the CLI (Claude Code or Codex on a person's computer, a script, a Cloud Computer session) says
|
|
12
|
+
* who it is with `--agent-name`, `--agent-id` and `--agent-thread`, or the NOTIS_AGENT_NAME, NOTIS_AGENT_ID and
|
|
13
|
+
* NOTIS_AGENT_THREAD variables (a flag wins over its variable). The backend then treats what the call writes as that
|
|
14
|
+
* agent's, not the person's: a comment's Author is the declared name, it never counts as the person's comment and it
|
|
15
|
+
* never wakes the agent that wrote it. The declaration is self-asserted: it names the writer, it never grants access.
|
|
16
|
+
*
|
|
17
|
+
* The name is a band name: a fresh lowercase imaginary rock-band name, lowercase letters and digits in at least two
|
|
18
|
+
* words joined by hyphens, 3 to 60 characters, such as fred-and-the-machine. The name is only a name: the id decides
|
|
19
|
+
* which comments are the agent's own. Without an explicit id the CLI generates a random one the first time a name is
|
|
20
|
+
* used on this computer and keeps it for that name in `agents.json`, next to the CLI config file (so
|
|
21
|
+
* NOTIS_CLI_CONFIG_FILE moves it too), written under the config lock. An explicit id always wins.
|
|
22
|
+
*
|
|
23
|
+
* The values travel percent-encoded (encodeURIComponent) in the X-Notis-Agent-* headers. The backend applies the same
|
|
24
|
+
* rules (server/lib/delegated_agents/declared_agent.py) and refuses a comment written through the CLI without a name.
|
|
25
|
+
*/
|
|
26
|
+
export const AGENT_NAME_HEADER = 'X-Notis-Agent-Name';
|
|
27
|
+
export const AGENT_ID_HEADER = 'X-Notis-Agent-Id';
|
|
28
|
+
export const AGENT_THREAD_HEADER = 'X-Notis-Agent-Thread';
|
|
29
|
+
export const AGENT_IDENTITY_ENV = {
|
|
30
|
+
name: 'NOTIS_AGENT_NAME',
|
|
31
|
+
id: 'NOTIS_AGENT_ID',
|
|
32
|
+
thread: 'NOTIS_AGENT_THREAD',
|
|
33
|
+
};
|
|
34
|
+
export const AGENT_NAME_MIN = 3;
|
|
35
|
+
export const AGENT_NAME_LIMIT = 60;
|
|
36
|
+
export const BAND_NAME_EXAMPLE = 'fred-and-the-machine';
|
|
37
|
+
export const BAND_NAME_RULE = `a fresh lowercase imaginary rock-band name: lowercase letters and digits in at least two words joined by hyphens, ${AGENT_NAME_MIN} to ${AGENT_NAME_LIMIT} characters, such as ${BAND_NAME_EXAMPLE}`;
|
|
38
|
+
export const AGENT_IDS_VERSION = 1;
|
|
39
|
+
export const AGENT_ID_LIMIT = 128;
|
|
40
|
+
export const AGENT_THREAD_LIMIT = 512;
|
|
41
|
+
|
|
42
|
+
const BAND_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)+$/;
|
|
43
|
+
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:@/+-]*$/;
|
|
44
|
+
// Printable ASCII without spaces: an id or a link.
|
|
45
|
+
const THREAD_PATTERN = /^[\x21-\x7e]+$/;
|
|
46
|
+
|
|
47
|
+
function pick(flag, variable) {
|
|
48
|
+
if (typeof flag === 'string') return flag;
|
|
49
|
+
return typeof variable === 'string' ? variable : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The raw declaration from the global flags and the environment, or null when nothing is declared. */
|
|
53
|
+
export function readAgentIdentity(globalOptions = {}, env = process.env) {
|
|
54
|
+
const raw = {
|
|
55
|
+
name: pick(globalOptions.agentName, env[AGENT_IDENTITY_ENV.name]),
|
|
56
|
+
id: pick(globalOptions.agentId, env[AGENT_IDENTITY_ENV.id]),
|
|
57
|
+
thread: pick(globalOptions.agentThread, env[AGENT_IDENTITY_ENV.thread]),
|
|
58
|
+
};
|
|
59
|
+
return Object.values(raw).some((value) => typeof value === 'string' && value.trim()) ? raw : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The validated declaration ({name, id?, thread?}), or null; a usage error names what to fix. */
|
|
63
|
+
export function validateAgentIdentity(raw) {
|
|
64
|
+
if (!raw) return null;
|
|
65
|
+
const name = String(raw.name ?? '').trim();
|
|
66
|
+
const id = String(raw.id ?? '').trim();
|
|
67
|
+
const thread = String(raw.thread ?? '').trim();
|
|
68
|
+
if (!name) {
|
|
69
|
+
throw usageError(
|
|
70
|
+
`Name the agent: set ${AGENT_IDENTITY_ENV.name} (or --agent-name) whenever ${AGENT_IDENTITY_ENV.id} or ${AGENT_IDENTITY_ENV.thread} is set.`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (!isBandName(name)) {
|
|
74
|
+
throw usageError(
|
|
75
|
+
`${AGENT_IDENTITY_ENV.name} (or --agent-name) must be ${BAND_NAME_RULE}. Pick one for this agent and keep it.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (id && (id.length > AGENT_ID_LIMIT || !ID_PATTERN.test(id))) {
|
|
79
|
+
throw usageError(
|
|
80
|
+
`${AGENT_IDENTITY_ENV.id} must be at most ${AGENT_ID_LIMIT} characters: letters, digits and . _ : @ / + - , starting with a letter or digit.`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (thread && (thread.length > AGENT_THREAD_LIMIT || !THREAD_PATTERN.test(thread))) {
|
|
84
|
+
throw usageError(
|
|
85
|
+
`${AGENT_IDENTITY_ENV.thread} must be a thread id or link of at most ${AGENT_THREAD_LIMIT} characters, without spaces.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return { name, ...(id ? { id } : {}), ...(thread ? { thread } : {}) };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const RAW_HEADER_LIMIT = AGENT_THREAD_LIMIT;
|
|
92
|
+
|
|
93
|
+
function rawIdentityHeaders(raw) {
|
|
94
|
+
const headers = {};
|
|
95
|
+
const put = (header, value) => {
|
|
96
|
+
// Capped by whole characters (never splitting one, which encodeURIComponent refuses), one past the longest
|
|
97
|
+
// valid value, so a value too long stays too long for the backend to refuse.
|
|
98
|
+
const text = Array.from(String(value ?? '').trim()).slice(0, RAW_HEADER_LIMIT + 1).join('');
|
|
99
|
+
if (text) headers[header] = encodeURIComponent(text);
|
|
100
|
+
};
|
|
101
|
+
put(AGENT_NAME_HEADER, raw?.name);
|
|
102
|
+
put(AGENT_ID_HEADER, raw?.id);
|
|
103
|
+
put(AGENT_THREAD_HEADER, raw?.thread);
|
|
104
|
+
return headers;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Whether `name` follows the band-name rule (BAND_NAME_RULE). */
|
|
108
|
+
export function isBandName(name) {
|
|
109
|
+
return typeof name === 'string' && name.length >= AGENT_NAME_MIN && name.length <= AGENT_NAME_LIMIT
|
|
110
|
+
&& BAND_NAME.test(name);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function agentIdsFile(configFile = resolveCliConfigFile()) {
|
|
114
|
+
return join(dirname(configFile), 'agents.json');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function readAgentIds(file) {
|
|
118
|
+
try {
|
|
119
|
+
const raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
120
|
+
if (raw?.version === AGENT_IDS_VERSION && raw.agents && typeof raw.agents === 'object' && !Array.isArray(raw.agents)) {
|
|
121
|
+
return raw.agents;
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
// A missing or broken file holds no ids yet.
|
|
125
|
+
}
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function storedId(agents, name) {
|
|
130
|
+
const id = Object.hasOwn(agents, name) ? agents[name] : null;
|
|
131
|
+
return typeof id === 'string' && id.length <= AGENT_ID_LIMIT && ID_PATTERN.test(id) ? id : null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The id this computer keeps for an agent name, generated (a random UUID) the first time the name is used. Read again
|
|
136
|
+
* under the config lock so two first calls agree on one id.
|
|
137
|
+
*/
|
|
138
|
+
export function agentIdForName(name, options = {}) {
|
|
139
|
+
const configFile = options.configFile ?? resolveCliConfigFile();
|
|
140
|
+
const file = agentIdsFile(configFile);
|
|
141
|
+
const known = storedId(readAgentIds(file), name);
|
|
142
|
+
if (known) return known;
|
|
143
|
+
return withConfigFileWriteLock(configFile, () => {
|
|
144
|
+
const agents = readAgentIds(file);
|
|
145
|
+
const existing = storedId(agents, name);
|
|
146
|
+
if (existing) return existing;
|
|
147
|
+
const id = randomUUID();
|
|
148
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
149
|
+
const temporaryFile = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
150
|
+
writeFileSync(temporaryFile, `${JSON.stringify({ version: AGENT_IDS_VERSION, agents: { ...agents, [name]: id } }, null, 2)}\n`,
|
|
151
|
+
{ mode: 0o600 });
|
|
152
|
+
renameSync(temporaryFile, file);
|
|
153
|
+
return id;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The headers that declare the runtime's agent (empty when it declares none). A name without an explicit id carries
|
|
159
|
+
* the id this computer keeps for it; when that id cannot be kept (a read-only disk) the name goes alone and the
|
|
160
|
+
* backend asks for NOTIS_AGENT_ID before a comment write.
|
|
161
|
+
*/
|
|
162
|
+
export function agentIdentityHeaders(runtime, options = {}) {
|
|
163
|
+
const raw = runtime?.agentIdentity ?? null;
|
|
164
|
+
let identity;
|
|
165
|
+
try {
|
|
166
|
+
identity = validateAgentIdentity(raw);
|
|
167
|
+
} catch {
|
|
168
|
+
// A declaration that breaks the rules is sent as written, with no kept id: where declarations count (unified
|
|
169
|
+
// comments on) the routes that read them (tools, Space data and actions, document restores and removes) refuse
|
|
170
|
+
// the call with invalid_agent_identity, reads included; elsewhere it is ignored, so a stray NOTIS_AGENT_NAME never
|
|
171
|
+
// breaks a person without unified comments.
|
|
172
|
+
return rawIdentityHeaders(raw);
|
|
173
|
+
}
|
|
174
|
+
if (!identity) return {};
|
|
175
|
+
let id = identity.id;
|
|
176
|
+
if (!id) {
|
|
177
|
+
try {
|
|
178
|
+
id = agentIdForName(identity.name, options);
|
|
179
|
+
} catch {
|
|
180
|
+
id = undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const headers = { [AGENT_NAME_HEADER]: encodeURIComponent(identity.name) };
|
|
184
|
+
if (id) headers[AGENT_ID_HEADER] = encodeURIComponent(id);
|
|
185
|
+
if (identity.thread) headers[AGENT_THREAD_HEADER] = encodeURIComponent(identity.thread);
|
|
186
|
+
return headers;
|
|
187
|
+
}
|