@notis_ai/cli 0.2.29 → 0.2.31
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 +26 -8
- package/dist/agent-hooks/notis-agent-hook.mjs +38399 -10883
- 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-cli/references/native-databases.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/references/query.md +6 -4
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +8 -3
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -1
- package/dist/base-skills/notis-spaces/references/design.md +7 -1
- package/dist/base-skills/notis-spaces/references/fixtures.md +27 -2
- package/dist/base-skills/notis-spaces/references/release.md +6 -5
- package/dist/base-skills/notis-spaces/references/sdk.md +172 -48
- package/dist/base-skills/notis-spaces/references/troubleshooting.md +3 -0
- package/dist/base-skills/notis-spaces/references/views.md +20 -0
- package/dist/sdk/src/hooks/useNativeDocuments.ts +50 -12
- package/dist/sdk/src/hooks/useThreadItem.ts +56 -0
- package/dist/sdk/src/index.ts +7 -2
- package/dist/sdk/src/runtime.ts +8 -1
- package/dist/sdk/src/space.ts +233 -1
- package/dist/sdk/src/tailwind.ts +53 -3
- package/dist/sdk/src/ui/icons.tsx +1 -0
- package/dist/sdk/src/words/types.ts +28 -0
- package/dist/skill-sync/index.js +10 -90
- package/dist/skill-sync-worker.mjs +232 -120
- package/dist/space-harness/host.js +309 -96
- package/dist/space-sdk/dist/chunk-3DFOGU26.js +3 -0
- package/dist/space-sdk/dist/index.js +4 -2
- package/dist/space-sdk/dist/ui.js +19 -14
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +23 -0
- package/dist/space-sdk/src/hooks/useThreadItem.d.ts +28 -0
- package/dist/space-sdk/src/index.d.ts +4 -2
- package/dist/space-sdk/src/runtime.d.ts +8 -1
- package/dist/space-sdk/src/space.ts +233 -1
- package/dist/space-sdk/src/tailwind-candidates.d.ts +765 -16
- package/dist/space-sdk/src/tailwind.ts +53 -3
- package/dist/space-sdk/src/ui/actions/useToast.d.ts +2 -0
- package/dist/space-sdk/src/ui/blocks/DataTable.d.ts +19 -4
- package/dist/space-sdk/src/ui/blocks/Meter.d.ts +12 -3
- package/dist/space-sdk/src/ui/blocks/Tabs.d.ts +7 -1
- package/dist/space-sdk/src/ui/blocks/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/charts/CalendarHeatmap.d.ts +69 -0
- package/dist/space-sdk/src/ui/charts/Chart.d.ts +18 -3
- package/dist/space-sdk/src/ui/charts/chartData.d.ts +19 -0
- package/dist/space-sdk/src/ui/charts/heatmapData.d.ts +81 -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 +6 -3
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +6 -1
- package/dist/space-sdk/src/ui/list/Row.d.ts +11 -1
- package/dist/space-sdk/src/ui/overlay/Tooltip.d.ts +8 -2
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +2 -0
- package/dist/space-sdk/src/ui/period/dateWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/period/periods.d.ts +15 -2
- package/dist/space-sdk/src/ui/styles.d.ts +27 -5
- package/dist/space-sdk/src/words/types.ts +28 -0
- package/dist/view-renderer/dist/host.js +379 -166
- package/dist/view-renderer/src/dom.js +3 -2
- package/dist/view-renderer/src/errors.js +9 -0
- package/dist/view-renderer/src/host.tsx +18 -8
- package/dist/view-renderer/src/remote-broker.js +3 -1
- package/dist/view-renderer/src/renderer.js +87 -17
- package/dist/view-renderer/src/skeleton.js +70 -18
- package/package.json +5 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -1
- package/skills/notis-query/cli.md +3 -0
- 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 +101 -31
- package/src/command-specs/tools.js +3 -0
- package/src/runtime/agent-identity.js +187 -0
- package/src/runtime/api-hosts.generated.js +35 -0
- package/src/runtime/api-hosts.js +109 -0
- package/src/runtime/app-platform.js +68 -24
- package/src/runtime/channel.js +3 -7
- package/src/runtime/http-agent.js +53 -0
- package/src/runtime/native-record-files.js +11 -0
- package/src/runtime/oauth.js +97 -5
- package/src/runtime/profiles.js +200 -41
- package/src/runtime/skill-sync/cloud-client.ts +0 -10
- package/src/runtime/skill-sync/index.ts +13 -15
- package/src/runtime/skill-sync/local-scanner.ts +0 -67
- package/src/runtime/skill-sync/types.ts +1 -0
- package/src/runtime/skill-sync/write-cloud-skill.ts +7 -23
- package/src/runtime/skill-sync-service.js +4 -5
- package/src/runtime/space-dependencies.js +66 -0
- package/src/runtime/space-fixture-broker.js +23 -8
- package/src/runtime/space-platform.js +49 -3
- package/src/runtime/space-source.js +76 -2
- package/src/runtime/space-test-server.js +125 -10
- package/src/runtime/space-verification.js +106 -42
- package/src/runtime/space-view-manifest.js +38 -5
- package/src/runtime/telemetry.js +14 -1
- package/src/runtime/transport.js +31 -4
- package/src/runtime/upsell.js +3 -6
- package/src/runtime/view-render.js +6 -1
- package/src/skill-sync-worker.js +13 -2
- package/src/space-harness-host.ts +6 -3
- package/template/tailwind.config.ts +2 -35
- package/dist/space-sdk/dist/chunk-BFGB6XXC.js +0 -5
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,6 +1,6 @@
|
|
|
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';
|
|
3
|
-
import { buildSpaceArtifact, prepareSpaceRelease, requireSpaceIcon } from '../runtime/space-platform.js';
|
|
2
|
+
import { appFilesDigest, clearSpaceScreenshots, loadAppConfig, pullAppSource, resolveProjectDir, saveSpacePendingScreenshots, saveSpaceScreenshots, saveSpaceVerification, spacePublicationIntent, syncSpaceSdk } from '../runtime/app-platform.js';
|
|
3
|
+
import { buildSpaceArtifact, compileSpaceSqlReads, 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';
|
|
6
6
|
import { refreshSpaceAuthoring } from '../runtime/space-database-structures.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) {
|
|
@@ -131,11 +145,15 @@ function describePendingChanges(summary) {
|
|
|
131
145
|
|
|
132
146
|
const SKELETON_FILE = 'bundle/skeleton.json';
|
|
133
147
|
|
|
134
|
-
/**
|
|
148
|
+
/**
|
|
149
|
+
* Reviewable: where the screenshots of the loaded view are (each width in English and French, per fixture context),
|
|
150
|
+
* and each one that had not finished loading its data.
|
|
151
|
+
*/
|
|
135
152
|
function describeScreenshots(render) {
|
|
136
153
|
const renders = render?.renders || [];
|
|
137
154
|
const paths = renders.filter(value => value.loaded && value.screenshot_path).map(value => value.screenshot_path);
|
|
138
|
-
const parts =
|
|
155
|
+
const parts = render?.contexts?.length ? [`Fixture contexts checked: ${render.contexts.join(', ')}.`] : [];
|
|
156
|
+
if (paths.length) parts.push(`Screenshots after the data loaded: ${paths.join(', ')}.`);
|
|
139
157
|
for (const value of renders.filter(item => item.loaded === false)) {
|
|
140
158
|
const message = value.message;
|
|
141
159
|
if (message) parts.push(value.screenshot_path ? `${message.replace(/\.$/, '')}; ${value.screenshot_path} shows what it showed then.` : message);
|
|
@@ -148,11 +166,10 @@ function describeSkeleton(skeleton) {
|
|
|
148
166
|
if (!skeleton) return '';
|
|
149
167
|
const parts = [skeleton.status === 'captured' ? `Loading skeleton measured for ${skeleton.regions.join(', ')}${skeleton.audience === 'public' ? ', as the public sees the view' : ''}.`
|
|
150
168
|
: skeleton.status === 'failed' ? 'The loading skeleton could not be measured; the view keeps its fallback skeleton.' : ''];
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
parts.push(`Loading state warnings (${findings.length}): ${shown.join(' ')}${findings.length > 5 ? ` And ${findings.length - 5} more in the diagnostic.` : ''}`);
|
|
169
|
+
const groups = groupFindings(skeleton.findings || []);
|
|
170
|
+
if (groups.length) {
|
|
171
|
+
const shown = groups.slice(0, 5).map(value => `${value.where ? `[${value.where}] ` : ''}${value.message}`);
|
|
172
|
+
parts.push(`Loading state warnings (${groups.length}): ${shown.join(' ')}${groups.length > 5 ? ` And ${groups.length - 5} more in the diagnostic.` : ''}`);
|
|
156
173
|
}
|
|
157
174
|
const paths = (skeleton.pending_screenshots || []).map(value => value.path).filter(Boolean);
|
|
158
175
|
if (paths.length) parts.push(`Loading screenshots: ${paths.join(', ')}.`);
|
|
@@ -160,6 +177,25 @@ function describeSkeleton(skeleton) {
|
|
|
160
177
|
return text ? ` ${text}` : '';
|
|
161
178
|
}
|
|
162
179
|
|
|
180
|
+
/**
|
|
181
|
+
* One line per identical finding across widths and locales: `{ where: '390 and 1440, EN and FR, reader', message }`.
|
|
182
|
+
* The reader's loading state and each fixture context stay apart.
|
|
183
|
+
*/
|
|
184
|
+
function groupFindings(findings) {
|
|
185
|
+
const groups = new Map();
|
|
186
|
+
for (const value of findings) {
|
|
187
|
+
const id = JSON.stringify([value.check, value.message, value.region ?? null, value.state ?? null, value.context ?? null]);
|
|
188
|
+
const group = groups.get(id) || { widths: new Set(), locales: new Set(), state: value.state, context: value.context, message: value.message };
|
|
189
|
+
if (value.width) group.widths.add(value.width);
|
|
190
|
+
if (value.locale) group.locales.add(value.locale);
|
|
191
|
+
groups.set(id, group);
|
|
192
|
+
}
|
|
193
|
+
const and = values => values.join(' and ');
|
|
194
|
+
return [...groups.values()].map(group => ({ message: group.message, where: [and([...group.widths].sort((a, b) => a - b)),
|
|
195
|
+
and([...group.locales].sort().map(value => value.toUpperCase())), group.context ? `context ${group.context}` : '', group.state || '']
|
|
196
|
+
.filter(Boolean).join(', ') }));
|
|
197
|
+
}
|
|
198
|
+
|
|
163
199
|
/** Same server verification for this Space, source, grants and authorization mode. */
|
|
164
200
|
function sameVerification(verification, body, sourceDigest) {
|
|
165
201
|
return verification?.valid === true && verification.space_id === body.space_id && verification.source_digest === sourceDigest
|
|
@@ -167,9 +203,31 @@ function sameVerification(verification, body, sourceDigest) {
|
|
|
167
203
|
&& (verification.authorization_mode ?? 'authorize_missing') === (body.authorization_mode ?? 'authorize_missing');
|
|
168
204
|
}
|
|
169
205
|
|
|
206
|
+
// What each server step of a verify or deploy is doing, said before it starts so a long wait never looks like a hang.
|
|
207
|
+
const RELEASE_STEPS = { 'sql-reads': 'Compiling the SQL reads', 'source-verify': 'Checking the source and its authorizations',
|
|
208
|
+
'source-publish': 'Publishing', 'source-stage': 'Preparing the candidate revision' };
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* A verify or deploy whose server step got no answer says how to continue: a deploy resumes under the same
|
|
212
|
+
* request ID (the server finishes or confirms that release, never a second one); a verify published nothing.
|
|
213
|
+
*/
|
|
214
|
+
function resumableReleaseError(error, ctx, intentKey) {
|
|
215
|
+
if (!(error instanceof CliError) || !['network_error', 'network_timeout'].includes(error.code)) return error;
|
|
216
|
+
// The same command: its folder, --space, --space-id and --profile decide which release the request ID resumes.
|
|
217
|
+
const command = `notis ${ctx.spec.command_path.join(' ')}`;
|
|
218
|
+
const next = intentKey
|
|
219
|
+
? `Nothing is lost: run the same ${command} command again (same folder and options) with --request-id ${intentKey}; `
|
|
220
|
+
+ 'it resumes this release and never publishes it twice.'
|
|
221
|
+
: `Nothing was published: run the same ${command} command again.`;
|
|
222
|
+
return new CliError({ code: error.code, message: `${error.message} ${next}`, exitCode: error.exitCode, retryable: true,
|
|
223
|
+
details: { ...error.details, ...(intentKey ? { request_id_to_reuse: intentKey } : {}) },
|
|
224
|
+
hints: [intentKey ? { command: `--request-id ${intentKey}`, reason: `Add to the same ${command} command to resume this release` }
|
|
225
|
+
: { command, reason: 'Run the same command again' }, ...(error.hints || [])], cause: error.cause });
|
|
226
|
+
}
|
|
227
|
+
|
|
170
228
|
async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
171
|
-
const { directory, key } = selected(ctx);
|
|
172
|
-
|
|
229
|
+
const { directory, key } = await selected(ctx);
|
|
230
|
+
const spaceId = destinationSpaceId(ctx, directory);
|
|
173
231
|
const intentKey = publish ? requestId(ctx) : null;
|
|
174
232
|
// A verify that stops at any point (a build older than its source, a refused source check, a cancelled render), or
|
|
175
233
|
// a release without a loading skeleton, leaves no image of an older build.
|
|
@@ -177,17 +235,23 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
177
235
|
const release = await prepareSpaceRelease(directory, key);
|
|
178
236
|
try {
|
|
179
237
|
if (publish) requireSpaceIcon(release.manifest, key);
|
|
180
|
-
const
|
|
238
|
+
const call = async (operation, data) => {
|
|
239
|
+
ctx.output.emitProgress?.({ phase: operation, message: `${RELEASE_STEPS[operation] || operation} on the server` });
|
|
240
|
+
try {
|
|
241
|
+
return await httpRequest({ runtime: { ...ctx.runtime, timeoutMs: Math.max(ctx.runtime.timeoutMs || 0, 600_000) },
|
|
242
|
+
method: 'POST', path: `/portal_spaces/${operation}`, body: data, spacesProtocol: true });
|
|
243
|
+
} catch (error) { throw resumableReleaseError(error, ctx, publish && !ctx.options.dryRun ? intentKey : null); }
|
|
244
|
+
};
|
|
245
|
+
const compiledReads = await compileSpaceSqlReads(release, call);
|
|
246
|
+
const identity = [ctx.runtime.apiBase.replace(/\/$/, ''), ctx.runtime.profileName, key, spaceId, intentKey];
|
|
181
247
|
let verification = publish && !ctx.options.dryRun ? spacePublicationIntent(directory, identity) : null;
|
|
182
|
-
const local = intentChanges(directory,
|
|
183
|
-
localSpaceChanges(directory,
|
|
184
|
-
const body = { space_id:
|
|
248
|
+
const local = intentChanges(directory, spaceId, release.manifest,
|
|
249
|
+
localSpaceChanges(directory, spaceId, release.manifest), verification);
|
|
250
|
+
const body = { space_id: spaceId, manifest: release.manifest, source_files: release.sourceFiles,
|
|
185
251
|
artifact_files: release.files, reuse_grants: object(ctx.options.reuseGrants || '{}', '--reuse-grants'),
|
|
186
252
|
...(ctx.options.reuseGrantsOnly ? { authorization_mode: 'reuse_only' } : {}),
|
|
187
253
|
...(local.changes ? { changes: local.changes } : {}) };
|
|
188
254
|
const sourceDigest = appFilesDigest(release.sourceFiles), builtDigest = appFilesDigest(release.files);
|
|
189
|
-
const call = (operation, data) => httpRequest({ runtime: { ...ctx.runtime, timeoutMs: Math.max(ctx.runtime.timeoutMs || 0, 600_000) },
|
|
190
|
-
method: 'POST', path: `/portal_spaces/${operation}`, body: data, spacesProtocol: true });
|
|
191
255
|
if (verification && (verification.local_changes_fingerprint ?? null) !== local.fingerprint) {
|
|
192
256
|
throw usageError('This request ID belongs to different Skill folders or list entries. Restore the state you first deployed to retry, or use a new request ID for a new release.');
|
|
193
257
|
}
|
|
@@ -206,6 +270,7 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
206
270
|
const cancel = () => controller.abort();
|
|
207
271
|
process.once('SIGINT', cancel); process.once('SIGTERM', cancel);
|
|
208
272
|
let render;
|
|
273
|
+
ctx.output.emitProgress?.({ phase: 'render', message: 'Rendering the fixtures in a local browser' });
|
|
209
274
|
try { render = await verifySpaceRelease(release, { capabilities: verification.capabilities, signal: controller.signal,
|
|
210
275
|
authorizationMode: body.authorization_mode, unavailableActions: verification.unavailable_actions,
|
|
211
276
|
// Test seam only: the command context never carries it from user options.
|
|
@@ -213,7 +278,7 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
213
278
|
finally { process.removeListener('SIGINT', cancel); process.removeListener('SIGTERM', cancel); }
|
|
214
279
|
const saved = saveSpaceScreenshots(directory, key, render.screenshots || []);
|
|
215
280
|
if (render.renders) render.renders = render.renders.map(value => {
|
|
216
|
-
const path = saved.find(item => item.width === value.width)?.path;
|
|
281
|
+
const path = saved.find(item => item.width === value.width && item.locale === value.locale && item.context === value.context)?.path;
|
|
217
282
|
return path ? { ...value, screenshot_path: path } : value;
|
|
218
283
|
});
|
|
219
284
|
if (render.skeleton) {
|
|
@@ -265,8 +330,9 @@ async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
|
265
330
|
? (await call(stageOnly ? 'source-stage' : 'source-publish', { ...body, verification: serverVerification, request_id: intentKey })).payload
|
|
266
331
|
: serverVerification;
|
|
267
332
|
if (publish && !ctx.options.dryRun && !stageOnly) recordPublication(directory, local, result);
|
|
268
|
-
const data = { ...result, render, diagnostic_path: diagnosticPath, ...(local.summary ? { local_changes: local.summary } : {})
|
|
269
|
-
|
|
333
|
+
const data = { ...result, render, diagnostic_path: diagnosticPath, ...(local.summary ? { local_changes: local.summary } : {}),
|
|
334
|
+
...(compiledReads.length ? { compiled_sql_reads: compiledReads } : {}) };
|
|
335
|
+
const skeletonSummary = describeSkeleton(render.skeleton) + (compiledReads.length ? ` Compiled the SQL read${compiledReads.length > 1 ? 's' : ''} ${compiledReads.join(', ')}.` : ''), screenshotSummary = describeScreenshots(render);
|
|
270
336
|
return ctx.output.emitSuccess({ command: ctx.spec.command_path.join(' '), data,
|
|
271
337
|
humanSummary: publish && !ctx.options.dryRun
|
|
272
338
|
? stageOnly ? `Prepared ${key} as revision ${result.candidate_revision}. ${result.preview_url || 'This container has no executable preview.'} Live source was not changed.${describePendingChanges(local.summary).replace(/\.$/, '; they go live with notis spaces promote.')}${screenshotSummary}`
|
|
@@ -691,8 +757,8 @@ export const spacesCommandSpecs = [
|
|
|
691
757
|
: operation === 'preview' ? 'Review a checked candidate using current Editor access without changing live source or cloning the Space.'
|
|
692
758
|
: 'Update only the selected existing Space; this does not publish to the Store or change siblings.',
|
|
693
759
|
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.' },
|
|
760
|
+
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace index. Optional when the workspace holds one Space.' },
|
|
761
|
+
{ flags: '--space-id <id>', description: 'Exact existing destination Space. Optional in a pulled workspace: the Space it was pulled from.' },
|
|
696
762
|
{ flags: '--reuse-grants <json>', description: 'Explicit action-key to saved-grant-ID map. Otherwise your own connections are used.' },
|
|
697
763
|
{ flags: '--reuse-grants-only', description: 'Never authorize new actions. Reuse only the supplied saved grants; other declarations remain unavailable. Requires existing bound databases.' },
|
|
698
764
|
...(operation !== 'verify' ? [requestOption, { flags: '--dry-run', description: 'Validate without uploading or publishing.' }] : [])] },
|
|
@@ -906,14 +972,18 @@ export const spacesCommandSpecs = [
|
|
|
906
972
|
summary: 'Build one independent Space and save its frozen source/artifact snapshot.',
|
|
907
973
|
when_to_use: 'Prepare a selected Space for verification without publishing it or changing siblings.',
|
|
908
974
|
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.' }] },
|
|
975
|
+
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace Space index. Optional when the workspace holds one Space.' }] },
|
|
910
976
|
examples: ['notis spaces build . --space overview'],
|
|
911
977
|
mutates: true, idempotent: true, require_auth: false,
|
|
912
978
|
backend_call: { type: 'local', name: 'space_build' },
|
|
913
979
|
async handler(ctx) {
|
|
914
|
-
const { directory, key } = selected(ctx);
|
|
915
|
-
|
|
916
|
-
|
|
980
|
+
const { directory, key } = await selected(ctx);
|
|
981
|
+
// A folder with no packages yet (a copy, a fresh clone) installs them once here, never asking for a separate npm ci.
|
|
982
|
+
const result = await buildSpaceArtifact(directory, key, { stdio: ctx.output.isMachineMode() ? 'pipe' : 'inherit', installDependencies: true,
|
|
983
|
+
installLog: message => ctx.output.emitProgress?.({ phase: 'install', message }) });
|
|
984
|
+
const installed = result.installed_dependencies;
|
|
985
|
+
return ctx.output.emitSuccess({ command: 'spaces build', data: result,
|
|
986
|
+
humanSummary: `${installed ? `Installed this Space's packages (${installed.command}, ${installed.seconds} s). ` : ''}Built ${key}; no Space was published.` });
|
|
917
987
|
},
|
|
918
988
|
},
|
|
919
989
|
{
|
|
@@ -921,12 +991,12 @@ export const spacesCommandSpecs = [
|
|
|
921
991
|
summary: 'Inspect one local Space definition and its declared capabilities.',
|
|
922
992
|
when_to_use: 'Read the selected source definition without loading sibling definitions or account resources.',
|
|
923
993
|
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.' }] },
|
|
994
|
+
options: [{ flags: '--space <key>', description: 'Exact source key from the workspace Space index. Optional when the workspace holds one Space.' }] },
|
|
925
995
|
examples: ['notis spaces inspect . --space overview'],
|
|
926
996
|
mutates: false, idempotent: true, require_auth: false,
|
|
927
997
|
backend_call: { type: 'local', name: 'space_source_inspect' },
|
|
928
998
|
async handler(ctx) {
|
|
929
|
-
const { directory, key } = selected(ctx);
|
|
999
|
+
const { directory, key } = await selected(ctx);
|
|
930
1000
|
const selection = await loadSelectedSpace(directory, key);
|
|
931
1001
|
return ctx.output.emitSuccess({ command: 'spaces inspect', data: { key, definition: selection.definition, definition_path: selection.definitionPath },
|
|
932
1002
|
humanSummary: `${selection.definition.name} (${key})` });
|
|
@@ -2,6 +2,7 @@ import { accessSync, constants as fsConstants, createReadStream, existsSync, rea
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { basename } from 'node:path';
|
|
4
4
|
import { usageError } from '../runtime/errors.js';
|
|
5
|
+
import { ENV_FILE_MESSAGE, isEnvFileName } from '../runtime/native-record-files.js';
|
|
5
6
|
import {
|
|
6
7
|
canPrompt,
|
|
7
8
|
createStderrPrompter,
|
|
@@ -296,6 +297,7 @@ async function parseFileBindingSpec(spec, index) {
|
|
|
296
297
|
if (!localPath) {
|
|
297
298
|
throw usageError('--file local path is required');
|
|
298
299
|
}
|
|
300
|
+
if (isEnvFileName(localPath)) throw usageError(ENV_FILE_MESSAGE);
|
|
299
301
|
if (!existsSync(localPath)) {
|
|
300
302
|
throw usageError(`File not found: ${localPath}`);
|
|
301
303
|
}
|
|
@@ -762,6 +764,7 @@ export const toolsCommandSpecs = [
|
|
|
762
764
|
},
|
|
763
765
|
examples: [
|
|
764
766
|
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --arguments \'{"database_slug":"tasks","query":{}}\'',
|
|
767
|
+
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --arguments \'{"protocol":1,"target":{"database_id":"<database id>"},"input":{"mode":"rows"}}\'',
|
|
765
768
|
'notis tools exec LOCAL_NOTIS_DATABASE_GET_DATABASE --arguments \'{"database_slug":"tasks"}\'',
|
|
766
769
|
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --get-schema',
|
|
767
770
|
'notis tools exec LOCAL_NOTIS_DATABASE_QUERY --dry-run --arguments \'{"database_slug":"tasks","query":{}}\'',
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// GENERATED by scripts/generate_channel_hosts.py from server/lib/release_channels.py
|
|
2
|
+
// (CHANNEL_ORIGINS and _LEGACY_HOSTNAMES). Do not edit: change the server list, then run
|
|
3
|
+
// python3 scripts/generate_channel_hosts.py
|
|
4
|
+
|
|
5
|
+
/** Each channel's public origin per surface. */
|
|
6
|
+
export const CHANNEL_ORIGINS = {
|
|
7
|
+
stable: {
|
|
8
|
+
portal: 'https://app.notis.ai',
|
|
9
|
+
api: 'https://api.notis.ai',
|
|
10
|
+
mcp: 'https://mcp.notis.ai',
|
|
11
|
+
realtime: 'wss://realtime.notis.ai',
|
|
12
|
+
},
|
|
13
|
+
nightly: {
|
|
14
|
+
portal: 'https://app-nightly.notis.ai',
|
|
15
|
+
api: 'https://api-nightly.notis.ai',
|
|
16
|
+
mcp: 'https://mcp-nightly.notis.ai',
|
|
17
|
+
realtime: 'wss://realtime-nightly.notis.ai',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Each channel's hostnames per surface, the current name first, then the retired ones. */
|
|
22
|
+
export const CHANNEL_HOSTNAMES = {
|
|
23
|
+
stable: {
|
|
24
|
+
portal: ['app.notis.ai'],
|
|
25
|
+
api: ['api.notis.ai'],
|
|
26
|
+
mcp: ['mcp.notis.ai'],
|
|
27
|
+
realtime: ['realtime.notis.ai', 'websocket-prod.onrender.com'],
|
|
28
|
+
},
|
|
29
|
+
nightly: {
|
|
30
|
+
portal: ['app-nightly.notis.ai'],
|
|
31
|
+
api: ['api-nightly.notis.ai'],
|
|
32
|
+
mcp: ['mcp-nightly.notis.ai'],
|
|
33
|
+
realtime: ['realtime-nightly.notis.ai', 'notis-websocket.onrender.com'],
|
|
34
|
+
},
|
|
35
|
+
};
|