@notis_ai/cli 0.2.32 → 0.2.34
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 +75 -11
- package/dist/agent-hooks/notis-agent-hook.mjs +4407 -905
- 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 +102 -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/NotisSelectionBoundary.tsx +13 -5
- package/dist/sdk/src/components/SelectionActionBar.tsx +45 -8
- package/dist/sdk/src/components/SpaceTextComments.tsx +293 -0
- package/dist/sdk/src/components/selectionRange.ts +65 -0
- package/dist/sdk/src/config.ts +3 -1
- package/dist/sdk/src/functions.ts +218 -0
- package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +66 -9
- 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 +16 -4
- package/dist/sdk/src/interactions/shortcuts.tsx +6 -1
- package/dist/sdk/src/interactions/swipeDownToDismiss.ts +158 -0
- package/dist/sdk/src/interactions/textBoxTwoState.ts +174 -0
- package/dist/sdk/src/interactions.ts +17 -0
- package/dist/sdk/src/runtime.ts +16 -1
- package/dist/sdk/src/space.ts +401 -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 +262 -31
- package/dist/skill-sync-worker.mjs +515 -127
- package/dist/space-harness/host.js +389 -154
- package/dist/space-sdk/dist/chunk-3NPBCE6E.js +3 -0
- package/dist/space-sdk/dist/index.js +3 -3
- package/dist/space-sdk/dist/ui.js +16 -11
- package/dist/space-sdk/src/config.ts +3 -1
- package/dist/space-sdk/src/functions.ts +218 -0
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +7 -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/interactions/shortcuts.d.ts +5 -0
- package/dist/space-sdk/src/runtime.d.ts +14 -1
- package/dist/space-sdk/src/space.ts +401 -33
- package/dist/space-sdk/src/tailwind-candidates.d.ts +400 -204
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +90 -15
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +4 -1
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +4 -2
- package/dist/space-sdk/src/ui/comments/commentDrafts.d.ts +63 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +59 -88
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +32 -1
- package/dist/space-sdk/src/ui/comments/handover.d.ts +34 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
- package/dist/space-sdk/src/ui/comments/hostPanel.d.ts +113 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +7 -2
- package/dist/space-sdk/src/ui/comments/paneOutlet.d.ts +33 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +71 -27
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
- package/dist/space-sdk/src/ui/comments/reviewRun.d.ts +190 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +116 -77
- 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 +450 -215
- 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 +95 -19
- package/src/runtime/app-platform.js +8 -0
- package/src/runtime/auth-recovery.js +14 -0
- package/src/runtime/profiles.js +74 -2
- package/src/runtime/skill-sync/cloud-client.ts +33 -3
- package/src/runtime/skill-sync/index.ts +4 -3
- package/src/runtime/skill-sync/symlink-manager.ts +354 -35
- package/src/runtime/skill-sync/types.ts +14 -2
- package/src/runtime/space-functions.js +213 -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
|
@@ -9,16 +9,22 @@ import { usageError } from './errors.js';
|
|
|
9
9
|
* An agent's declared identity, sent on every backend call.
|
|
10
10
|
*
|
|
11
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,
|
|
13
|
-
* NOTIS_AGENT_THREAD variables (a flag wins over its variable). The backend then treats what the call writes as that
|
|
12
|
+
* who it is with `--agent-name`, `--agent-id`, `--agent-thread` and `--agent-thread-name`, or the NOTIS_AGENT_NAME,
|
|
13
|
+
* NOTIS_AGENT_ID, NOTIS_AGENT_THREAD and NOTIS_AGENT_THREAD_NAME variables (a flag wins over its variable). The backend then treats what the call writes as that
|
|
14
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
15
|
* never wakes the agent that wrote it. The declaration is self-asserted: it names the writer, it never grants access.
|
|
16
16
|
*
|
|
17
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
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* words joined by hyphens, 3 to 60 characters, such as fred-and-the-machine, never a harness or product name
|
|
19
|
+
* (RESERVED_AGENT_NAMES: claude, codex, notis-agent...), so each sub-agent shows. The name is only a name: the id
|
|
20
|
+
* decides which comments are the agent's own. The id may be the agent's own session id (a T3 thread id, a Codex or
|
|
21
|
+
* Claude session id); without one the CLI generates a random one the first time a name is used on this computer and
|
|
22
|
+
* keeps it for that name in `agents.json`, next to the CLI config file (so NOTIS_CLI_CONFIG_FILE moves it too),
|
|
23
|
+
* written under the config lock. An explicit id always wins.
|
|
24
|
+
*
|
|
25
|
+
* The thread name labels the thread the agent works in (a T3 thread title, "PR #3851"), shown after its name on its
|
|
26
|
+
* comments and on the Goes to line. The harness (claude_code, codex, cursor_agent...) is detected from the
|
|
27
|
+
* environment the agent's tool sets (detectAgentHarness), or NOTIS_AGENT_HARNESS, and shows as its logo.
|
|
22
28
|
*
|
|
23
29
|
* The values travel percent-encoded (encodeURIComponent) in the X-Notis-Agent-* headers. The backend applies the same
|
|
24
30
|
* rules (server/lib/delegated_agents/declared_agent.py) and refuses a comment written through the CLI without a name.
|
|
@@ -26,23 +32,64 @@ import { usageError } from './errors.js';
|
|
|
26
32
|
export const AGENT_NAME_HEADER = 'X-Notis-Agent-Name';
|
|
27
33
|
export const AGENT_ID_HEADER = 'X-Notis-Agent-Id';
|
|
28
34
|
export const AGENT_THREAD_HEADER = 'X-Notis-Agent-Thread';
|
|
35
|
+
export const AGENT_THREAD_NAME_HEADER = 'X-Notis-Agent-Thread-Name';
|
|
36
|
+
export const AGENT_HARNESS_HEADER = 'X-Notis-Agent-Harness';
|
|
29
37
|
export const AGENT_IDENTITY_ENV = {
|
|
30
38
|
name: 'NOTIS_AGENT_NAME',
|
|
31
39
|
id: 'NOTIS_AGENT_ID',
|
|
32
40
|
thread: 'NOTIS_AGENT_THREAD',
|
|
41
|
+
threadName: 'NOTIS_AGENT_THREAD_NAME',
|
|
42
|
+
harness: 'NOTIS_AGENT_HARNESS',
|
|
33
43
|
};
|
|
34
44
|
export const AGENT_NAME_MIN = 3;
|
|
35
45
|
export const AGENT_NAME_LIMIT = 60;
|
|
36
46
|
export const BAND_NAME_EXAMPLE = 'fred-and-the-machine';
|
|
37
47
|
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
48
|
export const AGENT_IDS_VERSION = 1;
|
|
49
|
+
export const AGENT_ID_MIN = 3;
|
|
39
50
|
export const AGENT_ID_LIMIT = 128;
|
|
40
51
|
export const AGENT_THREAD_LIMIT = 512;
|
|
52
|
+
export const AGENT_THREAD_NAME_LIMIT = 80;
|
|
53
|
+
export const AGENT_HARNESS_LIMIT = 40;
|
|
54
|
+
// A harness or product name is no band name (server/lib/delegated_agents/declared_agent.py RESERVED_NAMES, the same list).
|
|
55
|
+
const RESERVED_BASES = ['claude', 'claude-code', 'codex', 'cursor', 'cursor-agent', 'gemini', 'notis', 't3', 't3-code',
|
|
56
|
+
'opencode', 'agent', 'assistant', 'bot'];
|
|
57
|
+
export const RESERVED_AGENT_NAMES = Object.freeze(new Set(
|
|
58
|
+
RESERVED_BASES.flatMap((base) => [base, `${base}-cli`, `${base}-agent`]),
|
|
59
|
+
));
|
|
41
60
|
|
|
42
61
|
const BAND_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)+$/;
|
|
43
62
|
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:@/+-]*$/;
|
|
44
63
|
// Printable ASCII without spaces: an id or a link.
|
|
45
64
|
const THREAD_PATTERN = /^[\x21-\x7e]+$/;
|
|
65
|
+
// eslint-disable-next-line no-control-regex
|
|
66
|
+
const CONTROL_PATTERN = /[\x00-\x1f\x7f]/;
|
|
67
|
+
const HARNESS_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The harness running this process, from the variables each tool sets in the shells it starts, or null. Claude Code
|
|
71
|
+
* sets CLAUDECODE=1 with CLAUDE_CODE_ENTRYPOINT and CLAUDE_CODE_SESSION_ID, Codex CODEX_* (CODEX_SANDBOX,
|
|
72
|
+
* CODEX_THREAD_ID...; CODEX_HOME is a person's own setting), Cursor's agent CURSOR_AGENT, Gemini CLI GEMINI_CLI,
|
|
73
|
+
* OpenCode OPENCODE; AI_AGENT names it in the shared convention. T3 Code runs one of these, which names the harness.
|
|
74
|
+
*/
|
|
75
|
+
export function detectAgentHarness(env = process.env) {
|
|
76
|
+
const set = (name) => typeof env[name] === 'string' && env[name].trim() !== '';
|
|
77
|
+
if (set('CLAUDECODE') || set('CLAUDE_CODE_ENTRYPOINT') || set('CLAUDE_CODE_SESSION_ID')) return 'claude_code';
|
|
78
|
+
if (Object.keys(env).some((key) => key.startsWith('CODEX_') && key !== 'CODEX_HOME' && set(key))) return 'codex';
|
|
79
|
+
if (set('CURSOR_AGENT')) return 'cursor_agent';
|
|
80
|
+
if (set('GEMINI_CLI')) return 'gemini';
|
|
81
|
+
if (set('OPENCODE')) return 'opencode';
|
|
82
|
+
const named = String(env.AI_AGENT ?? '').toLowerCase();
|
|
83
|
+
if (named.startsWith('claude')) return 'claude_code';
|
|
84
|
+
if (named.startsWith('codex')) return 'codex';
|
|
85
|
+
if (named.startsWith('cursor')) return 'cursor_agent';
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Whether `name` is a harness or product name rather than a band name (RESERVED_AGENT_NAMES). */
|
|
90
|
+
export function isReservedAgentName(name) {
|
|
91
|
+
return typeof name === 'string' && RESERVED_AGENT_NAMES.has(name.trim().toLowerCase());
|
|
92
|
+
}
|
|
46
93
|
|
|
47
94
|
function pick(flag, variable) {
|
|
48
95
|
if (typeof flag === 'string') return flag;
|
|
@@ -56,18 +103,30 @@ export function readAgentIdentity(globalOptions = {}, env = process.env) {
|
|
|
56
103
|
id: pick(globalOptions.agentId, env[AGENT_IDENTITY_ENV.id]),
|
|
57
104
|
thread: pick(globalOptions.agentThread, env[AGENT_IDENTITY_ENV.thread]),
|
|
58
105
|
};
|
|
59
|
-
|
|
106
|
+
const threadName = pick(globalOptions.agentThreadName, env[AGENT_IDENTITY_ENV.threadName]);
|
|
107
|
+
if (threadName !== undefined) raw.threadName = threadName;
|
|
108
|
+
if (!Object.values(raw).some((value) => typeof value === 'string' && value.trim())) return null;
|
|
109
|
+
// The harness alone declares nothing: it is only sent with a declaration.
|
|
110
|
+
const harness = pick(undefined, env[AGENT_IDENTITY_ENV.harness]) ?? detectAgentHarness(env);
|
|
111
|
+
return harness ? { ...raw, harness } : raw;
|
|
60
112
|
}
|
|
61
113
|
|
|
62
|
-
/** The validated declaration ({name, id?, thread?}), or null; a usage error names what to fix. */
|
|
114
|
+
/** The validated declaration ({name, id?, thread?, threadName?, harness?}), or null; a usage error names what to fix. */
|
|
63
115
|
export function validateAgentIdentity(raw) {
|
|
64
116
|
if (!raw) return null;
|
|
65
117
|
const name = String(raw.name ?? '').trim();
|
|
66
118
|
const id = String(raw.id ?? '').trim();
|
|
67
119
|
const thread = String(raw.thread ?? '').trim();
|
|
120
|
+
const threadName = String(raw.threadName ?? '').trim();
|
|
121
|
+
const harnessText = String(raw.harness ?? '').trim().toLowerCase();
|
|
68
122
|
if (!name) {
|
|
69
123
|
throw usageError(
|
|
70
|
-
`Name the agent: set ${AGENT_IDENTITY_ENV.name} (or --agent-name) whenever ${AGENT_IDENTITY_ENV.id} or ${AGENT_IDENTITY_ENV.
|
|
124
|
+
`Name the agent: set ${AGENT_IDENTITY_ENV.name} (or --agent-name) whenever ${AGENT_IDENTITY_ENV.id}, ${AGENT_IDENTITY_ENV.thread} or ${AGENT_IDENTITY_ENV.threadName} is set.`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (isReservedAgentName(name)) {
|
|
128
|
+
throw usageError(
|
|
129
|
+
`${AGENT_IDENTITY_ENV.name} (or --agent-name) "${name.slice(0, AGENT_NAME_LIMIT)}" is a harness or product name, not a band name. Pick ${BAND_NAME_RULE}, of your own for this agent, and keep it.`,
|
|
71
130
|
);
|
|
72
131
|
}
|
|
73
132
|
if (!isBandName(name)) {
|
|
@@ -75,9 +134,9 @@ export function validateAgentIdentity(raw) {
|
|
|
75
134
|
`${AGENT_IDENTITY_ENV.name} (or --agent-name) must be ${BAND_NAME_RULE}. Pick one for this agent and keep it.`,
|
|
76
135
|
);
|
|
77
136
|
}
|
|
78
|
-
if (id && (id.length > AGENT_ID_LIMIT || !ID_PATTERN.test(id))) {
|
|
137
|
+
if (id && (id.length < AGENT_ID_MIN || id.length > AGENT_ID_LIMIT || !ID_PATTERN.test(id))) {
|
|
79
138
|
throw usageError(
|
|
80
|
-
`${AGENT_IDENTITY_ENV.id} must be
|
|
139
|
+
`${AGENT_IDENTITY_ENV.id} must be ${AGENT_ID_MIN} to ${AGENT_ID_LIMIT} characters: letters, digits and . _ : @ / + - , starting with a letter or digit (your own session id, or leave it unset and the CLI keeps one for the name).`,
|
|
81
140
|
);
|
|
82
141
|
}
|
|
83
142
|
if (thread && (thread.length > AGENT_THREAD_LIMIT || !THREAD_PATTERN.test(thread))) {
|
|
@@ -85,7 +144,20 @@ export function validateAgentIdentity(raw) {
|
|
|
85
144
|
`${AGENT_IDENTITY_ENV.thread} must be a thread id or link of at most ${AGENT_THREAD_LIMIT} characters, without spaces.`,
|
|
86
145
|
);
|
|
87
146
|
}
|
|
88
|
-
|
|
147
|
+
if (threadName && (Array.from(threadName).length > AGENT_THREAD_NAME_LIMIT || CONTROL_PATTERN.test(threadName))) {
|
|
148
|
+
throw usageError(
|
|
149
|
+
`${AGENT_IDENTITY_ENV.threadName} (or --agent-thread-name) must be the name of the thread you work in, at most ${AGENT_THREAD_NAME_LIMIT} characters on one line.`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
// A harness that is no identifier is dropped, never refused: it only picks a logo.
|
|
153
|
+
const harness = harnessText.length <= AGENT_HARNESS_LIMIT && HARNESS_PATTERN.test(harnessText) ? harnessText : '';
|
|
154
|
+
return {
|
|
155
|
+
name,
|
|
156
|
+
...(id ? { id } : {}),
|
|
157
|
+
...(thread ? { thread } : {}),
|
|
158
|
+
...(threadName ? { threadName } : {}),
|
|
159
|
+
...(harness ? { harness } : {}),
|
|
160
|
+
};
|
|
89
161
|
}
|
|
90
162
|
|
|
91
163
|
const RAW_HEADER_LIMIT = AGENT_THREAD_LIMIT;
|
|
@@ -101,13 +173,15 @@ function rawIdentityHeaders(raw) {
|
|
|
101
173
|
put(AGENT_NAME_HEADER, raw?.name);
|
|
102
174
|
put(AGENT_ID_HEADER, raw?.id);
|
|
103
175
|
put(AGENT_THREAD_HEADER, raw?.thread);
|
|
176
|
+
put(AGENT_THREAD_NAME_HEADER, raw?.threadName);
|
|
177
|
+
put(AGENT_HARNESS_HEADER, raw?.harness);
|
|
104
178
|
return headers;
|
|
105
179
|
}
|
|
106
180
|
|
|
107
|
-
/** Whether `name` follows the band-name rule (BAND_NAME_RULE). */
|
|
181
|
+
/** Whether `name` follows the band-name rule (BAND_NAME_RULE) and is no harness or product name. */
|
|
108
182
|
export function isBandName(name) {
|
|
109
183
|
return typeof name === 'string' && name.length >= AGENT_NAME_MIN && name.length <= AGENT_NAME_LIMIT
|
|
110
|
-
&& BAND_NAME.test(name);
|
|
184
|
+
&& BAND_NAME.test(name) && !isReservedAgentName(name);
|
|
111
185
|
}
|
|
112
186
|
|
|
113
187
|
export function agentIdsFile(configFile = resolveCliConfigFile()) {
|
|
@@ -128,7 +202,8 @@ function readAgentIds(file) {
|
|
|
128
202
|
|
|
129
203
|
function storedId(agents, name) {
|
|
130
204
|
const id = Object.hasOwn(agents, name) ? agents[name] : null;
|
|
131
|
-
return typeof id === 'string' && id.length <= AGENT_ID_LIMIT && ID_PATTERN.test(id)
|
|
205
|
+
return typeof id === 'string' && id.length >= AGENT_ID_MIN && id.length <= AGENT_ID_LIMIT && ID_PATTERN.test(id)
|
|
206
|
+
? id : null;
|
|
132
207
|
}
|
|
133
208
|
|
|
134
209
|
/**
|
|
@@ -165,10 +240,9 @@ export function agentIdentityHeaders(runtime, options = {}) {
|
|
|
165
240
|
try {
|
|
166
241
|
identity = validateAgentIdentity(raw);
|
|
167
242
|
} catch {
|
|
168
|
-
// A declaration that breaks the rules is sent as written, with no kept id:
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
// breaks a person without unified comments.
|
|
243
|
+
// A declaration that breaks the rules is sent as written, with no kept id: the routes that read declarations
|
|
244
|
+
// (tools, Space data and actions, document restores and removes) refuse the call with invalid_agent_identity,
|
|
245
|
+
// reads included. The server is the one judge, so the CLI never refuses it first.
|
|
172
246
|
return rawIdentityHeaders(raw);
|
|
173
247
|
}
|
|
174
248
|
if (!identity) return {};
|
|
@@ -183,5 +257,7 @@ export function agentIdentityHeaders(runtime, options = {}) {
|
|
|
183
257
|
const headers = { [AGENT_NAME_HEADER]: encodeURIComponent(identity.name) };
|
|
184
258
|
if (id) headers[AGENT_ID_HEADER] = encodeURIComponent(id);
|
|
185
259
|
if (identity.thread) headers[AGENT_THREAD_HEADER] = encodeURIComponent(identity.thread);
|
|
260
|
+
if (identity.threadName) headers[AGENT_THREAD_NAME_HEADER] = encodeURIComponent(identity.threadName);
|
|
261
|
+
if (identity.harness) headers[AGENT_HARNESS_HEADER] = encodeURIComponent(identity.harness);
|
|
186
262
|
return headers;
|
|
187
263
|
}
|
|
@@ -189,12 +189,20 @@ function stripNotisSdkImports(source) {
|
|
|
189
189
|
.replace(/import\s+type\s+[\s\S]*?from\s+['"][^'"]*['"]\s*;?/g, '')
|
|
190
190
|
.replace(/import\s*{([^}]+)}\s+from\s+['"]@notis\/sdk\/config['"]\s*;?/g, (_statement, names) => {
|
|
191
191
|
const declarations = [];
|
|
192
|
+
const schemas = [];
|
|
192
193
|
for (const imported of names.split(',').map(value => value.trim()).filter(Boolean)) {
|
|
193
194
|
if (imported.startsWith('type ')) continue;
|
|
195
|
+
// The function input schemas are values, not identity helpers: take them from the project's own
|
|
196
|
+
// SDK package entry (built JavaScript), the one copy of them.
|
|
197
|
+
if (/^(threadHookInput|threadIdleInput|threadSettleInput|commentOptionInput)(?:\s+as\s+[A-Za-z_$][\w$]*)?$/.test(imported)) {
|
|
198
|
+
schemas.push(imported);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
194
201
|
const match = imported.match(/^(defineNotisApp|defineSpace|defineSpaces)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);
|
|
195
202
|
if (!match) throw usageError(`Unsupported configuration helper: ${imported}`);
|
|
196
203
|
declarations.push(`const ${match[2] || match[1]} = (value) => value;`);
|
|
197
204
|
}
|
|
205
|
+
if (schemas.length) declarations.unshift(`import { ${schemas.join(', ')} } from '@notis/sdk';`);
|
|
198
206
|
return declarations.join('\n');
|
|
199
207
|
});
|
|
200
208
|
}
|
|
@@ -88,6 +88,20 @@ export function createExpiredAuthError(runtime) {
|
|
|
88
88
|
],
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
+
if (runtime?.credentialSource === 'env' && runtime.agentEnvJwt) {
|
|
92
|
+
// A Notis agent's Cloud Computer credential and every renewal of it lapsed (agent-credential.js).
|
|
93
|
+
return new CliError({
|
|
94
|
+
code: 'auth_expired',
|
|
95
|
+
message: 'NOTIS_JWT is expired: this agent\'s Notis credential lapsed',
|
|
96
|
+
exitCode: EXIT_CODES.auth,
|
|
97
|
+
details: { credential_source: 'env', agent_credential: true },
|
|
98
|
+
hints: [
|
|
99
|
+
{
|
|
100
|
+
message: 'Start a new Cloud Computer command: it gets a fresh credential naming this agent.',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
91
105
|
if (runtime?.credentialSource === 'env') {
|
|
92
106
|
return new CliError({
|
|
93
107
|
code: 'auth_expired',
|
package/src/runtime/profiles.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
3
|
import {
|
|
3
4
|
existsSync,
|
|
@@ -14,6 +15,7 @@ import { getAuthRecovery, quoteShellArgument } from './auth-recovery.js';
|
|
|
14
15
|
import { channelFromProfile, cliCommandForChannel, pinnedReleaseChannel } from './channel.js';
|
|
15
16
|
import { resolveRetryEnabled } from './retry.js';
|
|
16
17
|
import { readAgentIdentity } from './agent-identity.js';
|
|
18
|
+
import { selectAgentCredential } from './agent-credential.js';
|
|
17
19
|
import {
|
|
18
20
|
LIVE_API_HOSTS,
|
|
19
21
|
currentApiOrigin,
|
|
@@ -38,6 +40,9 @@ const LEGACY_DESKTOP_PROFILE_KEYS = [
|
|
|
38
40
|
'desktop_pid',
|
|
39
41
|
];
|
|
40
42
|
const WORKTREE_RUNTIME_FILENAME = join('.context', 'notis-runtime.json');
|
|
43
|
+
// dev.sh keeps the lease's session tokens beside it in a mode-0600 file whose name says
|
|
44
|
+
// it holds secrets; notis-runtime.json itself holds none.
|
|
45
|
+
const WORKTREE_RUNTIME_SECRETS_FILENAME = 'notis-runtime-secrets.json';
|
|
41
46
|
const WORKTREE_ROUTING_FILENAME = join('.context', 'notis-routing.json');
|
|
42
47
|
// WHATWG URL keeps the brackets of an IPv6 hostname: `new URL('http://[::1]:8123').hostname` is '[::1]'.
|
|
43
48
|
const LOCAL_API_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]']);
|
|
@@ -260,6 +265,52 @@ function processIsAlive(pid) {
|
|
|
260
265
|
}
|
|
261
266
|
}
|
|
262
267
|
|
|
268
|
+
// A dev.sh started inside another pid namespace (a preview stack) has a
|
|
269
|
+
// dev_pid this process cannot see at all: process.kill answers ESRCH exactly
|
|
270
|
+
// as for a dead supervisor. Its loopback backend still answers, so the lease
|
|
271
|
+
// counts as live when the lease's own API serves its schema, the readiness
|
|
272
|
+
// probe dev.sh itself waits on. Nothing answering (or an error status) keeps
|
|
273
|
+
// the refusal. The CLI resolves runtimes synchronously, so the probe runs in a
|
|
274
|
+
// short child process.
|
|
275
|
+
const RUNTIME_API_PROBE_TIMEOUT_MS = 1500;
|
|
276
|
+
const RUNTIME_API_PROBE_SOURCE = `
|
|
277
|
+
const target = process.argv[1].replace(/\\/+$/, '') + '/openapi.json';
|
|
278
|
+
fetch(target, { redirect: 'manual', signal: AbortSignal.timeout(${RUNTIME_API_PROBE_TIMEOUT_MS}) })
|
|
279
|
+
.then((response) => {
|
|
280
|
+
response.body?.cancel().catch(() => {});
|
|
281
|
+
process.exit(response.ok ? 0 : 1);
|
|
282
|
+
})
|
|
283
|
+
.catch(() => process.exit(1));
|
|
284
|
+
`;
|
|
285
|
+
const runtimeApiProbeResults = new Map();
|
|
286
|
+
|
|
287
|
+
function localRuntimeApiAnswers(apiBase) {
|
|
288
|
+
if (runtimeApiProbeResults.has(apiBase)) {
|
|
289
|
+
return runtimeApiProbeResults.get(apiBase);
|
|
290
|
+
}
|
|
291
|
+
let answered = false;
|
|
292
|
+
try {
|
|
293
|
+
const probe = spawnSync(process.execPath, ['-e', RUNTIME_API_PROBE_SOURCE, apiBase], {
|
|
294
|
+
env: { PATH: process.env.PATH || '' },
|
|
295
|
+
stdio: 'ignore',
|
|
296
|
+
timeout: RUNTIME_API_PROBE_TIMEOUT_MS + 2500,
|
|
297
|
+
});
|
|
298
|
+
answered = probe.status === 0;
|
|
299
|
+
} catch {
|
|
300
|
+
answered = false;
|
|
301
|
+
}
|
|
302
|
+
runtimeApiProbeResults.set(apiBase, answered);
|
|
303
|
+
return answered;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function devRuntimeIsAlive(pid, apiBase) {
|
|
307
|
+
if (processIsAlive(pid)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
// A lease without a real supervisor pid was never written by dev.sh.
|
|
311
|
+
return Number.isInteger(pid) && pid > 0 && localRuntimeApiAnswers(apiBase);
|
|
312
|
+
}
|
|
313
|
+
|
|
263
314
|
export function resolveWorktreeRuntime(startDir = process.cwd()) {
|
|
264
315
|
if (
|
|
265
316
|
process.env.NODE_ENV === 'test' &&
|
|
@@ -293,10 +344,17 @@ export function resolveWorktreeRuntime(startDir = process.cwd()) {
|
|
|
293
344
|
}
|
|
294
345
|
|
|
295
346
|
const runtime = readJsonFile(runtimePath);
|
|
347
|
+
const secrets = readJsonFile(join(dirname(runtimePath), WORKTREE_RUNTIME_SECRETS_FILENAME));
|
|
348
|
+
// The secrets of this same dev session win; a lease from an older dev.sh still carries
|
|
349
|
+
// its token itself (kept as a fallback for one release).
|
|
350
|
+
const sessionSecrets =
|
|
351
|
+
secrets && runtime && secrets.dev_session_id === runtime.dev_session_id ? secrets : null;
|
|
296
352
|
const apiBase = typeof runtime?.api_base === 'string' ? runtime.api_base.replace(/\/+$/, '') : '';
|
|
297
353
|
const profile = typeof runtime?.profile === 'string' ? runtime.profile.trim() : '';
|
|
298
354
|
const devAccessToken =
|
|
299
|
-
typeof
|
|
355
|
+
typeof sessionSecrets?.dev_access_token === 'string' && sessionSecrets.dev_access_token.trim()
|
|
356
|
+
? sessionSecrets.dev_access_token.trim()
|
|
357
|
+
: typeof runtime?.dev_access_token === 'string' ? runtime.dev_access_token.trim() : '';
|
|
300
358
|
const desktopDeepLinkScheme =
|
|
301
359
|
typeof runtime?.desktop_deep_link_scheme === 'string'
|
|
302
360
|
? runtime.desktop_deep_link_scheme.trim()
|
|
@@ -307,7 +365,7 @@ export function resolveWorktreeRuntime(startDir = process.cwd()) {
|
|
|
307
365
|
!isLocalApiBase(apiBase) ||
|
|
308
366
|
!profile ||
|
|
309
367
|
!devAccessToken ||
|
|
310
|
-
!
|
|
368
|
+
!devRuntimeIsAlive(pid, apiBase)
|
|
311
369
|
) {
|
|
312
370
|
// Reported rather than thrown: an unusable lease must not stop someone
|
|
313
371
|
// from listing profiles or switching to a live account from inside the
|
|
@@ -864,6 +922,7 @@ export function resolveRuntimeProfile(
|
|
|
864
922
|
const oauthJwt = profile.oauth_access_token;
|
|
865
923
|
let jwt;
|
|
866
924
|
let credentialKind;
|
|
925
|
+
let agentEnvJwt = null;
|
|
867
926
|
|
|
868
927
|
// A dev credential is a real Supabase token for the worktree's test user. It
|
|
869
928
|
// is only ever spendable against the loopback backend that minted it, so a
|
|
@@ -890,6 +949,17 @@ export function resolveRuntimeProfile(
|
|
|
890
949
|
} else if (envJwt) {
|
|
891
950
|
jwt = envJwt;
|
|
892
951
|
credentialKind = 'env';
|
|
952
|
+
// A Cloud Computer command's credential naming its agent: the newest unexpired of it and its renewal
|
|
953
|
+
// (agent-credential.js). Any other environment token is used as is.
|
|
954
|
+
try {
|
|
955
|
+
const selected = selectAgentCredential(envJwt, { configFile: resolveConfigFile() });
|
|
956
|
+
if (selected) {
|
|
957
|
+
jwt = selected.jwt;
|
|
958
|
+
agentEnvJwt = envJwt;
|
|
959
|
+
}
|
|
960
|
+
} catch {
|
|
961
|
+
// An unreadable cache leaves the environment token in use.
|
|
962
|
+
}
|
|
893
963
|
} else if (
|
|
894
964
|
oauthJwt
|
|
895
965
|
&& !credentialIsExpired({ credentialKind: 'oauth', jwt: oauthJwt }, profile)
|
|
@@ -997,6 +1067,8 @@ export function resolveRuntimeProfile(
|
|
|
997
1067
|
jwt,
|
|
998
1068
|
credentialKind,
|
|
999
1069
|
credentialSource: credentialKind,
|
|
1070
|
+
// The NOTIS_JWT of a managed agent credential, set only when `jwt` may be renewed (agent-credential.js).
|
|
1071
|
+
agentEnvJwt,
|
|
1000
1072
|
oauthAccessToken: profile.oauth_access_token,
|
|
1001
1073
|
oauthRefreshToken: profile.oauth_refresh_token,
|
|
1002
1074
|
oauthAccessExpiresAt: profile.oauth_access_expires_at,
|
|
@@ -82,6 +82,28 @@ async function skillPushPayload(skill: LocalSkill): Promise<Record<string, unkno
|
|
|
82
82
|
/** The request body around the skills array, counted in every batch's size. */
|
|
83
83
|
const SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* The server refuses any request body above 64 MiB with 413 before reading it
|
|
87
|
+
* (server/lib/request_body_limit.py DEFAULT_REQUEST_BODY_MAX_BYTES, truth SKL-065).
|
|
88
|
+
* A Skill whose payload alone would exceed it is never sent.
|
|
89
|
+
*/
|
|
90
|
+
export const SERVER_REQUEST_BODY_MAX_BYTES = 64 * 1024 * 1024;
|
|
91
|
+
export const MAX_SYNC_PUSH_SKILL_BYTES = SERVER_REQUEST_BODY_MAX_BYTES - SYNC_PUSH_ENVELOPE_BYTES;
|
|
92
|
+
|
|
93
|
+
function mib(bytes: number): string {
|
|
94
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function tooLargeFailure(name: string, sizeBytes: number, limitBytes: number): SkillSyncFailure {
|
|
98
|
+
return {
|
|
99
|
+
name,
|
|
100
|
+
error: `Skill is too large to sync (${mib(sizeBytes)}, the limit is ${mib(limitBytes)}); remove large files from its folder to sync it`,
|
|
101
|
+
code: 'skill_too_large',
|
|
102
|
+
size_bytes: sizeBytes,
|
|
103
|
+
limit_bytes: limitBytes,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
85
107
|
function pushBatches(payloads: Record<string, unknown>[], maxBodyBytes: number): Record<string, unknown>[][] {
|
|
86
108
|
const batches: Record<string, unknown>[][] = [];
|
|
87
109
|
let batch: Record<string, unknown>[] = [];
|
|
@@ -118,18 +140,26 @@ function pushFailure(name: string, error: unknown): SkillSyncFailure {
|
|
|
118
140
|
|
|
119
141
|
/**
|
|
120
142
|
* Push changed skills in bodies of at most `maxBodyBytes` (one skill when it is
|
|
121
|
-
* larger alone). A
|
|
143
|
+
* larger alone). A skill above `maxSkillBytes` (the server's body ceiling) is
|
|
144
|
+
* never sent and fails as `skill_too_large` with its size and the limit. A batch the server or the edge refuses fails only its own skills,
|
|
122
145
|
* recorded with the HTTP status, and the other batches still push.
|
|
123
146
|
*/
|
|
124
147
|
export async function pushChangedSkills(
|
|
125
148
|
serverUrl: string,
|
|
126
149
|
jwt: string,
|
|
127
150
|
changedSkills: LocalSkill[],
|
|
128
|
-
options: { maxBodyBytes?: number } = {},
|
|
151
|
+
options: { maxBodyBytes?: number; maxSkillBytes?: number } = {},
|
|
129
152
|
): Promise<SyncPushResponse> {
|
|
130
|
-
const
|
|
153
|
+
const maxSkillBytes = options.maxSkillBytes ?? MAX_SYNC_PUSH_SKILL_BYTES;
|
|
131
154
|
const saved: unknown[] = [];
|
|
132
155
|
const failed: SkillSyncFailure[] = [];
|
|
156
|
+
const payloadSkills: Record<string, unknown>[] = [];
|
|
157
|
+
for (const payload of await Promise.all(changedSkills.map(skillPushPayload))) {
|
|
158
|
+
// +1 for the comma between array items, as in pushBatches.
|
|
159
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
|
|
160
|
+
if (bytes > maxSkillBytes) failed.push(tooLargeFailure(String(payload.name), bytes, maxSkillBytes));
|
|
161
|
+
else payloadSkills.push(payload);
|
|
162
|
+
}
|
|
133
163
|
for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
|
|
134
164
|
try {
|
|
135
165
|
const result = await requestJson<SyncPushResponse>(`${serverUrl}/portal_skills/sync-push`, jwt, {
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
SyncPullResponse,
|
|
11
11
|
SyncSettings,
|
|
12
12
|
SyncedSkill,
|
|
13
|
+
VerifiedAgentLinks,
|
|
13
14
|
} from "./types";
|
|
14
15
|
import { normalizeAgentTargets } from "./types";
|
|
15
16
|
import { assertNativePull, checkedNativeReference, isNativeSkill, nativeState } from './native-identity';
|
|
@@ -39,7 +40,7 @@ import {
|
|
|
39
40
|
} from "./symlink-manager";
|
|
40
41
|
import { getPushCandidates, selectCloudSkillsToApply } from "./sync-plan";
|
|
41
42
|
import { writeCloudSkill } from "./write-cloud-skill";
|
|
42
|
-
export { fetchSyncSettings, pushChangedSkills } from './cloud-client';
|
|
43
|
+
export { fetchSyncSettings, MAX_SYNC_PUSH_SKILL_BYTES, pushChangedSkills, SERVER_REQUEST_BODY_MAX_BYTES } from './cloud-client';
|
|
43
44
|
|
|
44
45
|
export interface RunSkillSyncResult {
|
|
45
46
|
syncEnabled: boolean;
|
|
@@ -343,7 +344,7 @@ function buildSyncState(
|
|
|
343
344
|
pullResponse: SyncPullResponse,
|
|
344
345
|
localSkills: LocalSkill[],
|
|
345
346
|
lastSyncedAt: string | null,
|
|
346
|
-
verifiedAgentLinks: Record<string,
|
|
347
|
+
verifiedAgentLinks: Record<string, VerifiedAgentLinks> = {},
|
|
347
348
|
failedContentNames: ReadonlySet<string> = new Set(),
|
|
348
349
|
appliedRevisions: AppliedCloudRevisions = {},
|
|
349
350
|
appliedFiles: Record<string, string[] | undefined> = {},
|
|
@@ -636,7 +637,7 @@ export async function materializeCloudSkillsForLocalShell(
|
|
|
636
637
|
|
|
637
638
|
const relinkSkillNames = new Set(options.relinkSkillNames || []);
|
|
638
639
|
const failures = [...failedDownloads];
|
|
639
|
-
const verifiedLinks: Record<string,
|
|
640
|
+
const verifiedLinks: Record<string, VerifiedAgentLinks> = {};
|
|
640
641
|
for (const skill of pullResponse.skills) {
|
|
641
642
|
const previous = previousState.skills[skill.name];
|
|
642
643
|
if (skill.updated_at && previous?.cloudId === skill.id && previous.cloudUpdatedAt === skill.updated_at) {
|