@notis_ai/cli 0.2.31 → 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 +88 -9
- package/config/notis_app_design_rules.json +22 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +4677 -913
- 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 +9 -4
- 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/fixtures.md +4 -2
- package/dist/base-skills/notis-spaces/references/reading.md +3 -1
- package/dist/base-skills/notis-spaces/references/release.md +3 -1
- package/dist/base-skills/notis-spaces/references/sdk.md +160 -88
- 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/sdk/src/ui/icons.tsx +17 -1
- package/dist/skill-sync/index.js +239 -30
- package/dist/skill-sync-worker.mjs +453 -124
- package/dist/space-harness/host.js +218 -93
- 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 +9 -8
- 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 +227 -152
- package/dist/space-sdk/src/ui/blocks/blocks.d.ts +18 -0
- package/dist/space-sdk/src/ui/blocks/index.d.ts +2 -2
- 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/icons.d.ts +6 -0
- package/dist/space-sdk/src/ui/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +8 -0
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
- package/dist/view-renderer/dist/host.js +285 -160
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
- package/skills/notis-spaces/cli.md +17 -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 +70 -3
- package/src/runtime/agent-credential.js +175 -0
- package/src/runtime/agent-identity.js +92 -15
- package/src/runtime/app-boundary-validator.js +248 -3
- package/src/runtime/app-data-literals.js +32 -23
- 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 +44 -7
- 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-3DFOGU26.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
|
/**
|
|
@@ -183,5 +258,7 @@ export function agentIdentityHeaders(runtime, options = {}) {
|
|
|
183
258
|
const headers = { [AGENT_NAME_HEADER]: encodeURIComponent(identity.name) };
|
|
184
259
|
if (id) headers[AGENT_ID_HEADER] = encodeURIComponent(id);
|
|
185
260
|
if (identity.thread) headers[AGENT_THREAD_HEADER] = encodeURIComponent(identity.thread);
|
|
261
|
+
if (identity.threadName) headers[AGENT_THREAD_NAME_HEADER] = encodeURIComponent(identity.threadName);
|
|
262
|
+
if (identity.harness) headers[AGENT_HARNESS_HEADER] = encodeURIComponent(identity.harness);
|
|
186
263
|
return headers;
|
|
187
264
|
}
|
|
@@ -3,7 +3,7 @@ import { dirname, extname, join, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import { usageError } from './errors.js';
|
|
6
|
-
import { maskSerializedJsonData } from './app-data-literals.js';
|
|
6
|
+
import { maskSerializedJsonData, maskSerializedJsonDataOrNull } from './app-data-literals.js';
|
|
7
7
|
|
|
8
8
|
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
|
|
@@ -341,7 +341,7 @@ export function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile
|
|
|
341
341
|
);
|
|
342
342
|
}
|
|
343
343
|
if (!payload) {
|
|
344
|
-
return { profile, include: [], exclude: [], extensions: DEFAULT_DESIGN_EXTENSIONS, rules: [], allowDirective: 'notis-design-allow', allowReasonMinLength: 12 };
|
|
344
|
+
return { profile, include: [], exclude: [], extensions: DEFAULT_DESIGN_EXTENSIONS, rules: [], icons: null, allowDirective: 'notis-design-allow', allowReasonMinLength: 12 };
|
|
345
345
|
}
|
|
346
346
|
const profiles = payload.profiles && typeof payload.profiles === 'object' && !Array.isArray(payload.profiles) ? payload.profiles : {};
|
|
347
347
|
const selected = profile !== 'app' && profiles[profile] && typeof profiles[profile] === 'object' ? profiles[profile] : null;
|
|
@@ -355,6 +355,7 @@ export function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile
|
|
|
355
355
|
extensions: Array.isArray(payload.extensions) ? payload.extensions : DEFAULT_DESIGN_EXTENSIONS,
|
|
356
356
|
allowDirective: typeof payload.allow_directive === 'string' ? payload.allow_directive : 'notis-design-allow',
|
|
357
357
|
allowReasonMinLength: Number.isInteger(payload.allow_reason_min_length) ? payload.allow_reason_min_length : 12,
|
|
358
|
+
icons: loadIconCheck(payload.icons, profile),
|
|
358
359
|
rules: (Array.isArray(payload.rules) ? payload.rules : [])
|
|
359
360
|
.filter((rule) => !Array.isArray(rule.profiles) || rule.profiles.includes(profile))
|
|
360
361
|
.map((rule) => ({
|
|
@@ -373,6 +374,243 @@ export function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile
|
|
|
373
374
|
};
|
|
374
375
|
}
|
|
375
376
|
|
|
377
|
+
// ---------------------------------------------------------------------------
|
|
378
|
+
// Icon names
|
|
379
|
+
//
|
|
380
|
+
// The toolkit's Icon draws a fixed set of names (`icons.names` in the rules
|
|
381
|
+
// file, kept equal to the SDK's ICON_NAMES by packages/sdk/src/ui/icons.test.tsx)
|
|
382
|
+
// and an unknown one draws nothing, so a guessed Phosphor name ships an empty
|
|
383
|
+
// button. Only toolkit inputs are checked, and only when the whole value is one
|
|
384
|
+
// kebab-case string literal:
|
|
385
|
+
// - `name` on the SDK's Icon and `icon` on any other SDK component, the tag
|
|
386
|
+
// resolved through the file's @notis/sdk imports (aliases and namespaces);
|
|
387
|
+
// - an `icon` field of an object that also has a `label` (reader actions,
|
|
388
|
+
// view menu items, tabs: the toolkit's labelled items).
|
|
389
|
+
// Text inside strings and comments is never read. Mirrored by
|
|
390
|
+
// _icon_candidates in server/lib/app_boundary_validator.py.
|
|
391
|
+
// ---------------------------------------------------------------------------
|
|
392
|
+
|
|
393
|
+
const ICON_NAME_SHAPE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
394
|
+
const SDK_IMPORTS = /(?<![\w$.])import\s+([\w$\s{},*]+?)\s+from\s*(["'])@notis\/sdk(?:\/[^"'\s]*)?\2/g;
|
|
395
|
+
const JSX_TAG = /<([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)?)(?=[\s/>])/g;
|
|
396
|
+
const JSX_ATTRIBUTE = /(?<![\w$.-])(icon|name)\s*=\s*/g;
|
|
397
|
+
const ICON_FIELD = /(?<![\w$.-])icon\s*:\s*/g;
|
|
398
|
+
const LABEL_KEY = /(?<![\w$.-])label\s*[:,}]/g;
|
|
399
|
+
// What a JSX opening tag holds at its own level besides strings and braced values.
|
|
400
|
+
const TAG_TEXT = /[\w$\-:.=\t\n\v\f\r /]/;
|
|
401
|
+
|
|
402
|
+
/** Local component names bound to @notis/sdk (local -> exported) and namespace names. Type-only imports bind nothing. */
|
|
403
|
+
function sdkBindings(text) {
|
|
404
|
+
const components = new Map(), namespaces = new Set();
|
|
405
|
+
for (const match of text.matchAll(SDK_IMPORTS)) {
|
|
406
|
+
const clause = match[1].trim();
|
|
407
|
+
if (/^type\s/.test(clause)) continue;
|
|
408
|
+
const namespace = clause.match(/\*\s*as\s+([\w$]+)/);
|
|
409
|
+
if (namespace) namespaces.add(namespace[1]);
|
|
410
|
+
const named = clause.match(/\{([^}]*)\}/);
|
|
411
|
+
for (const part of named ? named[1].split(',') : []) {
|
|
412
|
+
const item = part.trim();
|
|
413
|
+
if (!item || /^type\s/.test(item)) continue;
|
|
414
|
+
const [exported, local = exported] = item.split(/\s+as\s+/).map((value) => value.trim());
|
|
415
|
+
components.set(local, exported);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return { components, namespaces };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* One pass over comment-masked source: which characters sit inside a string, the innermost open
|
|
423
|
+
* brace around each character, and where each brace closes. A quote left open at the end of its
|
|
424
|
+
* line is JSX text (an apostrophe), not a string.
|
|
425
|
+
*/
|
|
426
|
+
function sourceShape(text) {
|
|
427
|
+
const length = text.length;
|
|
428
|
+
const inString = new Uint8Array(length), owner = new Int32Array(length).fill(-1), closes = new Map(), stack = [];
|
|
429
|
+
let index = 0;
|
|
430
|
+
while (index < length) {
|
|
431
|
+
const char = text[index];
|
|
432
|
+
const top = stack.length ? stack[stack.length - 1] : -1;
|
|
433
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
434
|
+
let cursor = index + 1, closed = false;
|
|
435
|
+
while (cursor < length) {
|
|
436
|
+
const inner = text[cursor];
|
|
437
|
+
if (inner === '\\') { cursor += 2; continue; }
|
|
438
|
+
if (inner === char) { cursor += 1; closed = true; break; }
|
|
439
|
+
if (inner === '\n' && char !== '`') break;
|
|
440
|
+
cursor += 1;
|
|
441
|
+
}
|
|
442
|
+
if (closed) {
|
|
443
|
+
for (let at = index; at < cursor; at += 1) { inString[at] = 1; owner[at] = top; }
|
|
444
|
+
index = cursor;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
owner[index] = top;
|
|
449
|
+
if (char === '{') stack.push(index);
|
|
450
|
+
else if (char === '}' && stack.length) closes.set(stack.pop(), index);
|
|
451
|
+
index += 1;
|
|
452
|
+
}
|
|
453
|
+
return { inString, owner, closes };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The literal at `at` when it is the whole value: 'x', "x", `x` (no ${}), or {'x'} in JSX. */
|
|
457
|
+
function literalAt(text, shape, at, { braced = false } = {}) {
|
|
458
|
+
let start = at;
|
|
459
|
+
if (braced && text[at] === '{' && shape.closes.has(at)) {
|
|
460
|
+
const inner = text.slice(at + 1, shape.closes.get(at));
|
|
461
|
+
const match = inner.match(/^\s*(["'`])([^"'`\n\\$]*)\1\s*$/);
|
|
462
|
+
if (!match) return null;
|
|
463
|
+
start = at + 1 + inner.indexOf(match[1]);
|
|
464
|
+
return { name: match[2], index: start + 1 };
|
|
465
|
+
}
|
|
466
|
+
const match = text.slice(start).match(/^(["'`])([^"'`\n\\$]*)\1/);
|
|
467
|
+
return match ? { name: match[2], index: start + 1, end: start + match[0].length } : null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Where a JSX opening tag ends: its `>` at the tag's own brace level, outside strings, jumping over
|
|
472
|
+
* braced values. Any other character at that level means this is not a tag (`a <B && c`): stop there.
|
|
473
|
+
*/
|
|
474
|
+
function tagEnd(text, shape, from) {
|
|
475
|
+
const level = shape.owner[from];
|
|
476
|
+
let index = from + 1;
|
|
477
|
+
while (index < text.length) {
|
|
478
|
+
const char = text[index];
|
|
479
|
+
if (shape.inString[index]) { index += 1; continue; }
|
|
480
|
+
if (char === '>') return index;
|
|
481
|
+
if (char === '{') {
|
|
482
|
+
if (!shape.closes.has(index)) return index;
|
|
483
|
+
index = shape.closes.get(index) + 1;
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
if (shape.owner[index] !== level || !TAG_TEXT.test(char)) return index;
|
|
487
|
+
index += 1;
|
|
488
|
+
}
|
|
489
|
+
return text.length;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** True when the key at `at` sits where an object key does: right after `{` or `,`, outside strings. */
|
|
493
|
+
function keyPosition(text, shape, at) {
|
|
494
|
+
let index = at - 1;
|
|
495
|
+
while (index >= 0 && ' \t\n\v\f\r'.includes(text[index])) index -= 1;
|
|
496
|
+
return index >= 0 && !shape.inString[index] && (text[index] === '{' || text[index] === ',');
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** `{ index, name }` for every literal handed to a toolkit icon input in this comment-masked file. */
|
|
500
|
+
function iconCandidates(text) {
|
|
501
|
+
const { components, namespaces } = sdkBindings(text);
|
|
502
|
+
if (!components.size && !namespaces.size) return [];
|
|
503
|
+
const shape = sourceShape(text), found = [];
|
|
504
|
+
for (const match of text.matchAll(JSX_TAG)) {
|
|
505
|
+
if (shape.inString[match.index]) continue;
|
|
506
|
+
const [first, second] = match[1].split('.');
|
|
507
|
+
const exported = second === undefined ? components.get(first) : namespaces.has(first) ? second : undefined;
|
|
508
|
+
if (!exported) continue;
|
|
509
|
+
const wanted = exported === 'Icon' ? 'name' : 'icon';
|
|
510
|
+
const end = tagEnd(text, shape, match.index);
|
|
511
|
+
const level = shape.owner[match.index];
|
|
512
|
+
JSX_ATTRIBUTE.lastIndex = match.index + match[0].length;
|
|
513
|
+
let attribute;
|
|
514
|
+
while ((attribute = JSX_ATTRIBUTE.exec(text)) !== null && attribute.index < end) {
|
|
515
|
+
if (attribute[1] !== wanted || shape.inString[attribute.index] || shape.owner[attribute.index] !== level) continue;
|
|
516
|
+
const literal = literalAt(text, shape, attribute.index + attribute[0].length, { braced: true });
|
|
517
|
+
if (literal) found.push(literal);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
for (const match of text.matchAll(ICON_FIELD)) {
|
|
521
|
+
if (shape.inString[match.index] || !keyPosition(text, shape, match.index)) continue;
|
|
522
|
+
const literal = literalAt(text, shape, match.index + match[0].length);
|
|
523
|
+
if (!literal || !/^\s*[,}]/.test(text.slice(literal.end))) continue;
|
|
524
|
+
const object = shape.owner[match.index];
|
|
525
|
+
if (object < 0 || !shape.closes.has(object)) continue;
|
|
526
|
+
const body = text.slice(object, shape.closes.get(object) + 1);
|
|
527
|
+
const labelled = [...body.matchAll(LABEL_KEY)].some((key) => !shape.inString[object + key.index]
|
|
528
|
+
&& shape.owner[object + key.index] === object && keyPosition(text, shape, object + key.index));
|
|
529
|
+
if (labelled) found.push(literal);
|
|
530
|
+
}
|
|
531
|
+
return found;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function loadIconCheck(icons, profile) {
|
|
535
|
+
if (!icons || typeof icons !== 'object' || !Array.isArray(icons.names) || icons.names.length === 0) return null;
|
|
536
|
+
if (Array.isArray(icons.profiles) && !icons.profiles.includes(profile)) return null;
|
|
537
|
+
const names = icons.names.filter((name) => typeof name === 'string');
|
|
538
|
+
return {
|
|
539
|
+
id: typeof icons.id === 'string' ? icons.id : 'space-unknown-icon',
|
|
540
|
+
message: typeof icons.message === 'string' ? icons.message : 'Unknown icon "{name}". Closest names: {suggestions}.',
|
|
541
|
+
suggestions: Number.isInteger(icons.suggestions) && icons.suggestions > 0 ? icons.suggestions : 3,
|
|
542
|
+
exclude: Array.isArray(icons.exclude) ? icons.exclude : [],
|
|
543
|
+
names,
|
|
544
|
+
known: new Set(names),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function editDistance(a, b) {
|
|
549
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
550
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
551
|
+
const current = [i];
|
|
552
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
553
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
554
|
+
}
|
|
555
|
+
previous = current;
|
|
556
|
+
}
|
|
557
|
+
return previous[b.length];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* The names the refusal suggests: those sharing a word with the unknown name first ("funnel" finds
|
|
562
|
+
* funnel-simple), then by edit distance, ties by name.
|
|
563
|
+
*/
|
|
564
|
+
export function closestIconNames(name, names, count = 3) {
|
|
565
|
+
const words = new Set(name.split('-'));
|
|
566
|
+
return names
|
|
567
|
+
.map((candidate) => ({
|
|
568
|
+
candidate,
|
|
569
|
+
shared: candidate.split('-').some((word) => words.has(word)) ? 0 : 1,
|
|
570
|
+
distance: editDistance(name, candidate),
|
|
571
|
+
}))
|
|
572
|
+
.sort((left, right) => left.shared - right.shared || left.distance - right.distance
|
|
573
|
+
|| (left.candidate < right.candidate ? -1 : left.candidate > right.candidate ? 1 : 0))
|
|
574
|
+
.slice(0, count)
|
|
575
|
+
.map((entry) => entry.candidate);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function iconViolations(normalized, content, checked, lines, config) {
|
|
579
|
+
const icons = config.icons;
|
|
580
|
+
if (!icons || matchesAny(normalized, icons.exclude)) return [];
|
|
581
|
+
const found = new Map(), suggestions = new Map(), lineStarts = [0];
|
|
582
|
+
for (let cursor = 0; cursor < content.length; cursor += 1) if (content.charCodeAt(cursor) === 10) lineStarts.push(cursor + 1);
|
|
583
|
+
const lineAt = (index) => {
|
|
584
|
+
let low = 0, high = lineStarts.length - 1;
|
|
585
|
+
while (low < high) { const middle = (low + high + 1) >> 1; if (lineStarts[middle] <= index) low = middle; else high = middle - 1; }
|
|
586
|
+
return low + 1;
|
|
587
|
+
};
|
|
588
|
+
for (const { index, name } of iconCandidates(checked)) {
|
|
589
|
+
if (!ICON_NAME_SHAPE.test(name) || icons.known.has(name)) continue;
|
|
590
|
+
const line = lineAt(index);
|
|
591
|
+
const key = `${line}:${name}`;
|
|
592
|
+
if (!found.has(key)) found.set(key, { line, name });
|
|
593
|
+
}
|
|
594
|
+
return [...found.values()].sort((left, right) => left.line - right.line).map(({ line, name }) => {
|
|
595
|
+
const message = icons.message
|
|
596
|
+
.replace('{name}', name)
|
|
597
|
+
.replace('{suggestions}', suggestions.get(name) ?? suggestions.set(name, closestIconNames(name, icons.names, icons.suggestions).join(', ')).get(name));
|
|
598
|
+
const reason = findAllowDirective(lines, line, icons.id, config.allowDirective);
|
|
599
|
+
const allowed = reason !== null && reason.length >= config.allowReasonMinLength;
|
|
600
|
+
return {
|
|
601
|
+
file: normalized,
|
|
602
|
+
line,
|
|
603
|
+
ruleId: icons.id,
|
|
604
|
+
severity: allowed ? 'warn' : 'error',
|
|
605
|
+
message: reason !== null && !allowed
|
|
606
|
+
? `${message} (a notis-design-allow directive needs a reason of at least ${config.allowReasonMinLength} characters)`
|
|
607
|
+
: message,
|
|
608
|
+
allowed,
|
|
609
|
+
reason: allowed ? reason : null,
|
|
610
|
+
};
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
|
|
376
614
|
function getCompiledDesignRules(profile = 'app') {
|
|
377
615
|
if (!compiledDesignRules.has(profile)) {
|
|
378
616
|
compiledDesignRules.set(profile, loadDesignRules({ profile }));
|
|
@@ -411,7 +649,13 @@ export function collectDesignViolationsForFile(relPath, content, config = getCom
|
|
|
411
649
|
// directive; comments are masked after, for matching only, so a real
|
|
412
650
|
// directive comment is still read from `lines`.
|
|
413
651
|
const unserialized = ['.js', '.jsx', '.ts', '.tsx'].includes(extension)
|
|
414
|
-
?
|
|
652
|
+
? maskSerializedJsonDataOrNull(content, extension) : content;
|
|
653
|
+
// Too deep to parse here: checked unmasked, data deep in it would read as code. The server checks it when the
|
|
654
|
+
// Space is released, at any depth, so this file is left to it.
|
|
655
|
+
if (unserialized === null) {
|
|
656
|
+
return [{ file: normalized, line: 1, ruleId: 'too-deep', severity: 'info', allowed: false, reason: null,
|
|
657
|
+
message: 'nested too deep to check here; the server checks this file when you deploy' }];
|
|
658
|
+
}
|
|
415
659
|
const checked = maskComments(unserialized, extension);
|
|
416
660
|
const lines = unserialized.split('\n');
|
|
417
661
|
const violations = [];
|
|
@@ -452,6 +696,7 @@ export function collectDesignViolationsForFile(relPath, content, config = getCom
|
|
|
452
696
|
});
|
|
453
697
|
}
|
|
454
698
|
}
|
|
699
|
+
if (extension !== '.css') violations.push(...iconViolations(normalized, content, checked, lines, config));
|
|
455
700
|
return violations;
|
|
456
701
|
}
|
|
457
702
|
|
|
@@ -10,22 +10,19 @@ function isJsonParse(node) {
|
|
|
10
10
|
&& callee.property?.type === 'Identifier' && callee.property.name === 'parse';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (node.type === 'ExpressionStatement') return false;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
13
|
+
const NOT_DATA = new Set(['JSXAttribute', 'ImportDeclaration', 'ImportExpression', 'TSImportType',
|
|
14
|
+
'ExportAllDeclaration', 'ExportNamedDeclaration', 'NewExpression', 'TaggedTemplateExpression',
|
|
15
|
+
'MemberExpression', 'OptionalMemberExpression']);
|
|
16
|
+
const DATA = new Set(['VariableDeclarator', 'ExportDefaultDeclaration', 'ReturnStatement']);
|
|
17
|
+
|
|
18
|
+
// What this ancestor says about a literal below it: true or false, or null to ask its parent.
|
|
19
|
+
// The nearest ancestor that answers decides, as climbing from the literal would.
|
|
20
|
+
function decides(node) {
|
|
21
|
+
if (NOT_DATA.has(node.type)) return false;
|
|
22
|
+
if ((node.type === 'CallExpression' || node.type === 'OptionalCallExpression') && !isJsonParse(node)) return false;
|
|
23
|
+
if (DATA.has(node.type)) return true;
|
|
24
|
+
if (node.type === 'ExpressionStatement') return false;
|
|
25
|
+
return null;
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
/**
|
|
@@ -37,6 +34,15 @@ function dataContext(ancestors) {
|
|
|
37
34
|
* Source/archive bytes are never rewritten; offsets and line breaks survive.
|
|
38
35
|
*/
|
|
39
36
|
export function maskSerializedJsonData(content, extension = '.js') {
|
|
37
|
+
return maskSerializedJsonDataOrNull(content, extension) ?? content;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The same mask, or null when the file nests too deep for the parser (Babel
|
|
42
|
+
* runs out of stack at about 200 levels): the caller then leaves the file to
|
|
43
|
+
* the server's check, which reads any depth.
|
|
44
|
+
*/
|
|
45
|
+
export function maskSerializedJsonDataOrNull(content, extension = '.js') {
|
|
40
46
|
let ast;
|
|
41
47
|
try {
|
|
42
48
|
babelParse ||= require('@babel/parser').parse;
|
|
@@ -46,15 +52,17 @@ export function maskSerializedJsonData(content, extension = '.js') {
|
|
|
46
52
|
plugins: [...(['.ts', '.tsx'].includes(extension) ? ['typescript'] : []),
|
|
47
53
|
...(extension !== '.ts' ? ['jsx'] : [])],
|
|
48
54
|
});
|
|
49
|
-
} catch { return content; }
|
|
55
|
+
} catch (error) { return error instanceof RangeError ? null : content; }
|
|
50
56
|
const ranges = [];
|
|
51
|
-
|
|
57
|
+
// Each node carries what its ancestors decided, so no literal looks back up the tree and no
|
|
58
|
+
// ancestor list is copied per node: deep data (objects nested a thousand levels) stays linear.
|
|
59
|
+
const pending = [[ast, false, null]];
|
|
52
60
|
while (pending.length) {
|
|
53
|
-
const [node,
|
|
61
|
+
const [node, underAttribute, decided] = pending.pop();
|
|
54
62
|
if (!node || typeof node !== 'object') continue;
|
|
55
63
|
const literal = node.type === 'StringLiteral' ? node.value
|
|
56
64
|
: node.type === 'TemplateLiteral' && node.expressions.length === 0 ? node.quasis[0]?.value.cooked : null;
|
|
57
|
-
if (typeof literal === 'string' &&
|
|
65
|
+
if (typeof literal === 'string' && !underAttribute && decided === true) {
|
|
58
66
|
try {
|
|
59
67
|
const value = JSON.parse(literal);
|
|
60
68
|
if (value !== null && typeof value === 'object') {
|
|
@@ -63,12 +71,13 @@ export function maskSerializedJsonData(content, extension = '.js') {
|
|
|
63
71
|
}
|
|
64
72
|
} catch { /* Ordinary/non-JSON strings keep their original checks. */ }
|
|
65
73
|
}
|
|
66
|
-
const
|
|
74
|
+
const own = node.type ? decides(node) : null;
|
|
75
|
+
const below = [underAttribute || node.type === 'JSXAttribute', own ?? decided];
|
|
67
76
|
for (const [key, value] of Object.entries(node)) {
|
|
68
77
|
if (['loc', 'extra', 'tokens', 'comments', 'errors'].includes(key)) continue;
|
|
69
78
|
if (Array.isArray(value)) {
|
|
70
|
-
for (const child of value) if (child?.type) pending.push([child,
|
|
71
|
-
} else if (value?.type) pending.push([value,
|
|
79
|
+
for (const child of value) if (child?.type) pending.push([child, ...below]);
|
|
80
|
+
} else if (value?.type) pending.push([value, ...below]);
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
let cursor = 0;
|
|
@@ -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|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',
|