@notis_ai/cli 0.2.25 → 0.2.27
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 +186 -5
- package/config/notis_app_design_rules.json +36 -14
- package/config/portal-route-roots.json +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +2866 -553
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/SKILL.md +0 -1
- package/dist/base-skills/notis-query/references/documents.md +7 -0
- package/dist/base-skills/notis-query/references/query.md +1 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +96 -24
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
- package/dist/base-skills/notis-spaces/references/context.md +3 -0
- package/dist/base-skills/notis-spaces/references/design.md +37 -18
- package/dist/base-skills/notis-spaces/references/reading.md +8 -1
- package/dist/base-skills/notis-spaces/references/reports.md +6 -6
- package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
- package/dist/base-skills/notis-spaces/references/store.md +22 -13
- package/dist/base-skills/notis-spaces/references/views.md +99 -6
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/src/cloudComputerWords.ts +53 -0
- package/dist/sdk/src/components/Audience.tsx +76 -0
- package/dist/sdk/src/components/DocumentPage.tsx +15 -4
- package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
- package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
- package/dist/sdk/src/components/NotisSelectionBoundary.tsx +79 -25
- package/dist/sdk/src/components/Skeleton.tsx +162 -6
- package/dist/sdk/src/hooks/useAction.ts +12 -2
- package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
- package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
- package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
- package/dist/sdk/src/hooks/useItemThread.ts +58 -0
- package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
- package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
- package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
- package/dist/sdk/src/hooks/useQuery.ts +67 -10
- package/dist/sdk/src/hooks/useViewParams.ts +47 -11
- package/dist/sdk/src/index.ts +31 -4
- package/dist/sdk/src/interactions.ts +2 -0
- package/dist/sdk/src/nativeData.ts +2 -0
- package/dist/sdk/src/optimisticRows.ts +329 -0
- package/dist/sdk/src/perf.ts +188 -0
- package/dist/sdk/src/provider.tsx +2 -1
- package/dist/sdk/src/queryCache.ts +366 -17
- package/dist/sdk/src/runtime.ts +55 -4
- package/dist/sdk/src/skeleton.ts +103 -0
- package/dist/sdk/src/space.ts +662 -28
- package/dist/sdk/src/spacePublicUI.ts +36 -0
- package/dist/sdk/src/ui/engine/step.ts +54 -0
- package/dist/sdk/src/ui/icons.tsx +3 -1
- package/dist/sdk/src/words/shell.ts +1 -0
- package/dist/skill-sync/index.js +88 -13
- package/dist/skill-sync-worker.mjs +127 -38
- package/dist/space-harness/host.js +272 -105
- package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
- package/dist/space-sdk/dist/index.js +9 -4
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/package.json +3 -0
- package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
- package/dist/space-sdk/src/components/Audience.d.ts +46 -0
- package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
- package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
- package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
- package/dist/space-sdk/src/components/NotisSelectionBoundary.d.ts +19 -2
- package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
- package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
- package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
- package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
- package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
- package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
- package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
- package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
- package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
- package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
- package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
- package/dist/space-sdk/src/index.d.ts +24 -4
- package/dist/space-sdk/src/nativeData.d.ts +6 -0
- package/dist/space-sdk/src/queryCache.d.ts +97 -2
- package/dist/space-sdk/src/runtime.d.ts +53 -4
- package/dist/space-sdk/src/skeleton.d.ts +42 -0
- package/dist/space-sdk/src/space.ts +662 -28
- package/dist/space-sdk/src/tailwind-candidates.d.ts +761 -6
- package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
- package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
- package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
- package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
- package/dist/space-sdk/src/ui/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
- package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
- package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
- package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
- package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
- package/dist/space-sdk/src/words/shell.ts +1 -0
- package/dist/view-renderer/dist/host.js +355 -188
- package/dist/view-renderer/dist/theme.css +1 -1
- package/dist/view-renderer/src/dom.js +15 -2
- package/dist/view-renderer/src/host.tsx +4 -1
- package/dist/view-renderer/src/index.js +3 -0
- package/dist/view-renderer/src/pool.js +8 -4
- package/dist/view-renderer/src/renderer.js +92 -23
- package/dist/view-renderer/src/skeleton.js +450 -0
- package/package.json +4 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
- package/skills/notis-onboarding/BRIEF.md +15 -9
- package/skills/notis-spaces/cli.md +43 -4
- package/src/command-specs/auth.js +5 -3
- package/src/command-specs/cc.js +410 -0
- package/src/command-specs/computer.js +320 -0
- package/src/command-specs/diagnostics.js +2 -13
- package/src/command-specs/documents.js +22 -4
- package/src/command-specs/index.js +7 -0
- package/src/command-specs/onboarding.js +127 -7
- package/src/command-specs/skills.js +2 -2
- package/src/command-specs/spaces.js +162 -30
- package/src/command-specs/tools.js +26 -8
- package/src/command-specs/views.js +4 -1
- package/src/runtime/agent-setup.js +20 -2
- package/src/runtime/app-boundary-validator.js +2 -1
- package/src/runtime/app-platform.js +13 -0
- package/src/runtime/auth-recovery.js +5 -0
- package/src/runtime/channel.js +16 -2
- package/src/runtime/cloud-transfer.js +587 -0
- package/src/runtime/computer-ssh.js +127 -0
- package/src/runtime/oauth.js +50 -4
- package/src/runtime/skill-sync/cloud-client.ts +98 -15
- package/src/runtime/skill-sync/index.ts +42 -4
- package/src/runtime/skill-sync/local-scanner.ts +1 -0
- package/src/runtime/skill-sync/types.ts +6 -0
- package/src/runtime/space-audience.js +94 -0
- package/src/runtime/space-collection-scaffold.js +2 -1
- package/src/runtime/space-fixture-broker.js +2 -1
- package/src/runtime/space-lock.js +1 -4
- package/src/runtime/space-platform.js +18 -2
- package/src/runtime/space-source.js +105 -7
- package/src/runtime/space-test-server.js +13 -2
- package/src/runtime/space-verification.js +99 -6
- package/src/runtime/space-view-manifest.js +22 -4
- package/src/runtime/sync-skills.js +24 -20
- package/src/runtime/transport.js +19 -0
- package/src/runtime/view-render.js +2 -2
- package/src/skill-sync-worker.js +5 -1
- package/template/.harness/index.html.tmpl +1 -1
- package/dist/skill-sync/index.js.map +0 -7
- package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// `notis computer ssh`: SSH from this device to the user's Cloud Computer.
|
|
2
|
+
//
|
|
3
|
+
// --setup makes this device's key, registers it, and writes the
|
|
4
|
+
// `notis-computer` SSH host so `ssh notis-computer` (and tools such as T3 that
|
|
5
|
+
// read ~/.ssh/config) connect. --proxy is that host's ProxyCommand: it asks
|
|
6
|
+
// Notis where the computer is, fails fast while a stopped computer starts (the
|
|
7
|
+
// caller's retry connects), saves the current host key and relays the bytes.
|
|
8
|
+
// With neither, the command sets up when needed, waits for the computer and
|
|
9
|
+
// runs ssh.
|
|
10
|
+
//
|
|
11
|
+
// `notis computer status | restart | recover` (CC-150, CC-151) go through
|
|
12
|
+
// LOCAL_NOTIS_GET_CLOUD_COMPUTER and LOCAL_NOTIS_MANAGE_CLOUD_COMPUTER, so the
|
|
13
|
+
// server keeps every check. Restart and recover preview first and ask.
|
|
14
|
+
|
|
15
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
16
|
+
import { randomUUID } from 'node:crypto';
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { connect as netConnect } from 'node:net';
|
|
19
|
+
import { CliError, EXIT_CODES, asCliError, usageError } from '../runtime/errors.js';
|
|
20
|
+
import {
|
|
21
|
+
canPrompt, createStderrPrompter, extractToolResult, findConfirmationPreview, renderPreview, resolveConfirmation,
|
|
22
|
+
} from '../runtime/tool-confirmation.js';
|
|
23
|
+
import { runToolCommand } from './helpers.js';
|
|
24
|
+
import { httpRequest } from '../runtime/transport.js';
|
|
25
|
+
import { readComputerIdentity } from '../runtime/computer-identity.js';
|
|
26
|
+
import { resolveConfigFile } from '../runtime/profiles.js';
|
|
27
|
+
import {
|
|
28
|
+
SSH_HOST_ALIAS, parseConnectReply, sshPaths, writeHostKey, writeSshFiles,
|
|
29
|
+
} from '../runtime/computer-ssh.js';
|
|
30
|
+
|
|
31
|
+
const PATH = '/cloud_computer_ssh';
|
|
32
|
+
const GET_TOOL = 'LOCAL_NOTIS_GET_CLOUD_COMPUTER';
|
|
33
|
+
const MANAGE_TOOL = 'LOCAL_NOTIS_MANAGE_CLOUD_COMPUTER';
|
|
34
|
+
const WAIT_TIMEOUT_MS = 240_000;
|
|
35
|
+
const PROXY_TIMEOUT_MS = 90_000;
|
|
36
|
+
|
|
37
|
+
function readPublicKey(paths) {
|
|
38
|
+
return existsSync(paths.publicKey) ? readFileSync(paths.publicKey, 'utf8').trim() : '';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function makeKey(paths, deviceName) {
|
|
42
|
+
mkdirSync(paths.dir, { recursive: true, mode: 0o700 });
|
|
43
|
+
const result = spawnSync('ssh-keygen', [
|
|
44
|
+
'-q', '-t', 'ed25519', '-N', '', '-C', `notis-computer@${deviceName}`, '-f', paths.key,
|
|
45
|
+
], { encoding: 'utf8' });
|
|
46
|
+
if (result.error || result.status !== 0) {
|
|
47
|
+
throw new CliError({
|
|
48
|
+
code: 'ssh_keygen_failed',
|
|
49
|
+
message: 'Could not create an SSH key on this device. Check that OpenSSH (ssh-keygen) is installed.',
|
|
50
|
+
exitCode: EXIT_CODES.unexpected,
|
|
51
|
+
details: { stderr: String(result.stderr || result.error?.message || '').slice(0, 2000) },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function post(runtime, body, timeoutMs) {
|
|
57
|
+
return httpRequest({ runtime, method: 'POST', path: PATH, body, ...(timeoutMs ? { timeoutMs } : {}) });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function setup(ctx, paths) {
|
|
61
|
+
if (process.platform === 'win32') {
|
|
62
|
+
throw usageError('notis computer ssh works on macOS and Linux.');
|
|
63
|
+
}
|
|
64
|
+
const deviceName = readComputerIdentity().displayName;
|
|
65
|
+
if (!readPublicKey(paths)) makeKey(paths, deviceName);
|
|
66
|
+
const publicKey = readPublicKey(paths);
|
|
67
|
+
const registered = await post(ctx.runtime, { operation: 'register', public_key: publicKey, device_name: deviceName });
|
|
68
|
+
writeSshFiles({
|
|
69
|
+
paths,
|
|
70
|
+
nodePath: process.execPath,
|
|
71
|
+
cliPath: process.argv[1],
|
|
72
|
+
profileName: ctx.runtime.profileName,
|
|
73
|
+
// Only a config moved with NOTIS_CLI_CONFIG_FILE needs pinning.
|
|
74
|
+
configFile: process.env.NOTIS_CLI_CONFIG_FILE ? resolveConfigFile() : undefined,
|
|
75
|
+
});
|
|
76
|
+
// Checks the plan (the upsell comes back here) and starts a stopped computer.
|
|
77
|
+
const connected = await post(ctx.runtime, { operation: 'connect', public_key: publicKey, wait: false });
|
|
78
|
+
if (parseConnectReply(connected.payload)) writeHostKey(paths, connected.payload.host_key);
|
|
79
|
+
return { key: registered.payload?.key, status: connected.payload?.status, publicKey };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function proxyFail(message) {
|
|
83
|
+
process.stderr.write(`notis computer ssh: ${message}\n`);
|
|
84
|
+
return EXIT_CODES.backend;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function proxy(ctx, paths) {
|
|
88
|
+
try {
|
|
89
|
+
const publicKey = readPublicKey(paths);
|
|
90
|
+
if (!publicKey) return proxyFail('this device is not set up. Run: notis computer ssh --setup');
|
|
91
|
+
const { payload } = await post(ctx.runtime, { operation: 'connect', public_key: publicKey, wait: false }, PROXY_TIMEOUT_MS);
|
|
92
|
+
if (payload?.status === 'starting') {
|
|
93
|
+
return proxyFail(payload.message || 'your Cloud Computer is starting. Connect again in a few seconds.');
|
|
94
|
+
}
|
|
95
|
+
const target = parseConnectReply(payload);
|
|
96
|
+
if (!target) return proxyFail('Notis did not say where your Cloud Computer is. Try again.');
|
|
97
|
+
if (!writeHostKey(paths, target.hostKey)) return proxyFail('Notis did not send the computer\'s host key. Try again.');
|
|
98
|
+
return await relay(target);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return proxyFail(asCliError(error).message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function relay({ host, port }) {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
const socket = netConnect({ host, port });
|
|
107
|
+
let settled = false;
|
|
108
|
+
const finish = (code) => {
|
|
109
|
+
if (settled) return;
|
|
110
|
+
settled = true;
|
|
111
|
+
process.stdin.unpipe(socket);
|
|
112
|
+
process.stdin.pause();
|
|
113
|
+
process.stdin.unref?.();
|
|
114
|
+
resolve(code);
|
|
115
|
+
};
|
|
116
|
+
socket.once('connect', () => {
|
|
117
|
+
process.stdin.pipe(socket);
|
|
118
|
+
socket.pipe(process.stdout);
|
|
119
|
+
});
|
|
120
|
+
socket.once('error', (error) => {
|
|
121
|
+
process.stderr.write(`notis computer ssh: could not reach your Cloud Computer (${error.code || error.message}).\n`);
|
|
122
|
+
finish(EXIT_CODES.network);
|
|
123
|
+
});
|
|
124
|
+
socket.once('close', () => finish(0));
|
|
125
|
+
process.stdin.once('end', () => socket.end());
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function waitForComputer(ctx, publicKey) {
|
|
130
|
+
const { payload } = await post(ctx.runtime, { operation: 'connect', public_key: publicKey, wait: true }, WAIT_TIMEOUT_MS);
|
|
131
|
+
if (!parseConnectReply(payload)) {
|
|
132
|
+
throw new CliError({
|
|
133
|
+
code: 'cloud_computer_not_ready', exitCode: EXIT_CODES.backend, details: payload || {},
|
|
134
|
+
message: payload?.message || 'Your Cloud Computer did not start. Try again in a moment.',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function runSsh(args) {
|
|
140
|
+
return new Promise((resolve) => {
|
|
141
|
+
const child = spawn('ssh', [SSH_HOST_ALIAS, ...args], { stdio: 'inherit' });
|
|
142
|
+
child.once('error', () => {
|
|
143
|
+
process.stderr.write('notis computer ssh: ssh is not installed on this device.\n');
|
|
144
|
+
resolve(EXIT_CODES.unexpected);
|
|
145
|
+
});
|
|
146
|
+
child.once('exit', (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function keyLine(key) {
|
|
151
|
+
const used = key.last_used_at ? `last used ${key.last_used_at}` : 'never used';
|
|
152
|
+
return `${key.key_id} ${key.device_name || 'unnamed device'} ${key.fingerprint} ${used}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** One Cloud Computer tool call; a refusal (status error) becomes a CliError. */
|
|
156
|
+
async function callComputer(ctx, toolName, args, idempotencyKey) {
|
|
157
|
+
const result = await runToolCommand({ runtime: ctx.runtime, toolName, arguments_: args,
|
|
158
|
+
mutating: toolName === MANAGE_TOOL, idempotencyKey, sendIdempotencyKeyWhenReading: true });
|
|
159
|
+
const payload = extractToolResult(result.payload) || {};
|
|
160
|
+
if (payload.status === 'error') {
|
|
161
|
+
throw new CliError({
|
|
162
|
+
code: payload.code || 'cloud_computer_error', exitCode: EXIT_CODES.backend, details: payload,
|
|
163
|
+
message: payload.message || 'The Cloud Computer could not do this.',
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return { result, payload };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const STATUS_LINES = {
|
|
170
|
+
running: 'Your Cloud Computer is working.',
|
|
171
|
+
stopped: 'Your Cloud Computer is asleep. It wakes up when Notis has work to do.',
|
|
172
|
+
moving: 'Your Cloud Computer is moving to a bigger disk.',
|
|
173
|
+
none: 'You have no Cloud Computer yet. It starts the first time Notis needs it.',
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
function statusText(computer) {
|
|
177
|
+
if (computer.status !== 'not_responding') return STATUS_LINES[computer.status] || STATUS_LINES.none;
|
|
178
|
+
const reason = computer.status_reason ? ` Reason: ${computer.status_reason}.` : '';
|
|
179
|
+
const saved = computer.last_saved_at ? ` Last saved ${computer.last_saved_at}.` : '';
|
|
180
|
+
return `Your Cloud Computer is not responding.${reason}${saved} Restart it with: notis computer restart`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function machineAction(ctx, action) {
|
|
184
|
+
const command = `computer ${action}`;
|
|
185
|
+
// As in notis tools exec: a key the caller chose takes the preview, and the confirming call
|
|
186
|
+
// takes that key plus ".confirm", so a retry with the same key replays both answers.
|
|
187
|
+
const callerKey = ctx.globalOptions.idempotencyKey;
|
|
188
|
+
const first = await callComputer(ctx, MANAGE_TOOL, { action }, callerKey || randomUUID());
|
|
189
|
+
const preview = findConfirmationPreview(first.payload);
|
|
190
|
+
if (!preview) {
|
|
191
|
+
throw new CliError({ code: 'cloud_computer_preview_missing', exitCode: EXIT_CODES.backend, details: first.payload,
|
|
192
|
+
message: 'Notis did not say what this would do. Nothing changed.' });
|
|
193
|
+
}
|
|
194
|
+
const yes = Boolean(ctx.options.yes);
|
|
195
|
+
const interactive = canPrompt({ runtime: ctx.runtime, output: ctx.output });
|
|
196
|
+
const previewText = renderPreview(preview);
|
|
197
|
+
if (interactive && !yes) process.stderr.write(`${previewText}\n`);
|
|
198
|
+
const prompter = interactive && !yes ? createStderrPrompter() : null;
|
|
199
|
+
let decision;
|
|
200
|
+
try {
|
|
201
|
+
decision = await resolveConfirmation({ preview, yes, interactive, ask: (question) => prompter.ask(question) });
|
|
202
|
+
} finally {
|
|
203
|
+
prompter?.close();
|
|
204
|
+
}
|
|
205
|
+
if (decision.decision !== 'apply') {
|
|
206
|
+
const reason = decision.decision === 'not_interactive'
|
|
207
|
+
? `Nothing has changed. Run notis computer ${action} --yes to apply it.` : decision.reason;
|
|
208
|
+
return ctx.output.emitSuccess({
|
|
209
|
+
command, data: first.payload, requestId: first.result.requestId, humanSummary: reason,
|
|
210
|
+
hints: decision.decision === 'not_interactive' ? [{ command: `notis computer ${action} --yes`, reason: 'Apply it' }] : [],
|
|
211
|
+
meta: { mutating: false, confirmation: decision.decision, applied: false },
|
|
212
|
+
renderHuman: () => (interactive && !yes ? reason : `${previewText}\n\n${reason}`),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const applied = await callComputer(ctx, MANAGE_TOOL, decision.arguments,
|
|
216
|
+
callerKey ? `${callerKey}.confirm` : randomUUID());
|
|
217
|
+
return ctx.output.emitSuccess({
|
|
218
|
+
command, data: applied.payload, requestId: applied.result.requestId,
|
|
219
|
+
humanSummary: applied.payload.message || 'Done.', meta: { mutating: true, confirmation: 'confirmed', applied: true },
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const YES_OPTION = { flags: '--yes', description: 'Apply without the Continue? [y/N] question.' };
|
|
224
|
+
|
|
225
|
+
export const computerCommandSpecs = [{
|
|
226
|
+
command_path: ['computer', 'status'],
|
|
227
|
+
summary: 'Show whether your Cloud Computer is working, asleep or not responding.',
|
|
228
|
+
when_to_use: 'Check your Cloud Computer, for example when a command on it fails or an agent says it stopped answering.',
|
|
229
|
+
args_schema: { arguments: [], options: [] },
|
|
230
|
+
examples: ['notis computer status'],
|
|
231
|
+
mutates: false, idempotent: true, require_auth: true,
|
|
232
|
+
backend_call: { type: 'tool', name: GET_TOOL },
|
|
233
|
+
async handler(ctx) {
|
|
234
|
+
const { result, payload } = await callComputer(ctx, GET_TOOL, {}, randomUUID());
|
|
235
|
+
const computer = payload.cloud_computer || {};
|
|
236
|
+
return ctx.output.emitSuccess({
|
|
237
|
+
command: 'computer status', data: computer, requestId: result.requestId, humanSummary: statusText(computer),
|
|
238
|
+
hints: computer.status === 'not_responding' ? [{ command: 'notis computer restart', reason: 'Restart it; its files are kept' }] : [],
|
|
239
|
+
meta: { mutating: false },
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
}, {
|
|
243
|
+
command_path: ['computer', 'restart'],
|
|
244
|
+
summary: 'Restart a Cloud Computer that stopped answering. Its files are kept.',
|
|
245
|
+
when_to_use: 'Only while notis computer status says it is not responding. Whatever was running on it stops; it answers again in 1 to 2 minutes.',
|
|
246
|
+
args_schema: { arguments: [], options: [YES_OPTION] },
|
|
247
|
+
examples: ['notis computer restart', 'notis computer restart --yes'],
|
|
248
|
+
mutates: true, idempotent: false, require_auth: true,
|
|
249
|
+
backend_call: { type: 'tool', name: MANAGE_TOOL },
|
|
250
|
+
handler: (ctx) => machineAction(ctx, 'restart'),
|
|
251
|
+
}, {
|
|
252
|
+
command_path: ['computer', 'recover'],
|
|
253
|
+
summary: 'Bring back a Cloud Computer that cannot restart, from its last save.',
|
|
254
|
+
when_to_use: 'Only after notis computer restart failed. Anything written after the last save is lost, and this cannot be undone; the preview says when that save was made.',
|
|
255
|
+
args_schema: { arguments: [], options: [YES_OPTION] },
|
|
256
|
+
examples: ['notis computer recover'],
|
|
257
|
+
mutates: true, idempotent: false, require_auth: true,
|
|
258
|
+
backend_call: { type: 'tool', name: MANAGE_TOOL },
|
|
259
|
+
handler: (ctx) => machineAction(ctx, 'recover'),
|
|
260
|
+
}, {
|
|
261
|
+
command_path: ['computer', 'ssh'],
|
|
262
|
+
summary: 'Open SSH to your Cloud Computer from this device.',
|
|
263
|
+
when_to_use: 'Use a terminal, an editor or T3 on your Cloud Computer. The first run sets this device up; after that `ssh notis-computer` works anywhere. A stopped computer starts; it stays on while you are connected.',
|
|
264
|
+
args_schema: {
|
|
265
|
+
arguments: [{ token: '[ssh_args...]', key: 'sshArgs', description: 'Extra ssh arguments or a remote command, after --.' }],
|
|
266
|
+
options: [
|
|
267
|
+
{ flags: '--setup', description: 'Create and register this device\'s key and write the notis-computer SSH host, then stop.' },
|
|
268
|
+
{ flags: '--list', description: 'List the devices that can open SSH to your Cloud Computer.' },
|
|
269
|
+
{ flags: '--revoke <key_id>', description: 'Remove a device\'s key; it can no longer connect.' },
|
|
270
|
+
{ flags: '--proxy', description: 'Used by ssh as the notis-computer ProxyCommand.' },
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
examples: [
|
|
274
|
+
'notis computer ssh',
|
|
275
|
+
'notis computer ssh --setup',
|
|
276
|
+
'notis computer ssh -- -L 3000:localhost:3000',
|
|
277
|
+
'notis computer ssh --list',
|
|
278
|
+
'notis computer ssh --revoke <key_id>',
|
|
279
|
+
],
|
|
280
|
+
mutates: true, idempotent: false, require_auth: true,
|
|
281
|
+
backend_call: { type: 'http', path: PATH },
|
|
282
|
+
async handler(ctx) {
|
|
283
|
+
const paths = sshPaths();
|
|
284
|
+
const { setup: setupOnly, list, revoke, proxy: proxyMode } = ctx.options;
|
|
285
|
+
if ([setupOnly, list, revoke, proxyMode].filter(Boolean).length > 1) {
|
|
286
|
+
throw usageError('Choose one of --setup, --list, --revoke or --proxy.');
|
|
287
|
+
}
|
|
288
|
+
if (proxyMode) return proxy(ctx, paths);
|
|
289
|
+
if (list) {
|
|
290
|
+
const { payload, requestId } = await post(ctx.runtime, { operation: 'list' });
|
|
291
|
+
const keys = Array.isArray(payload?.keys) ? payload.keys : [];
|
|
292
|
+
return ctx.output.emitSuccess({
|
|
293
|
+
command: 'computer ssh', data: { keys }, meta: { mutating: false, request_id: requestId },
|
|
294
|
+
humanSummary: keys.length ? keys.map(keyLine).join('\n') : 'No device can open SSH to your Cloud Computer yet.',
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (revoke) {
|
|
298
|
+
const { payload, requestId } = await post(ctx.runtime, { operation: 'revoke', key_id: revoke });
|
|
299
|
+
return ctx.output.emitSuccess({
|
|
300
|
+
command: 'computer ssh', data: payload, meta: { mutating: true, request_id: requestId },
|
|
301
|
+
humanSummary: `Removed the key of ${payload?.key?.device_name || 'that device'}. It can no longer connect.`,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
const configured = Boolean(readPublicKey(paths)) && existsSync(paths.config) && existsSync(paths.proxy);
|
|
305
|
+
if (setupOnly || !configured) {
|
|
306
|
+
const result = await setup(ctx, paths);
|
|
307
|
+
if (setupOnly) {
|
|
308
|
+
const starting = result.status === 'starting' ? ' Your Cloud Computer is starting.' : '';
|
|
309
|
+
return ctx.output.emitSuccess({
|
|
310
|
+
command: 'computer ssh', data: { key: result.key, host: SSH_HOST_ALIAS, status: result.status },
|
|
311
|
+
meta: { mutating: true },
|
|
312
|
+
humanSummary: `This device can open SSH to your Cloud Computer.${starting} Connect with: ssh ${SSH_HOST_ALIAS}`,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
ctx.output.note('Connecting to your Cloud Computer. A stopped one takes about a minute to start.');
|
|
317
|
+
await waitForComputer(ctx, readPublicKey(paths));
|
|
318
|
+
return runSsh(ctx.args.sshArgs || []);
|
|
319
|
+
},
|
|
320
|
+
}];
|
|
@@ -474,14 +474,6 @@ async function debugEntitlementOverrideHandler(ctx) {
|
|
|
474
474
|
});
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
export function langfuseTraceIdCandidates(reference) {
|
|
478
|
-
const value = String(reference);
|
|
479
|
-
const compact = value.replaceAll('-', '').toLowerCase();
|
|
480
|
-
const providerId = /^[0-9a-f]{32}$/.test(compact) && !/^0+$/.test(compact)
|
|
481
|
-
? compact : createHash('sha256').update(value).digest('hex').slice(0, 32);
|
|
482
|
-
return [...new Set([providerId, value])];
|
|
483
|
-
}
|
|
484
|
-
|
|
485
477
|
export function buildTraceCostSql(reference) {
|
|
486
478
|
const literal = sqlLiteral(reference);
|
|
487
479
|
return `
|
|
@@ -618,10 +610,7 @@ async function debugTraceCostHandler(ctx) {
|
|
|
618
610
|
refund_basis: refundableEstimate === null
|
|
619
611
|
? 'Requires confirmed Notis bug evidence and an explicit bug-attributable cost. Misunderstandings and service limitations are not goodwill bugs.'
|
|
620
612
|
: 'Capped at the lower of recorded provider cost and the explicitly attributed true-bug amount.',
|
|
621
|
-
interactions
|
|
622
|
-
...item,
|
|
623
|
-
langfuse_trace_id_candidates: langfuseTraceIdCandidates(item.trace_id || item.id),
|
|
624
|
-
})),
|
|
613
|
+
interactions,
|
|
625
614
|
trace_file: traceDiagnostics,
|
|
626
615
|
};
|
|
627
616
|
return ctx.output.emitSuccess({
|
|
@@ -724,7 +713,7 @@ export const diagnosticCommandSpecs = [
|
|
|
724
713
|
summary: 'Attribute latency, retries, failures, generations, and refundable cost for a trace.',
|
|
725
714
|
when_to_use: 'Use when investigating looping, unexpectedly expensive, or failed Notis work.',
|
|
726
715
|
args_schema: {
|
|
727
|
-
arguments: [{ token: '<trace-or-interaction>', key: 'traceOrInteraction', description: 'Interaction UUID or
|
|
716
|
+
arguments: [{ token: '<trace-or-interaction>', key: 'traceOrInteraction', description: 'Interaction UUID, with or without dashes.' }],
|
|
728
717
|
options: [
|
|
729
718
|
{ flags: '--trace-file <path>', description: 'Optional exported trace JSON for generation and tool-failure attribution.' },
|
|
730
719
|
{ flags: '--confirmed-bug', description: 'Mark that evidence confirms a true Notis bug.' },
|
|
@@ -6,7 +6,8 @@ const documentArgument = { token: '<document-id>', key: 'documentId', descriptio
|
|
|
6
6
|
const versionOption = { flags: '--version-id <version-id>', description: 'Saved version ID from versions list.' };
|
|
7
7
|
|
|
8
8
|
async function remote(ctx, operation, { method = 'POST', body, query, humanSummary } = {}) {
|
|
9
|
-
const
|
|
9
|
+
const search = query ? `${new URLSearchParams(Object.entries(query).filter(([, value]) => value != null))}` : '';
|
|
10
|
+
const suffix = search ? `?${search}` : '';
|
|
10
11
|
const result = await httpRequest({ runtime: ctx.runtime, method, path: `/portal_documents/${operation}${suffix}`, body, spacesProtocol: true });
|
|
11
12
|
return ctx.output.emitSuccess({ command: ctx.spec.command_path.join(' '), data: result.payload,
|
|
12
13
|
humanSummary: humanSummary ? humanSummary(result.payload) : JSON.stringify(result.payload, null, 2),
|
|
@@ -24,6 +25,14 @@ function limit(value) {
|
|
|
24
25
|
return Number(value);
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
// An older server answers without next_before: that reads as the last page.
|
|
29
|
+
function binSummary(payload) {
|
|
30
|
+
const text = JSON.stringify(payload, null, 2);
|
|
31
|
+
const next = payload?.next_before;
|
|
32
|
+
if (typeof next !== 'string' || !next) return text;
|
|
33
|
+
return `${text}\nMore deletions: rerun with --before '${next.replaceAll("'", "'\\''")}'`;
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
function confirmed(options, what) {
|
|
28
37
|
if (!options.yes) throw usageError(`${what} cannot be undone. Only do it when the user asked, then pass --yes.`);
|
|
29
38
|
}
|
|
@@ -124,11 +133,20 @@ export const documentsCommandSpecs = [
|
|
|
124
133
|
command_path: ['documents', 'bin', 'list'],
|
|
125
134
|
summary: 'List the documents in your Bin.',
|
|
126
135
|
when_to_use: 'Find a deleted document to bring back, or to remove for good.',
|
|
127
|
-
args_schema: { arguments: [], options: [
|
|
128
|
-
|
|
136
|
+
args_schema: { arguments: [], options: [
|
|
137
|
+
{ flags: '--before <cursor>', description: 'Read older deletions, from the next_before of the previous page.' },
|
|
138
|
+
{ flags: '--limit <count>', description: 'How many deletions to read (1 to 100).' },
|
|
139
|
+
] },
|
|
140
|
+
examples: ['notis documents bin list', "notis documents bin list --before '<next_before>'"],
|
|
141
|
+
mutates: false, idempotent: true, require_auth: true,
|
|
129
142
|
backend_call: { type: 'http', path: '/portal_documents/bin' },
|
|
130
143
|
handler(ctx) {
|
|
131
|
-
|
|
144
|
+
const before = ctx.options.before;
|
|
145
|
+
if (before !== undefined && (typeof before !== 'string' || !before.trim())) {
|
|
146
|
+
throw usageError('Pass --before with the next_before of the previous Bin page.');
|
|
147
|
+
}
|
|
148
|
+
return remote(ctx, 'bin', { method: 'GET', humanSummary: binSummary,
|
|
149
|
+
query: { before, limit: limit(ctx.options.limit) } });
|
|
132
150
|
},
|
|
133
151
|
},
|
|
134
152
|
{
|
|
@@ -12,8 +12,13 @@ import { spacesCommandSpecs } from './spaces.js';
|
|
|
12
12
|
import { documentsCommandSpecs } from './documents.js';
|
|
13
13
|
import { viewsCommandSpecs } from './views.js';
|
|
14
14
|
import { filesCommandSpecs } from './files.js';
|
|
15
|
+
import { ccCommandSpecs } from './cc.js';
|
|
16
|
+
import { computerCommandSpecs } from './computer.js';
|
|
15
17
|
|
|
16
18
|
export const GROUP_SUMMARIES = {
|
|
19
|
+
cc: 'Run commands and background jobs on your Cloud Computer.',
|
|
20
|
+
job: 'Check, read and stop background jobs.',
|
|
21
|
+
computer: 'Check, restart or open SSH to your Cloud Computer.',
|
|
17
22
|
files: 'Upload local files for native records with verified byte receipts.',
|
|
18
23
|
views: 'Discover and render the views you can open.',
|
|
19
24
|
spaces: 'Build independent Spaces and their declared capabilities.',
|
|
@@ -37,6 +42,8 @@ export const COMMAND_SPECS = [
|
|
|
37
42
|
...documentsCommandSpecs,
|
|
38
43
|
...viewsCommandSpecs,
|
|
39
44
|
...filesCommandSpecs,
|
|
45
|
+
...ccCommandSpecs,
|
|
46
|
+
...computerCommandSpecs,
|
|
40
47
|
...handoverCommandSpecs,
|
|
41
48
|
...toolsCommandSpecs,
|
|
42
49
|
...diagnosticCommandSpecs,
|
|
@@ -3,7 +3,7 @@ import { dirname, join } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import { CliError, EXIT_CODES } from '../runtime/errors.js';
|
|
6
|
-
import { getAuthRecovery } from '../runtime/auth-recovery.js';
|
|
6
|
+
import { cliCommandWithProfile, getAuthRecovery } from '../runtime/auth-recovery.js';
|
|
7
7
|
import {
|
|
8
8
|
credentialIsExpired,
|
|
9
9
|
getProfile,
|
|
@@ -84,6 +84,39 @@ async function fetchBrief(apiBase, timeoutMs) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
88
|
+
|
|
89
|
+
function spaceListing(options) {
|
|
90
|
+
if (options.space === undefined) return null;
|
|
91
|
+
if (typeof options.space !== 'string' || !UUID_PATTERN.test(options.space)) {
|
|
92
|
+
throw new CliError({
|
|
93
|
+
code: 'invalid_arguments',
|
|
94
|
+
message: 'Pass --space <listing-id> with the Store listing ID from the Space link.',
|
|
95
|
+
exitCode: EXIT_CODES.usage,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return options.space.toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The Space step for `start --space <listing-id>`: the person arrived from a Space link, so the agent
|
|
103
|
+
* checks it, asks, installs it with the check receipt, then follows its onboarding Skill. The server
|
|
104
|
+
* refuses an agent install without the receipt and the person's yes (store_check_required).
|
|
105
|
+
*/
|
|
106
|
+
function spaceSteps(listingId, runtime = {}) {
|
|
107
|
+
// The steps name the exact command to run: a bare `notis` is not on PATH when the CLI runs through npx.
|
|
108
|
+
const notis = cliCommandWithProfile(runtime);
|
|
109
|
+
return [
|
|
110
|
+
'## Install the Space this person came for',
|
|
111
|
+
'',
|
|
112
|
+
`1. Check it: \`${notis} spaces store check ${listingId}\` (add \`--locale fr\` for a French speaker).`,
|
|
113
|
+
'2. Tell the person, in plain words, what it brings, each item of `risks` and the `recommendation`. If the result has a `trust_line`, say it word for word.',
|
|
114
|
+
'3. Wait for an explicit yes. A question or "maybe" is not a yes.',
|
|
115
|
+
`4. Install it: \`${notis} spaces store install ${listingId} --request-id space-${listingId} --receipt <receipt_id> --confirmed\`. Its automations arrive paused. Give the person the \`portal_url\` it returns to open their copy.`,
|
|
116
|
+
'5. If the result has `onboarding_skill`, follow its `instructions` now. Never ask again for what you already know, and never call LOCAL_NOTIS_COMPLETE_TUTORIAL from it.',
|
|
117
|
+
].join('\n');
|
|
118
|
+
}
|
|
119
|
+
|
|
87
120
|
function isAuthenticated(runtime) {
|
|
88
121
|
return Boolean(runtime.jwt)
|
|
89
122
|
&& !credentialIsExpired(runtime, getProfile(loadConfig(), runtime.profileName));
|
|
@@ -136,6 +169,7 @@ function agentSetupHints(results) {
|
|
|
136
169
|
* brief, so `brief: null` is a positive signal to the agent, not a failure.
|
|
137
170
|
*/
|
|
138
171
|
async function authenticatedResult(ctx) {
|
|
172
|
+
const listingId = spaceListing(ctx.options);
|
|
139
173
|
const state = await fetchOnboardingState(ctx.runtime);
|
|
140
174
|
const onboardingComplete = state?.onboardingComplete === true;
|
|
141
175
|
const base = {
|
|
@@ -157,6 +191,27 @@ async function authenticatedResult(ctx) {
|
|
|
157
191
|
base.agent_setup = [];
|
|
158
192
|
}
|
|
159
193
|
|
|
194
|
+
if (listingId) base.space = { listing_id: listingId, steps: spaceSteps(listingId, ctx.runtime) };
|
|
195
|
+
|
|
196
|
+
if (onboardingComplete && listingId) {
|
|
197
|
+
// Already onboarded: only the Space's check, install and onboarding-Skill steps.
|
|
198
|
+
return ctx.output.emitSuccess({
|
|
199
|
+
command: 'start',
|
|
200
|
+
data: { ...base, brief: base.space.steps, brief_source: 'space' },
|
|
201
|
+
humanSummary: `Profile "${ctx.runtime.profileName}" is set up. Check and install Space listing ${listingId}.`,
|
|
202
|
+
renderHuman: () => [
|
|
203
|
+
'This account has already completed onboarding. Do not run an onboarding',
|
|
204
|
+
'flow and do not call LOCAL_NOTIS_COMPLETE_TUTORIAL.',
|
|
205
|
+
'',
|
|
206
|
+
base.space.steps,
|
|
207
|
+
].join('\n'),
|
|
208
|
+
hints: [
|
|
209
|
+
{ command: `${cliCommandWithProfile(ctx.runtime)} spaces store check ${listingId}`, reason: 'Check the Space before installing it' },
|
|
210
|
+
...agentSetupHints(base.agent_setup),
|
|
211
|
+
],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
160
215
|
if (onboardingComplete) {
|
|
161
216
|
const name = state?.settings?.first_name;
|
|
162
217
|
const setupSummary = renderAgentSetup(base.agent_setup);
|
|
@@ -182,7 +237,11 @@ async function authenticatedResult(ctx) {
|
|
|
182
237
|
});
|
|
183
238
|
}
|
|
184
239
|
|
|
185
|
-
const
|
|
240
|
+
const fetched = await fetchBrief(ctx.runtime.apiBase, ctx.runtime.timeoutMs);
|
|
241
|
+
// A new account from a Space link: the basics first, then this Space step, then the rest of the brief.
|
|
242
|
+
const brief = listingId
|
|
243
|
+
? { ...fetched, markdown: [fetched.markdown, `${base.space.steps}\n\nDo this step right after the basics (step 1), before connections.`].filter(Boolean).join('\n\n') }
|
|
244
|
+
: fetched;
|
|
186
245
|
const setupSummary = renderAgentSetup(base.agent_setup);
|
|
187
246
|
return ctx.output.emitSuccess({
|
|
188
247
|
command: 'start',
|
|
@@ -196,8 +255,49 @@ async function authenticatedResult(ctx) {
|
|
|
196
255
|
});
|
|
197
256
|
}
|
|
198
257
|
|
|
258
|
+
// How long a confirmation waits for the person to finish in the browser: under the two minutes a code agent's shell
|
|
259
|
+
// command gets by default, so the agent sees the result instead of a timeout.
|
|
260
|
+
const CONFIRM_WAIT_SECONDS = 90;
|
|
261
|
+
const WAIT_POLL_MS = 2000;
|
|
262
|
+
|
|
263
|
+
function waitSeconds(options) {
|
|
264
|
+
if (options.wait === undefined) return 0;
|
|
265
|
+
const seconds = Number(options.wait);
|
|
266
|
+
if (!Number.isInteger(seconds) || seconds < 0 || seconds > 600) {
|
|
267
|
+
throw new CliError({
|
|
268
|
+
code: 'invalid_arguments',
|
|
269
|
+
message: 'Pass --wait <seconds> with a whole number from 0 to 600.',
|
|
270
|
+
exitCode: EXIT_CODES.usage,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return seconds;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The command an agent runs once the person signed in: it keeps the Space they came for and waits for them. */
|
|
277
|
+
export function startConfirmCommand(command, listingId = null) {
|
|
278
|
+
return [command, ...(listingId ? [`--space ${listingId}`] : []), `--wait ${CONFIRM_WAIT_SECONDS}`].join(' ');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Whether the background listener has stored this profile's sign-in yet. */
|
|
282
|
+
function storedSignIn(runtime) {
|
|
283
|
+
const profile = getProfile(loadConfig(), runtime.profileName);
|
|
284
|
+
return Boolean(profile?.oauth_access_token) && !credentialIsExpired({ credentialKind: 'oauth' }, profile);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Waits up to `seconds` for the person to finish signing in in the browser; true once they have. */
|
|
288
|
+
export async function waitForSignIn(runtime, seconds, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) {
|
|
289
|
+
const deadline = Date.now() + seconds * 1000;
|
|
290
|
+
while (Date.now() < deadline) {
|
|
291
|
+
if (storedSignIn(runtime)) return true;
|
|
292
|
+
await sleep(Math.min(WAIT_POLL_MS, Math.max(0, deadline - Date.now())));
|
|
293
|
+
}
|
|
294
|
+
return storedSignIn(runtime);
|
|
295
|
+
}
|
|
296
|
+
|
|
199
297
|
async function startHandler(ctx) {
|
|
200
298
|
const { runtime, options, output } = ctx;
|
|
299
|
+
const listingId = spaceListing(options);
|
|
300
|
+
const wait = waitSeconds(options);
|
|
201
301
|
if (runtime.credentialKind === 'oauth') {
|
|
202
302
|
try {
|
|
203
303
|
await ensureFreshOAuthCredential(runtime);
|
|
@@ -216,17 +316,34 @@ async function startHandler(ctx) {
|
|
|
216
316
|
output,
|
|
217
317
|
});
|
|
218
318
|
const authorizationResult = (authorization) => {
|
|
219
|
-
const
|
|
319
|
+
const agentAuthorization = { ...authorization.agentAuthorization };
|
|
320
|
+
// Confirming keeps the Space the person came for, and waits for them instead of asking them to say they are done.
|
|
321
|
+
if (agentAuthorization.hand_off === 'browser_callback' && agentAuthorization.confirm_command) {
|
|
322
|
+
agentAuthorization.confirm_command = startConfirmCommand(agentAuthorization.confirm_command, listingId);
|
|
323
|
+
}
|
|
324
|
+
const presentation = loginAgentAuthorizationPresentation(agentAuthorization);
|
|
220
325
|
return output.emitSuccess({
|
|
221
326
|
command: 'start',
|
|
222
327
|
data: {
|
|
223
328
|
authenticated: false,
|
|
224
329
|
profile: runtime.profileName,
|
|
225
|
-
...
|
|
330
|
+
...agentAuthorization,
|
|
226
331
|
},
|
|
227
332
|
...presentation,
|
|
228
333
|
});
|
|
229
334
|
};
|
|
335
|
+
// An agent's confirmation with --wait: return as soon as the background listener stores the sign-in.
|
|
336
|
+
const signInOrAuthorization = async (authorization) => {
|
|
337
|
+
if (!authorization?.agentAuthorization || authorization.agentAuthorization.hand_off !== 'browser_callback' || !wait) {
|
|
338
|
+
return authorization;
|
|
339
|
+
}
|
|
340
|
+
if (!(await waitForSignIn(runtime, wait))) return authorization;
|
|
341
|
+
return followChannel(await loginWithOAuth(
|
|
342
|
+
runtime,
|
|
343
|
+
{ browser: true, mode: options.mode, reusePersistedCredential: true },
|
|
344
|
+
output,
|
|
345
|
+
));
|
|
346
|
+
};
|
|
230
347
|
|
|
231
348
|
// Safe to re-run: an already-authorized profile skips straight to the brief.
|
|
232
349
|
if (isAuthenticated(runtime)) {
|
|
@@ -247,11 +364,11 @@ async function startHandler(ctx) {
|
|
|
247
364
|
// Browser authorization is the whole signup path: it creates the account when
|
|
248
365
|
// the address is new and authorizes this machine either way. There is nothing
|
|
249
366
|
// for the CLI to collect up front, and nothing to wait on afterwards.
|
|
250
|
-
const authorization = await followChannel(await loginWithOAuth(
|
|
367
|
+
const authorization = await signInOrAuthorization(await followChannel(await loginWithOAuth(
|
|
251
368
|
runtime,
|
|
252
369
|
{ browser: true, mode: options.mode, reusePersistedCredential: true },
|
|
253
370
|
output,
|
|
254
|
-
));
|
|
371
|
+
)));
|
|
255
372
|
if (authorization?.agentAuthorization) {
|
|
256
373
|
return authorizationResult(authorization);
|
|
257
374
|
}
|
|
@@ -281,7 +398,9 @@ export const onboardingCommandSpecs = [
|
|
|
281
398
|
arguments: [],
|
|
282
399
|
options: [
|
|
283
400
|
{ flags: '--brief-only', description: 'Print the onboarding brief for an already-signed-in profile.' },
|
|
401
|
+
{ flags: '--space <listing-id>', description: 'The Store Space the person came for: adds its check, install and onboarding-Skill steps (the only steps for an account already set up).' },
|
|
284
402
|
{ flags: '--mode <mode>', description: 'auto (default) hands the browser callback to a background listener when this command cannot wait; browser waits in-process; code shows a one-time code to copy.' },
|
|
403
|
+
{ flags: '--wait <seconds>', description: 'While a browser sign-in is pending, wait up to this many seconds (0 to 600) for the person to finish before answering.' },
|
|
285
404
|
],
|
|
286
405
|
},
|
|
287
406
|
examples: [
|
|
@@ -289,10 +408,11 @@ export const onboardingCommandSpecs = [
|
|
|
289
408
|
'notis start --profile work',
|
|
290
409
|
'notis start --mode browser',
|
|
291
410
|
'notis start --brief-only',
|
|
411
|
+
'notis start --space <listing-id>',
|
|
292
412
|
'notis start --json',
|
|
293
413
|
],
|
|
294
414
|
output_schema:
|
|
295
|
-
'Returns {authenticated, profile, api_base, onboarding_complete, known_settings, missing_settings, agent_setup, brief, brief_source} once signed in — brief is null when onboarding_complete is true — or {authorize_url, expires_in, hand_off, ...} while waiting for browser authorization. hand_off is "browser_callback" when signing in finishes the login by itself (re-run confirm_command to see it land) or "code" when the user must be asked for the code the page shows and it redeemed with redeem_command.',
|
|
415
|
+
'Returns {authenticated, profile, api_base, onboarding_complete, known_settings, missing_settings, agent_setup, brief, brief_source, space} once signed in — brief is null when onboarding_complete is true, except with --space, where it holds only the Space steps (brief_source "space") — or {authorize_url, expires_in, hand_off, ...} while waiting for browser authorization. hand_off is "browser_callback" when signing in finishes the login by itself (re-run confirm_command to see it land) or "code" when the user must be asked for the code the page shows and it redeemed with redeem_command.',
|
|
296
416
|
mutates: true,
|
|
297
417
|
idempotent: true,
|
|
298
418
|
require_auth: false,
|
|
@@ -271,8 +271,8 @@ export const skillsCommandSpecs = [
|
|
|
271
271
|
{
|
|
272
272
|
command_path: ['skills', 'read'],
|
|
273
273
|
summary: 'Inspect a native Skill through direct ownership or an editable Space link.',
|
|
274
|
-
when_to_use: 'Read the exact target and content version before editing. A Space target uses its current Editor authority, never a personal fallback.',
|
|
275
|
-
args_schema: { arguments: [{ token: '[skill-id]', key: 'skillId', description: 'Exact
|
|
274
|
+
when_to_use: 'Read the exact target and content version before editing. A Skill ID opens your own Skill, or a Space Skill through a Space where you are an Editor, and answers that link as its target; a Space target uses its current Editor authority, never a personal fallback. A refusal names the Skill and what is missing.',
|
|
275
|
+
args_schema: { arguments: [{ token: '[skill-id]', key: 'skillId', description: 'Exact Skill ID from skills list; omit when passing --target.' }],
|
|
276
276
|
options: [{ flags: '--files', description: 'Include every verified supporting file as base64.' },
|
|
277
277
|
{ flags: '--target <json>', description: 'Exact {skill_id} or {space_id,binding_id} read target; do not combine with a Skill ID.' }] },
|
|
278
278
|
examples: ['notis skills read <skill-id> --files', 'notis skills read --target \'{"space_id":"<id>","binding_id":"<binding>"}\' --files'],
|