@notis_ai/cli 0.2.32 → 0.2.33
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 +74 -9
- package/dist/agent-hooks/notis-agent-hook.mjs +4330 -891
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +7 -3
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +5 -3
- package/dist/base-skills/notis-spaces/references/comments.md +94 -0
- package/dist/base-skills/notis-spaces/references/context.md +20 -19
- package/dist/base-skills/notis-spaces/references/design.md +3 -2
- package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
- package/dist/base-skills/notis-spaces/references/store.md +24 -1
- package/dist/sdk/src/components/SelectionActionBar.tsx +42 -7
- package/dist/sdk/src/components/SpaceTextComments.tsx +284 -0
- package/dist/sdk/src/config.ts +3 -1
- package/dist/sdk/src/functions.ts +203 -0
- package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +7 -2
- package/dist/sdk/src/hooks/useConnection.ts +102 -0
- package/dist/sdk/src/hooks/useFunction.ts +42 -0
- package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
- package/dist/sdk/src/index.ts +15 -4
- package/dist/sdk/src/runtime.ts +16 -1
- package/dist/sdk/src/space.ts +333 -33
- package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
- package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
- package/dist/skill-sync/index.js +239 -30
- package/dist/skill-sync-worker.mjs +453 -124
- package/dist/space-harness/host.js +213 -92
- package/dist/space-sdk/dist/chunk-4GWS2IFO.js +3 -0
- package/dist/space-sdk/dist/index.js +3 -3
- package/dist/space-sdk/dist/ui.js +8 -7
- package/dist/space-sdk/src/config.ts +3 -1
- package/dist/space-sdk/src/functions.ts +203 -0
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +2 -0
- package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
- package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
- package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
- package/dist/space-sdk/src/index.d.ts +10 -4
- package/dist/space-sdk/src/runtime.d.ts +14 -1
- package/dist/space-sdk/src/space.ts +333 -33
- package/dist/space-sdk/src/tailwind-candidates.d.ts +185 -152
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +7 -4
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +10 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +55 -88
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
- package/dist/space-sdk/src/ui/comments/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +27 -5
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +64 -74
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
- package/dist/space-sdk/src/ui/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
- package/dist/view-renderer/dist/host.js +280 -159
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
- package/skills/notis-spaces/cli.md +3 -3
- package/src/cli.js +2 -1
- package/src/command-specs/index.js +3 -0
- package/src/command-specs/repository-secrets.js +171 -0
- package/src/command-specs/spaces.js +3 -3
- package/src/runtime/agent-credential.js +175 -0
- package/src/runtime/agent-identity.js +92 -15
- package/src/runtime/app-platform.js +8 -0
- package/src/runtime/auth-recovery.js +14 -0
- package/src/runtime/profiles.js +15 -0
- package/src/runtime/skill-sync/index.ts +3 -2
- package/src/runtime/skill-sync/symlink-manager.ts +354 -35
- package/src/runtime/skill-sync/types.ts +10 -1
- package/src/runtime/space-functions.js +211 -0
- package/src/runtime/space-platform.js +12 -3
- package/src/runtime/space-source.js +116 -13
- package/src/runtime/space-test-server.js +22 -4
- package/src/runtime/space-verification.js +3 -1
- package/src/runtime/transport.js +15 -0
- package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
- package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
- package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notis_ai/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
4
4
|
"description": "Agent-first Notis CLI for Spaces, Skills and generic tool execution",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"react-dom": "19.3.0"
|
|
54
54
|
},
|
|
55
55
|
"notisRelease": {
|
|
56
|
-
"sourceSha": "
|
|
56
|
+
"sourceSha": "f09e2798430a8975fc45a48f786a4c155368285f",
|
|
57
57
|
"channel": "stable"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f09e2798430a8975fc45a48f786a4c155368285f"
|
|
60
60
|
}
|
|
@@ -69,7 +69,7 @@ Call these with `notis tools exec <TOOL>` (add `--get-schema` first when you nee
|
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
"name": "LOCAL_NOTIS_SEND_USER_MESSAGE",
|
|
72
|
-
"description": "Send a message to the Notis account owner on a connected channel or account, returning immediately after durable acceptance (not delivery or a user reply). Only for delivering a message to the user on another channel or account; never to answer in the current conversation (your final message is that answer) and never to message other people. Choose the destination explicitly on every send; no automatic channel forwarding. When an account selection is ambiguous, the result lists available selectors. Supply agent_name and agent_description on every call; optional context adds message-specific detail. Omit thread_id to create a topic or supply an existing account-owned thread_id to continue it. Do not resend a pending message. A send from an agent Notis runs (a Notis sub-agent) claims nothing: the user's reply in that thread goes to the Notis orchestrator like any other message, so do not poll for it. Every other accepted send, such as one from an agent outside Notis, claims its thread for your agent: latest send wins, and the orchestrator cannot answer or launch work in agent-owned threads. Poll LOCAL_NOTIS_LOAD_CONVERSATION_HISTORY with that thread_id at your chosen frequency for delivery status and all user replies; reuse its cursor for incremental reads."
|
|
72
|
+
"description": "Send a message to the Notis account owner on a connected channel or account, returning immediately after durable acceptance (not delivery or a user reply). Only for delivering a message to the user on another channel or account; never to answer in the current conversation (your final message is that answer) and never to message other people. Exception: a Notis operator using the Notis CLI or MCP may pass recipient_user_id to have Notis send the exact message to that user as a Notis message (Source notis, in a thread no agent has taken over, on the given channel or else the user's last active channel); it claims no thread, and everyone else is refused. Choose the destination explicitly on every send; no automatic channel forwarding. When an account selection is ambiguous, the result lists available selectors. Supply agent_name and agent_description on every call; optional context adds message-specific detail. Omit thread_id to create a topic or supply an existing account-owned thread_id to continue it. Do not resend a pending message. A send from an agent Notis runs (a Notis sub-agent) claims nothing: the user's reply in that thread goes to the Notis orchestrator like any other message, so do not poll for it. Every other accepted send, such as one from an agent outside Notis, claims its thread for your agent: latest send wins, and the orchestrator cannot answer or launch work in agent-owned threads. Poll LOCAL_NOTIS_LOAD_CONVERSATION_HISTORY with that thread_id at your chosen frequency for delivery status and all user replies; reuse its cursor for incremental reads."
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"name": "LOCAL_NOTIS_REPORT_BUG",
|
|
@@ -86,7 +86,7 @@ Call these with `notis tools exec <TOOL>` (add `--get-schema` first when you nee
|
|
|
86
86
|
|
|
87
87
|
- Cold discovery can exceed 30 seconds. Use `--timeout-ms 90000` for discovery calls when needed; after `network_timeout`, retry the exact command once with that timeout instead of looping.
|
|
88
88
|
- Before writing a Notion or native database row, read the schema and relevant property descriptions.
|
|
89
|
-
- Before writing for the user (comments, rows), declare yourself once per session
|
|
89
|
+
- Before writing for the user (comments, rows), declare yourself once per session: `export NOTIS_AGENT_NAME="fred-and-the-machine"` (or `--agent-name`), a fresh lowercase imaginary rock-band name of your own, never a harness or product name such as `claude-code`, `codex` or `notis-agent` (lowercase letters and digits in at least two words joined by hyphens, 3 to 60 characters); every sub-agent picks its own. Set `NOTIS_AGENT_ID` to your own unique id, such as your session or T3 thread id (without it the CLI keeps one id per name on this computer), and `NOTIS_AGENT_THREAD_NAME` to the name of the thread you work in (a T3 thread title, `PR #3851`, at most 80 characters). Where the user has unified comments on, the write then shows your name, never reads as the user's own, and never wakes you, and a comment written through the CLI without a name is refused (`agent_name_required`); elsewhere the name is ignored. A comment thread you wrote in last stays yours: Notis wakes no agent when the user replies there, so read the replies yourself with `LOCAL_NOTIS_SPACE_COMMENT_THREADS` (`waiting`, `list` or `thread`) when you check.
|
|
90
90
|
- When answering about meetings or availability, check every connected calendar.
|
|
91
91
|
- Use `notis doctor` before concluding that authentication or API reachability is broken.
|
|
92
92
|
- Keep credentials and other secrets out of tool arguments and search queries unless the target tool explicitly requires them.
|
|
@@ -472,9 +472,9 @@ Examples:
|
|
|
472
472
|
|
|
473
473
|
### `npx --package @notis_ai/cli@latest -- notis spaces store publish <space-id>`
|
|
474
474
|
|
|
475
|
-
Publish a Space
|
|
475
|
+
Publish what a Space's source lists in store.ships as the next Store version.
|
|
476
476
|
|
|
477
|
-
When to use: Share a Space you own as an installable template: link and team listings publish at once, public ones wait for review. A link listing never shows in the Store; only people with its link see it. Notis runs the same safety scan and Owner check as the submission page and explains any refusal.
|
|
477
|
+
When to use: Share a Space you own as an installable template: link and team listings publish at once, public ones wait for review. A link listing never shows in the Store; only people with its link see it. Only what the root's defineSpace lists in store: { ships: { <source key>: [<alias>, ...] } } ships; every other sub-Space and linked item stays private, and publishing (an update of an existing listing included) is refused until that list is deployed. The result (and --dry-run) names what ships and what stays private under ships. Notis runs the same safety scan and Owner check as the submission page and explains any refusal, including a shipped view that reads or writes a database that stays private.
|
|
478
478
|
|
|
479
479
|
Options:
|
|
480
480
|
- `--channel <link|team|public>` — Where to publish: anyone with the link, your team or everyone.
|
|
@@ -482,7 +482,7 @@ Options:
|
|
|
482
482
|
- `--starter <json>` — Starter row IDs per database ({"<database-id>":["<record-key>"]}).
|
|
483
483
|
- `--notes <text>` — Release notes for this version.
|
|
484
484
|
- `--request-id <key>` — Stable intent key. Reuse after timeouts or lost replies.
|
|
485
|
-
- `--dry-run` — Show the package counts and review diff without publishing.
|
|
485
|
+
- `--dry-run` — Show what ships and stays private, the package counts and the review diff without publishing.
|
|
486
486
|
|
|
487
487
|
Examples:
|
|
488
488
|
- `npx --package @notis_ai/cli@latest -- notis spaces store publish <space-id> --channel team --request-id publish-1 --dry-run`
|
package/src/cli.js
CHANGED
|
@@ -240,8 +240,9 @@ export function createProgram(launchContext = {}) {
|
|
|
240
240
|
// Any agent using the CLI declares itself, so what it writes is its own (a comment's Author), not the person's.
|
|
241
241
|
// A comment written through the CLI needs the name (agent-identity.js).
|
|
242
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>', '
|
|
243
|
+
.option('--agent-id <id>', 'The agent\'s own unique id, such as its session id; without one the CLI keeps a generated id per name on this computer (or set NOTIS_AGENT_ID)')
|
|
244
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)')
|
|
245
|
+
.option('--agent-thread-name <name>', 'The name of the thread the agent works in (a T3 thread title, "PR #3851"), at most 80 characters, shown after its name (or set NOTIS_AGENT_THREAD_NAME)')
|
|
245
246
|
.addOption(new Option('--notis-managed-agent-hook').hideHelp());
|
|
246
247
|
|
|
247
248
|
const parentMap = new Map([['', program]]);
|
|
@@ -14,11 +14,13 @@ import { viewsCommandSpecs } from './views.js';
|
|
|
14
14
|
import { filesCommandSpecs } from './files.js';
|
|
15
15
|
import { ccCommandSpecs } from './cc.js';
|
|
16
16
|
import { computerCommandSpecs } from './computer.js';
|
|
17
|
+
import { repositorySecretsCommandSpecs } from './repository-secrets.js';
|
|
17
18
|
|
|
18
19
|
export const GROUP_SUMMARIES = {
|
|
19
20
|
cc: 'Run commands and background jobs on your Cloud Computer.',
|
|
20
21
|
job: 'Check, read and stop background jobs.',
|
|
21
22
|
computer: 'Check, restart or open SSH to your Cloud Computer.',
|
|
23
|
+
'repository-secrets': 'Keep variables and env files encrypted for your team and run commands with them as environment variables.',
|
|
22
24
|
files: 'Upload local files for native records with verified byte receipts.',
|
|
23
25
|
views: 'Discover and render the views you can open.',
|
|
24
26
|
spaces: 'Build independent Spaces and their declared capabilities.',
|
|
@@ -44,6 +46,7 @@ export const COMMAND_SPECS = [
|
|
|
44
46
|
...filesCommandSpecs,
|
|
45
47
|
...ccCommandSpecs,
|
|
46
48
|
...computerCommandSpecs,
|
|
49
|
+
...repositorySecretsCommandSpecs,
|
|
47
50
|
...handoverCommandSpecs,
|
|
48
51
|
...toolsCommandSpecs,
|
|
49
52
|
...diagnosticCommandSpecs,
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// `notis repository-secrets`: the repository secrets of your team (or your own), FAC-039 and FAC-070.
|
|
2
|
+
//
|
|
3
|
+
// A repository secret is a variable (STRIPE_SECRET_KEY) or a whole env file named by its path in the checkout
|
|
4
|
+
// (server/.env). Notis keeps it encrypted and never shows it again: list answers names, kinds, who set each one and
|
|
5
|
+
// when. set reads the value from a file or stdin here and sends it straight to POST /repository_secrets, never
|
|
6
|
+
// through the generic tool pipeline, so it is not part of any tool request record. exec is the only way a value
|
|
7
|
+
// leaves Notis: it asks for one repository's environment (the CLI-only `environment` action) and starts a command
|
|
8
|
+
// with those variables in its environment, so they never land in a file. It never prints a value.
|
|
9
|
+
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { constants } from 'node:os';
|
|
13
|
+
import { httpRequest } from '../runtime/transport.js';
|
|
14
|
+
import { usageError } from '../runtime/errors.js';
|
|
15
|
+
|
|
16
|
+
const PATH = '/repository_secrets';
|
|
17
|
+
const VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
18
|
+
const FORWARDED_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
19
|
+
|
|
20
|
+
async function call(ctx, body) {
|
|
21
|
+
return httpRequest({ runtime: ctx.runtime, method: 'POST', path: PATH, body });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function label(secret) {
|
|
25
|
+
return secret?.kind === 'variable' ? `${secret.repository} · ${secret.name}` : `${secret.repository}/${secret.name}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function secretLine(secret) {
|
|
29
|
+
const who = secret?.set_by?.you ? 'you' : (secret?.set_by?.name || 'a teammate');
|
|
30
|
+
return `${label(secret)} set by ${who} ${secret.updated_at || ''}`.trimEnd();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readValue(ctx, isVariable) {
|
|
34
|
+
if (ctx.options.file && ctx.options.stdin) throw usageError('Choose --file or --stdin, not both.');
|
|
35
|
+
let value;
|
|
36
|
+
if (ctx.options.file) value = readFileSync(ctx.options.file, 'utf8');
|
|
37
|
+
else if (ctx.options.stdin) value = readFileSync(0, 'utf8');
|
|
38
|
+
else throw usageError('Pass --file <path> or --stdin with the value to store. Values are never typed as arguments.');
|
|
39
|
+
// `echo value | ... --stdin` ends with a newline that is not part of a variable's value.
|
|
40
|
+
return isVariable ? value.replace(/\r?\n$/, '') : value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function names(items) {
|
|
44
|
+
return (Array.isArray(items) ? items : []).map(item => (typeof item === 'string' ? item : label(item))).filter(Boolean);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Starts argv with env, inheriting stdio; resolves with its exit code (128 + the signal's number when killed). */
|
|
48
|
+
export function runWithEnvironment(argv, env) {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
let child;
|
|
51
|
+
const forward = (signal) => {
|
|
52
|
+
// From a terminal, Ctrl-C already reached the command (same foreground process group): a second SIGINT
|
|
53
|
+
// would read as "force quit" to servers that stop gracefully on the first.
|
|
54
|
+
if (signal === 'SIGINT' && process.stdin.isTTY) return;
|
|
55
|
+
try { child?.kill(signal); } catch { /* already gone */ }
|
|
56
|
+
};
|
|
57
|
+
const stopForwarding = () => { for (const signal of FORWARDED_SIGNALS) process.removeListener(signal, forward); };
|
|
58
|
+
for (const signal of FORWARDED_SIGNALS) process.on(signal, forward);
|
|
59
|
+
try {
|
|
60
|
+
child = spawn(argv[0], argv.slice(1), { stdio: 'inherit', env });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
stopForwarding();
|
|
63
|
+
process.stderr.write(`notis repository-secrets exec: could not start ${argv[0]} (${error?.code || 'error'})\n`);
|
|
64
|
+
resolve(127);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
child.once('error', (error) => {
|
|
68
|
+
stopForwarding();
|
|
69
|
+
process.stderr.write(`notis repository-secrets exec: could not start ${argv[0]} (${error?.code || 'error'})\n`);
|
|
70
|
+
resolve(error?.code === 'ENOENT' ? 127 : 126);
|
|
71
|
+
});
|
|
72
|
+
child.once('exit', (code, signal) => {
|
|
73
|
+
stopForwarding();
|
|
74
|
+
resolve(typeof code === 'number' ? code : 128 + (constants.signals[signal] || 0));
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const repositoryOption = { flags: '--repository <name>', description: 'The repository\'s short name, such as notis.' };
|
|
80
|
+
|
|
81
|
+
export const repositorySecretsCommandSpecs = [{
|
|
82
|
+
command_path: ['repository-secrets', 'list'],
|
|
83
|
+
summary: 'List the repository secrets of your team (or your own): names, kinds, who set each one and when.',
|
|
84
|
+
when_to_use: 'See which variables and env files Notis keeps for a repository. Values are never shown.',
|
|
85
|
+
args_schema: { options: [{ ...repositoryOption, description: 'Only this repository.' }] },
|
|
86
|
+
examples: ['notis repository-secrets list', 'notis repository-secrets list --repository notis'],
|
|
87
|
+
mutates: false, idempotent: true, require_auth: true,
|
|
88
|
+
backend_call: { type: 'http', path: PATH },
|
|
89
|
+
async handler(ctx) {
|
|
90
|
+
const { payload, requestId } = await call(ctx, { action: 'list', ...(ctx.options.repository ? { repository: ctx.options.repository } : {}) });
|
|
91
|
+
const secrets = Array.isArray(payload?.secrets) ? payload.secrets : [];
|
|
92
|
+
return ctx.output.emitSuccess({ command: 'repository-secrets list', data: payload, meta: { mutating: false, request_id: requestId },
|
|
93
|
+
humanSummary: secrets.length ? secrets.map(secretLine).join('\n') : 'No repository secrets yet.' });
|
|
94
|
+
},
|
|
95
|
+
}, {
|
|
96
|
+
command_path: ['repository-secrets', 'set'],
|
|
97
|
+
summary: 'Store or replace a variable or an env file as a repository secret, encrypted. It is never shown again.',
|
|
98
|
+
when_to_use: 'Give the team\'s dev servers a key (--name STRIPE_SECRET_KEY --stdin) or a whole env file (--file server/.env). Any team member can replace one.',
|
|
99
|
+
args_schema: { options: [
|
|
100
|
+
repositoryOption,
|
|
101
|
+
{ flags: '--name <name>', description: 'A variable\'s name, such as STRIPE_SECRET_KEY, or the env file\'s path in the repository, such as server/.env (defaults to --file).' },
|
|
102
|
+
{ flags: '--file <path>', description: 'Read the value from this file.' },
|
|
103
|
+
{ flags: '--stdin', description: 'Read the value from standard input.' },
|
|
104
|
+
] },
|
|
105
|
+
examples: [
|
|
106
|
+
'notis repository-secrets set --repository notis --file server/.env',
|
|
107
|
+
'printf %s "$KEY" | notis repository-secrets set --repository web --name STRIPE_SECRET_KEY --stdin',
|
|
108
|
+
],
|
|
109
|
+
mutates: true, idempotent: true, require_auth: true,
|
|
110
|
+
backend_call: { type: 'http', path: PATH },
|
|
111
|
+
async handler(ctx) {
|
|
112
|
+
const repository = ctx.options.repository;
|
|
113
|
+
if (!repository) throw usageError('Pass --repository <name>.');
|
|
114
|
+
const name = ctx.options.name || (ctx.options.file ? String(ctx.options.file).replace(/^\.\//, '') : '');
|
|
115
|
+
if (!name) throw usageError('Pass --name <name> with --stdin.');
|
|
116
|
+
const isVariable = VARIABLE_NAME.test(name);
|
|
117
|
+
const { payload, requestId } = await call(ctx, { action: 'set', repository, name, secret: readValue(ctx, isVariable) });
|
|
118
|
+
const shown = isVariable ? `${repository} · ${name}` : `${repository}/${name}`;
|
|
119
|
+
return ctx.output.emitSuccess({ command: 'repository-secrets set', data: payload, meta: { mutating: true, request_id: requestId },
|
|
120
|
+
humanSummary: `${payload?.replaced ? 'Replaced' : 'Stored'} ${shown}, encrypted. It is never shown again.` });
|
|
121
|
+
},
|
|
122
|
+
}, {
|
|
123
|
+
command_path: ['repository-secrets', 'delete'],
|
|
124
|
+
summary: 'Remove a repository secret.',
|
|
125
|
+
when_to_use: 'A variable or env file the repository no longer needs.',
|
|
126
|
+
args_schema: { options: [repositoryOption, { flags: '--name <name>', description: 'The variable\'s name or the env file\'s path, such as server/.env.' }] },
|
|
127
|
+
examples: ['notis repository-secrets delete --repository notis --name portal/.env.local', 'notis repository-secrets delete --repository web --name STRIPE_SECRET_KEY'],
|
|
128
|
+
mutates: true, idempotent: true, require_auth: true,
|
|
129
|
+
backend_call: { type: 'http', path: PATH },
|
|
130
|
+
async handler(ctx) {
|
|
131
|
+
if (!ctx.options.repository || !ctx.options.name) throw usageError('Pass --repository <name> and --name <name>.');
|
|
132
|
+
const { payload, requestId } = await call(ctx, { action: 'delete', repository: ctx.options.repository, name: ctx.options.name });
|
|
133
|
+
return ctx.output.emitSuccess({ command: 'repository-secrets delete', data: payload, meta: { mutating: true, request_id: requestId },
|
|
134
|
+
humanSummary: payload?.deleted ? `Removed ${ctx.options.name} from ${ctx.options.repository}.` : 'There was no such secret.' });
|
|
135
|
+
},
|
|
136
|
+
}, {
|
|
137
|
+
command_path: ['repository-secrets', 'exec'],
|
|
138
|
+
summary: 'Run a command with the repository\'s secrets as environment variables. Never prints a value.',
|
|
139
|
+
when_to_use: 'Start a dev server or a script that needs the repository\'s keys, without writing them to a file. Everything after -- is the command; it gets your environment plus the secrets, and NOTIS_REPOSITORY_SECRET_NAMES lists their names. Needs a CLI sign-in that can write.',
|
|
140
|
+
args_schema: {
|
|
141
|
+
arguments: [{ token: '[command...]', key: 'command', description: 'The command and its arguments, after --.' }],
|
|
142
|
+
options: [repositoryOption],
|
|
143
|
+
},
|
|
144
|
+
examples: ['notis repository-secrets exec --repository notis -- ./dev.sh', 'notis repository-secrets exec --repository web -- npm run dev'],
|
|
145
|
+
mutates: false, idempotent: true, require_auth: true,
|
|
146
|
+
backend_call: { type: 'http', path: PATH },
|
|
147
|
+
async handler(ctx) {
|
|
148
|
+
const repository = ctx.options.repository;
|
|
149
|
+
if (!repository) throw usageError('Pass --repository <name>.');
|
|
150
|
+
const argv = Array.isArray(ctx.args.command) ? ctx.args.command.map(String) : [];
|
|
151
|
+
if (!argv.length) throw usageError('Give the command after --, such as: notis repository-secrets exec --repository notis -- ./dev.sh');
|
|
152
|
+
const { payload } = await call(ctx, { action: 'environment', repository });
|
|
153
|
+
const given = payload?.variables && typeof payload.variables === 'object' ? payload.variables : {};
|
|
154
|
+
const variables = Object.fromEntries(Object.entries(given).filter(([key, value]) => key && typeof value === 'string'));
|
|
155
|
+
// Names only, on stderr: stdout belongs to the command.
|
|
156
|
+
const notes = [
|
|
157
|
+
[names(payload?.refused), 'not given (it holds a Notis credential)'],
|
|
158
|
+
[names(payload?.overridden), 'set by more than one secret (the variable, or the deeper env file, won)'],
|
|
159
|
+
[names(payload?.skipped), 'left out (a reserved or invalid name, a value no process can take, or past the size or count limits)'],
|
|
160
|
+
];
|
|
161
|
+
// A stored name that replaces one already set here: named, so a surprise override is never silent.
|
|
162
|
+
notes.push([Object.keys(variables).filter((key) => Object.prototype.hasOwnProperty.call(process.env, key)).sort(),
|
|
163
|
+
'replaced the value already set in this environment']);
|
|
164
|
+
for (const [list, why] of notes) {
|
|
165
|
+
if (list.length) process.stderr.write(`notis repository-secrets exec: ${list.join(', ')}: ${why}\n`);
|
|
166
|
+
}
|
|
167
|
+
const keys = Object.keys(variables).sort();
|
|
168
|
+
const env = { ...process.env, ...variables, NOTIS_REPOSITORY_SECRET_NAMES: keys.join(',') };
|
|
169
|
+
return runWithEnvironment(argv, env);
|
|
170
|
+
},
|
|
171
|
+
}];
|
|
@@ -979,13 +979,13 @@ export const spacesCommandSpecs = [
|
|
|
979
979
|
},
|
|
980
980
|
},
|
|
981
981
|
{
|
|
982
|
-
command_path: ['spaces', 'store', 'publish'], summary: 'Publish a Space
|
|
983
|
-
when_to_use: 'Share a Space you own as an installable template: link and team listings publish at once, public ones wait for review. A link listing never shows in the Store; only people with its link see it. Notis runs the same safety scan and Owner check as the submission page and explains any refusal.',
|
|
982
|
+
command_path: ['spaces', 'store', 'publish'], summary: 'Publish what a Space\'s source lists in store.ships as the next Store version.',
|
|
983
|
+
when_to_use: 'Share a Space you own as an installable template: link and team listings publish at once, public ones wait for review. A link listing never shows in the Store; only people with its link see it. Only what the root\'s defineSpace lists in store: { ships: { <source key>: [<alias>, ...] } } ships; every other sub-Space and linked item stays private, and publishing (an update of an existing listing included) is refused until that list is deployed. The result (and --dry-run) names what ships and what stays private under ships. Notis runs the same safety scan and Owner check as the submission page and explains any refusal, including a shipped view that reads or writes a database that stays private.',
|
|
984
984
|
args_schema: { arguments: [idArgument], options: [{ flags: '--channel <link|team|public>', description: 'Where to publish: anyone with the link, your team or everyone.' },
|
|
985
985
|
{ flags: '--metadata <json>', description: 'Listing name, tagline, description, category, icon, accent.' },
|
|
986
986
|
{ flags: '--starter <json>', description: 'Starter row IDs per database ({"<database-id>":["<record-key>"]}).' },
|
|
987
987
|
{ flags: '--notes <text>', description: 'Release notes for this version.' },
|
|
988
|
-
requestOption, { flags: '--dry-run', description: 'Show the package counts and review diff without publishing.' }] },
|
|
988
|
+
requestOption, { flags: '--dry-run', description: 'Show what ships and stays private, the package counts and the review diff without publishing.' }] },
|
|
989
989
|
examples: ['notis spaces store publish <space-id> --channel team --request-id publish-1 --dry-run',
|
|
990
990
|
'notis spaces store publish <space-id> --channel link --request-id share-link-1'],
|
|
991
991
|
mutates: true, idempotent: true, require_auth: true, backend_call: { type: 'http', path: '/portal_spaces/store-publish' },
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
chmodSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
renameSync,
|
|
8
|
+
unlinkSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from 'node:fs';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
// A Notis agent's Cloud Computer command gets NOTIS_JWT naming that agent, for a few hours only
|
|
14
|
+
// (server/lib/delegated_agents/cli_caller.py). A process that outlives it renews it here: the newest renewed token
|
|
15
|
+
// sits in a per-token cache file next to the CLI's config, and each run uses the newest unexpired of the
|
|
16
|
+
// environment token and the cached one. No other credential kind is ever renewed.
|
|
17
|
+
const MANAGED_AGENT_TYPE = 'notis_managed_agent';
|
|
18
|
+
const AGENT_CLAIM = 'notis_agent';
|
|
19
|
+
const CACHE_DIRNAME = 'agent-credentials';
|
|
20
|
+
// Renew once the token in use has less than this left.
|
|
21
|
+
export const AGENT_RENEW_WINDOW_SECONDS = 60 * 60;
|
|
22
|
+
// The renewal never holds a command up for long: on failure the current token is still used.
|
|
23
|
+
const RENEW_TIMEOUT_MS = 15_000;
|
|
24
|
+
|
|
25
|
+
function nowSeconds() {
|
|
26
|
+
return Math.floor(Date.now() / 1000);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Read without verifying, only for `type`, `notis_agent`, `sub` and `exp`: the server verifies every token.
|
|
30
|
+
function unverifiedPayload(jwt) {
|
|
31
|
+
if (typeof jwt !== 'string' || !jwt) return null;
|
|
32
|
+
try {
|
|
33
|
+
const parts = jwt.split('.');
|
|
34
|
+
if (parts.length !== 3) return null;
|
|
35
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
|
|
36
|
+
return payload && typeof payload === 'object' ? payload : null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The exp of a managed credential naming an agent, or null for any other token. */
|
|
43
|
+
function agentCredentialExpiry(jwt) {
|
|
44
|
+
const payload = unverifiedPayload(jwt);
|
|
45
|
+
if (
|
|
46
|
+
!payload
|
|
47
|
+
|| payload.type !== MANAGED_AGENT_TYPE
|
|
48
|
+
|| !payload[AGENT_CLAIM]
|
|
49
|
+
|| typeof payload[AGENT_CLAIM] !== 'object'
|
|
50
|
+
|| typeof payload.exp !== 'number'
|
|
51
|
+
) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return payload.exp;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isManagedAgentCredential(jwt) {
|
|
58
|
+
return agentCredentialExpiry(jwt) !== null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function cacheDirectory(configFile) {
|
|
62
|
+
return join(dirname(configFile), CACHE_DIRNAME);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function agentCredentialCacheFile(configFile, envJwt) {
|
|
66
|
+
return join(cacheDirectory(configFile), `${createHash('sha256').update(envJwt).digest('hex')}.json`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readCachedToken(configFile, envJwt) {
|
|
70
|
+
try {
|
|
71
|
+
const cached = JSON.parse(readFileSync(agentCredentialCacheFile(configFile, envJwt), 'utf-8'));
|
|
72
|
+
const token = typeof cached?.token === 'string' ? cached.token : null;
|
|
73
|
+
// Only a credential naming the same person's agent ever replaces the environment one.
|
|
74
|
+
if (
|
|
75
|
+
!token
|
|
76
|
+
|| agentCredentialExpiry(token) === null
|
|
77
|
+
|| unverifiedPayload(token).sub !== unverifiedPayload(envJwt).sub
|
|
78
|
+
) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return token;
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The credential a run should use for an environment token: null when it is not a managed agent credential (it is
|
|
89
|
+
* used as is), else the newest unexpired of it and its cached renewal, or the environment token once both lapsed.
|
|
90
|
+
*/
|
|
91
|
+
export function selectAgentCredential(envJwt, { configFile, now = nowSeconds() } = {}) {
|
|
92
|
+
const envExpiry = agentCredentialExpiry(envJwt);
|
|
93
|
+
if (envExpiry === null) return null;
|
|
94
|
+
const cached = configFile ? readCachedToken(configFile, envJwt) : null;
|
|
95
|
+
const cachedExpiry = cached ? agentCredentialExpiry(cached) : null;
|
|
96
|
+
if (cached && cachedExpiry > now && cachedExpiry > envExpiry) {
|
|
97
|
+
return { jwt: cached };
|
|
98
|
+
}
|
|
99
|
+
return { jwt: envJwt };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function pruneExpired(directory, keep, now) {
|
|
103
|
+
let names = [];
|
|
104
|
+
try {
|
|
105
|
+
names = readdirSync(directory);
|
|
106
|
+
} catch {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const name of names) {
|
|
110
|
+
if (name === keep || !name.endsWith('.json')) continue;
|
|
111
|
+
const path = join(directory, name);
|
|
112
|
+
try {
|
|
113
|
+
const expiry = agentCredentialExpiry(JSON.parse(readFileSync(path, 'utf-8'))?.token);
|
|
114
|
+
if (expiry === null || expiry <= now) unlinkSync(path);
|
|
115
|
+
} catch {
|
|
116
|
+
try {
|
|
117
|
+
unlinkSync(path);
|
|
118
|
+
} catch {
|
|
119
|
+
// Another process removed it first.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function storeAgentCredential(configFile, envJwt, token, { now = nowSeconds() } = {}) {
|
|
126
|
+
const directory = cacheDirectory(configFile);
|
|
127
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
128
|
+
const file = agentCredentialCacheFile(configFile, envJwt);
|
|
129
|
+
const temporaryFile = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
130
|
+
writeFileSync(temporaryFile, JSON.stringify({ token, exp: agentCredentialExpiry(token) }), { mode: 0o600 });
|
|
131
|
+
// writeFileSync's mode is masked by the umask; the file holds a credential, so it is the owner's only.
|
|
132
|
+
chmodSync(temporaryFile, 0o600);
|
|
133
|
+
renameSync(temporaryFile, file);
|
|
134
|
+
pruneExpired(directory, file.slice(directory.length + 1), now);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Renew the run's agent credential once when it expires within AGENT_RENEW_WINDOW_SECONDS. `renew` sends the
|
|
139
|
+
* renewal request with the current token and resolves to the server's `{ token, expires_at }`. A refused or failed
|
|
140
|
+
* renewal changes nothing: the current token is used while it is valid (no dead ends).
|
|
141
|
+
*/
|
|
142
|
+
export async function renewAgentCredentialIfDue(runtime, { configFile, renew, now = nowSeconds() }) {
|
|
143
|
+
if (!runtime?.agentEnvJwt || runtime.agentRenewAttempted) return false;
|
|
144
|
+
const expiry = agentCredentialExpiry(runtime.jwt);
|
|
145
|
+
// The server renews only an unexpired credential.
|
|
146
|
+
if (expiry === null || expiry <= now || expiry - now > AGENT_RENEW_WINDOW_SECONDS) return false;
|
|
147
|
+
runtime.agentRenewAttempted = true;
|
|
148
|
+
try {
|
|
149
|
+
const answer = await renew();
|
|
150
|
+
const token = typeof answer?.token === 'string' ? answer.token : null;
|
|
151
|
+
const renewedExpiry = token ? agentCredentialExpiry(token) : null;
|
|
152
|
+
if (
|
|
153
|
+
renewedExpiry === null
|
|
154
|
+
|| renewedExpiry <= expiry
|
|
155
|
+
|| unverifiedPayload(token).sub !== unverifiedPayload(runtime.jwt).sub
|
|
156
|
+
) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
runtime.jwt = token;
|
|
160
|
+
try {
|
|
161
|
+
storeAgentCredential(configFile, runtime.agentEnvJwt, token, { now });
|
|
162
|
+
} catch {
|
|
163
|
+
// This run still uses the fresh token; the next run renews again.
|
|
164
|
+
}
|
|
165
|
+
return true;
|
|
166
|
+
} catch {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const AGENT_RENEW_REQUEST = Object.freeze({
|
|
172
|
+
path: '/cli_tools',
|
|
173
|
+
body: Object.freeze({ operation: 'renew_agent_credential' }),
|
|
174
|
+
timeoutMs: RENEW_TIMEOUT_MS,
|
|
175
|
+
});
|