@notis_ai/cli 0.2.29 → 0.2.30
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 +25 -8
- package/dist/agent-hooks/notis-agent-hook.mjs +1030 -610
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +11 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/references/release.md +6 -5
- package/dist/base-skills/notis-spaces/references/sdk.md +82 -17
- package/dist/sdk/src/hooks/useThreadItem.ts +56 -0
- package/dist/sdk/src/index.ts +6 -1
- package/dist/sdk/src/runtime.ts +8 -1
- package/dist/sdk/src/space.ts +230 -0
- package/dist/skill-sync-worker.mjs +185 -30
- package/dist/space-harness/host.js +237 -93
- package/dist/space-sdk/dist/{chunk-BFGB6XXC.js → chunk-6GJ2BS7B.js} +1 -3
- package/dist/space-sdk/dist/index.js +4 -2
- package/dist/space-sdk/dist/ui.js +18 -13
- package/dist/space-sdk/src/hooks/useThreadItem.d.ts +28 -0
- package/dist/space-sdk/src/index.d.ts +3 -1
- package/dist/space-sdk/src/runtime.d.ts +8 -1
- package/dist/space-sdk/src/space.ts +230 -0
- package/dist/space-sdk/src/tailwind-candidates.d.ts +492 -14
- package/dist/space-sdk/src/ui/actions/useToast.d.ts +2 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +56 -10
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +16 -7
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +59 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +5 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +103 -8
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +37 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +119 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +75 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +147 -15
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +24 -8
- package/dist/space-sdk/src/ui/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +6 -1
- package/dist/space-sdk/src/ui/overlay/Tooltip.d.ts +8 -2
- package/dist/space-sdk/src/ui/styles.d.ts +27 -5
- package/dist/view-renderer/dist/host.js +307 -163
- package/dist/view-renderer/src/host.tsx +6 -3
- package/dist/view-renderer/src/renderer.js +25 -2
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -1
- package/skills/notis-spaces/cli.md +8 -8
- package/src/cli.js +10 -2
- package/src/command-specs/computer.js +21 -1
- package/src/command-specs/profile.js +12 -5
- package/src/command-specs/spaces.js +30 -16
- package/src/runtime/agent-identity.js +187 -0
- package/src/runtime/api-hosts.js +92 -0
- package/src/runtime/channel.js +3 -7
- package/src/runtime/oauth.js +95 -4
- package/src/runtime/profiles.js +200 -41
- package/src/runtime/skill-sync-service.js +4 -5
- package/src/runtime/space-platform.js +2 -0
- package/src/runtime/space-source.js +66 -1
- package/src/runtime/space-test-server.js +20 -4
- package/src/runtime/space-verification.js +5 -1
- package/src/runtime/telemetry.js +14 -1
- package/src/runtime/transport.js +12 -0
- package/src/runtime/upsell.js +3 -6
- package/src/runtime/view-render.js +3 -1
- package/src/skill-sync-worker.js +13 -2
- package/src/space-harness-host.ts +6 -3
|
@@ -100,6 +100,61 @@ var init_errors = __esm({
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
// src/runtime/api-hosts.js
|
|
104
|
+
function channelForApiHost(hostname) {
|
|
105
|
+
return HOST_ROWS.find((row) => row.host === hostname)?.channel || null;
|
|
106
|
+
}
|
|
107
|
+
function portalOriginForApiHost(hostname) {
|
|
108
|
+
const channel = channelForApiHost(hostname);
|
|
109
|
+
return channel ? CHANNEL_APIS[channel].portal : null;
|
|
110
|
+
}
|
|
111
|
+
function currentApiOrigin(channel) {
|
|
112
|
+
return `https://${CHANNEL_APIS[channel].current}`;
|
|
113
|
+
}
|
|
114
|
+
function isRetiredApiHost(hostname) {
|
|
115
|
+
return HOST_ROWS.some((row) => row.host === hostname && !row.current);
|
|
116
|
+
}
|
|
117
|
+
function parsedHttps(value) {
|
|
118
|
+
if (typeof value !== "string" || !value) return null;
|
|
119
|
+
try {
|
|
120
|
+
const parsed = new URL(value);
|
|
121
|
+
return parsed.protocol === "https:" ? parsed : null;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function isLiveApiOrigin(value) {
|
|
127
|
+
const parsed = parsedHttps(value);
|
|
128
|
+
return Boolean(parsed) && LIVE_API_HOSTS.includes(parsed.hostname) && !parsed.port && /^\/*$/.test(parsed.pathname) && !parsed.search && !parsed.hash;
|
|
129
|
+
}
|
|
130
|
+
function renamedRetiredApiOrigin(value) {
|
|
131
|
+
if (!isLiveApiOrigin(value)) return null;
|
|
132
|
+
const { hostname } = new URL(value);
|
|
133
|
+
return isRetiredApiHost(hostname) ? currentApiOrigin(channelForApiHost(hostname)) : null;
|
|
134
|
+
}
|
|
135
|
+
function isOnRetiredApiHost(value) {
|
|
136
|
+
const parsed = parsedHttps(value);
|
|
137
|
+
return Boolean(parsed) && isRetiredApiHost(parsed.hostname);
|
|
138
|
+
}
|
|
139
|
+
var CHANNEL_APIS, HOST_ROWS, LIVE_API_HOSTS, LIVE_API_ORIGINS;
|
|
140
|
+
var init_api_hosts = __esm({
|
|
141
|
+
"src/runtime/api-hosts.js"() {
|
|
142
|
+
CHANNEL_APIS = {
|
|
143
|
+
stable: { current: "api.notis.ai", retired: [], portal: "https://app.notis.ai" },
|
|
144
|
+
nightly: { current: "api-nightly.notis.ai", retired: ["api-beta.notis.ai"], portal: "https://app-nightly.notis.ai" }
|
|
145
|
+
};
|
|
146
|
+
HOST_ROWS = Object.entries(CHANNEL_APIS).flatMap(([channel, row]) => [
|
|
147
|
+
{ host: row.current, channel, current: true },
|
|
148
|
+
...row.retired.map((host) => ({ host, channel, current: false }))
|
|
149
|
+
]);
|
|
150
|
+
LIVE_API_HOSTS = [
|
|
151
|
+
...HOST_ROWS.filter((row) => row.current),
|
|
152
|
+
...HOST_ROWS.filter((row) => !row.current)
|
|
153
|
+
].map((row) => row.host);
|
|
154
|
+
LIVE_API_ORIGINS = LIVE_API_HOSTS.map((host) => `https://${host}`);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
103
158
|
// node_modules/ajv/dist/compile/codegen/code.js
|
|
104
159
|
var require_code = __commonJS({
|
|
105
160
|
"node_modules/ajv/dist/compile/codegen/code.js"(exports) {
|
|
@@ -7430,6 +7485,151 @@ var init_config_lock = __esm({
|
|
|
7430
7485
|
}
|
|
7431
7486
|
});
|
|
7432
7487
|
|
|
7488
|
+
// src/runtime/agent-identity.js
|
|
7489
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
7490
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7491
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
7492
|
+
function pick(flag, variable) {
|
|
7493
|
+
if (typeof flag === "string") return flag;
|
|
7494
|
+
return typeof variable === "string" ? variable : void 0;
|
|
7495
|
+
}
|
|
7496
|
+
function readAgentIdentity(globalOptions = {}, env = process.env) {
|
|
7497
|
+
const raw = {
|
|
7498
|
+
name: pick(globalOptions.agentName, env[AGENT_IDENTITY_ENV.name]),
|
|
7499
|
+
id: pick(globalOptions.agentId, env[AGENT_IDENTITY_ENV.id]),
|
|
7500
|
+
thread: pick(globalOptions.agentThread, env[AGENT_IDENTITY_ENV.thread])
|
|
7501
|
+
};
|
|
7502
|
+
return Object.values(raw).some((value) => typeof value === "string" && value.trim()) ? raw : null;
|
|
7503
|
+
}
|
|
7504
|
+
function validateAgentIdentity(raw) {
|
|
7505
|
+
if (!raw) return null;
|
|
7506
|
+
const name = String(raw.name ?? "").trim();
|
|
7507
|
+
const id = String(raw.id ?? "").trim();
|
|
7508
|
+
const thread = String(raw.thread ?? "").trim();
|
|
7509
|
+
if (!name) {
|
|
7510
|
+
throw usageError(
|
|
7511
|
+
`Name the agent: set ${AGENT_IDENTITY_ENV.name} (or --agent-name) whenever ${AGENT_IDENTITY_ENV.id} or ${AGENT_IDENTITY_ENV.thread} is set.`
|
|
7512
|
+
);
|
|
7513
|
+
}
|
|
7514
|
+
if (!isBandName(name)) {
|
|
7515
|
+
throw usageError(
|
|
7516
|
+
`${AGENT_IDENTITY_ENV.name} (or --agent-name) must be ${BAND_NAME_RULE}. Pick one for this agent and keep it.`
|
|
7517
|
+
);
|
|
7518
|
+
}
|
|
7519
|
+
if (id && (id.length > AGENT_ID_LIMIT || !ID_PATTERN.test(id))) {
|
|
7520
|
+
throw usageError(
|
|
7521
|
+
`${AGENT_IDENTITY_ENV.id} must be at most ${AGENT_ID_LIMIT} characters: letters, digits and . _ : @ / + - , starting with a letter or digit.`
|
|
7522
|
+
);
|
|
7523
|
+
}
|
|
7524
|
+
if (thread && (thread.length > AGENT_THREAD_LIMIT || !THREAD_PATTERN.test(thread))) {
|
|
7525
|
+
throw usageError(
|
|
7526
|
+
`${AGENT_IDENTITY_ENV.thread} must be a thread id or link of at most ${AGENT_THREAD_LIMIT} characters, without spaces.`
|
|
7527
|
+
);
|
|
7528
|
+
}
|
|
7529
|
+
return { name, ...id ? { id } : {}, ...thread ? { thread } : {} };
|
|
7530
|
+
}
|
|
7531
|
+
function rawIdentityHeaders(raw) {
|
|
7532
|
+
const headers = {};
|
|
7533
|
+
const put = (header, value) => {
|
|
7534
|
+
const text2 = Array.from(String(value ?? "").trim()).slice(0, RAW_HEADER_LIMIT + 1).join("");
|
|
7535
|
+
if (text2) headers[header] = encodeURIComponent(text2);
|
|
7536
|
+
};
|
|
7537
|
+
put(AGENT_NAME_HEADER, raw?.name);
|
|
7538
|
+
put(AGENT_ID_HEADER, raw?.id);
|
|
7539
|
+
put(AGENT_THREAD_HEADER, raw?.thread);
|
|
7540
|
+
return headers;
|
|
7541
|
+
}
|
|
7542
|
+
function isBandName(name) {
|
|
7543
|
+
return typeof name === "string" && name.length >= AGENT_NAME_MIN && name.length <= AGENT_NAME_LIMIT && BAND_NAME.test(name);
|
|
7544
|
+
}
|
|
7545
|
+
function agentIdsFile(configFile = resolveCliConfigFile()) {
|
|
7546
|
+
return join2(dirname2(configFile), "agents.json");
|
|
7547
|
+
}
|
|
7548
|
+
function readAgentIds(file) {
|
|
7549
|
+
try {
|
|
7550
|
+
const raw = JSON.parse(readFileSync2(file, "utf8"));
|
|
7551
|
+
if (raw?.version === AGENT_IDS_VERSION && raw.agents && typeof raw.agents === "object" && !Array.isArray(raw.agents)) {
|
|
7552
|
+
return raw.agents;
|
|
7553
|
+
}
|
|
7554
|
+
} catch {
|
|
7555
|
+
}
|
|
7556
|
+
return {};
|
|
7557
|
+
}
|
|
7558
|
+
function storedId(agents, name) {
|
|
7559
|
+
const id = Object.hasOwn(agents, name) ? agents[name] : null;
|
|
7560
|
+
return typeof id === "string" && id.length <= AGENT_ID_LIMIT && ID_PATTERN.test(id) ? id : null;
|
|
7561
|
+
}
|
|
7562
|
+
function agentIdForName(name, options = {}) {
|
|
7563
|
+
const configFile = options.configFile ?? resolveCliConfigFile();
|
|
7564
|
+
const file = agentIdsFile(configFile);
|
|
7565
|
+
const known = storedId(readAgentIds(file), name);
|
|
7566
|
+
if (known) return known;
|
|
7567
|
+
return withConfigFileWriteLock(configFile, () => {
|
|
7568
|
+
const agents = readAgentIds(file);
|
|
7569
|
+
const existing = storedId(agents, name);
|
|
7570
|
+
if (existing) return existing;
|
|
7571
|
+
const id = randomUUID2();
|
|
7572
|
+
mkdirSync2(dirname2(file), { recursive: true });
|
|
7573
|
+
const temporaryFile = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
7574
|
+
writeFileSync2(
|
|
7575
|
+
temporaryFile,
|
|
7576
|
+
`${JSON.stringify({ version: AGENT_IDS_VERSION, agents: { ...agents, [name]: id } }, null, 2)}
|
|
7577
|
+
`,
|
|
7578
|
+
{ mode: 384 }
|
|
7579
|
+
);
|
|
7580
|
+
renameSync2(temporaryFile, file);
|
|
7581
|
+
return id;
|
|
7582
|
+
});
|
|
7583
|
+
}
|
|
7584
|
+
function agentIdentityHeaders(runtime, options = {}) {
|
|
7585
|
+
const raw = runtime?.agentIdentity ?? null;
|
|
7586
|
+
let identity;
|
|
7587
|
+
try {
|
|
7588
|
+
identity = validateAgentIdentity(raw);
|
|
7589
|
+
} catch {
|
|
7590
|
+
return rawIdentityHeaders(raw);
|
|
7591
|
+
}
|
|
7592
|
+
if (!identity) return {};
|
|
7593
|
+
let id = identity.id;
|
|
7594
|
+
if (!id) {
|
|
7595
|
+
try {
|
|
7596
|
+
id = agentIdForName(identity.name, options);
|
|
7597
|
+
} catch {
|
|
7598
|
+
id = void 0;
|
|
7599
|
+
}
|
|
7600
|
+
}
|
|
7601
|
+
const headers = { [AGENT_NAME_HEADER]: encodeURIComponent(identity.name) };
|
|
7602
|
+
if (id) headers[AGENT_ID_HEADER] = encodeURIComponent(id);
|
|
7603
|
+
if (identity.thread) headers[AGENT_THREAD_HEADER] = encodeURIComponent(identity.thread);
|
|
7604
|
+
return headers;
|
|
7605
|
+
}
|
|
7606
|
+
var AGENT_NAME_HEADER, AGENT_ID_HEADER, AGENT_THREAD_HEADER, AGENT_IDENTITY_ENV, AGENT_NAME_MIN, AGENT_NAME_LIMIT, BAND_NAME_EXAMPLE, BAND_NAME_RULE, AGENT_IDS_VERSION, AGENT_ID_LIMIT, AGENT_THREAD_LIMIT, BAND_NAME, ID_PATTERN, THREAD_PATTERN, RAW_HEADER_LIMIT;
|
|
7607
|
+
var init_agent_identity = __esm({
|
|
7608
|
+
"src/runtime/agent-identity.js"() {
|
|
7609
|
+
init_config_lock();
|
|
7610
|
+
init_errors();
|
|
7611
|
+
AGENT_NAME_HEADER = "X-Notis-Agent-Name";
|
|
7612
|
+
AGENT_ID_HEADER = "X-Notis-Agent-Id";
|
|
7613
|
+
AGENT_THREAD_HEADER = "X-Notis-Agent-Thread";
|
|
7614
|
+
AGENT_IDENTITY_ENV = {
|
|
7615
|
+
name: "NOTIS_AGENT_NAME",
|
|
7616
|
+
id: "NOTIS_AGENT_ID",
|
|
7617
|
+
thread: "NOTIS_AGENT_THREAD"
|
|
7618
|
+
};
|
|
7619
|
+
AGENT_NAME_MIN = 3;
|
|
7620
|
+
AGENT_NAME_LIMIT = 60;
|
|
7621
|
+
BAND_NAME_EXAMPLE = "fred-and-the-machine";
|
|
7622
|
+
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}`;
|
|
7623
|
+
AGENT_IDS_VERSION = 1;
|
|
7624
|
+
AGENT_ID_LIMIT = 128;
|
|
7625
|
+
AGENT_THREAD_LIMIT = 512;
|
|
7626
|
+
BAND_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)+$/;
|
|
7627
|
+
ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:@/+-]*$/;
|
|
7628
|
+
THREAD_PATTERN = /^[\x21-\x7e]+$/;
|
|
7629
|
+
RAW_HEADER_LIMIT = AGENT_THREAD_LIMIT;
|
|
7630
|
+
}
|
|
7631
|
+
});
|
|
7632
|
+
|
|
7433
7633
|
// src/runtime/channel.js
|
|
7434
7634
|
import { existsSync as existsSync2 } from "node:fs";
|
|
7435
7635
|
import { isAbsolute } from "node:path";
|
|
@@ -7443,7 +7643,7 @@ function normalizeReleaseChannel(value) {
|
|
|
7443
7643
|
function channelFromApiBase(apiBase) {
|
|
7444
7644
|
if (typeof apiBase !== "string" || !apiBase) return null;
|
|
7445
7645
|
try {
|
|
7446
|
-
return
|
|
7646
|
+
return channelForApiHost(new URL(apiBase).hostname);
|
|
7447
7647
|
} catch {
|
|
7448
7648
|
return null;
|
|
7449
7649
|
}
|
|
@@ -7520,16 +7720,12 @@ function resolveChannelSwitch({
|
|
|
7520
7720
|
args: ["--yes", "--package", `${CLI_PACKAGE_NAME}@${packageTagForChannel(targetChannel)}`, "--", "notis"]
|
|
7521
7721
|
};
|
|
7522
7722
|
}
|
|
7523
|
-
var RELEASE_CHANNELS, CHANNEL_TAGS,
|
|
7723
|
+
var RELEASE_CHANNELS, CHANNEL_TAGS, CLI_PACKAGE_NAME, CHANNEL_SWITCH_ENV, LEGACY_CHANNEL_SWITCHED, CHANNEL_DISABLE_ENV, CLI_LAUNCHER_ENV;
|
|
7524
7724
|
var init_channel = __esm({
|
|
7525
7725
|
"src/runtime/channel.js"() {
|
|
7726
|
+
init_api_hosts();
|
|
7526
7727
|
RELEASE_CHANNELS = ["stable", "nightly"];
|
|
7527
7728
|
CHANNEL_TAGS = { stable: "latest", nightly: "nightly" };
|
|
7528
|
-
API_HOST_CHANNELS = {
|
|
7529
|
-
"api.notis.ai": "stable",
|
|
7530
|
-
"api-beta.notis.ai": "nightly",
|
|
7531
|
-
"api-nightly.notis.ai": "nightly"
|
|
7532
|
-
};
|
|
7533
7729
|
CLI_PACKAGE_NAME = "@notis_ai/cli";
|
|
7534
7730
|
CHANNEL_SWITCH_ENV = "NOTIS_CLI_CHANNEL_SWITCHED";
|
|
7535
7731
|
LEGACY_CHANNEL_SWITCHED = "1";
|
|
@@ -7752,15 +7948,16 @@ var init_retry = __esm({
|
|
|
7752
7948
|
});
|
|
7753
7949
|
|
|
7754
7950
|
// src/runtime/profiles.js
|
|
7951
|
+
import { createHash } from "node:crypto";
|
|
7755
7952
|
import {
|
|
7756
7953
|
existsSync as existsSync3,
|
|
7757
|
-
mkdirSync as
|
|
7758
|
-
readFileSync as
|
|
7759
|
-
renameSync as
|
|
7760
|
-
writeFileSync as
|
|
7954
|
+
mkdirSync as mkdirSync3,
|
|
7955
|
+
readFileSync as readFileSync3,
|
|
7956
|
+
renameSync as renameSync3,
|
|
7957
|
+
writeFileSync as writeFileSync3
|
|
7761
7958
|
} from "node:fs";
|
|
7762
7959
|
import { homedir as homedir2 } from "node:os";
|
|
7763
|
-
import { dirname as
|
|
7960
|
+
import { dirname as dirname3, join as join3, parse, resolve as resolve2 } from "node:path";
|
|
7764
7961
|
function clone(value) {
|
|
7765
7962
|
return JSON.parse(JSON.stringify(value));
|
|
7766
7963
|
}
|
|
@@ -7804,6 +8001,12 @@ function normalizeProfile(rawProfile = {}) {
|
|
|
7804
8001
|
oauth_refresh_token: typeof raw.oauth_refresh_token === "string" ? raw.oauth_refresh_token : void 0,
|
|
7805
8002
|
oauth_access_expires_at: typeof raw.oauth_access_expires_at === "number" ? raw.oauth_access_expires_at : void 0,
|
|
7806
8003
|
oauth_refresh_expires_at: typeof raw.oauth_refresh_expires_at === "number" ? raw.oauth_refresh_expires_at : void 0,
|
|
8004
|
+
// True only when the token answer carried `refresh_expires_in`; otherwise
|
|
8005
|
+
// oauth_refresh_expires_at is the CLI's own guess and proves nothing.
|
|
8006
|
+
oauth_refresh_expiry_from_server: raw.oauth_refresh_expiry_from_server === true ? true : void 0,
|
|
8007
|
+
// A fingerprint of the refresh token the sign-in server refused with
|
|
8008
|
+
// `invalid_grant` (oauthGrantIsDead).
|
|
8009
|
+
oauth_refresh_rejected_for: typeof raw.oauth_refresh_rejected_for === "string" ? raw.oauth_refresh_rejected_for : void 0,
|
|
7807
8010
|
oauth_client_id: typeof raw.oauth_client_id === "string" ? raw.oauth_client_id : void 0,
|
|
7808
8011
|
oauth_issuer: typeof raw.oauth_issuer === "string" ? raw.oauth_issuer : void 0,
|
|
7809
8012
|
oauth_api_base: typeof raw.oauth_api_base === "string" ? raw.oauth_api_base : void 0,
|
|
@@ -7838,28 +8041,38 @@ function normalizeConfig(rawConfig = {}) {
|
|
|
7838
8041
|
function profileHasCredential(profile = {}) {
|
|
7839
8042
|
return Boolean(profile.oauth_access_token || profile.dev_access_token);
|
|
7840
8043
|
}
|
|
8044
|
+
function profileIsSignedIn(profile = {}, grantIsDead = oauthGrantIsDead(profile)) {
|
|
8045
|
+
if (profile.oauth_access_token) return !grantIsDead;
|
|
8046
|
+
return Boolean(profile.dev_access_token);
|
|
8047
|
+
}
|
|
7841
8048
|
function listProfiles(config) {
|
|
7842
8049
|
const normalized = normalizeConfig(config);
|
|
7843
|
-
return Object.entries(normalized.profiles).map(([name, profile]) =>
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
8050
|
+
return Object.entries(normalized.profiles).map(([name, profile]) => {
|
|
8051
|
+
const routed = routingProfile(profile, {});
|
|
8052
|
+
const grantIsDead = oauthGrantIsDead(profile);
|
|
8053
|
+
const liveGrant = Boolean(profile.oauth_access_token) && !grantIsDead;
|
|
8054
|
+
return {
|
|
8055
|
+
name,
|
|
8056
|
+
active: name === normalized.current_profile,
|
|
8057
|
+
// Report the endpoint the stored profile routes to (CLI-036).
|
|
8058
|
+
// - A live OAuth grant: its recorded OAuth server, which commands use
|
|
8059
|
+
// over any api_base an older Desktop release left behind; with none
|
|
8060
|
+
// recorded, where getApiBase sends it (storedApiBase).
|
|
8061
|
+
// - Otherwise, where the next login starts (routingProfile), keeping the
|
|
8062
|
+
// loopback address of a `./dev.sh` profile: getApiBase resolves a
|
|
8063
|
+
// stale loopback value to the live API for routing, and showing that
|
|
8064
|
+
// here would claim a dev profile targets production.
|
|
8065
|
+
api_base: liveGrant ? getOAuthApiBase(profile) || storedApiBase(profile) : isLocalApiBase(routed.api_base) ? routed.api_base : storedApiBase(routed),
|
|
8066
|
+
label: profile.label || null,
|
|
8067
|
+
credential_kind: profile.oauth_access_token ? "oauth" : profile.dev_access_token ? "dev" : null,
|
|
8068
|
+
user_id: profile.oauth_user_id || profile.dev_user_id || null,
|
|
8069
|
+
authenticated: profileIsSignedIn(profile, grantIsDead)
|
|
8070
|
+
};
|
|
8071
|
+
});
|
|
7859
8072
|
}
|
|
7860
8073
|
function readJsonFile(path4) {
|
|
7861
8074
|
try {
|
|
7862
|
-
return JSON.parse(
|
|
8075
|
+
return JSON.parse(readFileSync3(path4, "utf-8"));
|
|
7863
8076
|
} catch {
|
|
7864
8077
|
return null;
|
|
7865
8078
|
}
|
|
@@ -7868,14 +8081,14 @@ function findUp(filename, startDir = process.cwd(), boundary = null) {
|
|
|
7868
8081
|
let current = resolve2(startDir);
|
|
7869
8082
|
const root = parse(current).root;
|
|
7870
8083
|
while (true) {
|
|
7871
|
-
const candidate =
|
|
8084
|
+
const candidate = join3(current, filename);
|
|
7872
8085
|
if (existsSync3(candidate)) {
|
|
7873
8086
|
return candidate;
|
|
7874
8087
|
}
|
|
7875
8088
|
if (current === root || current === boundary) {
|
|
7876
8089
|
return null;
|
|
7877
8090
|
}
|
|
7878
|
-
current =
|
|
8091
|
+
current = dirname3(current);
|
|
7879
8092
|
}
|
|
7880
8093
|
}
|
|
7881
8094
|
function processIsAlive(pid) {
|
|
@@ -7894,7 +8107,7 @@ function resolveWorktreeRuntime(startDir = process.cwd()) {
|
|
|
7894
8107
|
return null;
|
|
7895
8108
|
}
|
|
7896
8109
|
const routingPath = findUp(WORKTREE_ROUTING_FILENAME, startDir);
|
|
7897
|
-
const boundary = routingPath ?
|
|
8110
|
+
const boundary = routingPath ? dirname3(dirname3(routingPath)) : null;
|
|
7898
8111
|
const runtimePath = findUp(WORKTREE_RUNTIME_FILENAME, startDir, boundary);
|
|
7899
8112
|
const routing = routingPath ? readJsonFile(routingPath) : null;
|
|
7900
8113
|
if (!runtimePath) {
|
|
@@ -7957,7 +8170,7 @@ function loadConfig() {
|
|
|
7957
8170
|
return normalizeConfig({});
|
|
7958
8171
|
}
|
|
7959
8172
|
try {
|
|
7960
|
-
return normalizeConfig(JSON.parse(
|
|
8173
|
+
return normalizeConfig(JSON.parse(readFileSync3(configFile, "utf-8")));
|
|
7961
8174
|
} catch {
|
|
7962
8175
|
return normalizeConfig({});
|
|
7963
8176
|
}
|
|
@@ -7965,7 +8178,7 @@ function loadConfig() {
|
|
|
7965
8178
|
function writeConfig(configFile, config) {
|
|
7966
8179
|
let rawConfig = null;
|
|
7967
8180
|
try {
|
|
7968
|
-
rawConfig = JSON.parse(
|
|
8181
|
+
rawConfig = JSON.parse(readFileSync3(configFile, "utf-8"));
|
|
7969
8182
|
} catch {
|
|
7970
8183
|
}
|
|
7971
8184
|
const normalized = normalizeConfig(config);
|
|
@@ -7983,10 +8196,10 @@ function writeConfig(configFile, config) {
|
|
|
7983
8196
|
writeRawConfig(configFile, persisted);
|
|
7984
8197
|
}
|
|
7985
8198
|
function writeRawConfig(configFile, config) {
|
|
7986
|
-
|
|
8199
|
+
mkdirSync3(dirname3(configFile), { recursive: true });
|
|
7987
8200
|
const temporaryFile = `${configFile}.${process.pid}.${Date.now()}.tmp`;
|
|
7988
|
-
|
|
7989
|
-
|
|
8201
|
+
writeFileSync3(temporaryFile, JSON.stringify(config, null, 2), { mode: 384 });
|
|
8202
|
+
renameSync3(temporaryFile, configFile);
|
|
7990
8203
|
}
|
|
7991
8204
|
function withConfigWriteLock(callback) {
|
|
7992
8205
|
return withConfigFileWriteLock(resolveConfigFile(), callback);
|
|
@@ -8069,11 +8282,49 @@ function isLiveApiBase(value) {
|
|
|
8069
8282
|
}
|
|
8070
8283
|
try {
|
|
8071
8284
|
const parsed = new URL(value);
|
|
8072
|
-
return parsed.protocol === "https:" && LIVE_API_HOSTS.
|
|
8285
|
+
return parsed.protocol === "https:" && LIVE_API_HOSTS.includes(parsed.hostname);
|
|
8073
8286
|
} catch {
|
|
8074
8287
|
return false;
|
|
8075
8288
|
}
|
|
8076
8289
|
}
|
|
8290
|
+
function signedOutRoute(profile = {}) {
|
|
8291
|
+
const apiBase = profile.api_base;
|
|
8292
|
+
if (!apiBase || isLiveApiBase(apiBase)) return {};
|
|
8293
|
+
if (isLocalApiBase(apiBase)) return { api_base: apiBase };
|
|
8294
|
+
const releaseChannel = pinnedReleaseChannel(profile);
|
|
8295
|
+
return releaseChannel ? { api_base: apiBase, release_channel: releaseChannel } : { api_base: apiBase };
|
|
8296
|
+
}
|
|
8297
|
+
function routingProfile(profile = {}, env = process.env) {
|
|
8298
|
+
if (holdsAccount(profile) || env.NOTIS_JWT) return profile;
|
|
8299
|
+
const apiBase = profile.api_base;
|
|
8300
|
+
const local = isLocalApiBase(apiBase);
|
|
8301
|
+
if (apiBase && !local && !isLiveApiBase(apiBase)) return profile;
|
|
8302
|
+
const { api_base: _apiBase, oauth_api_base: _oauthApiBase, release_channel: _releaseChannel, ...rest } = profile;
|
|
8303
|
+
return local ? { ...rest, api_base: apiBase } : rest;
|
|
8304
|
+
}
|
|
8305
|
+
function holdsAccount(profile = {}) {
|
|
8306
|
+
if (profile.dev_access_token) return true;
|
|
8307
|
+
return Boolean(profile.oauth_access_token || profile.oauth_refresh_token) && !oauthGrantIsDead(profile);
|
|
8308
|
+
}
|
|
8309
|
+
function oauthGrantOnRetiredAddress(profile = {}) {
|
|
8310
|
+
if (!profile.oauth_access_token && !profile.oauth_refresh_token) return false;
|
|
8311
|
+
return isOnRetiredApiHost(profile.oauth_issuer) || isOnRetiredApiHost(getOAuthResource(profile));
|
|
8312
|
+
}
|
|
8313
|
+
function refreshTokenFingerprint(refreshToken) {
|
|
8314
|
+
return createHash("sha256").update(String(refreshToken)).digest("hex").slice(0, 32);
|
|
8315
|
+
}
|
|
8316
|
+
function oauthGrantIsDead(profile = {}, nowSeconds = Math.floor(Date.now() / 1e3)) {
|
|
8317
|
+
if (oauthGrantOnRetiredAddress(profile)) return true;
|
|
8318
|
+
const refreshToken = profile.oauth_refresh_token;
|
|
8319
|
+
if (!refreshToken) return false;
|
|
8320
|
+
if (typeof profile.oauth_refresh_rejected_for === "string" && profile.oauth_refresh_rejected_for === refreshTokenFingerprint(refreshToken)) {
|
|
8321
|
+
return true;
|
|
8322
|
+
}
|
|
8323
|
+
if (profile.oauth_refresh_expiry_from_server !== true) return false;
|
|
8324
|
+
const refreshExpiry = Number(profile.oauth_refresh_expires_at);
|
|
8325
|
+
const accessExpiry = Number(profile.oauth_access_expires_at);
|
|
8326
|
+
return Number.isFinite(refreshExpiry) && refreshExpiry <= nowSeconds && Number.isFinite(accessExpiry) && accessExpiry <= nowSeconds;
|
|
8327
|
+
}
|
|
8077
8328
|
function resolveDefaultLiveApiBase(profile = {}) {
|
|
8078
8329
|
const channel = pinnedReleaseChannel(profile) || (isLiveApiBase(profile.api_base) ? channelFromProfile({ api_base: profile.api_base }) : null);
|
|
8079
8330
|
return channel === "nightly" ? NIGHTLY_API_BASE : DEFAULT_API_BASE;
|
|
@@ -8086,10 +8337,12 @@ function getApiBase(config, profileName, override) {
|
|
|
8086
8337
|
if (env) {
|
|
8087
8338
|
return env;
|
|
8088
8339
|
}
|
|
8089
|
-
|
|
8340
|
+
return storedApiBase(routingProfile(getProfile(config, profileName)));
|
|
8341
|
+
}
|
|
8342
|
+
function storedApiBase(profile = {}) {
|
|
8090
8343
|
const profileApiBase = profile.api_base;
|
|
8091
8344
|
if (typeof profileApiBase === "string" && profileApiBase && !isLocalApiBase(profileApiBase)) {
|
|
8092
|
-
return profileApiBase.replace(/\/+$/, "");
|
|
8345
|
+
return renamedRetiredApiOrigin(profileApiBase) || profileApiBase.replace(/\/+$/, "");
|
|
8093
8346
|
}
|
|
8094
8347
|
return resolveDefaultLiveApiBase(profile);
|
|
8095
8348
|
}
|
|
@@ -8169,7 +8422,7 @@ function getOAuthResource(profile = {}) {
|
|
|
8169
8422
|
}
|
|
8170
8423
|
function getOAuthApiBase(profile = {}) {
|
|
8171
8424
|
if (typeof profile.oauth_api_base === "string" && profile.oauth_api_base) {
|
|
8172
|
-
return profile.oauth_api_base.replace(/\/+$/, "");
|
|
8425
|
+
return renamedRetiredApiOrigin(profile.oauth_api_base) || profile.oauth_api_base.replace(/\/+$/, "");
|
|
8173
8426
|
}
|
|
8174
8427
|
const resource = getOAuthResource(profile);
|
|
8175
8428
|
if (resource?.endsWith("/cli")) {
|
|
@@ -8243,8 +8496,8 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
8243
8496
|
}
|
|
8244
8497
|
const oauthApiBase = getOAuthApiBase(profile);
|
|
8245
8498
|
const oauthResource = getOAuthResource(profile);
|
|
8246
|
-
const normalizedRequestedApiBase = requestedApiBase ? requestedApiBase.replace(/\/+$/, "") : null;
|
|
8247
|
-
if (requireAuth && credentialKind === "oauth" && normalizedRequestedApiBase && oauthApiBase && normalizedRequestedApiBase !== oauthApiBase) {
|
|
8499
|
+
const normalizedRequestedApiBase = requestedApiBase ? renamedRetiredApiOrigin(requestedApiBase) || requestedApiBase.replace(/\/+$/, "") : null;
|
|
8500
|
+
if (requireAuth && credentialKind === "oauth" && !oauthGrantOnRetiredAddress(profile) && normalizedRequestedApiBase && oauthApiBase && normalizedRequestedApiBase !== oauthApiBase) {
|
|
8248
8501
|
throw new CliError({
|
|
8249
8502
|
code: "oauth_api_target_mismatch",
|
|
8250
8503
|
message: `The OAuth credential for profile ${profileName} belongs to ${oauthApiBase}, not ${normalizedRequestedApiBase}`,
|
|
@@ -8260,7 +8513,7 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
8260
8513
|
}]
|
|
8261
8514
|
});
|
|
8262
8515
|
}
|
|
8263
|
-
if (credentialKind === "oauth" && oauthApiBase && !requestedApiBase) {
|
|
8516
|
+
if (credentialKind === "oauth" && oauthApiBase && !requestedApiBase && !oauthGrantIsDead(profile)) {
|
|
8264
8517
|
apiBase = oauthApiBase;
|
|
8265
8518
|
}
|
|
8266
8519
|
const agentMode = isAgentMode(globalOptions);
|
|
@@ -8295,7 +8548,7 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
8295
8548
|
// Which published build serves this profile. Carried on the runtime so
|
|
8296
8549
|
// every recovery hint prints the command that will actually run.
|
|
8297
8550
|
channel: devRuntime ? null : channelFromProfile(
|
|
8298
|
-
globalOptions.apiBase || process.env.NOTIS_API_BASE ? { api_base: apiBase } : { ...profile, api_base: apiBase }
|
|
8551
|
+
globalOptions.apiBase || process.env.NOTIS_API_BASE ? { api_base: apiBase } : { ...routingProfile(profile), api_base: apiBase }
|
|
8299
8552
|
),
|
|
8300
8553
|
apiBase,
|
|
8301
8554
|
requestedApiBase: normalizedRequestedApiBase,
|
|
@@ -8318,6 +8571,8 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
8318
8571
|
timeoutMs,
|
|
8319
8572
|
// Automatic retries of interrupted calls that are safe to repeat.
|
|
8320
8573
|
retry: resolveRetryEnabled(globalOptions),
|
|
8574
|
+
// The agent this run declares (--agent-name / NOTIS_AGENT_NAME, ...), checked and sent by httpRequest.
|
|
8575
|
+
agentIdentity: readAgentIdentity(globalOptions),
|
|
8321
8576
|
debugEntitlementOverride,
|
|
8322
8577
|
worktreeRuntime: devRuntime,
|
|
8323
8578
|
detachedWorktreeRuntime: devRuntime ? null : worktreeRuntime,
|
|
@@ -8359,7 +8614,7 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds = Math.floor(Date
|
|
|
8359
8614
|
switch (credentialKind) {
|
|
8360
8615
|
case "oauth": {
|
|
8361
8616
|
const expiration = Number(profile.oauth_access_expires_at);
|
|
8362
|
-
return !Number.isFinite(expiration) || expiration <= nowSeconds;
|
|
8617
|
+
return !Number.isFinite(expiration) || expiration <= nowSeconds || oauthGrantIsDead(profile, nowSeconds);
|
|
8363
8618
|
}
|
|
8364
8619
|
case "env": {
|
|
8365
8620
|
const expiration = getJwtExpiration(runtime?.jwt);
|
|
@@ -8378,9 +8633,9 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds = Math.floor(Date
|
|
|
8378
8633
|
}
|
|
8379
8634
|
}
|
|
8380
8635
|
function workspacePath(appId) {
|
|
8381
|
-
return
|
|
8636
|
+
return join3(WORKSPACE_DIR, appId);
|
|
8382
8637
|
}
|
|
8383
|
-
var CONFIG_DIR, CONFIG_FILE, WORKSPACE_DIR, DEFAULT_API_BASE, NIGHTLY_API_BASE, DEFAULT_PROFILE, PROFILE_NAME_PATTERN, LEGACY_DESKTOP_PROFILE_KEYS, WORKTREE_RUNTIME_FILENAME, WORKTREE_ROUTING_FILENAME, LOCAL_API_HOSTS
|
|
8638
|
+
var CONFIG_DIR, CONFIG_FILE, WORKSPACE_DIR, DEFAULT_API_BASE, NIGHTLY_API_BASE, DEFAULT_PROFILE, PROFILE_NAME_PATTERN, LEGACY_DESKTOP_PROFILE_KEYS, WORKTREE_RUNTIME_FILENAME, WORKTREE_ROUTING_FILENAME, LOCAL_API_HOSTS;
|
|
8384
8639
|
var init_profiles = __esm({
|
|
8385
8640
|
"src/runtime/profiles.js"() {
|
|
8386
8641
|
init_errors();
|
|
@@ -8388,11 +8643,13 @@ var init_profiles = __esm({
|
|
|
8388
8643
|
init_auth_recovery();
|
|
8389
8644
|
init_channel();
|
|
8390
8645
|
init_retry();
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8646
|
+
init_agent_identity();
|
|
8647
|
+
init_api_hosts();
|
|
8648
|
+
CONFIG_DIR = join3(homedir2(), ".notis");
|
|
8649
|
+
CONFIG_FILE = join3(CONFIG_DIR, "config.json");
|
|
8650
|
+
WORKSPACE_DIR = join3(CONFIG_DIR, "workspace");
|
|
8651
|
+
DEFAULT_API_BASE = currentApiOrigin("stable");
|
|
8652
|
+
NIGHTLY_API_BASE = currentApiOrigin("nightly");
|
|
8396
8653
|
DEFAULT_PROFILE = "default";
|
|
8397
8654
|
PROFILE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
8398
8655
|
LEGACY_DESKTOP_PROFILE_KEYS = [
|
|
@@ -8404,21 +8661,20 @@ var init_profiles = __esm({
|
|
|
8404
8661
|
"desktop_app_name",
|
|
8405
8662
|
"desktop_pid"
|
|
8406
8663
|
];
|
|
8407
|
-
WORKTREE_RUNTIME_FILENAME =
|
|
8408
|
-
WORKTREE_ROUTING_FILENAME =
|
|
8409
|
-
LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"]);
|
|
8410
|
-
LIVE_API_HOSTS = /* @__PURE__ */ new Set(["api.notis.ai", "api-nightly.notis.ai", "api-beta.notis.ai"]);
|
|
8664
|
+
WORKTREE_RUNTIME_FILENAME = join3(".context", "notis-runtime.json");
|
|
8665
|
+
WORKTREE_ROUTING_FILENAME = join3(".context", "notis-routing.json");
|
|
8666
|
+
LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
8411
8667
|
}
|
|
8412
8668
|
});
|
|
8413
8669
|
|
|
8414
8670
|
// src/runtime/computer-identity.js
|
|
8415
|
-
import { randomUUID as
|
|
8671
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
8416
8672
|
import { execFileSync } from "node:child_process";
|
|
8417
|
-
import { mkdirSync as
|
|
8673
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync4, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
8418
8674
|
import { hostname as osHostname } from "node:os";
|
|
8419
|
-
import { dirname as
|
|
8675
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
8420
8676
|
function computerIdentityFile(configFile = resolveCliConfigFile()) {
|
|
8421
|
-
return
|
|
8677
|
+
return join4(dirname4(configFile), "computer.json");
|
|
8422
8678
|
}
|
|
8423
8679
|
function normalizeComputerName(value) {
|
|
8424
8680
|
if (typeof value !== "string") return null;
|
|
@@ -8456,7 +8712,7 @@ function defaultComputerName(options = {}) {
|
|
|
8456
8712
|
function parseIdentityFile(file) {
|
|
8457
8713
|
let raw;
|
|
8458
8714
|
try {
|
|
8459
|
-
raw = JSON.parse(
|
|
8715
|
+
raw = JSON.parse(readFileSync4(file, "utf8"));
|
|
8460
8716
|
} catch {
|
|
8461
8717
|
return null;
|
|
8462
8718
|
}
|
|
@@ -8472,16 +8728,16 @@ function validStored(raw) {
|
|
|
8472
8728
|
};
|
|
8473
8729
|
}
|
|
8474
8730
|
function writeIdentityFile(file, stored) {
|
|
8475
|
-
|
|
8731
|
+
mkdirSync4(dirname4(file), { recursive: true });
|
|
8476
8732
|
const contents = {
|
|
8477
8733
|
version: COMPUTER_IDENTITY_VERSION,
|
|
8478
8734
|
computer_id: stored.computerId,
|
|
8479
8735
|
...stored.name ? { name: stored.name } : {}
|
|
8480
8736
|
};
|
|
8481
8737
|
const temporaryFile = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
8482
|
-
|
|
8738
|
+
writeFileSync4(temporaryFile, `${JSON.stringify(contents, null, 2)}
|
|
8483
8739
|
`, { mode: 384 });
|
|
8484
|
-
|
|
8740
|
+
renameSync4(temporaryFile, file);
|
|
8485
8741
|
}
|
|
8486
8742
|
function withIdentity(stored, options) {
|
|
8487
8743
|
const defaultName = defaultComputerName(options);
|
|
@@ -8497,7 +8753,7 @@ function readOrCreateLocked(configFile, file) {
|
|
|
8497
8753
|
const existing = validStored(raw);
|
|
8498
8754
|
if (existing) return existing;
|
|
8499
8755
|
const created = {
|
|
8500
|
-
computerId:
|
|
8756
|
+
computerId: randomUUID3(),
|
|
8501
8757
|
// A file with a broken id keeps the name the user chose.
|
|
8502
8758
|
name: normalizeComputerName(raw?.name)
|
|
8503
8759
|
};
|
|
@@ -8547,25 +8803,25 @@ __export(oauth_exports, {
|
|
|
8547
8803
|
stopPendingListener: () => stopPendingListener
|
|
8548
8804
|
});
|
|
8549
8805
|
import {
|
|
8550
|
-
createHash,
|
|
8806
|
+
createHash as createHash2,
|
|
8551
8807
|
randomBytes,
|
|
8552
8808
|
timingSafeEqual
|
|
8553
8809
|
} from "node:crypto";
|
|
8554
8810
|
import { subscribe, unsubscribe } from "node:diagnostics_channel";
|
|
8555
8811
|
import {
|
|
8556
|
-
mkdirSync as
|
|
8812
|
+
mkdirSync as mkdirSync5,
|
|
8557
8813
|
readdirSync,
|
|
8558
|
-
readFileSync as
|
|
8559
|
-
renameSync as
|
|
8814
|
+
readFileSync as readFileSync5,
|
|
8815
|
+
renameSync as renameSync5,
|
|
8560
8816
|
rmdirSync,
|
|
8561
8817
|
rmSync as rmSync2,
|
|
8562
8818
|
statSync as statSync2,
|
|
8563
8819
|
utimesSync,
|
|
8564
|
-
writeFileSync as
|
|
8820
|
+
writeFileSync as writeFileSync5
|
|
8565
8821
|
} from "node:fs";
|
|
8566
8822
|
import { createServer } from "node:http";
|
|
8567
8823
|
import { homedir as homedir3 } from "node:os";
|
|
8568
|
-
import { basename, dirname as
|
|
8824
|
+
import { basename, dirname as dirname5, join as join5 } from "node:path";
|
|
8569
8825
|
import { fileURLToPath } from "node:url";
|
|
8570
8826
|
import { execFileSync as execFileSync2, spawn } from "node:child_process";
|
|
8571
8827
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
@@ -8574,7 +8830,7 @@ function defaultCliOAuthScopes(metadata) {
|
|
|
8574
8830
|
return advertised.length > 0 ? [...new Set(advertised)] : DEFAULT_CLI_OAUTH_SCOPES;
|
|
8575
8831
|
}
|
|
8576
8832
|
function oauthLockDir() {
|
|
8577
|
-
return
|
|
8833
|
+
return join5(homedir3(), ".notis", "oauth.lock");
|
|
8578
8834
|
}
|
|
8579
8835
|
function oauthError(code, message, hints = null, details = {}) {
|
|
8580
8836
|
return new CliError({
|
|
@@ -8776,6 +9032,21 @@ function readRefreshAnswer(runtime, { response, text: text2 }) {
|
|
|
8776
9032
|
}
|
|
8777
9033
|
return payload;
|
|
8778
9034
|
}
|
|
9035
|
+
function recordRefusedRefreshToken(runtime, refreshToken) {
|
|
9036
|
+
if (!refreshToken) return;
|
|
9037
|
+
try {
|
|
9038
|
+
updateConfig((latest) => {
|
|
9039
|
+
const current = latest.profiles?.[runtime.profileName];
|
|
9040
|
+
if (!current || current.oauth_refresh_token !== refreshToken) return latest;
|
|
9041
|
+
latest.profiles[runtime.profileName] = {
|
|
9042
|
+
...current,
|
|
9043
|
+
oauth_refresh_rejected_for: refreshTokenFingerprint(refreshToken)
|
|
9044
|
+
};
|
|
9045
|
+
return latest;
|
|
9046
|
+
});
|
|
9047
|
+
} catch {
|
|
9048
|
+
}
|
|
9049
|
+
}
|
|
8779
9050
|
async function persistRefreshedSignIn(runtime, metadata, tokenResponse) {
|
|
8780
9051
|
let lastError = null;
|
|
8781
9052
|
for (const delay3 of [0, ...OAUTH_REFRESH_SAVE_RETRY_DELAYS_MS]) {
|
|
@@ -8833,7 +9104,7 @@ async function discoverCliOAuth(apiBase, fetchImpl = fetch) {
|
|
|
8833
9104
|
}
|
|
8834
9105
|
function createPkce() {
|
|
8835
9106
|
const verifier = base64url(randomBytes(64));
|
|
8836
|
-
const challenge =
|
|
9107
|
+
const challenge = createHash2("sha256").update(verifier, "ascii").digest("base64url");
|
|
8837
9108
|
return { verifier, challenge };
|
|
8838
9109
|
}
|
|
8839
9110
|
function stateMatches(expected, actual) {
|
|
@@ -9376,6 +9647,7 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
9376
9647
|
const now = Math.floor(Date.now() / 1e3);
|
|
9377
9648
|
const payload = decodeJwtPayload(tokenResponse.access_token);
|
|
9378
9649
|
const oauthApiBase = (metadata.apiBase || runtime.apiBase || "").replace(/\/+$/, "");
|
|
9650
|
+
const refreshExpiryFromServer = Boolean(tokenResponse.refresh_token) && tokenResponse.refresh_expires_in !== null && tokenResponse.refresh_expires_in !== "" && Number.isFinite(Number(tokenResponse.refresh_expires_in));
|
|
9379
9651
|
const config = updateConfig((latest) => {
|
|
9380
9652
|
const next = ensureProfile(latest, runtime.profileName);
|
|
9381
9653
|
const profile = next.profiles[runtime.profileName];
|
|
@@ -9396,7 +9668,12 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
9396
9668
|
oauth_access_token: tokenResponse.access_token,
|
|
9397
9669
|
oauth_refresh_token: tokenResponse.refresh_token || profile.oauth_refresh_token,
|
|
9398
9670
|
oauth_access_expires_at: now + Number(tokenResponse.expires_in || 0),
|
|
9399
|
-
oauth_refresh_expires_at: now + Number(tokenResponse.refresh_expires_in
|
|
9671
|
+
oauth_refresh_expires_at: now + (refreshExpiryFromServer ? Number(tokenResponse.refresh_expires_in) : DEFAULT_REFRESH_EXPIRES_IN),
|
|
9672
|
+
// Only an expiry the server sent for the refresh token it sent may later
|
|
9673
|
+
// prove the grant dead (oauthGrantIsDead); the default above is a guess.
|
|
9674
|
+
oauth_refresh_expiry_from_server: refreshExpiryFromServer || void 0,
|
|
9675
|
+
// A new grant or a renewed one is no longer the token the server refused.
|
|
9676
|
+
oauth_refresh_rejected_for: void 0,
|
|
9400
9677
|
oauth_client_id: metadata.clientId,
|
|
9401
9678
|
oauth_issuer: metadata.issuer,
|
|
9402
9679
|
oauth_scopes: String(tokenResponse.scope || "").split(/\s+/).filter(Boolean),
|
|
@@ -9407,7 +9684,7 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
9407
9684
|
return config.profiles[runtime.profileName];
|
|
9408
9685
|
}
|
|
9409
9686
|
function pendingAuthorizationFile(runtime) {
|
|
9410
|
-
const profileKey =
|
|
9687
|
+
const profileKey = createHash2("sha256").update(String(runtime.profileName || "default")).digest("hex").slice(0, 16);
|
|
9411
9688
|
return `${resolveConfigFile()}.pending-login.${profileKey}`;
|
|
9412
9689
|
}
|
|
9413
9690
|
function legacyPendingAuthorizationFile(runtime) {
|
|
@@ -9415,8 +9692,8 @@ function legacyPendingAuthorizationFile(runtime) {
|
|
|
9415
9692
|
}
|
|
9416
9693
|
function savePendingAuthorization(runtime, pending) {
|
|
9417
9694
|
const file = pendingAuthorizationFile(runtime);
|
|
9418
|
-
|
|
9419
|
-
|
|
9695
|
+
mkdirSync5(dirname5(file), { recursive: true });
|
|
9696
|
+
writeFileSync5(file, JSON.stringify(pending, null, 2), { mode: 384 });
|
|
9420
9697
|
}
|
|
9421
9698
|
function readPendingAuthorization(runtime, { includeExpired = false } = {}) {
|
|
9422
9699
|
for (const file of [
|
|
@@ -9425,7 +9702,7 @@ function readPendingAuthorization(runtime, { includeExpired = false } = {}) {
|
|
|
9425
9702
|
]) {
|
|
9426
9703
|
let pending;
|
|
9427
9704
|
try {
|
|
9428
|
-
pending = JSON.parse(
|
|
9705
|
+
pending = JSON.parse(readFileSync5(file, "utf-8"));
|
|
9429
9706
|
} catch {
|
|
9430
9707
|
continue;
|
|
9431
9708
|
}
|
|
@@ -9446,7 +9723,7 @@ function clearPendingAuthorizations(runtime) {
|
|
|
9446
9723
|
clearPendingAuthorization(runtime);
|
|
9447
9724
|
const legacyFile = legacyPendingAuthorizationFile(runtime);
|
|
9448
9725
|
try {
|
|
9449
|
-
const pending = JSON.parse(
|
|
9726
|
+
const pending = JSON.parse(readFileSync5(legacyFile, "utf-8"));
|
|
9450
9727
|
if (pending?.profile === runtime.profileName) rmSync2(legacyFile);
|
|
9451
9728
|
} catch {
|
|
9452
9729
|
}
|
|
@@ -9484,7 +9761,7 @@ function listenerChildEnvironment(env = process.env) {
|
|
|
9484
9761
|
return childEnv;
|
|
9485
9762
|
}
|
|
9486
9763
|
function listenerStateFile(runtime) {
|
|
9487
|
-
const profileKey =
|
|
9764
|
+
const profileKey = createHash2("sha256").update(String(runtime.profileName || "default")).digest("hex").slice(0, 16);
|
|
9488
9765
|
return `${resolveConfigFile()}.login-listener.${profileKey}`;
|
|
9489
9766
|
}
|
|
9490
9767
|
function listenerStartLockDir(runtime) {
|
|
@@ -9494,11 +9771,11 @@ function listenerGlobalLockDir() {
|
|
|
9494
9771
|
return `${resolveConfigFile()}.oauth-listener-global.lock`;
|
|
9495
9772
|
}
|
|
9496
9773
|
function listenerGlobalLockOwnerFile(lockDir) {
|
|
9497
|
-
return
|
|
9774
|
+
return join5(lockDir, "owner.json");
|
|
9498
9775
|
}
|
|
9499
9776
|
function readListenerGlobalLockOwner(lockDir) {
|
|
9500
9777
|
try {
|
|
9501
|
-
return JSON.parse(
|
|
9778
|
+
return JSON.parse(readFileSync5(listenerGlobalLockOwnerFile(lockDir), "utf-8"));
|
|
9502
9779
|
} catch {
|
|
9503
9780
|
return null;
|
|
9504
9781
|
}
|
|
@@ -9506,7 +9783,7 @@ function readListenerGlobalLockOwner(lockDir) {
|
|
|
9506
9783
|
function writeListenerGlobalLockOwner(lock) {
|
|
9507
9784
|
const current = readListenerGlobalLockOwner(lock.lockDir);
|
|
9508
9785
|
if (current && current.owner_token !== lock.ownerToken) return false;
|
|
9509
|
-
|
|
9786
|
+
writeFileSync5(listenerGlobalLockOwnerFile(lock.lockDir), JSON.stringify({
|
|
9510
9787
|
owner_token: lock.ownerToken,
|
|
9511
9788
|
owner_pid: process.pid,
|
|
9512
9789
|
updated_at: Date.now()
|
|
@@ -9527,7 +9804,7 @@ function listenerGlobalLockIsStale(lockDir, staleMs) {
|
|
|
9527
9804
|
function retireStaleListenerGlobalLock(lockDir) {
|
|
9528
9805
|
const retiredDir = `${lockDir}.stale-${process.pid}-${base64url(randomBytes(8))}`;
|
|
9529
9806
|
try {
|
|
9530
|
-
|
|
9807
|
+
renameSync5(lockDir, retiredDir);
|
|
9531
9808
|
} catch {
|
|
9532
9809
|
return false;
|
|
9533
9810
|
}
|
|
@@ -9536,11 +9813,11 @@ function retireStaleListenerGlobalLock(lockDir) {
|
|
|
9536
9813
|
}
|
|
9537
9814
|
async function acquireListenerStartLock(runtime) {
|
|
9538
9815
|
const lockDir = listenerStartLockDir(runtime);
|
|
9539
|
-
|
|
9816
|
+
mkdirSync5(dirname5(lockDir), { recursive: true });
|
|
9540
9817
|
const deadline = Date.now() + LISTENER_START_LOCK_STALE_MS * 2;
|
|
9541
9818
|
for (; ; ) {
|
|
9542
9819
|
try {
|
|
9543
|
-
|
|
9820
|
+
mkdirSync5(lockDir);
|
|
9544
9821
|
return lockDir;
|
|
9545
9822
|
} catch (error) {
|
|
9546
9823
|
if (error?.code !== "EEXIST") throw error;
|
|
@@ -9574,11 +9851,11 @@ async function acquireListenerGlobalLock({
|
|
|
9574
9851
|
heartbeatMs = LISTENER_GLOBAL_LOCK_HEARTBEAT_MS
|
|
9575
9852
|
} = {}) {
|
|
9576
9853
|
const lockDir = listenerGlobalLockDir();
|
|
9577
|
-
|
|
9854
|
+
mkdirSync5(dirname5(lockDir), { recursive: true });
|
|
9578
9855
|
const deadline = Date.now() + waitMs;
|
|
9579
9856
|
for (; ; ) {
|
|
9580
9857
|
try {
|
|
9581
|
-
|
|
9858
|
+
mkdirSync5(lockDir);
|
|
9582
9859
|
const lock = {
|
|
9583
9860
|
lockDir,
|
|
9584
9861
|
ownerToken: base64url(randomBytes(24)),
|
|
@@ -9615,14 +9892,14 @@ function releaseListenerGlobalLock(lock) {
|
|
|
9615
9892
|
if (owner?.owner_token !== lock.ownerToken) return;
|
|
9616
9893
|
const releasedDir = `${lock.lockDir}.released-${process.pid}-${lock.ownerToken}`;
|
|
9617
9894
|
try {
|
|
9618
|
-
|
|
9895
|
+
renameSync5(lock.lockDir, releasedDir);
|
|
9619
9896
|
} catch {
|
|
9620
9897
|
return;
|
|
9621
9898
|
}
|
|
9622
9899
|
const movedOwner = readListenerGlobalLockOwner(releasedDir);
|
|
9623
9900
|
if (movedOwner?.owner_token !== lock.ownerToken) {
|
|
9624
9901
|
try {
|
|
9625
|
-
|
|
9902
|
+
renameSync5(releasedDir, lock.lockDir);
|
|
9626
9903
|
} catch {
|
|
9627
9904
|
}
|
|
9628
9905
|
return;
|
|
@@ -9631,12 +9908,12 @@ function releaseListenerGlobalLock(lock) {
|
|
|
9631
9908
|
}
|
|
9632
9909
|
function saveListenerState(runtime, state) {
|
|
9633
9910
|
const file = listenerStateFile(runtime);
|
|
9634
|
-
|
|
9635
|
-
|
|
9911
|
+
mkdirSync5(dirname5(file), { recursive: true });
|
|
9912
|
+
writeFileSync5(file, JSON.stringify(state, null, 2), { mode: 384 });
|
|
9636
9913
|
}
|
|
9637
9914
|
function readListenerState(runtime) {
|
|
9638
9915
|
try {
|
|
9639
|
-
const state = JSON.parse(
|
|
9916
|
+
const state = JSON.parse(readFileSync5(listenerStateFile(runtime), "utf-8"));
|
|
9640
9917
|
return state?.profile === runtime.profileName ? state : null;
|
|
9641
9918
|
} catch {
|
|
9642
9919
|
return null;
|
|
@@ -9651,7 +9928,7 @@ function listenerStateAllowsPersistence(runtime, ownerPid) {
|
|
|
9651
9928
|
function clearListenerState(runtime, { ownerPid = null } = {}) {
|
|
9652
9929
|
if (ownerPid !== null) {
|
|
9653
9930
|
try {
|
|
9654
|
-
const state = JSON.parse(
|
|
9931
|
+
const state = JSON.parse(readFileSync5(listenerStateFile(runtime), "utf-8"));
|
|
9655
9932
|
if (Number(state?.pid) !== Number(ownerPid)) return;
|
|
9656
9933
|
} catch {
|
|
9657
9934
|
return;
|
|
@@ -9749,8 +10026,8 @@ async function startDetachedLoopbackListener(runtime, {
|
|
|
9749
10026
|
const identityToken = randomBytes(24).toString("base64url");
|
|
9750
10027
|
const payloadFile = `${listenerStateFile(runtime)}.payload.${process.pid}.${randomBytes(8).toString("hex")}`;
|
|
9751
10028
|
try {
|
|
9752
|
-
|
|
9753
|
-
|
|
10029
|
+
mkdirSync5(dirname5(payloadFile), { recursive: true });
|
|
10030
|
+
writeFileSync5(payloadFile, JSON.stringify({
|
|
9754
10031
|
profile: runtime.profileName,
|
|
9755
10032
|
api_base: runtime.apiBase,
|
|
9756
10033
|
verifier,
|
|
@@ -9842,7 +10119,7 @@ async function revokeCancelledToken(metadata, tokenResponse, fetchImpl) {
|
|
|
9842
10119
|
async function runDetachedLoginListener(payloadFile, fetchImpl = fetch, identityToken = process.argv[3] || null) {
|
|
9843
10120
|
let payload;
|
|
9844
10121
|
try {
|
|
9845
|
-
payload = JSON.parse(
|
|
10122
|
+
payload = JSON.parse(readFileSync5(payloadFile, "utf-8"));
|
|
9846
10123
|
} catch {
|
|
9847
10124
|
return 1;
|
|
9848
10125
|
}
|
|
@@ -10080,7 +10357,7 @@ function updateRuntimeFromOAuthProfile(runtime, profile) {
|
|
|
10080
10357
|
}
|
|
10081
10358
|
}
|
|
10082
10359
|
function assertOAuthApiTarget(runtime, profile) {
|
|
10083
|
-
const requestedApiBase = String(runtime.requestedApiBase || "").replace(/\/+$/, "");
|
|
10360
|
+
const requestedApiBase = renamedRetiredApiOrigin(runtime.requestedApiBase) || String(runtime.requestedApiBase || "").replace(/\/+$/, "");
|
|
10084
10361
|
const oauthApiBase = getOAuthApiBase(profile);
|
|
10085
10362
|
if (requestedApiBase && oauthApiBase && requestedApiBase !== oauthApiBase) {
|
|
10086
10363
|
throw oauthError(
|
|
@@ -10089,11 +10366,22 @@ function assertOAuthApiTarget(runtime, profile) {
|
|
|
10089
10366
|
);
|
|
10090
10367
|
}
|
|
10091
10368
|
}
|
|
10369
|
+
function retiredAddressGrantError(runtime, profile) {
|
|
10370
|
+
const { hints } = getAuthRecovery(runtime);
|
|
10371
|
+
const retiredHost = [profile.oauth_issuer, getOAuthResource(profile)].filter(isOnRetiredApiHost).map((value) => new URL(value).hostname)[0];
|
|
10372
|
+
return oauthError(
|
|
10373
|
+
"oauth_grant_retired_address",
|
|
10374
|
+
`This sign-in was made on ${retiredHost}, a retired address of Notis that no longer accepts it. Sign in again: ${hints[0].command}`,
|
|
10375
|
+
hints,
|
|
10376
|
+
{ retired_host: retiredHost }
|
|
10377
|
+
);
|
|
10378
|
+
}
|
|
10092
10379
|
async function ensureFreshOAuthCredential(runtime, fetchImpl = fetch) {
|
|
10093
10380
|
if (runtime.credentialKind !== "oauth") {
|
|
10094
10381
|
return Boolean(runtime.jwt);
|
|
10095
10382
|
}
|
|
10096
10383
|
const profile = getProfile(loadConfig(), runtime.profileName);
|
|
10384
|
+
if (oauthGrantOnRetiredAddress(profile)) throw retiredAddressGrantError(runtime, profile);
|
|
10097
10385
|
assertOAuthApiTarget(runtime, profile);
|
|
10098
10386
|
if (!credentialIsExpired({ credentialKind: "oauth" }, profile)) {
|
|
10099
10387
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -10221,7 +10509,7 @@ function reusablePendingAuthorization(runtime, metadata, scopes, requestedTimeou
|
|
|
10221
10509
|
pending && pending.state && pending.api_base === runtime.apiBase && pending.issuer === metadata.issuer && pending.resource === metadata.resource && pending.client_id === metadata.clientId && pending.token_endpoint === metadata.tokenEndpoint && pending.redirect_uri === metadata.copyPasteRedirectUri && (requestedTimeoutMs === null || Number(pending.authorization_timeout_ms) === requestedTimeoutMs) && JSON.stringify(pendingScopes) === JSON.stringify(scopes)
|
|
10222
10510
|
);
|
|
10223
10511
|
if (!sameAuthorization) return null;
|
|
10224
|
-
const challenge =
|
|
10512
|
+
const challenge = createHash2("sha256").update(pending.verifier, "ascii").digest("base64url");
|
|
10225
10513
|
return {
|
|
10226
10514
|
agentAuthorization: {
|
|
10227
10515
|
authorize_url: buildAuthorizeUrl(metadata, {
|
|
@@ -10290,7 +10578,7 @@ async function loginWithOAuth(runtime, options = {}, output, fetchImpl = fetch,
|
|
|
10290
10578
|
try {
|
|
10291
10579
|
if (options.reusePersistedCredential) {
|
|
10292
10580
|
const storedProfile = getProfile(loadConfig(), runtime.profileName);
|
|
10293
|
-
if (storedProfile.oauth_access_token && !credentialIsExpired({ credentialKind: "oauth" }, storedProfile)) {
|
|
10581
|
+
if (storedProfile.oauth_access_token && !credentialIsExpired({ credentialKind: "oauth" }, storedProfile) && !oauthGrantIsDead(storedProfile)) {
|
|
10294
10582
|
assertOAuthApiTarget(runtime, storedProfile);
|
|
10295
10583
|
updateRuntimeFromOAuthProfile(runtime, storedProfile);
|
|
10296
10584
|
return { profile: storedProfile, metadata, reusedPersistedCredential: true };
|
|
@@ -10559,7 +10847,7 @@ function pendingListenerProfiles() {
|
|
|
10559
10847
|
const prefix = `${basename(configFile)}.login-listener.`;
|
|
10560
10848
|
let entries;
|
|
10561
10849
|
try {
|
|
10562
|
-
entries = readdirSync(
|
|
10850
|
+
entries = readdirSync(dirname5(configFile));
|
|
10563
10851
|
} catch {
|
|
10564
10852
|
return [];
|
|
10565
10853
|
}
|
|
@@ -10567,7 +10855,7 @@ function pendingListenerProfiles() {
|
|
|
10567
10855
|
for (const entry of entries) {
|
|
10568
10856
|
if (!entry.startsWith(prefix) || entry.includes(".payload") || entry.endsWith(".lock")) continue;
|
|
10569
10857
|
try {
|
|
10570
|
-
const state = JSON.parse(
|
|
10858
|
+
const state = JSON.parse(readFileSync5(join5(dirname5(configFile), entry), "utf-8"));
|
|
10571
10859
|
if (typeof state?.profile === "string" && state.profile) profiles.add(state.profile);
|
|
10572
10860
|
} catch {
|
|
10573
10861
|
}
|
|
@@ -10581,7 +10869,7 @@ function pendingAuthorizationProfiles() {
|
|
|
10581
10869
|
const legacyName = `${configName}.pending-login`;
|
|
10582
10870
|
let entries;
|
|
10583
10871
|
try {
|
|
10584
|
-
entries = readdirSync(
|
|
10872
|
+
entries = readdirSync(dirname5(configFile));
|
|
10585
10873
|
} catch {
|
|
10586
10874
|
return [];
|
|
10587
10875
|
}
|
|
@@ -10589,7 +10877,7 @@ function pendingAuthorizationProfiles() {
|
|
|
10589
10877
|
for (const entry of entries) {
|
|
10590
10878
|
if (entry !== legacyName && !entry.startsWith(prefix)) continue;
|
|
10591
10879
|
try {
|
|
10592
|
-
const pending = JSON.parse(
|
|
10880
|
+
const pending = JSON.parse(readFileSync5(join5(dirname5(configFile), entry), "utf-8"));
|
|
10593
10881
|
if (typeof pending?.profile === "string" && pending.profile) profiles.add(pending.profile);
|
|
10594
10882
|
} catch {
|
|
10595
10883
|
}
|
|
@@ -10604,11 +10892,11 @@ function lockIsStale() {
|
|
|
10604
10892
|
}
|
|
10605
10893
|
}
|
|
10606
10894
|
async function acquireRefreshLock(runtime, staleAccessToken, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS) {
|
|
10607
|
-
|
|
10895
|
+
mkdirSync5(join5(homedir3(), ".notis"), { recursive: true });
|
|
10608
10896
|
const deadline = Date.now() + waitMs;
|
|
10609
10897
|
for (; ; ) {
|
|
10610
10898
|
try {
|
|
10611
|
-
|
|
10899
|
+
mkdirSync5(oauthLockDir());
|
|
10612
10900
|
return true;
|
|
10613
10901
|
} catch (error) {
|
|
10614
10902
|
if (error?.code !== "EEXIST") throw error;
|
|
@@ -10660,6 +10948,7 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
10660
10948
|
stopTouchingLocks = keepLockFoldersFresh([profileLock, oauthLockDir()]);
|
|
10661
10949
|
const config = loadConfig();
|
|
10662
10950
|
const profile = getProfile(config, runtime.profileName);
|
|
10951
|
+
if (oauthGrantOnRetiredAddress(profile)) throw retiredAddressGrantError(runtime, profile);
|
|
10663
10952
|
assertOAuthApiTarget(runtime, profile);
|
|
10664
10953
|
if (profile.oauth_access_token && profile.oauth_access_token !== staleAccessToken && !credentialIsExpired({ credentialKind: "oauth" }, profile)) {
|
|
10665
10954
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -10697,7 +10986,15 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
10697
10986
|
failure.cause
|
|
10698
10987
|
);
|
|
10699
10988
|
}
|
|
10700
|
-
|
|
10989
|
+
let rotatedResponse;
|
|
10990
|
+
try {
|
|
10991
|
+
rotatedResponse = readRefreshAnswer(runtime, answer);
|
|
10992
|
+
} catch (refusal2) {
|
|
10993
|
+
if (refusal2?.code === "invalid_grant") {
|
|
10994
|
+
recordRefusedRefreshToken(runtime, profile.oauth_refresh_token);
|
|
10995
|
+
}
|
|
10996
|
+
throw refusal2;
|
|
10997
|
+
}
|
|
10701
10998
|
const updated = await persistRefreshedSignIn(runtime, metadata, rotatedResponse);
|
|
10702
10999
|
updateRuntimeFromOAuthProfile(runtime, updated);
|
|
10703
11000
|
return true;
|
|
@@ -10770,7 +11067,7 @@ async function logoutOAuth(runtime, { allProfiles = false } = {}, fetchImpl = fe
|
|
|
10770
11067
|
stopPendingListener(profileRuntime);
|
|
10771
11068
|
const profile = loadConfig().profiles[profileName] || {};
|
|
10772
11069
|
const revocationToken = profile.oauth_refresh_token || profile.oauth_access_token;
|
|
10773
|
-
if (revocationToken && profile.oauth_client_id && profile.oauth_issuer) {
|
|
11070
|
+
if (revocationToken && profile.oauth_client_id && profile.oauth_issuer && !oauthGrantOnRetiredAddress(profile)) {
|
|
10774
11071
|
try {
|
|
10775
11072
|
const metadata = storedOAuthMetadata(runtime, profile);
|
|
10776
11073
|
await fetchJson(
|
|
@@ -10791,12 +11088,18 @@ async function logoutOAuth(runtime, { allProfiles = false } = {}, fetchImpl = fe
|
|
|
10791
11088
|
updateConfig((latest) => {
|
|
10792
11089
|
const current = latest.profiles[profileName];
|
|
10793
11090
|
if (!current) return latest;
|
|
11091
|
+
const signsOutAccount = Boolean(
|
|
11092
|
+
(current.oauth_access_token || current.oauth_refresh_token || current.oauth_client_id || current.oauth_issuer || current.oauth_resource || current.oauth_user_id) && !current.dev_access_token
|
|
11093
|
+
);
|
|
10794
11094
|
latest.profiles[profileName] = {
|
|
10795
11095
|
...current,
|
|
11096
|
+
...signsOutAccount ? { api_base: void 0, release_channel: void 0, ...signedOutRoute(current) } : {},
|
|
10796
11097
|
oauth_access_token: void 0,
|
|
10797
11098
|
oauth_refresh_token: void 0,
|
|
10798
11099
|
oauth_access_expires_at: void 0,
|
|
10799
11100
|
oauth_refresh_expires_at: void 0,
|
|
11101
|
+
oauth_refresh_expiry_from_server: void 0,
|
|
11102
|
+
oauth_refresh_rejected_for: void 0,
|
|
10800
11103
|
oauth_client_id: void 0,
|
|
10801
11104
|
oauth_issuer: void 0,
|
|
10802
11105
|
oauth_api_base: void 0,
|
|
@@ -10820,6 +11123,7 @@ var init_oauth = __esm({
|
|
|
10820
11123
|
"src/runtime/oauth.js"() {
|
|
10821
11124
|
init_errors();
|
|
10822
11125
|
init_computer_identity();
|
|
11126
|
+
init_api_hosts();
|
|
10823
11127
|
init_auth_recovery();
|
|
10824
11128
|
init_channel();
|
|
10825
11129
|
init_profiles();
|
|
@@ -10905,8 +11209,8 @@ __export(skill_sync_exports, {
|
|
|
10905
11209
|
});
|
|
10906
11210
|
import { createHash as createHash42 } from "node:crypto";
|
|
10907
11211
|
import { promises as fs3 } from "node:fs";
|
|
10908
|
-
import { dirname as
|
|
10909
|
-
import { createHash as
|
|
11212
|
+
import { dirname as dirname13, join as join12 } from "node:path";
|
|
11213
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
10910
11214
|
import { createHash as createHash22 } from "crypto";
|
|
10911
11215
|
import { execFile } from "child_process";
|
|
10912
11216
|
import { promises as fs2 } from "fs";
|
|
@@ -10965,7 +11269,7 @@ function assertNativePull(response) {
|
|
|
10965
11269
|
}
|
|
10966
11270
|
}
|
|
10967
11271
|
function nativeFileDigest(bytes) {
|
|
10968
|
-
return
|
|
11272
|
+
return createHash11("sha256").update(bytes).digest("hex");
|
|
10969
11273
|
}
|
|
10970
11274
|
function nativeFrontmatterName(markdown) {
|
|
10971
11275
|
const header = markdown.match(/^---\s*\n([\s\S]*?)\n---/);
|
|
@@ -12426,7 +12730,7 @@ function withoutBaseSkillState(state) {
|
|
|
12426
12730
|
};
|
|
12427
12731
|
}
|
|
12428
12732
|
async function forgetOtherAccountsAgentLinks(paths) {
|
|
12429
|
-
const usersDir =
|
|
12733
|
+
const usersDir = dirname13(dirname13(paths.syncStatePath));
|
|
12430
12734
|
let entries;
|
|
12431
12735
|
try {
|
|
12432
12736
|
entries = await fs3.readdir(usersDir, { withFileTypes: true });
|
|
@@ -12435,7 +12739,7 @@ async function forgetOtherAccountsAgentLinks(paths) {
|
|
|
12435
12739
|
}
|
|
12436
12740
|
for (const entry of entries) {
|
|
12437
12741
|
if (!entry.isDirectory()) continue;
|
|
12438
|
-
const statePath3 =
|
|
12742
|
+
const statePath3 = join12(usersDir, entry.name, ".notis-sync.json");
|
|
12439
12743
|
if (statePath3 === paths.syncStatePath) continue;
|
|
12440
12744
|
let state = null;
|
|
12441
12745
|
try {
|
|
@@ -12460,15 +12764,15 @@ async function forgetOtherAccountsAgentLinks(paths) {
|
|
|
12460
12764
|
}
|
|
12461
12765
|
function isolatedLinkOptions(paths) {
|
|
12462
12766
|
if (!paths.isolatedNamespace && !paths.homeDir) return void 0;
|
|
12463
|
-
const root = paths.isolatedNamespace ?
|
|
12767
|
+
const root = paths.isolatedNamespace ? join12(paths.syncRoot, "environments", paths.isolatedNamespace, "agents") : paths.homeDir;
|
|
12464
12768
|
return {
|
|
12465
12769
|
agentSkillDirs: {
|
|
12466
12770
|
notis: paths.skillsDir,
|
|
12467
|
-
claude_code:
|
|
12468
|
-
cursor:
|
|
12469
|
-
codex:
|
|
12771
|
+
claude_code: join12(root, ".claude", "skills"),
|
|
12772
|
+
cursor: join12(root, ".cursor", "skills"),
|
|
12773
|
+
codex: join12(root, ".codex", "skills")
|
|
12470
12774
|
},
|
|
12471
|
-
legacyGlobalSkillsDir:
|
|
12775
|
+
legacyGlobalSkillsDir: join12(root, ".agents", "skills")
|
|
12472
12776
|
};
|
|
12473
12777
|
}
|
|
12474
12778
|
function assertSyncEnvironment(pull2, settings) {
|
|
@@ -28958,8 +29262,8 @@ var require_lib = __commonJS({
|
|
|
28958
29262
|
});
|
|
28959
29263
|
|
|
28960
29264
|
// src/cli.js
|
|
28961
|
-
import { readFileSync as
|
|
28962
|
-
import { dirname as
|
|
29265
|
+
import { readFileSync as readFileSync25 } from "node:fs";
|
|
29266
|
+
import { dirname as dirname24, join as join27 } from "node:path";
|
|
28963
29267
|
import { fileURLToPath as fileURLToPath12 } from "node:url";
|
|
28964
29268
|
|
|
28965
29269
|
// node_modules/commander/lib/error.js
|
|
@@ -32336,8 +32640,8 @@ var program = new Command();
|
|
|
32336
32640
|
|
|
32337
32641
|
// src/command-specs/tools.js
|
|
32338
32642
|
init_errors();
|
|
32339
|
-
import { accessSync, constants as fsConstants, createReadStream as createReadStream2, existsSync as existsSync4, readFileSync as
|
|
32340
|
-
import { createHash as
|
|
32643
|
+
import { accessSync, constants as fsConstants, createReadStream as createReadStream2, existsSync as existsSync4, readFileSync as readFileSync6, statSync as statSync3 } from "node:fs";
|
|
32644
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
32341
32645
|
import { basename as basename2 } from "node:path";
|
|
32342
32646
|
|
|
32343
32647
|
// src/runtime/tool-confirmation.js
|
|
@@ -32452,16 +32756,12 @@ function createStderrPrompter({ input = process.stdin, output = process.stderr }
|
|
|
32452
32756
|
}
|
|
32453
32757
|
|
|
32454
32758
|
// src/runtime/upsell.js
|
|
32759
|
+
init_api_hosts();
|
|
32455
32760
|
var UPSELL_CODES = /* @__PURE__ */ new Set([
|
|
32456
32761
|
"entitlement_upgrade_required",
|
|
32457
32762
|
"cloud_computer_team_limit"
|
|
32458
32763
|
]);
|
|
32459
32764
|
var NESTED_KEYS = ["error", "details", "data", "result", "response", "entitlement_access"];
|
|
32460
|
-
var PORTAL_ORIGINS = {
|
|
32461
|
-
"api.notis.ai": "https://app.notis.ai",
|
|
32462
|
-
"api-nightly.notis.ai": "https://app-nightly.notis.ai",
|
|
32463
|
-
"api-beta.notis.ai": "https://app-nightly.notis.ai"
|
|
32464
|
-
};
|
|
32465
32765
|
function isUpsellBody(value) {
|
|
32466
32766
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
32467
32767
|
if (value.upgrade_required === true) return true;
|
|
@@ -32504,7 +32804,7 @@ function findUpsell(value, depth = 0) {
|
|
|
32504
32804
|
}
|
|
32505
32805
|
function portalOriginFor(apiBase) {
|
|
32506
32806
|
try {
|
|
32507
|
-
return
|
|
32807
|
+
return portalOriginForApiHost(new URL(apiBase).hostname);
|
|
32508
32808
|
} catch {
|
|
32509
32809
|
return null;
|
|
32510
32810
|
}
|
|
@@ -32638,16 +32938,17 @@ function renderUpsell(body, { apiBase } = {}) {
|
|
|
32638
32938
|
var import_ajv = __toESM(require_ajv(), 1);
|
|
32639
32939
|
var import_ajv_formats = __toESM(require_dist(), 1);
|
|
32640
32940
|
init_errors();
|
|
32641
|
-
import { randomUUID as
|
|
32941
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
32642
32942
|
|
|
32643
32943
|
// src/runtime/transport.js
|
|
32644
32944
|
init_errors();
|
|
32945
|
+
init_agent_identity();
|
|
32645
32946
|
init_profiles();
|
|
32646
32947
|
init_auth_recovery();
|
|
32647
32948
|
init_oauth();
|
|
32648
|
-
import { randomUUID as
|
|
32949
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
32649
32950
|
import { createReadStream } from "node:fs";
|
|
32650
|
-
import { dirname as
|
|
32951
|
+
import { dirname as dirname6 } from "node:path";
|
|
32651
32952
|
|
|
32652
32953
|
// src/runtime/release-channel.js
|
|
32653
32954
|
init_errors();
|
|
@@ -32816,7 +33117,7 @@ async function* multipartFileBody(boundary, payload, bindingMetadata, fileBindin
|
|
|
32816
33117
|
`);
|
|
32817
33118
|
}
|
|
32818
33119
|
function createMultipartFileUpload(payload, bindingMetadata, fileBindings) {
|
|
32819
|
-
const boundary = `----notis-cli-${
|
|
33120
|
+
const boundary = `----notis-cli-${randomUUID4().replace(/-/g, "")}`;
|
|
32820
33121
|
const textParts = [
|
|
32821
33122
|
multipartTextPart(boundary, "payload", JSON.stringify(payload)),
|
|
32822
33123
|
multipartTextPart(boundary, "file_bindings", JSON.stringify(bindingMetadata))
|
|
@@ -32955,7 +33256,7 @@ function reloadDevJwt(runtime, loadedProfile = null) {
|
|
|
32955
33256
|
const expectedUserId = runtime.worktreeRuntime?.expected_user_id;
|
|
32956
33257
|
const runtimePath = runtime.worktreeRuntime?.runtime_path;
|
|
32957
33258
|
if (runtimePath) {
|
|
32958
|
-
const refreshedRuntime = resolveWorktreeRuntime(
|
|
33259
|
+
const refreshedRuntime = resolveWorktreeRuntime(dirname6(runtimePath));
|
|
32959
33260
|
if (refreshedRuntime && !refreshedRuntime.unavailable && refreshedRuntime.runtime_path === runtimePath && refreshedRuntime.profile === runtime.profileName && refreshedRuntime.api_base === runtime.apiBase) {
|
|
32960
33261
|
if (expectedUserId && refreshedRuntime.expected_user_id !== expectedUserId) {
|
|
32961
33262
|
throw new CliError({
|
|
@@ -33020,8 +33321,16 @@ async function httpRequest({
|
|
|
33020
33321
|
}) {
|
|
33021
33322
|
let currentProfile;
|
|
33022
33323
|
if (runtime.credentialKind === "oauth") {
|
|
33324
|
+
const storedGrant = getProfile(loadConfig(), runtime.profileName);
|
|
33023
33325
|
if (requireAuth && credentialIsExpired(runtime, {
|
|
33024
|
-
oauth_access_expires_at: runtime.oauthAccessExpiresAt
|
|
33326
|
+
oauth_access_expires_at: runtime.oauthAccessExpiresAt,
|
|
33327
|
+
// The stored refusal evidence (oauthGrantIsDead) of the same grant.
|
|
33328
|
+
oauth_refresh_token: storedGrant.oauth_refresh_token,
|
|
33329
|
+
oauth_refresh_rejected_for: storedGrant.oauth_refresh_rejected_for,
|
|
33330
|
+
// A grant minted for a retired API name is spent too (CLI-038).
|
|
33331
|
+
oauth_issuer: storedGrant.oauth_issuer,
|
|
33332
|
+
oauth_resource: storedGrant.oauth_resource,
|
|
33333
|
+
oauth_access_token: storedGrant.oauth_access_token
|
|
33025
33334
|
})) {
|
|
33026
33335
|
await refreshOAuthCredential(runtime);
|
|
33027
33336
|
}
|
|
@@ -33034,9 +33343,10 @@ async function httpRequest({
|
|
|
33034
33343
|
if (requireAuth && credentialIsExpired(runtime, currentProfile)) {
|
|
33035
33344
|
throw createExpiredAuthError(runtime);
|
|
33036
33345
|
}
|
|
33346
|
+
const agentHeaders = agentIdentityHeaders(runtime);
|
|
33037
33347
|
let controller = new AbortController();
|
|
33038
33348
|
let timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
33039
|
-
const requestId2 = `req_${
|
|
33349
|
+
const requestId2 = `req_${randomUUID4().replace(/-/g, "")}`;
|
|
33040
33350
|
const resetTimeout = () => {
|
|
33041
33351
|
clearTimeout(timeout);
|
|
33042
33352
|
controller = new AbortController();
|
|
@@ -33044,7 +33354,8 @@ async function httpRequest({
|
|
|
33044
33354
|
};
|
|
33045
33355
|
const headers = {
|
|
33046
33356
|
"X-Notis-CLI-Version": runtime.cliVersion,
|
|
33047
|
-
"X-Notis-Request-Id": requestId2
|
|
33357
|
+
"X-Notis-Request-Id": requestId2,
|
|
33358
|
+
...agentHeaders
|
|
33048
33359
|
};
|
|
33049
33360
|
if (spacesProtocol) headers["X-Notis-Spaces-Protocol"] = String(SPACES_PROTOCOL);
|
|
33050
33361
|
if (!multipart) {
|
|
@@ -33164,7 +33475,7 @@ async function callTool({
|
|
|
33164
33475
|
idempotencyKey,
|
|
33165
33476
|
fileBindings = []
|
|
33166
33477
|
}) {
|
|
33167
|
-
const firstKey = idempotencyKey || (runtime.mutating ?
|
|
33478
|
+
const firstKey = idempotencyKey || (runtime.mutating ? randomUUID4() : null);
|
|
33168
33479
|
const buildPayload = (key3) => ({
|
|
33169
33480
|
tool_name: toolName,
|
|
33170
33481
|
arguments: argumentsPayload,
|
|
@@ -33224,7 +33535,7 @@ async function callTool({
|
|
|
33224
33535
|
throw transient ? withAttempts(error, attempt) : error;
|
|
33225
33536
|
}
|
|
33226
33537
|
if (runtime.mutating && key2 && findToolOutcomeUnknown(result.payload) && callCarriesToolRequestId(argumentsPayload) && await waitForNextAttempt({ attempt, deadline, budgetMs })) {
|
|
33227
|
-
key2 =
|
|
33538
|
+
key2 = randomUUID4();
|
|
33228
33539
|
continue;
|
|
33229
33540
|
}
|
|
33230
33541
|
return { ...result, idempotencyKey: key2, attempts: attempt };
|
|
@@ -33269,7 +33580,7 @@ function parseMaybeJson(value, label) {
|
|
|
33269
33580
|
return parseJson(value, label);
|
|
33270
33581
|
}
|
|
33271
33582
|
function nextIdempotencyKey(globalOptions) {
|
|
33272
|
-
return globalOptions.idempotencyKey ||
|
|
33583
|
+
return globalOptions.idempotencyKey || randomUUID5();
|
|
33273
33584
|
}
|
|
33274
33585
|
async function runToolCommand({
|
|
33275
33586
|
runtime,
|
|
@@ -33422,7 +33733,7 @@ async function resolveJsonInput(value, label) {
|
|
|
33422
33733
|
if (!existsSync4(filePath)) {
|
|
33423
33734
|
throw usageError(`File not found: ${filePath}`);
|
|
33424
33735
|
}
|
|
33425
|
-
return parseJson(
|
|
33736
|
+
return parseJson(readFileSync6(filePath, "utf-8"), label);
|
|
33426
33737
|
}
|
|
33427
33738
|
return parseJson(value, label);
|
|
33428
33739
|
}
|
|
@@ -33612,7 +33923,7 @@ function guessContentType(filePath) {
|
|
|
33612
33923
|
return EXTENSION_CONTENT_TYPES.get(lower.slice(dotIndex)) || "application/octet-stream";
|
|
33613
33924
|
}
|
|
33614
33925
|
async function hashFileSha256(localPath2) {
|
|
33615
|
-
const hash2 =
|
|
33926
|
+
const hash2 = createHash3("sha256");
|
|
33616
33927
|
for await (const chunk of createReadStream2(localPath2)) {
|
|
33617
33928
|
hash2.update(chunk);
|
|
33618
33929
|
}
|
|
@@ -34110,7 +34421,7 @@ var toolsCommandSpecs = [
|
|
|
34110
34421
|
];
|
|
34111
34422
|
|
|
34112
34423
|
// src/command-specs/meta.js
|
|
34113
|
-
import { dirname as
|
|
34424
|
+
import { dirname as dirname7 } from "node:path";
|
|
34114
34425
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
34115
34426
|
|
|
34116
34427
|
// src/runtime/help.js
|
|
@@ -34179,7 +34490,7 @@ function doctorToolRoundtripRuntime(runtime) {
|
|
|
34179
34490
|
timeoutMs: Math.max(runtime.timeoutMs || 0, DOCTOR_TOOL_ROUNDTRIP_TIMEOUT_MS)
|
|
34180
34491
|
};
|
|
34181
34492
|
}
|
|
34182
|
-
function doctorChannelSummary(runtime, moduleDirectory =
|
|
34493
|
+
function doctorChannelSummary(runtime, moduleDirectory = dirname7(fileURLToPath2(import.meta.url))) {
|
|
34183
34494
|
const decision = resolveChannelSwitch({
|
|
34184
34495
|
runningVersion: runtime.cliVersion,
|
|
34185
34496
|
profile: {
|
|
@@ -34425,50 +34736,50 @@ init_errors();
|
|
|
34425
34736
|
init_auth_recovery();
|
|
34426
34737
|
init_profiles();
|
|
34427
34738
|
init_oauth();
|
|
34428
|
-
import { readFileSync as
|
|
34429
|
-
import { dirname as
|
|
34739
|
+
import { readFileSync as readFileSync10 } from "node:fs";
|
|
34740
|
+
import { dirname as dirname11, join as join9 } from "node:path";
|
|
34430
34741
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
34431
34742
|
|
|
34432
34743
|
// src/command-specs/auth.js
|
|
34433
34744
|
init_oauth();
|
|
34434
34745
|
|
|
34435
34746
|
// src/command-specs/agents.js
|
|
34436
|
-
import { createHash as
|
|
34747
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
34437
34748
|
import { basename as basename3, isAbsolute as isAbsolute3 } from "node:path";
|
|
34438
34749
|
|
|
34439
34750
|
// src/runtime/agent-setup.js
|
|
34440
34751
|
import {
|
|
34441
34752
|
chmodSync,
|
|
34442
34753
|
existsSync as existsSync6,
|
|
34443
|
-
mkdirSync as
|
|
34444
|
-
readFileSync as
|
|
34754
|
+
mkdirSync as mkdirSync7,
|
|
34755
|
+
readFileSync as readFileSync8,
|
|
34445
34756
|
readdirSync as readdirSync3,
|
|
34446
34757
|
realpathSync,
|
|
34447
|
-
renameSync as
|
|
34448
|
-
writeFileSync as
|
|
34758
|
+
renameSync as renameSync7,
|
|
34759
|
+
writeFileSync as writeFileSync6
|
|
34449
34760
|
} from "node:fs";
|
|
34450
|
-
import { createHash as
|
|
34761
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
34451
34762
|
import { homedir as homedir5 } from "node:os";
|
|
34452
|
-
import { dirname as
|
|
34763
|
+
import { dirname as dirname9, isAbsolute as isAbsolute2, join as join7 } from "node:path";
|
|
34453
34764
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
34454
34765
|
|
|
34455
34766
|
// src/runtime/base-skills.js
|
|
34456
|
-
import { createHash as
|
|
34767
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
34457
34768
|
import {
|
|
34458
34769
|
cpSync,
|
|
34459
34770
|
existsSync as existsSync5,
|
|
34460
34771
|
lstatSync,
|
|
34461
|
-
mkdirSync as
|
|
34772
|
+
mkdirSync as mkdirSync6,
|
|
34462
34773
|
readdirSync as readdirSync2,
|
|
34463
|
-
readFileSync as
|
|
34774
|
+
readFileSync as readFileSync7,
|
|
34464
34775
|
readlinkSync,
|
|
34465
|
-
renameSync as
|
|
34776
|
+
renameSync as renameSync6,
|
|
34466
34777
|
rmSync as rmSync3,
|
|
34467
34778
|
symlinkSync,
|
|
34468
34779
|
unlinkSync
|
|
34469
34780
|
} from "node:fs";
|
|
34470
34781
|
import { homedir as homedir4 } from "node:os";
|
|
34471
|
-
import { dirname as
|
|
34782
|
+
import { dirname as dirname8, join as join6, relative, resolve as resolve3 } from "node:path";
|
|
34472
34783
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
34473
34784
|
var BASE_SKILL_NAMES = Object.freeze([
|
|
34474
34785
|
"notis-spaces",
|
|
@@ -34477,53 +34788,53 @@ var BASE_SKILL_NAMES = Object.freeze([
|
|
|
34477
34788
|
]);
|
|
34478
34789
|
var RETIRED_BASE_SKILL_NAMES = Object.freeze(["notis-apps", "notis-reports"]);
|
|
34479
34790
|
var BASE_SKILL_STAMP_FILE = ".notis-base-skill.json";
|
|
34480
|
-
var HERE =
|
|
34791
|
+
var HERE = dirname8(fileURLToPath3(import.meta.url));
|
|
34481
34792
|
function resolveBundledBaseSkillsRoot({ resourcesPath = process.resourcesPath } = {}) {
|
|
34482
34793
|
const sourceCheckout = resolve3(HERE, "../../../../server/skills");
|
|
34483
34794
|
const packaged = resolve3(HERE, "../../dist/base-skills");
|
|
34484
|
-
const desktopResource = resourcesPath ?
|
|
34795
|
+
const desktopResource = resourcesPath ? join6(resourcesPath, "base-skills") : null;
|
|
34485
34796
|
const desktopPackagerRoot = resourcesPath || null;
|
|
34486
34797
|
for (const candidate of [sourceCheckout, packaged, desktopResource, desktopPackagerRoot]) {
|
|
34487
|
-
if (candidate && BASE_SKILL_NAMES.every((name) => existsSync5(
|
|
34798
|
+
if (candidate && BASE_SKILL_NAMES.every((name) => existsSync5(join6(candidate, name, "SKILL.md")))) {
|
|
34488
34799
|
return candidate;
|
|
34489
34800
|
}
|
|
34490
34801
|
}
|
|
34491
34802
|
return packaged;
|
|
34492
34803
|
}
|
|
34493
34804
|
function getBaseSkillPaths({ home = homedir4(), userId = null } = {}) {
|
|
34494
|
-
const notisRoot =
|
|
34805
|
+
const notisRoot = join6(home, ".notis", "skills");
|
|
34495
34806
|
const targetRoots = [
|
|
34496
|
-
|
|
34497
|
-
|
|
34498
|
-
|
|
34499
|
-
|
|
34807
|
+
join6(home, ".agents", "skills"),
|
|
34808
|
+
join6(home, ".codex", "skills"),
|
|
34809
|
+
join6(home, ".cursor", "skills"),
|
|
34810
|
+
join6(home, ".claude", "skills")
|
|
34500
34811
|
];
|
|
34501
34812
|
if (userId) {
|
|
34502
|
-
targetRoots.push(
|
|
34813
|
+
targetRoots.push(join6(notisRoot, "users", userId, "skills"));
|
|
34503
34814
|
}
|
|
34504
34815
|
return {
|
|
34505
|
-
baseRoot:
|
|
34506
|
-
backupRoot:
|
|
34816
|
+
baseRoot: join6(notisRoot, "base"),
|
|
34817
|
+
backupRoot: join6(notisRoot, "backups"),
|
|
34507
34818
|
targetRoots
|
|
34508
34819
|
};
|
|
34509
34820
|
}
|
|
34510
34821
|
function sameLinkTarget(linkPath, expectedTarget) {
|
|
34511
34822
|
try {
|
|
34512
34823
|
if (!lstatSync(linkPath).isSymbolicLink()) return false;
|
|
34513
|
-
return resolve3(
|
|
34824
|
+
return resolve3(dirname8(linkPath), readlinkSync(linkPath)) === resolve3(expectedTarget);
|
|
34514
34825
|
} catch {
|
|
34515
34826
|
return false;
|
|
34516
34827
|
}
|
|
34517
34828
|
}
|
|
34518
34829
|
function backupConflict(linkPath, backupRoot, targetLabel, skillName, now) {
|
|
34519
|
-
const backupPath =
|
|
34520
|
-
|
|
34521
|
-
|
|
34830
|
+
const backupPath = join6(backupRoot, String(now), targetLabel, skillName);
|
|
34831
|
+
mkdirSync6(dirname8(backupPath), { recursive: true, mode: 448 });
|
|
34832
|
+
renameSync6(linkPath, backupPath);
|
|
34522
34833
|
return backupPath;
|
|
34523
34834
|
}
|
|
34524
34835
|
function readBaseSkillStamp(skillDir) {
|
|
34525
34836
|
try {
|
|
34526
|
-
const { stamp } = JSON.parse(
|
|
34837
|
+
const { stamp } = JSON.parse(readFileSync7(join6(skillDir, BASE_SKILL_STAMP_FILE), "utf8"));
|
|
34527
34838
|
return Number.isSafeInteger(stamp) && stamp > 0 ? stamp : null;
|
|
34528
34839
|
} catch {
|
|
34529
34840
|
return null;
|
|
@@ -34534,11 +34845,11 @@ function byName(left, right) {
|
|
|
34534
34845
|
return left.name < right.name ? -1 : 1;
|
|
34535
34846
|
}
|
|
34536
34847
|
function contentDigest(root) {
|
|
34537
|
-
const hash2 =
|
|
34848
|
+
const hash2 = createHash4("sha256");
|
|
34538
34849
|
const walk = (directory, prefix) => {
|
|
34539
34850
|
for (const entry of readdirSync2(directory, { withFileTypes: true }).sort(byName)) {
|
|
34540
34851
|
const path4 = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
34541
|
-
const full =
|
|
34852
|
+
const full = join6(directory, entry.name);
|
|
34542
34853
|
if (path4 === BASE_SKILL_STAMP_FILE) continue;
|
|
34543
34854
|
if (entry.isDirectory()) {
|
|
34544
34855
|
hash2.update(`dir\0${path4}\0`);
|
|
@@ -34546,7 +34857,7 @@ function contentDigest(root) {
|
|
|
34546
34857
|
} else if (entry.isSymbolicLink()) {
|
|
34547
34858
|
hash2.update(`link\0${path4}\0${readlinkSync(full)}\0`);
|
|
34548
34859
|
} else {
|
|
34549
|
-
const bytes =
|
|
34860
|
+
const bytes = readFileSync7(full);
|
|
34550
34861
|
hash2.update(`file\0${path4}\0${bytes.length}\0`);
|
|
34551
34862
|
hash2.update(bytes);
|
|
34552
34863
|
}
|
|
@@ -34556,7 +34867,7 @@ function contentDigest(root) {
|
|
|
34556
34867
|
return hash2.digest("hex");
|
|
34557
34868
|
}
|
|
34558
34869
|
function baseSkillAction(source, destination) {
|
|
34559
|
-
if (!existsSync5(
|
|
34870
|
+
if (!existsSync5(join6(destination, "SKILL.md"))) return "install";
|
|
34560
34871
|
const bundled = readBaseSkillStamp(source);
|
|
34561
34872
|
const installed = readBaseSkillStamp(destination);
|
|
34562
34873
|
if (bundled !== null && installed !== null && installed > bundled) return "keep";
|
|
@@ -34564,7 +34875,7 @@ function baseSkillAction(source, destination) {
|
|
|
34564
34875
|
return contentDigest(source) === contentDigest(destination) ? "current" : "install";
|
|
34565
34876
|
}
|
|
34566
34877
|
function replaceDirectory(source, destination) {
|
|
34567
|
-
|
|
34878
|
+
mkdirSync6(dirname8(destination), { recursive: true, mode: 448 });
|
|
34568
34879
|
const temporary = `${destination}.tmp-${process.pid}-${Date.now()}`;
|
|
34569
34880
|
const previous = `${destination}.previous-${process.pid}-${Date.now()}`;
|
|
34570
34881
|
rmSync3(temporary, { recursive: true, force: true });
|
|
@@ -34572,15 +34883,15 @@ function replaceDirectory(source, destination) {
|
|
|
34572
34883
|
let movedPrevious = false;
|
|
34573
34884
|
try {
|
|
34574
34885
|
if (existsSync5(destination)) {
|
|
34575
|
-
|
|
34886
|
+
renameSync6(destination, previous);
|
|
34576
34887
|
movedPrevious = true;
|
|
34577
34888
|
}
|
|
34578
|
-
|
|
34889
|
+
renameSync6(temporary, destination);
|
|
34579
34890
|
if (movedPrevious) rmSync3(previous, { recursive: true, force: true });
|
|
34580
34891
|
} catch (error) {
|
|
34581
34892
|
rmSync3(temporary, { recursive: true, force: true });
|
|
34582
34893
|
if (movedPrevious && !existsSync5(destination) && existsSync5(previous)) {
|
|
34583
|
-
|
|
34894
|
+
renameSync6(previous, destination);
|
|
34584
34895
|
}
|
|
34585
34896
|
throw error;
|
|
34586
34897
|
}
|
|
@@ -34601,11 +34912,11 @@ function reconcileBaseSkills({
|
|
|
34601
34912
|
skills: [...BASE_SKILL_NAMES]
|
|
34602
34913
|
};
|
|
34603
34914
|
for (const name of BASE_SKILL_NAMES) {
|
|
34604
|
-
const source =
|
|
34605
|
-
if (!existsSync5(
|
|
34915
|
+
const source = join6(sourceRoot, name);
|
|
34916
|
+
if (!existsSync5(join6(source, "SKILL.md"))) {
|
|
34606
34917
|
throw new Error(`Bundled base skill is missing: ${name}`);
|
|
34607
34918
|
}
|
|
34608
|
-
const destination =
|
|
34919
|
+
const destination = join6(paths.baseRoot, name);
|
|
34609
34920
|
let action;
|
|
34610
34921
|
try {
|
|
34611
34922
|
action = baseSkillAction(source, destination);
|
|
@@ -34620,15 +34931,15 @@ function reconcileBaseSkills({
|
|
|
34620
34931
|
}
|
|
34621
34932
|
}
|
|
34622
34933
|
for (const targetRoot of paths.targetRoots) {
|
|
34623
|
-
|
|
34934
|
+
mkdirSync6(targetRoot, { recursive: true, mode: 448 });
|
|
34624
34935
|
const targetLabel = relative(home, targetRoot).replaceAll("/", "_") || "home";
|
|
34625
34936
|
for (const retired of RETIRED_BASE_SKILL_NAMES) {
|
|
34626
|
-
const oldLink =
|
|
34627
|
-
if (sameLinkTarget(oldLink,
|
|
34937
|
+
const oldLink = join6(targetRoot, retired);
|
|
34938
|
+
if (sameLinkTarget(oldLink, join6(paths.baseRoot, retired))) unlinkSync(oldLink);
|
|
34628
34939
|
}
|
|
34629
34940
|
for (const name of BASE_SKILL_NAMES) {
|
|
34630
|
-
const skillTarget2 =
|
|
34631
|
-
const linkPath =
|
|
34941
|
+
const skillTarget2 = join6(paths.baseRoot, name);
|
|
34942
|
+
const linkPath = join6(targetRoot, name);
|
|
34632
34943
|
if (sameLinkTarget(linkPath, skillTarget2)) {
|
|
34633
34944
|
result.unchanged += 1;
|
|
34634
34945
|
continue;
|
|
@@ -34653,16 +34964,16 @@ function reconcileBaseSkills({
|
|
|
34653
34964
|
}
|
|
34654
34965
|
}
|
|
34655
34966
|
for (const retired of RETIRED_BASE_SKILL_NAMES) {
|
|
34656
|
-
const oldRoot =
|
|
34967
|
+
const oldRoot = join6(paths.baseRoot, retired);
|
|
34657
34968
|
if (existsSync5(oldRoot)) result.backups.push(backupConflict(oldRoot, paths.backupRoot, "base", retired, now));
|
|
34658
34969
|
}
|
|
34659
34970
|
return result;
|
|
34660
34971
|
}
|
|
34661
34972
|
|
|
34662
34973
|
// src/runtime/agent-setup.js
|
|
34663
|
-
var HERE2 =
|
|
34664
|
-
var INSTRUCTIONS_PATH =
|
|
34665
|
-
var HOOK_BUNDLE_PATH =
|
|
34974
|
+
var HERE2 = dirname9(fileURLToPath4(import.meta.url));
|
|
34975
|
+
var INSTRUCTIONS_PATH = join7(HERE2, "..", "..", "skills", "notis-cli", "AGENT_INSTRUCTIONS.md");
|
|
34976
|
+
var HOOK_BUNDLE_PATH = join7(HERE2, "..", "..", "dist", "agent-hooks", "notis-agent-hook.mjs");
|
|
34666
34977
|
var START_MARKER = "<!-- notis-cli:instructions:start -->";
|
|
34667
34978
|
var END_MARKER = "<!-- notis-cli:instructions:end -->";
|
|
34668
34979
|
var LEGACY_SENTINEL = "Use the Notis CLI (`npx --package @notis_ai/cli@latest -- notis ...`)";
|
|
@@ -34678,20 +34989,20 @@ var CODEX_EVENT_LABELS = Object.freeze({
|
|
|
34678
34989
|
var RECALL_ONLY_HOOK_EVENTS = Object.freeze(["SessionStart", "UserPromptSubmit"]);
|
|
34679
34990
|
var AGENT_IDS = Object.freeze(["codex", "claude-code"]);
|
|
34680
34991
|
function atomicWrite(filePath, contents, mode = 384) {
|
|
34681
|
-
|
|
34992
|
+
mkdirSync7(dirname9(filePath), { recursive: true, mode: 448 });
|
|
34682
34993
|
const temporaryPath = `${filePath}.notis-${process.pid}-${Date.now()}.tmp`;
|
|
34683
|
-
|
|
34684
|
-
|
|
34994
|
+
writeFileSync6(temporaryPath, contents, { mode });
|
|
34995
|
+
renameSync7(temporaryPath, filePath);
|
|
34685
34996
|
}
|
|
34686
34997
|
function readText(filePath) {
|
|
34687
|
-
return existsSync6(filePath) ?
|
|
34998
|
+
return existsSync6(filePath) ? readFileSync8(filePath, "utf-8") : "";
|
|
34688
34999
|
}
|
|
34689
35000
|
function activeCodexInstructionsPath(home) {
|
|
34690
|
-
const overridePath =
|
|
35001
|
+
const overridePath = join7(home, ".codex", "AGENTS.override.md");
|
|
34691
35002
|
if (existsSync6(overridePath) && readText(overridePath).trim()) {
|
|
34692
35003
|
return overridePath;
|
|
34693
35004
|
}
|
|
34694
|
-
return
|
|
35005
|
+
return join7(home, ".codex", "AGENTS.md");
|
|
34695
35006
|
}
|
|
34696
35007
|
function upsertInstructionBlock(filePath, block) {
|
|
34697
35008
|
const existing = readText(filePath);
|
|
@@ -34727,7 +35038,7 @@ function upsertInstructionBlock(filePath, block) {
|
|
|
34727
35038
|
}
|
|
34728
35039
|
function readJsonObject(filePath) {
|
|
34729
35040
|
if (!existsSync6(filePath)) return {};
|
|
34730
|
-
const raw =
|
|
35041
|
+
const raw = readFileSync8(filePath, "utf-8");
|
|
34731
35042
|
try {
|
|
34732
35043
|
const parsed = JSON.parse(raw);
|
|
34733
35044
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
@@ -34783,9 +35094,9 @@ function installManagedHookRuntime({
|
|
|
34783
35094
|
if (envFile && (platform === "win32" || !isAbsolute2(envFile))) {
|
|
34784
35095
|
throw new Error("A session environment file must be an absolute POSIX path");
|
|
34785
35096
|
}
|
|
34786
|
-
const bundle =
|
|
34787
|
-
const digest =
|
|
34788
|
-
const runtimePath =
|
|
35097
|
+
const bundle = readFileSync8(bundlePath2);
|
|
35098
|
+
const digest = createHash5("sha256").update(bundle).digest("hex");
|
|
35099
|
+
const runtimePath = join7(
|
|
34789
35100
|
home,
|
|
34790
35101
|
".notis",
|
|
34791
35102
|
"agent-hooks",
|
|
@@ -34793,10 +35104,10 @@ function installManagedHookRuntime({
|
|
|
34793
35104
|
digest,
|
|
34794
35105
|
"notis-agent-hook.mjs"
|
|
34795
35106
|
);
|
|
34796
|
-
const existingDigest = existsSync6(runtimePath) ?
|
|
35107
|
+
const existingDigest = existsSync6(runtimePath) ? createHash5("sha256").update(readFileSync8(runtimePath)).digest("hex") : null;
|
|
34797
35108
|
if (existingDigest !== digest) atomicWrite(runtimePath, bundle, 320);
|
|
34798
35109
|
chmodSync(runtimePath, 320);
|
|
34799
|
-
const launcherPath =
|
|
35110
|
+
const launcherPath = join7(
|
|
34800
35111
|
home,
|
|
34801
35112
|
".notis",
|
|
34802
35113
|
"agent-hooks",
|
|
@@ -34904,7 +35215,7 @@ function codexHookTrustHash(event, handler) {
|
|
|
34904
35215
|
async: false,
|
|
34905
35216
|
...handler.statusMessage ? { statusMessage: handler.statusMessage } : {}
|
|
34906
35217
|
};
|
|
34907
|
-
const digest =
|
|
35218
|
+
const digest = createHash5("sha256").update(JSON.stringify(canonicalJson({ event_name: label, hooks: [normalized] }))).digest("hex");
|
|
34908
35219
|
return `sha256:${digest}`;
|
|
34909
35220
|
}
|
|
34910
35221
|
function codexHookTrustKey(hooksPath, event, groupIndex, handlerIndex = 0) {
|
|
@@ -34949,16 +35260,16 @@ ${block}` : prefix ? `${prefix}
|
|
|
34949
35260
|
function agentPaths(agentId, home) {
|
|
34950
35261
|
if (agentId === "codex") {
|
|
34951
35262
|
return {
|
|
34952
|
-
root:
|
|
35263
|
+
root: join7(home, ".codex"),
|
|
34953
35264
|
instructions: activeCodexInstructionsPath(home),
|
|
34954
|
-
hooks:
|
|
35265
|
+
hooks: join7(home, ".codex", "hooks.json")
|
|
34955
35266
|
};
|
|
34956
35267
|
}
|
|
34957
35268
|
if (agentId === "claude-code") {
|
|
34958
35269
|
return {
|
|
34959
|
-
root:
|
|
34960
|
-
instructions:
|
|
34961
|
-
hooks:
|
|
35270
|
+
root: join7(home, ".claude"),
|
|
35271
|
+
instructions: join7(home, ".claude", "CLAUDE.md"),
|
|
35272
|
+
hooks: join7(home, ".claude", "settings.json")
|
|
34962
35273
|
};
|
|
34963
35274
|
}
|
|
34964
35275
|
throw new Error(`Unsupported agent: ${agentId}`);
|
|
@@ -34987,7 +35298,7 @@ function installAgentSetup({
|
|
|
34987
35298
|
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(String(profileName || ""))) {
|
|
34988
35299
|
throw new Error("A valid authenticated Notis profile is required for agent setup");
|
|
34989
35300
|
}
|
|
34990
|
-
const instructions =
|
|
35301
|
+
const instructions = readFileSync8(INSTRUCTIONS_PATH, "utf-8").trim();
|
|
34991
35302
|
const results = [];
|
|
34992
35303
|
const shouldRepairManagedHooks = memoryHooks === true || memoryHooks === null && agents.some((agentId) => fileHasManagedNotisHook(agentPaths(agentId, home).hooks));
|
|
34993
35304
|
const hookRuntime = shouldRepairManagedHooks ? installManagedHookRuntime({ home, platform }) : null;
|
|
@@ -35048,7 +35359,7 @@ function installRecallOnlyAgentHooks({
|
|
|
35048
35359
|
platform,
|
|
35049
35360
|
envFile
|
|
35050
35361
|
});
|
|
35051
|
-
const hooksPath =
|
|
35362
|
+
const hooksPath = join7(configDir, agentId === "codex" ? "hooks.json" : "settings.json");
|
|
35052
35363
|
const result = { agent: agentId, mode: "recall_only", instructions: null, memory_hook: null };
|
|
35053
35364
|
try {
|
|
35054
35365
|
const { managed, ...memoryHook } = upsertPromptHooks(
|
|
@@ -35062,7 +35373,7 @@ function installRecallOnlyAgentHooks({
|
|
|
35062
35373
|
);
|
|
35063
35374
|
result.memory_hook = memoryHook;
|
|
35064
35375
|
if (agentId === "codex") {
|
|
35065
|
-
result.hook_trust = upsertCodexHookTrust(
|
|
35376
|
+
result.hook_trust = upsertCodexHookTrust(join7(configDir, "config.toml"), hooksPath, managed);
|
|
35066
35377
|
}
|
|
35067
35378
|
} catch (error) {
|
|
35068
35379
|
result.memory_hook = {
|
|
@@ -35075,30 +35386,30 @@ function installRecallOnlyAgentHooks({
|
|
|
35075
35386
|
}
|
|
35076
35387
|
|
|
35077
35388
|
// src/runtime/agent-memory-state.js
|
|
35078
|
-
import { createHash as
|
|
35389
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
35079
35390
|
import {
|
|
35080
35391
|
existsSync as existsSync7,
|
|
35081
|
-
mkdirSync as
|
|
35082
|
-
readFileSync as
|
|
35083
|
-
renameSync as
|
|
35084
|
-
writeFileSync as
|
|
35392
|
+
mkdirSync as mkdirSync8,
|
|
35393
|
+
readFileSync as readFileSync9,
|
|
35394
|
+
renameSync as renameSync8,
|
|
35395
|
+
writeFileSync as writeFileSync7
|
|
35085
35396
|
} from "node:fs";
|
|
35086
35397
|
import { homedir as homedir6 } from "node:os";
|
|
35087
|
-
import { dirname as
|
|
35398
|
+
import { dirname as dirname10, join as join8 } from "node:path";
|
|
35088
35399
|
var MAX_SEEN_HASHES = 500;
|
|
35089
35400
|
var MAX_PROMPT_CHARS = 12e3;
|
|
35090
35401
|
function hash(value) {
|
|
35091
|
-
return
|
|
35402
|
+
return createHash6("sha256").update(String(value || "")).digest("hex").slice(0, 24);
|
|
35092
35403
|
}
|
|
35093
35404
|
function statePath(sessionId, home = homedir6()) {
|
|
35094
35405
|
if (!sessionId) return null;
|
|
35095
|
-
return
|
|
35406
|
+
return join8(home, ".notis", "agent-memory-hooks", `${hash(sessionId)}.json`);
|
|
35096
35407
|
}
|
|
35097
35408
|
function readState(sessionId, home) {
|
|
35098
35409
|
const filePath = statePath(sessionId, home);
|
|
35099
35410
|
if (!filePath || !existsSync7(filePath)) return { seen: [], pending: null };
|
|
35100
35411
|
try {
|
|
35101
|
-
const parsed = JSON.parse(
|
|
35412
|
+
const parsed = JSON.parse(readFileSync9(filePath, "utf-8"));
|
|
35102
35413
|
return parsed && typeof parsed === "object" ? {
|
|
35103
35414
|
seen: Array.isArray(parsed.seen) ? parsed.seen.filter((item) => typeof item === "string") : [],
|
|
35104
35415
|
pending: parsed.pending && typeof parsed.pending === "object" ? parsed.pending : null,
|
|
@@ -35128,11 +35439,11 @@ function stateForInput(sessionId, input, home) {
|
|
|
35128
35439
|
function writeState(sessionId, state, home) {
|
|
35129
35440
|
const filePath = statePath(sessionId, home);
|
|
35130
35441
|
if (!filePath) return;
|
|
35131
|
-
|
|
35442
|
+
mkdirSync8(dirname10(filePath), { recursive: true, mode: 448 });
|
|
35132
35443
|
const temporaryPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
35133
|
-
|
|
35444
|
+
writeFileSync7(temporaryPath, `${JSON.stringify(state)}
|
|
35134
35445
|
`, { mode: 384 });
|
|
35135
|
-
|
|
35446
|
+
renameSync8(temporaryPath, filePath);
|
|
35136
35447
|
}
|
|
35137
35448
|
function rememberPendingTurn(input, home = homedir6()) {
|
|
35138
35449
|
const sessionId = input?.session_id;
|
|
@@ -35479,7 +35790,7 @@ async function agentCaptureHandler(ctx) {
|
|
|
35479
35790
|
const agent = ["codex", "claude-code"].includes(ctx.options.agent) ? ctx.options.agent : "coding-agent";
|
|
35480
35791
|
const project = pending?.cwd ? basename3(pending.cwd) : null;
|
|
35481
35792
|
const stableTurn = `${ctx.runtime.profileName}:${agent}:${input.session_id}:${pending.turn_id || pending.recorded_at}`;
|
|
35482
|
-
const idempotencyKey =
|
|
35793
|
+
const idempotencyKey = createHash7("sha256").update(stableTurn).digest("hex");
|
|
35483
35794
|
const result = await runToolCommand({
|
|
35484
35795
|
runtime: ctx.runtime,
|
|
35485
35796
|
toolName: "LOCAL_NOTIS_SAVE_LONG_TERM_MEMORY",
|
|
@@ -35715,8 +36026,8 @@ var authCommandSpecs = [
|
|
|
35715
36026
|
];
|
|
35716
36027
|
|
|
35717
36028
|
// src/command-specs/onboarding.js
|
|
35718
|
-
var HERE3 =
|
|
35719
|
-
var BUNDLED_BRIEF_PATH =
|
|
36029
|
+
var HERE3 = dirname11(fileURLToPath5(import.meta.url));
|
|
36030
|
+
var BUNDLED_BRIEF_PATH = join9(HERE3, "..", "..", "skills", "notis-onboarding", "BRIEF.md");
|
|
35720
36031
|
async function fetchOnboardingState(runtime) {
|
|
35721
36032
|
try {
|
|
35722
36033
|
const { payload } = await runToolCommand({
|
|
@@ -35757,7 +36068,7 @@ async function fetchBrief(apiBase, timeoutMs) {
|
|
|
35757
36068
|
} catch {
|
|
35758
36069
|
}
|
|
35759
36070
|
try {
|
|
35760
|
-
return { markdown:
|
|
36071
|
+
return { markdown: readFileSync10(BUNDLED_BRIEF_PATH, "utf-8"), source: "bundled" };
|
|
35761
36072
|
} catch {
|
|
35762
36073
|
return { markdown: null, source: null };
|
|
35763
36074
|
}
|
|
@@ -36030,8 +36341,8 @@ var onboardingCommandSpecs = [
|
|
|
36030
36341
|
|
|
36031
36342
|
// src/command-specs/diagnostics.js
|
|
36032
36343
|
init_errors();
|
|
36033
|
-
import { createHash as
|
|
36034
|
-
import { existsSync as existsSync8, readFileSync as
|
|
36344
|
+
import { createHash as createHash8, randomUUID as randomUUID6 } from "node:crypto";
|
|
36345
|
+
import { existsSync as existsSync8, readFileSync as readFileSync11 } from "node:fs";
|
|
36035
36346
|
var ENTITLEMENT_FIELDS = [
|
|
36036
36347
|
"created_at",
|
|
36037
36348
|
"included_credit_seat_count",
|
|
@@ -36182,7 +36493,7 @@ async function executeReadOnlySql(ctx, query, phase) {
|
|
|
36182
36493
|
// Always a fresh key, never the operator's --idempotency-key: a diagnostic
|
|
36183
36494
|
// must observe current state rather than replay a cached response, and two
|
|
36184
36495
|
// different queries under one reused key would collide on the request hash.
|
|
36185
|
-
idempotencyKey:
|
|
36496
|
+
idempotencyKey: randomUUID6(),
|
|
36186
36497
|
sendIdempotencyKeyWhenReading: true
|
|
36187
36498
|
});
|
|
36188
36499
|
if (result.payload?.successful === false || result.payload?.error) {
|
|
@@ -36199,14 +36510,14 @@ async function executeReadOnlySql(ctx, query, phase) {
|
|
|
36199
36510
|
function redactIdentifier(value) {
|
|
36200
36511
|
if (!value) return null;
|
|
36201
36512
|
const text2 = String(value);
|
|
36202
|
-
const digest =
|
|
36513
|
+
const digest = createHash8("sha256").update(text2).digest("hex").slice(0, 12);
|
|
36203
36514
|
return `${text2.slice(0, 3)}\u2026#${digest}`;
|
|
36204
36515
|
}
|
|
36205
36516
|
function canonicalObjectHash(value) {
|
|
36206
36517
|
const ordered = Object.fromEntries(
|
|
36207
36518
|
Object.entries(value).sort(([left], [right]) => left.localeCompare(right))
|
|
36208
36519
|
);
|
|
36209
|
-
return
|
|
36520
|
+
return createHash8("sha256").update(JSON.stringify(ordered)).digest("hex");
|
|
36210
36521
|
}
|
|
36211
36522
|
function entitlementParityHash(context) {
|
|
36212
36523
|
const canonical = { scope_type: context.billing.scope_type };
|
|
@@ -36458,7 +36769,7 @@ ORDER BY i.created_at ASC;`;
|
|
|
36458
36769
|
function traceFileDiagnostics(path4) {
|
|
36459
36770
|
if (!path4) return null;
|
|
36460
36771
|
if (!existsSync8(path4)) throw usageError(`Trace file not found: ${path4}`);
|
|
36461
|
-
const trace = JSON.parse(
|
|
36772
|
+
const trace = JSON.parse(readFileSync11(path4, "utf-8"));
|
|
36462
36773
|
const text2 = JSON.stringify(trace).toLowerCase();
|
|
36463
36774
|
const modelCounts = {};
|
|
36464
36775
|
const generationIds = /* @__PURE__ */ new Set();
|
|
@@ -36686,15 +36997,15 @@ var diagnosticCommandSpecs = [
|
|
|
36686
36997
|
|
|
36687
36998
|
// src/command-specs/smoke.js
|
|
36688
36999
|
init_errors();
|
|
36689
|
-
import { createHash as
|
|
37000
|
+
import { createHash as createHash9, randomUUID as randomUUID7 } from "node:crypto";
|
|
36690
37001
|
import {
|
|
36691
37002
|
mkdtempSync,
|
|
36692
|
-
readFileSync as
|
|
37003
|
+
readFileSync as readFileSync12,
|
|
36693
37004
|
rmSync as rmSync4,
|
|
36694
|
-
writeFileSync as
|
|
37005
|
+
writeFileSync as writeFileSync8
|
|
36695
37006
|
} from "node:fs";
|
|
36696
37007
|
import { tmpdir } from "node:os";
|
|
36697
|
-
import { basename as basename4, join as
|
|
37008
|
+
import { basename as basename4, join as join10 } from "node:path";
|
|
36698
37009
|
import { setTimeout as delay } from "node:timers/promises";
|
|
36699
37010
|
function discoveryNames(payload) {
|
|
36700
37011
|
return [...new Set(
|
|
@@ -36766,7 +37077,7 @@ async function executeDropboxTool(ctx, toolName, args, {
|
|
|
36766
37077
|
toolName: COMPOSIO_MULTI_EXECUTE_TOOL,
|
|
36767
37078
|
arguments_: { tools: [{ tool_slug: toolName, arguments: args }] },
|
|
36768
37079
|
mutating,
|
|
36769
|
-
idempotencyKey: phaseKey.length <= 160 ? phaseKey :
|
|
37080
|
+
idempotencyKey: phaseKey.length <= 160 ? phaseKey : createHash9("sha256").update(phaseKey).digest("hex"),
|
|
36770
37081
|
// The batch wrapper is server-classified as unknown even for a read.
|
|
36771
37082
|
sendIdempotencyKeyWhenReading: true,
|
|
36772
37083
|
fileBindings
|
|
@@ -36778,12 +37089,12 @@ function remotePath(folder, name) {
|
|
|
36778
37089
|
return `${normalizedFolder}/${name}`;
|
|
36779
37090
|
}
|
|
36780
37091
|
async function smokeFileUploadHandler(ctx) {
|
|
36781
|
-
const tempDir = mkdtempSync(
|
|
36782
|
-
const marker = `${(/* @__PURE__ */ new Date()).toISOString().replaceAll(/[-:.]/g, "")}-${
|
|
37092
|
+
const tempDir = mkdtempSync(join10(tmpdir(), "notis-smoke-file-upload-"));
|
|
37093
|
+
const marker = `${(/* @__PURE__ */ new Date()).toISOString().replaceAll(/[-:.]/g, "")}-${randomUUID7().slice(0, 8)}`;
|
|
36783
37094
|
const generatedFixture = !ctx.options.sourceFile;
|
|
36784
|
-
const fixturePath = ctx.options.sourceFile ||
|
|
37095
|
+
const fixturePath = ctx.options.sourceFile || join10(tempDir, `notis-file-upload-${marker}.txt`);
|
|
36785
37096
|
if (generatedFixture) {
|
|
36786
|
-
|
|
37097
|
+
writeFileSync8(
|
|
36787
37098
|
fixturePath,
|
|
36788
37099
|
`Notis Dropbox file-upload smoke
|
|
36789
37100
|
marker=${marker}
|
|
@@ -36793,7 +37104,7 @@ unicode=\xE9t\xE9 Z\xFCrich \u6771\u4EAC
|
|
|
36793
37104
|
);
|
|
36794
37105
|
}
|
|
36795
37106
|
const localHash = await hashFileSha256(fixturePath);
|
|
36796
|
-
const localBytes =
|
|
37107
|
+
const localBytes = readFileSync12(fixturePath);
|
|
36797
37108
|
const destination = remotePath(
|
|
36798
37109
|
ctx.options.remoteFolder,
|
|
36799
37110
|
`notis-file-upload-${marker}-${basename4(fixturePath)}`
|
|
@@ -36905,7 +37216,7 @@ unicode=\xE9t\xE9 Z\xFCrich \u6771\u4EAC
|
|
|
36905
37216
|
throw usageError(`Dropbox temporary download returned HTTP ${downloadResponse.status}.`);
|
|
36906
37217
|
}
|
|
36907
37218
|
const downloaded = Buffer.from(await downloadResponse.arrayBuffer());
|
|
36908
|
-
const downloadedHash =
|
|
37219
|
+
const downloadedHash = createHash9("sha256").update(downloaded).digest("hex");
|
|
36909
37220
|
if (downloadedHash !== localHash) {
|
|
36910
37221
|
throw usageError("Downloaded Dropbox bytes did not match the uploaded fixture hash.");
|
|
36911
37222
|
}
|
|
@@ -37043,6 +37354,7 @@ var smokeCommandSpecs = [
|
|
|
37043
37354
|
];
|
|
37044
37355
|
|
|
37045
37356
|
// src/command-specs/profile.js
|
|
37357
|
+
init_api_hosts();
|
|
37046
37358
|
init_channel();
|
|
37047
37359
|
init_errors();
|
|
37048
37360
|
init_auth_recovery();
|
|
@@ -37124,7 +37436,6 @@ async function listHandler(ctx) {
|
|
|
37124
37436
|
]
|
|
37125
37437
|
});
|
|
37126
37438
|
}
|
|
37127
|
-
var SKILL_SYNC_API_BASE_PATTERN = /^https:\/\/api(?:-beta)?\.notis\.ai\/?$/;
|
|
37128
37439
|
var RELINK_DROPPED_ENV = ["NOTIS_JWT", "NOTIS_API_BASE", "NOTIS_PROFILE", CHANNEL_SWITCH_ENV];
|
|
37129
37440
|
function relinkSkillsInBackground(name, profile, {
|
|
37130
37441
|
env = process.env,
|
|
@@ -37134,7 +37445,8 @@ function relinkSkillsInBackground(name, profile, {
|
|
|
37134
37445
|
} = {}) {
|
|
37135
37446
|
if (env.NODE_ENV === "test" || env.NODE_TEST_CONTEXT || !argv[1]) return false;
|
|
37136
37447
|
if (!profile?.oauth_access_token && !profile?.oauth_refresh_token) return false;
|
|
37137
|
-
if (
|
|
37448
|
+
if (oauthGrantOnRetiredAddress(profile)) return false;
|
|
37449
|
+
if (!isLiveApiOrigin(profile.api_base)) return false;
|
|
37138
37450
|
const childEnv = { ...env };
|
|
37139
37451
|
for (const key2 of RELINK_DROPPED_ENV) delete childEnv[key2];
|
|
37140
37452
|
try {
|
|
@@ -37165,7 +37477,7 @@ async function useHandler(ctx) {
|
|
|
37165
37477
|
const profile = getProfile(next, requested);
|
|
37166
37478
|
const worktreeOverride = Boolean(worktreeRuntime);
|
|
37167
37479
|
const worktreeBlocked = Boolean(worktreeUnavailable);
|
|
37168
|
-
const authenticated =
|
|
37480
|
+
const authenticated = profileIsSignedIn(profile);
|
|
37169
37481
|
if (authenticated) relinkSkillsInBackground(requested, profile);
|
|
37170
37482
|
return ctx.output.emitSuccess({
|
|
37171
37483
|
command: ctx.spec.command_path.join(" "),
|
|
@@ -37176,7 +37488,7 @@ async function useHandler(ctx) {
|
|
|
37176
37488
|
effective_profile_source: worktreeBlocked ? "worktree-unavailable" : worktreeOverride ? "worktree" : "current",
|
|
37177
37489
|
worktree_runtime_unavailable: worktreeBlocked
|
|
37178
37490
|
},
|
|
37179
|
-
humanSummary: worktreeBlocked ? `Saved profile "${requested}" as the default outside this worktree; this local-only checkout is stopped, so use --profile explicitly or restart ./dev.sh.` : worktreeOverride ? `Saved profile "${requested}" as the default outside this worktree; this checkout still uses "${worktreeRuntime.profile}" unless --profile is explicit.` : authenticated ? `Switched to profile "${requested}".` : `Switched to profile "${requested}", which has no credential yet.`,
|
|
37491
|
+
humanSummary: worktreeBlocked ? `Saved profile "${requested}" as the default outside this worktree; this local-only checkout is stopped, so use --profile explicitly or restart ./dev.sh.` : worktreeOverride ? `Saved profile "${requested}" as the default outside this worktree; this checkout still uses "${worktreeRuntime.profile}" unless --profile is explicit.` : authenticated ? `Switched to profile "${requested}".` : profileHasCredential(profile) ? `Switched to profile "${requested}", whose sign-in has ended; sign in again.` : `Switched to profile "${requested}", which has no credential yet.`,
|
|
37180
37492
|
hints: worktreeBlocked ? [
|
|
37181
37493
|
{
|
|
37182
37494
|
command: `notis --profile ${quoteShellArgument(requested)} whoami`,
|
|
@@ -37354,12 +37666,12 @@ var profileCommandSpecs = [
|
|
|
37354
37666
|
|
|
37355
37667
|
// src/command-specs/handover.js
|
|
37356
37668
|
init_errors();
|
|
37357
|
-
import { randomUUID as
|
|
37669
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
37358
37670
|
|
|
37359
37671
|
// src/runtime/git.js
|
|
37360
37672
|
init_errors();
|
|
37361
37673
|
import { spawnSync } from "node:child_process";
|
|
37362
|
-
import { lstatSync as lstatSync2, readFileSync as
|
|
37674
|
+
import { lstatSync as lstatSync2, readFileSync as readFileSync13 } from "node:fs";
|
|
37363
37675
|
import { basename as basename5, relative as relative2, resolve as resolve4, sep } from "node:path";
|
|
37364
37676
|
var GIT_TIMEOUT_MS = 12e4;
|
|
37365
37677
|
var MAX_SECRET_SCAN_BYTES = 1e6;
|
|
@@ -37428,7 +37740,7 @@ function sensitiveAutoCommitFiles(repository) {
|
|
|
37428
37740
|
try {
|
|
37429
37741
|
const stat2 = lstatSync2(absolute);
|
|
37430
37742
|
if (!stat2.isFile() || stat2.size > MAX_SECRET_SCAN_BYTES) continue;
|
|
37431
|
-
const content =
|
|
37743
|
+
const content = readFileSync13(absolute, "utf8");
|
|
37432
37744
|
if (SENSITIVE_CONTENT.some((pattern) => pattern.test(content))) sensitive.push(path4);
|
|
37433
37745
|
} catch {
|
|
37434
37746
|
}
|
|
@@ -37893,7 +38205,7 @@ async function handoverStatusHandler(ctx) {
|
|
|
37893
38205
|
// The tool also writes, so the server asks every call for a key. A fresh
|
|
37894
38206
|
// one, never --idempotency-key: a reused key would replay a cached, stale
|
|
37895
38207
|
// read instead of asking again.
|
|
37896
|
-
idempotencyKey:
|
|
38208
|
+
idempotencyKey: randomUUID8(),
|
|
37897
38209
|
sendIdempotencyKeyWhenReading: true
|
|
37898
38210
|
});
|
|
37899
38211
|
const payload = result?.payload ?? {};
|
|
@@ -38016,17 +38328,17 @@ var handoverCommandSpecs = [
|
|
|
38016
38328
|
init_profiles();
|
|
38017
38329
|
|
|
38018
38330
|
// src/runtime/sync-skills.js
|
|
38019
|
-
import { createHash as
|
|
38331
|
+
import { createHash as createHash10, randomUUID as randomUUID9 } from "node:crypto";
|
|
38020
38332
|
import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
38021
38333
|
import { homedir as homedir7 } from "node:os";
|
|
38022
|
-
import { dirname as
|
|
38334
|
+
import { dirname as dirname12, join as join11 } from "node:path";
|
|
38023
38335
|
var DEFAULT_LOCK_TIMEOUT_MS = 3e4;
|
|
38024
38336
|
var DEFAULT_LOCK_STALE_MS = 10 * 6e4;
|
|
38025
38337
|
var DEFAULT_LOCK_POLL_MS = 50;
|
|
38026
38338
|
async function lockSnapshot(lockDirectory) {
|
|
38027
38339
|
try {
|
|
38028
38340
|
const [raw, metadata] = await Promise.all([
|
|
38029
|
-
readFile(
|
|
38341
|
+
readFile(join11(lockDirectory, "owner"), "utf8").catch(() => ""),
|
|
38030
38342
|
stat(lockDirectory)
|
|
38031
38343
|
]);
|
|
38032
38344
|
let owner = {};
|
|
@@ -38062,11 +38374,11 @@ function delay2(milliseconds) {
|
|
|
38062
38374
|
return new Promise((resolve17) => setTimeout(resolve17, milliseconds));
|
|
38063
38375
|
}
|
|
38064
38376
|
async function quarantineStaleLock(lockDirectory, snapshot) {
|
|
38065
|
-
const quarantineRoot =
|
|
38066
|
-
const snapshotToken =
|
|
38377
|
+
const quarantineRoot = join11(dirname12(lockDirectory), ".stale-operation-locks");
|
|
38378
|
+
const snapshotToken = createHash10("sha256").update(JSON.stringify(snapshot)).digest("hex");
|
|
38067
38379
|
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
38068
38380
|
try {
|
|
38069
|
-
await rename(lockDirectory,
|
|
38381
|
+
await rename(lockDirectory, join11(quarantineRoot, snapshotToken));
|
|
38070
38382
|
return true;
|
|
38071
38383
|
} catch (error) {
|
|
38072
38384
|
if (["EEXIST", "ENOTEMPTY", "ENOENT"].includes(error?.code)) return false;
|
|
@@ -38074,12 +38386,12 @@ async function quarantineStaleLock(lockDirectory, snapshot) {
|
|
|
38074
38386
|
}
|
|
38075
38387
|
}
|
|
38076
38388
|
async function publishOwnedLock(lockDirectory, owner) {
|
|
38077
|
-
const quarantineRoot =
|
|
38078
|
-
const staging =
|
|
38389
|
+
const quarantineRoot = join11(dirname12(lockDirectory), ".stale-operation-locks");
|
|
38390
|
+
const staging = join11(quarantineRoot, `staging.${owner.id}`);
|
|
38079
38391
|
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
38080
38392
|
await mkdir(staging, { mode: 448 });
|
|
38081
38393
|
try {
|
|
38082
|
-
await writeFile(
|
|
38394
|
+
await writeFile(join11(staging, "owner"), JSON.stringify(owner), { mode: 384 });
|
|
38083
38395
|
await rename(staging, lockDirectory);
|
|
38084
38396
|
} catch (error) {
|
|
38085
38397
|
await rm(staging, { recursive: true, force: true });
|
|
@@ -38091,8 +38403,8 @@ async function publishOwnedLock(lockDirectory, owner) {
|
|
|
38091
38403
|
async function releaseOwnedLock(lockDirectory, ownerId) {
|
|
38092
38404
|
const owner = await lockSnapshot(lockDirectory);
|
|
38093
38405
|
if (owner?.id !== ownerId) return;
|
|
38094
|
-
const quarantineRoot =
|
|
38095
|
-
const releasedDirectory =
|
|
38406
|
+
const quarantineRoot = join11(dirname12(lockDirectory), ".stale-operation-locks");
|
|
38407
|
+
const releasedDirectory = join11(quarantineRoot, `released.${ownerId}`);
|
|
38096
38408
|
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
38097
38409
|
try {
|
|
38098
38410
|
await rename(lockDirectory, releasedDirectory);
|
|
@@ -38109,10 +38421,10 @@ async function withSkillSyncLock(callback, {
|
|
|
38109
38421
|
pollMs = DEFAULT_LOCK_POLL_MS,
|
|
38110
38422
|
now = () => Date.now()
|
|
38111
38423
|
} = {}) {
|
|
38112
|
-
const lockDirectory =
|
|
38113
|
-
const ownerId = `${process.pid}.${
|
|
38424
|
+
const lockDirectory = join11(home, ".notis", "skills", ".operation-lock");
|
|
38425
|
+
const ownerId = `${process.pid}.${randomUUID9()}`;
|
|
38114
38426
|
const deadline = now() + timeoutMs;
|
|
38115
|
-
await mkdir(
|
|
38427
|
+
await mkdir(dirname12(lockDirectory), { recursive: true, mode: 448 });
|
|
38116
38428
|
for (; ; ) {
|
|
38117
38429
|
try {
|
|
38118
38430
|
await publishOwnedLock(lockDirectory, { id: ownerId, pid: process.pid, at: now() });
|
|
@@ -38138,7 +38450,7 @@ async function withSkillSyncLock(callback, {
|
|
|
38138
38450
|
let heartbeatInFlight = Promise.resolve();
|
|
38139
38451
|
const refreshHeartbeat = async () => {
|
|
38140
38452
|
if (heartbeatStopped) return;
|
|
38141
|
-
const temporaryOwnerPath =
|
|
38453
|
+
const temporaryOwnerPath = join11(lockDirectory, `.owner.${ownerId}.tmp`);
|
|
38142
38454
|
await writeFile(
|
|
38143
38455
|
temporaryOwnerPath,
|
|
38144
38456
|
JSON.stringify({ id: ownerId, pid: process.pid, at: now() }),
|
|
@@ -38149,7 +38461,7 @@ async function withSkillSyncLock(callback, {
|
|
|
38149
38461
|
await rm(temporaryOwnerPath, { force: true });
|
|
38150
38462
|
return;
|
|
38151
38463
|
}
|
|
38152
|
-
await rename(temporaryOwnerPath,
|
|
38464
|
+
await rename(temporaryOwnerPath, join11(lockDirectory, "owner"));
|
|
38153
38465
|
};
|
|
38154
38466
|
const heartbeat = setInterval(() => {
|
|
38155
38467
|
heartbeatInFlight = heartbeatInFlight.then(refreshHeartbeat).catch(() => void 0);
|
|
@@ -38202,21 +38514,21 @@ async function reconcileAllSkills({
|
|
|
38202
38514
|
init_oauth();
|
|
38203
38515
|
|
|
38204
38516
|
// src/runtime/skill-sync-service.js
|
|
38517
|
+
init_api_hosts();
|
|
38205
38518
|
init_profiles();
|
|
38206
38519
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
38207
|
-
import { createHash as
|
|
38208
|
-
import { existsSync as existsSync10, mkdirSync as
|
|
38520
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
38521
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync9, readFileSync as readFileSync14, renameSync as renameSync9, writeFileSync as writeFileSync9 } from "node:fs";
|
|
38209
38522
|
import { homedir as homedir8 } from "node:os";
|
|
38210
|
-
import { dirname as
|
|
38523
|
+
import { dirname as dirname14, join as join13 } from "node:path";
|
|
38211
38524
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
38212
|
-
var LIVE_API_BASES = ["https://api.notis.ai", "https://api-nightly.notis.ai", "https://api-beta.notis.ai"];
|
|
38213
38525
|
var SKILL_SYNC_SERVICE_LABEL = "ai.notis.skills-sync";
|
|
38214
38526
|
var bundlePath = fileURLToPath6(new URL("../../dist/skill-sync-worker.mjs", import.meta.url));
|
|
38215
38527
|
function atomicWrite2(target, value, mode = 384) {
|
|
38216
|
-
|
|
38528
|
+
mkdirSync9(dirname14(target), { recursive: true, mode: 448 });
|
|
38217
38529
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
38218
|
-
|
|
38219
|
-
|
|
38530
|
+
writeFileSync9(temporary, value, { mode });
|
|
38531
|
+
renameSync9(temporary, target);
|
|
38220
38532
|
}
|
|
38221
38533
|
function xml(value) {
|
|
38222
38534
|
return String(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
@@ -38227,10 +38539,10 @@ async function maybeInstallSkillSyncService(runtime, {
|
|
|
38227
38539
|
fetchSettings,
|
|
38228
38540
|
refresh
|
|
38229
38541
|
} = {}) {
|
|
38230
|
-
if (process.platform !== "darwin" || runtime.credentialKind !== "oauth" || config.current_profile !== runtime.profileName || !
|
|
38231
|
-
const plist =
|
|
38542
|
+
if (process.platform !== "darwin" || runtime.credentialKind !== "oauth" || config.current_profile !== runtime.profileName || !LIVE_API_ORIGINS.includes(runtime.apiBase)) return;
|
|
38543
|
+
const plist = join13(homedir8(), "Library", "LaunchAgents", `${SKILL_SYNC_SERVICE_LABEL}.plist`);
|
|
38232
38544
|
if (existsSync10(plist)) {
|
|
38233
|
-
const saved =
|
|
38545
|
+
const saved = readFileSync14(plist, "utf8");
|
|
38234
38546
|
if (runtime.oauthUserId && [runtime.profileName, runtime.apiBase, runtime.oauthUserId].every((value) => saved.includes(`<string>${xml(value)}</string>`))) return install(runtime);
|
|
38235
38547
|
return;
|
|
38236
38548
|
}
|
|
@@ -38242,7 +38554,7 @@ async function maybeInstallSkillSyncService(runtime, {
|
|
|
38242
38554
|
}
|
|
38243
38555
|
async function installSkillSyncService(runtime, options = {}) {
|
|
38244
38556
|
if ((options.platform || process.platform) !== "darwin") return { status: "unsupported_platform" };
|
|
38245
|
-
if (runtime.credentialKind !== "oauth" || !runtime.oauthUserId || !
|
|
38557
|
+
if (runtime.credentialKind !== "oauth" || !runtime.oauthUserId || !LIVE_API_ORIGINS.includes(runtime.apiBase)) {
|
|
38246
38558
|
return { status: "skipped_non_personal_profile" };
|
|
38247
38559
|
}
|
|
38248
38560
|
return withSkillSyncLock(
|
|
@@ -38259,14 +38571,14 @@ async function installSkillSyncServiceLocked(runtime, {
|
|
|
38259
38571
|
uid = process.getuid?.()
|
|
38260
38572
|
} = {}) {
|
|
38261
38573
|
if (platform !== "darwin") return { status: "unsupported_platform" };
|
|
38262
|
-
if (runtime.credentialKind !== "oauth" || runtime.envCredentialOverride || !isValidProfileName(runtime.profileName) || !
|
|
38574
|
+
if (runtime.credentialKind !== "oauth" || runtime.envCredentialOverride || !isValidProfileName(runtime.profileName) || !LIVE_API_ORIGINS.includes(runtime.apiBase)) {
|
|
38263
38575
|
return { status: "skipped_non_personal_profile" };
|
|
38264
38576
|
}
|
|
38265
|
-
const root =
|
|
38266
|
-
const bundle =
|
|
38267
|
-
const digest =
|
|
38268
|
-
const installedBundle =
|
|
38269
|
-
if (!existsSync10(installedBundle) || !
|
|
38577
|
+
const root = join13(home, ".notis", "skills", "service");
|
|
38578
|
+
const bundle = readFileSync14(source);
|
|
38579
|
+
const digest = createHash12("sha256").update(bundle).digest("hex");
|
|
38580
|
+
const installedBundle = join13(root, "runtime", digest, "worker.mjs");
|
|
38581
|
+
if (!existsSync10(installedBundle) || !readFileSync14(installedBundle).equals(bundle)) atomicWrite2(installedBundle, bundle, 320);
|
|
38270
38582
|
const args = [nodePath, installedBundle, runtime.profileName, runtime.apiBase, runtime.oauthUserId];
|
|
38271
38583
|
if (!runtime.oauthUserId) return { status: "skipped_missing_account" };
|
|
38272
38584
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -38279,10 +38591,10 @@ async function installSkillSyncServiceLocked(runtime, {
|
|
|
38279
38591
|
<key>ProcessType</key><string>Background</string>
|
|
38280
38592
|
</dict></plist>
|
|
38281
38593
|
`;
|
|
38282
|
-
const plistPath =
|
|
38594
|
+
const plistPath = join13(home, "Library", "LaunchAgents", `${SKILL_SYNC_SERVICE_LABEL}.plist`);
|
|
38283
38595
|
const domain = `gui/${uid}`;
|
|
38284
38596
|
const target = `${domain}/${SKILL_SYNC_SERVICE_LABEL}`;
|
|
38285
|
-
const unchanged = existsSync10(plistPath) &&
|
|
38597
|
+
const unchanged = existsSync10(plistPath) && readFileSync14(plistPath, "utf8") === plist;
|
|
38286
38598
|
const loaded = run("/bin/launchctl", ["print", target], { encoding: "utf8", timeout: 5e3 });
|
|
38287
38599
|
if (unchanged && loaded.status === 0) return { status: "installed", intervalSeconds: 60, profile: runtime.profileName };
|
|
38288
38600
|
if (loaded.status === 0) {
|
|
@@ -38301,9 +38613,9 @@ async function installSkillSyncServiceLocked(runtime, {
|
|
|
38301
38613
|
}
|
|
38302
38614
|
|
|
38303
38615
|
// src/command-specs/skills.js
|
|
38304
|
-
import { existsSync as existsSync11, lstatSync as lstatSync3, readFileSync as
|
|
38616
|
+
import { existsSync as existsSync11, lstatSync as lstatSync3, readFileSync as readFileSync15, readdirSync as readdirSync4, readlinkSync as readlinkSync2, unlinkSync as unlinkSync2 } from "node:fs";
|
|
38305
38617
|
import { homedir as homedir9 } from "node:os";
|
|
38306
|
-
import { dirname as
|
|
38618
|
+
import { dirname as dirname15, join as join14, resolve as resolve5 } from "node:path";
|
|
38307
38619
|
init_errors();
|
|
38308
38620
|
async function nativeSkillAuthoring(ctx, body, path4 = "/portal_skills/native-authoring") {
|
|
38309
38621
|
const spaceTarget = Boolean(body.target?.space_id || body.destination?.space_id || body.links);
|
|
@@ -38383,9 +38695,9 @@ function cliDefaultOwnsAgentFolders(runtime) {
|
|
|
38383
38695
|
}
|
|
38384
38696
|
var CLOUD_COMPUTER_ROOT2 = "/vercel/sandbox";
|
|
38385
38697
|
function removeDanglingNotisSkillLinks(home = homedir9()) {
|
|
38386
|
-
const notisRoot =
|
|
38698
|
+
const notisRoot = join14(home, ".notis", "skills");
|
|
38387
38699
|
let removed = 0;
|
|
38388
|
-
for (const agentDir of [
|
|
38700
|
+
for (const agentDir of [join14(home, ".claude", "skills"), join14(home, ".codex", "skills")]) {
|
|
38389
38701
|
let entries;
|
|
38390
38702
|
try {
|
|
38391
38703
|
entries = readdirSync4(agentDir);
|
|
@@ -38393,10 +38705,10 @@ function removeDanglingNotisSkillLinks(home = homedir9()) {
|
|
|
38393
38705
|
continue;
|
|
38394
38706
|
}
|
|
38395
38707
|
for (const name of entries) {
|
|
38396
|
-
const entryPath =
|
|
38708
|
+
const entryPath = join14(agentDir, name);
|
|
38397
38709
|
try {
|
|
38398
38710
|
if (!lstatSync3(entryPath).isSymbolicLink() || existsSync11(entryPath)) continue;
|
|
38399
|
-
const target = resolve5(
|
|
38711
|
+
const target = resolve5(dirname15(entryPath), readlinkSync2(entryPath));
|
|
38400
38712
|
if (target.startsWith(`${notisRoot}/`)) {
|
|
38401
38713
|
unlinkSync2(entryPath);
|
|
38402
38714
|
removed += 1;
|
|
@@ -38516,7 +38828,7 @@ var skillsCommandSpecs = [
|
|
|
38516
38828
|
require_auth: true,
|
|
38517
38829
|
backend_call: { type: "http", path: "/portal_skills/native-create" },
|
|
38518
38830
|
handler(ctx) {
|
|
38519
|
-
const payload = parseJson(
|
|
38831
|
+
const payload = parseJson(readFileSync15(resolve5(ctx.args.file), "utf8"), "Skill creation file");
|
|
38520
38832
|
if (!payload || typeof payload !== "object" || Array.isArray(payload) || Object.keys(payload).some((key2) => !["destination", "name", "description", "skill_md", "files"].includes(key2))) {
|
|
38521
38833
|
throw usageError("Provide a name, complete instructions or files, and an optional current destination; never override ownership.");
|
|
38522
38834
|
}
|
|
@@ -38562,7 +38874,7 @@ var skillsCommandSpecs = [
|
|
|
38562
38874
|
require_auth: true,
|
|
38563
38875
|
backend_call: { type: "http", path: "/portal_skills/native-settings" },
|
|
38564
38876
|
handler(ctx) {
|
|
38565
|
-
const payload = parseJson(
|
|
38877
|
+
const payload = parseJson(readFileSync15(resolve5(ctx.args.file), "utf8"), "Skill settings file");
|
|
38566
38878
|
if (!payload || typeof payload !== "object" || Array.isArray(payload) || Object.keys(payload).sort().join(",") !== "patch,revision,target" || !payload.target || Object.keys(payload.target).sort().join(",") !== "access_revision,skill_id") {
|
|
38567
38879
|
throw usageError("Use a current standalone target, settings revision and personal settings patch.");
|
|
38568
38880
|
}
|
|
@@ -38614,7 +38926,7 @@ var skillsCommandSpecs = [
|
|
|
38614
38926
|
require_auth: true,
|
|
38615
38927
|
backend_call: { type: "http", path: "/portal_skills/native-authoring" },
|
|
38616
38928
|
handler(ctx) {
|
|
38617
|
-
const payload = parseJson(
|
|
38929
|
+
const payload = parseJson(readFileSync15(resolve5(ctx.args.file), "utf8"), "Skill edit file");
|
|
38618
38930
|
if (!payload || typeof payload !== "object" || Array.isArray(payload) || Object.keys(payload).some((key2) => !["target", "version", "skill_md", "files", "name", "description", "links"].includes(key2))) {
|
|
38619
38931
|
throw usageError("Use an exact target, version, skill_md or files, and optional links; never override ownership.");
|
|
38620
38932
|
}
|
|
@@ -38687,24 +38999,24 @@ var skillsCommandSpecs = [
|
|
|
38687
38999
|
];
|
|
38688
39000
|
|
|
38689
39001
|
// src/runtime/space-collection-scaffold.js
|
|
38690
|
-
import { writeFileSync as
|
|
38691
|
-
import { join as
|
|
39002
|
+
import { writeFileSync as writeFileSync11, mkdirSync as mkdirSync11 } from "node:fs";
|
|
39003
|
+
import { join as join18 } from "node:path";
|
|
38692
39004
|
|
|
38693
39005
|
// src/runtime/app-platform.js
|
|
38694
39006
|
init_errors();
|
|
38695
39007
|
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
38696
|
-
import { createHash as
|
|
38697
|
-
import { closeSync, constants as fsConstants2, copyFileSync, cpSync as cpSync2, existsSync as existsSync13, fstatSync, linkSync, lstatSync as lstatSync4, mkdirSync as
|
|
39008
|
+
import { createHash as createHash13, randomUUID as randomUUID10 } from "node:crypto";
|
|
39009
|
+
import { closeSync, constants as fsConstants2, copyFileSync, cpSync as cpSync2, existsSync as existsSync13, fstatSync, linkSync, lstatSync as lstatSync4, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, openSync, readFileSync as readFileSync17, realpathSync as realpathSync2, renameSync as renameSync10, rmdirSync as rmdirSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync10, readdirSync as readdirSync6, rmSync as rmSync5, statSync as statSync5 } from "node:fs";
|
|
38698
39010
|
import { createRequire as createRequire2 } from "node:module";
|
|
38699
39011
|
import { homedir as homedir10 } from "node:os";
|
|
38700
|
-
import { basename as basename6, dirname as
|
|
39012
|
+
import { basename as basename6, dirname as dirname17, join as join17, relative as relative3, resolve as resolve8, sep as sep2 } from "node:path";
|
|
38701
39013
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
38702
39014
|
import { gunzipSync } from "node:zlib";
|
|
38703
39015
|
|
|
38704
39016
|
// src/runtime/app-boundary-validator.js
|
|
38705
39017
|
init_errors();
|
|
38706
|
-
import { readFileSync as
|
|
38707
|
-
import { dirname as
|
|
39018
|
+
import { readFileSync as readFileSync16, readdirSync as readdirSync5, existsSync as existsSync12 } from "node:fs";
|
|
39019
|
+
import { dirname as dirname16, extname, join as join15, resolve as resolve6 } from "node:path";
|
|
38708
39020
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
38709
39021
|
|
|
38710
39022
|
// src/runtime/app-data-literals.js
|
|
@@ -38778,7 +39090,7 @@ function maskSerializedJsonData(content, extension = ".js") {
|
|
|
38778
39090
|
}
|
|
38779
39091
|
|
|
38780
39092
|
// src/runtime/app-boundary-validator.js
|
|
38781
|
-
var moduleDir =
|
|
39093
|
+
var moduleDir = dirname16(fileURLToPath7(import.meta.url));
|
|
38782
39094
|
var RULES_PATH_CANDIDATES = [
|
|
38783
39095
|
resolve6(moduleDir, "../../../../server/config/notis_app_boundary_rules.json"),
|
|
38784
39096
|
resolve6(moduleDir, "../../config/notis_app_boundary_rules.json")
|
|
@@ -38814,7 +39126,7 @@ function getCompiledRules() {
|
|
|
38814
39126
|
}
|
|
38815
39127
|
let boundaryRules = { javascript: [], css: [] };
|
|
38816
39128
|
try {
|
|
38817
|
-
const parsed = JSON.parse(
|
|
39129
|
+
const parsed = JSON.parse(readFileSync16(resolveRulesPath(), "utf-8"));
|
|
38818
39130
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
38819
39131
|
boundaryRules = parsed;
|
|
38820
39132
|
} else {
|
|
@@ -38845,7 +39157,7 @@ function collectProjectFiles(projectDir, dir, results) {
|
|
|
38845
39157
|
continue;
|
|
38846
39158
|
}
|
|
38847
39159
|
}
|
|
38848
|
-
const fullPath =
|
|
39160
|
+
const fullPath = join15(dir, entry.name);
|
|
38849
39161
|
if (entry.isDirectory()) {
|
|
38850
39162
|
if (IGNORED_SOURCE_DIRS.has(entry.name)) {
|
|
38851
39163
|
continue;
|
|
@@ -38859,7 +39171,7 @@ function collectProjectFiles(projectDir, dir, results) {
|
|
|
38859
39171
|
results.push({
|
|
38860
39172
|
path: fullPath,
|
|
38861
39173
|
relPath: fullPath.slice(projectDir.length + 1),
|
|
38862
|
-
content:
|
|
39174
|
+
content: readFileSync16(fullPath, "utf-8")
|
|
38863
39175
|
});
|
|
38864
39176
|
}
|
|
38865
39177
|
}
|
|
@@ -39034,7 +39346,7 @@ var compiledDesignRules = /* @__PURE__ */ new Map();
|
|
|
39034
39346
|
function loadDesignRules({ rulesPath = resolveDesignRulesPath(), profile = "app" } = {}) {
|
|
39035
39347
|
let payload = null;
|
|
39036
39348
|
try {
|
|
39037
|
-
const parsed = JSON.parse(
|
|
39349
|
+
const parsed = JSON.parse(readFileSync16(rulesPath, "utf-8"));
|
|
39038
39350
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
39039
39351
|
payload = parsed;
|
|
39040
39352
|
}
|
|
@@ -39204,12 +39516,12 @@ var RETIRED_SDK_FILES = Object.freeze({
|
|
|
39204
39516
|
// src/runtime/source-root.js
|
|
39205
39517
|
init_errors();
|
|
39206
39518
|
import { statSync as statSync4 } from "node:fs";
|
|
39207
|
-
import { join as
|
|
39519
|
+
import { join as join16, resolve as resolve7 } from "node:path";
|
|
39208
39520
|
var SOURCE_ROOT_MARKERS = Object.freeze(["notis.config.ts", "notis.config.js", "notis.config.mjs", ".notis/space-lock.json"]);
|
|
39209
39521
|
function isSourceRoot(directory) {
|
|
39210
39522
|
return SOURCE_ROOT_MARKERS.some((name) => {
|
|
39211
39523
|
try {
|
|
39212
|
-
return statSync4(
|
|
39524
|
+
return statSync4(join16(directory, name)).isFile();
|
|
39213
39525
|
} catch {
|
|
39214
39526
|
return false;
|
|
39215
39527
|
}
|
|
@@ -39225,13 +39537,13 @@ function assertSourceRoot(directory) {
|
|
|
39225
39537
|
|
|
39226
39538
|
// src/runtime/app-platform.js
|
|
39227
39539
|
var NOTIS_DIR = ".notis";
|
|
39228
|
-
var SPACE_SOURCE_FILE =
|
|
39229
|
-
var OUTPUT_DIR =
|
|
39230
|
-
var BUNDLE_DIR =
|
|
39231
|
-
var MANIFEST_FILE =
|
|
39232
|
-
var CLI_ROOT = resolve8(
|
|
39233
|
-
var TEMPLATE_SDK_DIR =
|
|
39234
|
-
var SPACE_SDK_DIR =
|
|
39540
|
+
var SPACE_SOURCE_FILE = join17(NOTIS_DIR, "space-source.json");
|
|
39541
|
+
var OUTPUT_DIR = join17(NOTIS_DIR, "output");
|
|
39542
|
+
var BUNDLE_DIR = join17(OUTPUT_DIR, "bundle");
|
|
39543
|
+
var MANIFEST_FILE = join17(OUTPUT_DIR, "manifest.json");
|
|
39544
|
+
var CLI_ROOT = resolve8(dirname17(fileURLToPath8(import.meta.url)), "../..");
|
|
39545
|
+
var TEMPLATE_SDK_DIR = join17(CLI_ROOT, "dist", "sdk");
|
|
39546
|
+
var SPACE_SDK_DIR = join17(CLI_ROOT, "dist", "space-sdk");
|
|
39235
39547
|
var SOURCE_COPY_EXCLUDES = /* @__PURE__ */ new Set([
|
|
39236
39548
|
"node_modules",
|
|
39237
39549
|
".notis",
|
|
@@ -39264,7 +39576,7 @@ function expandHomePath(inputPath) {
|
|
|
39264
39576
|
return homedir10();
|
|
39265
39577
|
}
|
|
39266
39578
|
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
39267
|
-
return
|
|
39579
|
+
return join17(homedir10(), value.slice(2));
|
|
39268
39580
|
}
|
|
39269
39581
|
return value;
|
|
39270
39582
|
}
|
|
@@ -39272,11 +39584,11 @@ function resolveProjectDir(inputDir = ".") {
|
|
|
39272
39584
|
return resolve8(process.cwd(), expandHomePath(inputDir));
|
|
39273
39585
|
}
|
|
39274
39586
|
function getBundleDir(projectDir) {
|
|
39275
|
-
return
|
|
39587
|
+
return join17(projectDir, BUNDLE_DIR);
|
|
39276
39588
|
}
|
|
39277
39589
|
function resolveBuiltBundleDir(projectDir) {
|
|
39278
39590
|
const bundleDir = getBundleDir(projectDir);
|
|
39279
|
-
if (existsSync13(
|
|
39591
|
+
if (existsSync13(join17(bundleDir, "app.js"))) {
|
|
39280
39592
|
return bundleDir;
|
|
39281
39593
|
}
|
|
39282
39594
|
return null;
|
|
@@ -39332,7 +39644,7 @@ function normalizeShadowScopedCss(css) {
|
|
|
39332
39644
|
return output + css.slice(last);
|
|
39333
39645
|
}
|
|
39334
39646
|
function normalizeBundleStylesheets(projectDir) {
|
|
39335
|
-
const bundleDir =
|
|
39647
|
+
const bundleDir = join17(projectDir, BUNDLE_DIR);
|
|
39336
39648
|
if (!existsSync13(bundleDir)) {
|
|
39337
39649
|
return;
|
|
39338
39650
|
}
|
|
@@ -39340,9 +39652,9 @@ function normalizeBundleStylesheets(projectDir) {
|
|
|
39340
39652
|
if (!entry.endsWith(".css")) {
|
|
39341
39653
|
continue;
|
|
39342
39654
|
}
|
|
39343
|
-
const cssPath =
|
|
39344
|
-
const normalizedCss = normalizeShadowScopedCss(
|
|
39345
|
-
|
|
39655
|
+
const cssPath = join17(bundleDir, entry);
|
|
39656
|
+
const normalizedCss = normalizeShadowScopedCss(readFileSync17(cssPath, "utf-8"));
|
|
39657
|
+
writeFileSync10(cssPath, normalizedCss);
|
|
39346
39658
|
}
|
|
39347
39659
|
}
|
|
39348
39660
|
function stripNotisSdkImports(source) {
|
|
@@ -39373,7 +39685,7 @@ async function loadAppConfig(projectDir, { file = null } = {}) {
|
|
|
39373
39685
|
}
|
|
39374
39686
|
let configPath2 = null;
|
|
39375
39687
|
for (const name of configPaths) {
|
|
39376
|
-
const candidate =
|
|
39688
|
+
const candidate = join17(projectDir, name);
|
|
39377
39689
|
if (existsSync13(candidate)) {
|
|
39378
39690
|
configPath2 = candidate;
|
|
39379
39691
|
break;
|
|
@@ -39383,11 +39695,11 @@ async function loadAppConfig(projectDir, { file = null } = {}) {
|
|
|
39383
39695
|
throw usageError("No notis.config.ts found in project directory.");
|
|
39384
39696
|
}
|
|
39385
39697
|
{
|
|
39386
|
-
const source =
|
|
39698
|
+
const source = readFileSync17(configPath2, "utf-8");
|
|
39387
39699
|
const jsSource = configPath2.endsWith(".ts") ? transpileTsConfigSource(source, configPath2) : stripNotisSdkImports(source);
|
|
39388
|
-
const tmpPath =
|
|
39389
|
-
|
|
39390
|
-
|
|
39700
|
+
const tmpPath = join17(dirname17(configPath2), `._notis_config_${randomUUID10()}.mjs`);
|
|
39701
|
+
mkdirSync10(dirname17(tmpPath), { recursive: true });
|
|
39702
|
+
writeFileSync10(tmpPath, jsSource);
|
|
39391
39703
|
try {
|
|
39392
39704
|
const mod = await import(`file://${tmpPath}?v=${appConfigImportNonce++}`);
|
|
39393
39705
|
return mod.default || mod;
|
|
@@ -39455,7 +39767,7 @@ async function buildArtifact(projectDir, {
|
|
|
39455
39767
|
if (refreshSdk) syncEmbeddedSdk(projectDir);
|
|
39456
39768
|
const sourceHash = appFilesDigest(collectSourceFiles(projectDir));
|
|
39457
39769
|
await prepare(projectDir);
|
|
39458
|
-
const pkg = JSON.parse(
|
|
39770
|
+
const pkg = JSON.parse(readFileSync17(join17(projectDir, "package.json"), "utf8"));
|
|
39459
39771
|
const args = String(pkg.scripts?.build || "").trim() === "vite build" ? ["--configLoader", "runner"] : [];
|
|
39460
39772
|
if (executable) await runBuild({ projectDir, scriptName: "build", args, stdio });
|
|
39461
39773
|
withAppReleaseWorkspace(projectDir, () => {
|
|
@@ -39480,28 +39792,28 @@ async function buildArtifact(projectDir, {
|
|
|
39480
39792
|
artifact_hash: appFilesDigest(collectArtifactFiles(projectDir))
|
|
39481
39793
|
});
|
|
39482
39794
|
withAppReleaseWorkspace(projectDir, () => {
|
|
39483
|
-
const temporary = `.build-receipt-${
|
|
39795
|
+
const temporary = `.build-receipt-${randomUUID10()}`;
|
|
39484
39796
|
try {
|
|
39485
|
-
|
|
39486
|
-
|
|
39797
|
+
writeFileSync10(temporary, receipt, { flag: "wx" });
|
|
39798
|
+
renameSync10(temporary, "build-receipt.json");
|
|
39487
39799
|
} finally {
|
|
39488
39800
|
rmSync5(temporary, { force: true });
|
|
39489
39801
|
}
|
|
39490
39802
|
}, { expected: workspace });
|
|
39491
|
-
return { manifest, outputDir:
|
|
39803
|
+
return { manifest, outputDir: join17(projectDir, OUTPUT_DIR) };
|
|
39492
39804
|
}
|
|
39493
39805
|
function readManifest(projectDir) {
|
|
39494
|
-
const manifestPath =
|
|
39806
|
+
const manifestPath = join17(projectDir, MANIFEST_FILE);
|
|
39495
39807
|
if (!existsSync13(manifestPath)) {
|
|
39496
39808
|
throw usageError('No manifest found. Run "notis spaces build" first.');
|
|
39497
39809
|
}
|
|
39498
|
-
return JSON.parse(
|
|
39810
|
+
return JSON.parse(readFileSync17(manifestPath, "utf-8"));
|
|
39499
39811
|
}
|
|
39500
39812
|
async function scaffoldProject({ projectDir, appName }) {
|
|
39501
39813
|
return scaffoldProjectFromDir({
|
|
39502
39814
|
projectDir,
|
|
39503
39815
|
appName,
|
|
39504
|
-
templateDir:
|
|
39816
|
+
templateDir: join17(CLI_ROOT, "template")
|
|
39505
39817
|
});
|
|
39506
39818
|
}
|
|
39507
39819
|
function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
@@ -39510,9 +39822,9 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39510
39822
|
if (!existsSync13(sourceDir)) {
|
|
39511
39823
|
throw usageError(`SDK template not found at ${sourceDir}. Ensure @notis_ai/cli is installed correctly.`);
|
|
39512
39824
|
}
|
|
39513
|
-
const parentDir =
|
|
39825
|
+
const parentDir = dirname17(requestedProjectDir);
|
|
39514
39826
|
const targetName = basename6(requestedProjectDir);
|
|
39515
|
-
|
|
39827
|
+
mkdirSync10(parentDir, { recursive: true });
|
|
39516
39828
|
const canonicalParent = realpathSync2(parentDir);
|
|
39517
39829
|
const parentIdentity = capturePullTargetIdentity(canonicalParent);
|
|
39518
39830
|
const initialTargetIdentity = captureScaffoldTargetIdentity(requestedProjectDir);
|
|
@@ -39523,7 +39835,7 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39523
39835
|
let cleanupStage = true;
|
|
39524
39836
|
let activeTargetIdentity = null;
|
|
39525
39837
|
const scaffoldLockName = ".notis-app-scaffold-lock";
|
|
39526
|
-
const scaffoldLockOwnerId = `${process.pid}.${
|
|
39838
|
+
const scaffoldLockOwnerId = `${process.pid}.${randomUUID10()}`;
|
|
39527
39839
|
try {
|
|
39528
39840
|
process.chdir(canonicalParent);
|
|
39529
39841
|
cwdPinned = true;
|
|
@@ -39534,7 +39846,7 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39534
39846
|
}
|
|
39535
39847
|
if (!lockedTargetIdentity.exists) {
|
|
39536
39848
|
try {
|
|
39537
|
-
|
|
39849
|
+
mkdirSync10(targetName);
|
|
39538
39850
|
} catch (error) {
|
|
39539
39851
|
if (error?.code === "EEXIST") {
|
|
39540
39852
|
throw usageError(`Scaffold target changed before copying: ${requestedProjectDir}`);
|
|
@@ -39550,21 +39862,21 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39550
39862
|
)) {
|
|
39551
39863
|
throw usageError(`Scaffold target changed before copying: ${requestedProjectDir}`);
|
|
39552
39864
|
}
|
|
39553
|
-
|
|
39554
|
-
|
|
39555
|
-
|
|
39865
|
+
mkdirSync10(scaffoldLockName, { mode: 448 });
|
|
39866
|
+
writeFileSync10(
|
|
39867
|
+
join17(scaffoldLockName, "owner"),
|
|
39556
39868
|
JSON.stringify({ id: scaffoldLockOwnerId }),
|
|
39557
39869
|
{ mode: 384 }
|
|
39558
39870
|
);
|
|
39559
|
-
stageName = basename6(mkdtempSync2(
|
|
39871
|
+
stageName = basename6(mkdtempSync2(join17(".", ".notis-app-scaffold-")));
|
|
39560
39872
|
projectDir = stageName;
|
|
39561
39873
|
copyScaffoldSource(sourceDir, projectDir);
|
|
39562
|
-
const pkgPath =
|
|
39874
|
+
const pkgPath = join17(projectDir, "package.json");
|
|
39563
39875
|
if (existsSync13(pkgPath)) {
|
|
39564
|
-
const pkg = JSON.parse(
|
|
39876
|
+
const pkg = JSON.parse(readFileSync17(pkgPath, "utf-8"));
|
|
39565
39877
|
pkg.name = appName.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-");
|
|
39566
39878
|
ensureScaffoldLocalSdk(projectDir, pkg);
|
|
39567
|
-
|
|
39879
|
+
writeFileSync10(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
39568
39880
|
normalizeScaffoldLockfile(projectDir, pkg);
|
|
39569
39881
|
}
|
|
39570
39882
|
assertPullParentIdentity(parentDir, canonicalParent, parentIdentity);
|
|
@@ -39588,7 +39900,7 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39588
39900
|
throw usageError(`Refusing symlinked scaffold source entry: ${sourcePath}`);
|
|
39589
39901
|
}
|
|
39590
39902
|
if (sourceStat.isDirectory()) {
|
|
39591
|
-
|
|
39903
|
+
mkdirSync10(destinationName, { mode: sourceStat.mode & 511 });
|
|
39592
39904
|
const installedDirectory = captureInstalledEntry(destinationName);
|
|
39593
39905
|
installedDirectory.path = relativePath;
|
|
39594
39906
|
installedEntries.push(installedDirectory);
|
|
@@ -39603,15 +39915,15 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39603
39915
|
try {
|
|
39604
39916
|
for (const name of readdirSync6(sourcePath)) {
|
|
39605
39917
|
installExclusive(
|
|
39606
|
-
|
|
39918
|
+
join17(sourcePath, name),
|
|
39607
39919
|
name,
|
|
39608
39920
|
`${relativePath}/${name}`,
|
|
39609
39921
|
installedDirectory
|
|
39610
39922
|
);
|
|
39611
39923
|
}
|
|
39612
39924
|
} finally {
|
|
39613
|
-
const parentRelativePath =
|
|
39614
|
-
process.chdir(parentRelativePath ?
|
|
39925
|
+
const parentRelativePath = dirname17(relativePath) === "." ? "" : dirname17(relativePath);
|
|
39926
|
+
process.chdir(parentRelativePath ? join17(requestedProjectDir, parentRelativePath) : requestedProjectDir);
|
|
39615
39927
|
if (!pullTargetIdentitiesMatch(
|
|
39616
39928
|
parentIdentity2,
|
|
39617
39929
|
capturePullTargetIdentity(".")
|
|
@@ -39631,15 +39943,15 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39631
39943
|
};
|
|
39632
39944
|
try {
|
|
39633
39945
|
for (const name of readdirSync6(stageName)) {
|
|
39634
|
-
installExclusive(
|
|
39946
|
+
installExclusive(join17(stageRoot, name), name, name, activeTargetIdentity);
|
|
39635
39947
|
}
|
|
39636
39948
|
assertPullParentIdentity(parentDir, canonicalParent, parentIdentity);
|
|
39637
39949
|
assertPullTargetIdentity(requestedProjectDir, activeTargetIdentity);
|
|
39638
39950
|
} catch (error) {
|
|
39639
39951
|
try {
|
|
39640
39952
|
for (const installed of installedEntries.reverse()) {
|
|
39641
|
-
const parentRelativePath =
|
|
39642
|
-
const parentPath = parentRelativePath ?
|
|
39953
|
+
const parentRelativePath = dirname17(installed.path) === "." ? "" : dirname17(installed.path);
|
|
39954
|
+
const parentPath = parentRelativePath ? join17(requestedProjectDir, parentRelativePath) : requestedProjectDir;
|
|
39643
39955
|
const expectedParentIdentity = installedDirectoryIdentities.get(parentRelativePath);
|
|
39644
39956
|
process.chdir(parentPath);
|
|
39645
39957
|
if (!expectedParentIdentity || !pullTargetIdentitiesMatch(
|
|
@@ -39666,7 +39978,7 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39666
39978
|
} catch (rollbackError) {
|
|
39667
39979
|
cleanupStage = false;
|
|
39668
39980
|
throw usageError(
|
|
39669
|
-
`${error instanceof Error ? error.message : String(error)} Scaffold rollback failed; recovery files were retained at ${
|
|
39981
|
+
`${error instanceof Error ? error.message : String(error)} Scaffold rollback failed; recovery files were retained at ${join17(requestedProjectDir, stageName)}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`
|
|
39670
39982
|
);
|
|
39671
39983
|
}
|
|
39672
39984
|
throw error;
|
|
@@ -39677,7 +39989,7 @@ function scaffoldProjectFromDir({ projectDir, appName, templateDir }) {
|
|
|
39677
39989
|
} catch (error) {
|
|
39678
39990
|
cleanupStage = false;
|
|
39679
39991
|
throw usageError(
|
|
39680
|
-
`Scaffold was installed, but staging cleanup failed; recovery files were retained at ${
|
|
39992
|
+
`Scaffold was installed, but staging cleanup failed; recovery files were retained at ${join17(requestedProjectDir, stageName)}: ${error instanceof Error ? error.message : String(error)}`
|
|
39681
39993
|
);
|
|
39682
39994
|
}
|
|
39683
39995
|
} finally {
|
|
@@ -39727,16 +40039,16 @@ function captureScaffoldTargetIdentity(targetDir) {
|
|
|
39727
40039
|
}
|
|
39728
40040
|
}
|
|
39729
40041
|
function normalizeScaffoldLockfile(projectDir, pkg) {
|
|
39730
|
-
const lockPath =
|
|
40042
|
+
const lockPath = join17(projectDir, "package-lock.json");
|
|
39731
40043
|
if (!existsSync13(lockPath)) {
|
|
39732
40044
|
return;
|
|
39733
40045
|
}
|
|
39734
|
-
const lockfile = JSON.parse(
|
|
40046
|
+
const lockfile = JSON.parse(readFileSync17(lockPath, "utf-8"));
|
|
39735
40047
|
lockfile.name = pkg.name;
|
|
39736
40048
|
if (lockfile.packages?.[""]) {
|
|
39737
40049
|
lockfile.packages[""].name = pkg.name;
|
|
39738
40050
|
}
|
|
39739
|
-
|
|
40051
|
+
writeFileSync10(lockPath, JSON.stringify(lockfile, null, 2) + "\n");
|
|
39740
40052
|
}
|
|
39741
40053
|
function ensureScaffoldLocalSdk(projectDir, pkg) {
|
|
39742
40054
|
let shouldInstallLocalSdk = false;
|
|
@@ -39750,11 +40062,11 @@ function ensureScaffoldLocalSdk(projectDir, pkg) {
|
|
|
39750
40062
|
if (!shouldInstallLocalSdk) {
|
|
39751
40063
|
return;
|
|
39752
40064
|
}
|
|
39753
|
-
const localSdkDir =
|
|
39754
|
-
if (!existsSync13(
|
|
40065
|
+
const localSdkDir = join17(projectDir, "packages", "sdk");
|
|
40066
|
+
if (!existsSync13(join17(TEMPLATE_SDK_DIR, "package.json"))) {
|
|
39755
40067
|
throw usageError(`SDK template not found at ${TEMPLATE_SDK_DIR}. Ensure @notis_ai/cli is installed correctly.`);
|
|
39756
40068
|
}
|
|
39757
|
-
|
|
40069
|
+
mkdirSync10(dirname17(localSdkDir), { recursive: true });
|
|
39758
40070
|
cpSync2(TEMPLATE_SDK_DIR, localSdkDir, {
|
|
39759
40071
|
recursive: true,
|
|
39760
40072
|
dereference: true,
|
|
@@ -39765,7 +40077,7 @@ function listFilesRecursive2(dir, base = dir, results = []) {
|
|
|
39765
40077
|
if (!existsSync13(dir)) return results;
|
|
39766
40078
|
for (const entry of readdirSync6(dir, { withFileTypes: true })) {
|
|
39767
40079
|
if (entry.name === "node_modules" || entry.name === "dist") continue;
|
|
39768
|
-
const fullPath =
|
|
40080
|
+
const fullPath = join17(dir, entry.name);
|
|
39769
40081
|
if (entry.isDirectory()) {
|
|
39770
40082
|
listFilesRecursive2(fullPath, base, results);
|
|
39771
40083
|
} else {
|
|
@@ -39777,7 +40089,7 @@ function listFilesRecursive2(dir, base = dir, results = []) {
|
|
|
39777
40089
|
function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK_DIR, retiredFiles = RETIRED_SDK_FILES, prune = false } = {}) {
|
|
39778
40090
|
const canonicalProjectDir = realpathSync2(assertSourceRoot(projectDir));
|
|
39779
40091
|
const canonicalTemplateDir = resolve8(templateSdkDir);
|
|
39780
|
-
if (!existsSync13(
|
|
40092
|
+
if (!existsSync13(join17(canonicalTemplateDir, "package.json"))) {
|
|
39781
40093
|
return { updated: false, reason: "no-template-sdk" };
|
|
39782
40094
|
}
|
|
39783
40095
|
const previousCwd = process.cwd();
|
|
@@ -39785,7 +40097,7 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39785
40097
|
const projectIdentity = capturePullTargetIdentity(canonicalProjectDir);
|
|
39786
40098
|
const listOwned = (dir) => [
|
|
39787
40099
|
...listFilesRecursive2(dir),
|
|
39788
|
-
...prune ? listFilesRecursive2(
|
|
40100
|
+
...prune ? listFilesRecursive2(join17(dir, "dist")).map((relPath) => `dist/${relPath}`) : []
|
|
39789
40101
|
];
|
|
39790
40102
|
const templateFiles = listOwned(canonicalTemplateDir).filter(
|
|
39791
40103
|
(relPath) => !HOST_ONLY_SDK_FILES.includes(relPath) && (relPath === "package.json" || relPath === "tsconfig.json" || relPath.startsWith("src/") || relPath.startsWith("dist/"))
|
|
@@ -39797,7 +40109,7 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39797
40109
|
let identity = capturePullTargetIdentity(name);
|
|
39798
40110
|
if (!identity.exists) {
|
|
39799
40111
|
if (!create) return { updated: false, reason: "no-embedded-sdk" };
|
|
39800
|
-
|
|
40112
|
+
mkdirSync10(name);
|
|
39801
40113
|
identity = capturePullTargetIdentity(name);
|
|
39802
40114
|
}
|
|
39803
40115
|
process.chdir(name);
|
|
@@ -39831,10 +40143,10 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39831
40143
|
closeSync(descriptor);
|
|
39832
40144
|
}
|
|
39833
40145
|
}
|
|
39834
|
-
const temporary = `.notis-sdk-sync-${
|
|
40146
|
+
const temporary = `.notis-sdk-sync-${randomUUID10()}`;
|
|
39835
40147
|
try {
|
|
39836
|
-
|
|
39837
|
-
|
|
40148
|
+
writeFileSync10(temporary, source, { flag: "wx" });
|
|
40149
|
+
renameSync10(temporary, name);
|
|
39838
40150
|
} finally {
|
|
39839
40151
|
rmSync5(temporary, { force: true });
|
|
39840
40152
|
}
|
|
@@ -39854,9 +40166,9 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39854
40166
|
const descriptor = openSync(name, fsConstants2.O_RDONLY | fsConstants2.O_NOFOLLOW);
|
|
39855
40167
|
try {
|
|
39856
40168
|
const bytes = readStablePinnedFile(descriptor, before, `Retired SDK file ${name}`);
|
|
39857
|
-
if (!digests.includes(
|
|
39858
|
-
const temporary = `.notis-sdk-retired-${
|
|
39859
|
-
|
|
40169
|
+
if (!digests.includes(createHash13("sha256").update(bytes).digest("hex"))) return false;
|
|
40170
|
+
const temporary = `.notis-sdk-retired-${randomUUID10()}`;
|
|
40171
|
+
renameSync10(name, temporary);
|
|
39860
40172
|
try {
|
|
39861
40173
|
const captured = lstatSync4(temporary, { bigint: true });
|
|
39862
40174
|
if (captured.dev !== before.dev || captured.ino !== before.ino) {
|
|
@@ -39920,7 +40232,7 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39920
40232
|
throw usageError("Refusing to refresh the SDK through an unsafe package.json target.");
|
|
39921
40233
|
}
|
|
39922
40234
|
for (const relPath of templateFiles) {
|
|
39923
|
-
const source =
|
|
40235
|
+
const source = readFileSync17(join17(canonicalTemplateDir, relPath));
|
|
39924
40236
|
if (mirrorFile(relPath.split("/"), source)) changed.push(relPath);
|
|
39925
40237
|
}
|
|
39926
40238
|
const templateSet = new Set(templateFiles);
|
|
@@ -39949,7 +40261,7 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39949
40261
|
process.chdir(previousCwd);
|
|
39950
40262
|
assertPullTargetIdentity(".", previousIdentity);
|
|
39951
40263
|
}
|
|
39952
|
-
const templateVersion = JSON.parse(
|
|
40264
|
+
const templateVersion = JSON.parse(readFileSync17(join17(canonicalTemplateDir, "package.json"), "utf-8")).version;
|
|
39953
40265
|
const emit = typeof log === "function" ? log : (message) => process.stderr.write(`${message}
|
|
39954
40266
|
`);
|
|
39955
40267
|
if (changed.length > 0) {
|
|
@@ -39961,12 +40273,12 @@ function syncEmbeddedSdk(projectDir, { log = null, templateSdkDir = TEMPLATE_SDK
|
|
|
39961
40273
|
return { updated: changed.length > 0, changed, foreign, templateVersion };
|
|
39962
40274
|
}
|
|
39963
40275
|
function syncSpaceSdk(projectDir, { log = null, templateSdkDir = SPACE_SDK_DIR, updateLock = updatePackageLock } = {}) {
|
|
39964
|
-
if (!existsSync13(
|
|
40276
|
+
if (!existsSync13(join17(templateSdkDir, "package.json"))) {
|
|
39965
40277
|
throw usageError(`Space SDK not found at ${templateSdkDir}. Ensure @notis_ai/cli is installed correctly.`);
|
|
39966
40278
|
}
|
|
39967
40279
|
const result = syncEmbeddedSdk(projectDir, { log, templateSdkDir, retiredFiles: {}, prune: true });
|
|
39968
40280
|
if (result.reason) return result;
|
|
39969
|
-
const manifest = JSON.parse(
|
|
40281
|
+
const manifest = JSON.parse(readFileSync17(join17(templateSdkDir, "package.json"), "utf-8"));
|
|
39970
40282
|
return { ...result, lockfile: reconcileSdkLockfile(realpathSync2(projectDir), { manifest, log, updateLock }) };
|
|
39971
40283
|
}
|
|
39972
40284
|
var LOCKED_MANIFEST_FIELDS = ["name", "version", "dependencies", "devDependencies", "optionalDependencies", "peerDependencies", "peerDependenciesMeta"];
|
|
@@ -40017,11 +40329,11 @@ function npmFailureReason(output) {
|
|
|
40017
40329
|
function reconcileSdkLockfile(projectDir, { manifest, log = null, updateLock = updatePackageLock } = {}) {
|
|
40018
40330
|
const emit = typeof log === "function" ? log : (message) => process.stderr.write(`${message}
|
|
40019
40331
|
`);
|
|
40020
|
-
const lockPath =
|
|
40021
|
-
const readLock = () => JSON.parse(
|
|
40332
|
+
const lockPath = join17(projectDir, "package-lock.json");
|
|
40333
|
+
const readLock = () => JSON.parse(readFileSync17(lockPath, "utf-8"));
|
|
40022
40334
|
let project, lock;
|
|
40023
40335
|
try {
|
|
40024
|
-
project = JSON.parse(
|
|
40336
|
+
project = JSON.parse(readFileSync17(join17(projectDir, "package.json"), "utf-8"));
|
|
40025
40337
|
lock = readLock();
|
|
40026
40338
|
} catch {
|
|
40027
40339
|
return "absent";
|
|
@@ -40048,7 +40360,7 @@ function readStablePinnedFile(descriptor, expectedStat, label) {
|
|
|
40048
40360
|
if (!before.isFile() || before.dev !== expectedStat.dev || before.ino !== expectedStat.ino) {
|
|
40049
40361
|
throw usageError(`${label} changed before it could be read.`);
|
|
40050
40362
|
}
|
|
40051
|
-
const content =
|
|
40363
|
+
const content = readFileSync17(descriptor);
|
|
40052
40364
|
const after = fstatSync(descriptor, { bigint: true });
|
|
40053
40365
|
if (after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size || after.mtimeNs !== before.mtimeNs || after.ctimeNs !== before.ctimeNs) {
|
|
40054
40366
|
throw usageError(`${label} changed while it was being read.`);
|
|
@@ -40084,7 +40396,7 @@ function copyScaffoldSource(sourceDir, targetDir) {
|
|
|
40084
40396
|
const directoryRevision = captureDirectoryRevision();
|
|
40085
40397
|
const parentIdentity = expectedDirectoryIdentity;
|
|
40086
40398
|
for (const name of readdirSync6(".")) {
|
|
40087
|
-
const logicalSourcePath =
|
|
40399
|
+
const logicalSourcePath = join17(sourcePath, name);
|
|
40088
40400
|
if (!shouldCopy(logicalSourcePath)) {
|
|
40089
40401
|
continue;
|
|
40090
40402
|
}
|
|
@@ -40153,10 +40465,10 @@ function copyScaffoldSource(sourceDir, targetDir) {
|
|
|
40153
40465
|
}
|
|
40154
40466
|
const parentIdentity = expectedDirectoryIdentity;
|
|
40155
40467
|
for (const directory of node.directories) {
|
|
40156
|
-
|
|
40468
|
+
mkdirSync10(directory.name, { mode: directory.mode });
|
|
40157
40469
|
const directoryStat = lstatSync4(directory.name, { bigint: true });
|
|
40158
40470
|
if (directoryStat.isSymbolicLink() || !directoryStat.isDirectory()) {
|
|
40159
|
-
throw usageError(`Refusing unsafe scaffold destination: ${
|
|
40471
|
+
throw usageError(`Refusing unsafe scaffold destination: ${join17(logicalPath, directory.name)}`);
|
|
40160
40472
|
}
|
|
40161
40473
|
process.chdir(directory.name);
|
|
40162
40474
|
const childIdentity = capturePullTargetIdentity(".");
|
|
@@ -40164,10 +40476,10 @@ function copyScaffoldSource(sourceDir, targetDir) {
|
|
|
40164
40476
|
{ exists: true, dev: directoryStat.dev, ino: directoryStat.ino },
|
|
40165
40477
|
childIdentity
|
|
40166
40478
|
)) {
|
|
40167
|
-
throw usageError(`Scaffold destination changed while copying: ${
|
|
40479
|
+
throw usageError(`Scaffold destination changed while copying: ${join17(logicalPath, directory.name)}`);
|
|
40168
40480
|
}
|
|
40169
40481
|
try {
|
|
40170
|
-
writeSnapshot(directory,
|
|
40482
|
+
writeSnapshot(directory, join17(logicalPath, directory.name), childIdentity);
|
|
40171
40483
|
} finally {
|
|
40172
40484
|
process.chdir("..");
|
|
40173
40485
|
if (!pullTargetIdentitiesMatch(parentIdentity, capturePullTargetIdentity("."))) {
|
|
@@ -40176,7 +40488,7 @@ function copyScaffoldSource(sourceDir, targetDir) {
|
|
|
40176
40488
|
}
|
|
40177
40489
|
}
|
|
40178
40490
|
for (const file of node.files) {
|
|
40179
|
-
|
|
40491
|
+
writeFileSync10(file.name, file.content, { flag: "wx", mode: file.mode });
|
|
40180
40492
|
}
|
|
40181
40493
|
}
|
|
40182
40494
|
try {
|
|
@@ -40193,7 +40505,7 @@ function copyScaffoldSource(sourceDir, targetDir) {
|
|
|
40193
40505
|
}
|
|
40194
40506
|
}
|
|
40195
40507
|
function collectArtifactFiles(projectDir) {
|
|
40196
|
-
const outputDir =
|
|
40508
|
+
const outputDir = join17(projectDir, OUTPUT_DIR);
|
|
40197
40509
|
if (!existsSync13(outputDir)) {
|
|
40198
40510
|
throw usageError('No build output found. Run "notis spaces build" first.');
|
|
40199
40511
|
}
|
|
@@ -40203,12 +40515,12 @@ function collectArtifactFiles(projectDir) {
|
|
|
40203
40515
|
const entries = readdirSync6(dir, { withFileTypes: true });
|
|
40204
40516
|
for (const entry of entries) {
|
|
40205
40517
|
if (entry.name.startsWith(".") || !prefix && entry.name === "verify.json") continue;
|
|
40206
|
-
const fullPath =
|
|
40518
|
+
const fullPath = join17(dir, entry.name);
|
|
40207
40519
|
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
40208
40520
|
if (entry.isDirectory()) {
|
|
40209
40521
|
walk(fullPath, relPath);
|
|
40210
40522
|
} else {
|
|
40211
|
-
files[relPath] =
|
|
40523
|
+
files[relPath] = readFileSync17(fullPath).toString("base64");
|
|
40212
40524
|
}
|
|
40213
40525
|
}
|
|
40214
40526
|
}
|
|
@@ -40388,12 +40700,12 @@ function extractTarGz(buffer, targetDir) {
|
|
|
40388
40700
|
if (relPath.split("/").some((part) => shouldExcludeSourceEntry(part))) {
|
|
40389
40701
|
throw usageError(`Refusing to extract local-only path from source archive: ${relPath}`);
|
|
40390
40702
|
}
|
|
40391
|
-
const outputPath =
|
|
40703
|
+
const outputPath = join17(targetDir, relPath);
|
|
40392
40704
|
if (typeFlag === 53) {
|
|
40393
|
-
|
|
40705
|
+
mkdirSync10(outputPath, { recursive: true });
|
|
40394
40706
|
} else if (typeFlag === 0 || typeFlag === 48) {
|
|
40395
|
-
|
|
40396
|
-
|
|
40707
|
+
mkdirSync10(dirname17(outputPath), { recursive: true });
|
|
40708
|
+
writeFileSync10(outputPath, data);
|
|
40397
40709
|
} else {
|
|
40398
40710
|
throw usageError(`Refusing to extract unsupported source archive entry: ${relPath}`);
|
|
40399
40711
|
}
|
|
@@ -40413,7 +40725,7 @@ function collectPullPreservedPaths(targetDir) {
|
|
|
40413
40725
|
continue;
|
|
40414
40726
|
}
|
|
40415
40727
|
if (entry.isDirectory()) {
|
|
40416
|
-
walk(
|
|
40728
|
+
walk(join17(dir, entry.name), relPath);
|
|
40417
40729
|
}
|
|
40418
40730
|
}
|
|
40419
40731
|
}
|
|
@@ -40424,7 +40736,7 @@ function collectPullPreservedPaths(targetDir) {
|
|
|
40424
40736
|
}
|
|
40425
40737
|
function readPullLockOwner(lockDirectory) {
|
|
40426
40738
|
try {
|
|
40427
|
-
return JSON.parse(
|
|
40739
|
+
return JSON.parse(readFileSync17(join17(lockDirectory, "owner"), "utf-8"));
|
|
40428
40740
|
} catch {
|
|
40429
40741
|
return null;
|
|
40430
40742
|
}
|
|
@@ -40466,26 +40778,26 @@ function assertPullParentIdentity(parentDir, canonicalParent, expectedIdentity)
|
|
|
40466
40778
|
}
|
|
40467
40779
|
async function withPullTargetLock(targetDir, callback) {
|
|
40468
40780
|
const requestedTarget = resolve8(targetDir);
|
|
40469
|
-
const parentDir =
|
|
40470
|
-
|
|
40781
|
+
const parentDir = dirname17(requestedTarget);
|
|
40782
|
+
mkdirSync10(parentDir, { recursive: true });
|
|
40471
40783
|
const canonicalParent = realpathSync2(parentDir);
|
|
40472
40784
|
const canonicalParentIdentity = capturePullTargetIdentity(canonicalParent);
|
|
40473
40785
|
const initialRequestedIdentity = capturePullTargetIdentity(requestedTarget);
|
|
40474
|
-
const canonicalTarget = initialRequestedIdentity.exists ? realpathSync2(requestedTarget) :
|
|
40786
|
+
const canonicalTarget = initialRequestedIdentity.exists ? realpathSync2(requestedTarget) : join17(canonicalParent, basename6(requestedTarget));
|
|
40475
40787
|
if (initialRequestedIdentity.exists && !pullTargetIdentitiesMatch(
|
|
40476
40788
|
initialRequestedIdentity,
|
|
40477
40789
|
capturePullTargetIdentity(canonicalTarget)
|
|
40478
40790
|
)) {
|
|
40479
40791
|
throw usageError(`Space source pull target changed before locking: ${requestedTarget}`);
|
|
40480
40792
|
}
|
|
40481
|
-
const lockDirectory =
|
|
40482
|
-
const ownerId = `${process.pid}.${
|
|
40793
|
+
const lockDirectory = join17(canonicalParent, `.${basename6(canonicalTarget)}.notis-pull-lock`);
|
|
40794
|
+
const ownerId = `${process.pid}.${randomUUID10()}`;
|
|
40483
40795
|
const deadline = Date.now() + PULL_LOCK_TIMEOUT_MS;
|
|
40484
40796
|
for (; ; ) {
|
|
40485
40797
|
try {
|
|
40486
|
-
|
|
40487
|
-
|
|
40488
|
-
|
|
40798
|
+
mkdirSync10(lockDirectory, { mode: 448 });
|
|
40799
|
+
writeFileSync10(
|
|
40800
|
+
join17(lockDirectory, "owner"),
|
|
40489
40801
|
JSON.stringify({ id: ownerId, pid: process.pid, at: Date.now() }),
|
|
40490
40802
|
{ mode: 384 }
|
|
40491
40803
|
);
|
|
@@ -40542,7 +40854,7 @@ async function withPullTargetLock(targetDir, callback) {
|
|
|
40542
40854
|
}
|
|
40543
40855
|
}
|
|
40544
40856
|
function assertPullStatePathSafe(projectDir) {
|
|
40545
|
-
const notisDir =
|
|
40857
|
+
const notisDir = join17(projectDir, NOTIS_DIR);
|
|
40546
40858
|
try {
|
|
40547
40859
|
const directoryStat = lstatSync4(notisDir);
|
|
40548
40860
|
if (directoryStat.isSymbolicLink() || !directoryStat.isDirectory()) {
|
|
@@ -40551,7 +40863,7 @@ function assertPullStatePathSafe(projectDir) {
|
|
|
40551
40863
|
} catch (error) {
|
|
40552
40864
|
if (error?.code !== "ENOENT") throw error;
|
|
40553
40865
|
}
|
|
40554
|
-
const statePath3 =
|
|
40866
|
+
const statePath3 = join17(projectDir, SPACE_SOURCE_FILE);
|
|
40555
40867
|
try {
|
|
40556
40868
|
const stateStat = lstatSync4(statePath3);
|
|
40557
40869
|
if (stateStat.isSymbolicLink() || !stateStat.isFile()) {
|
|
@@ -40611,7 +40923,7 @@ async function pullAppSourceUnlocked({
|
|
|
40611
40923
|
const previousCwd = process.cwd();
|
|
40612
40924
|
const previousCwdIdentity = capturePullTargetIdentity(previousCwd);
|
|
40613
40925
|
try {
|
|
40614
|
-
const parentDir =
|
|
40926
|
+
const parentDir = dirname17(targetDir);
|
|
40615
40927
|
const targetName = basename6(targetDir);
|
|
40616
40928
|
const parentIdentity = capturePullTargetIdentity(parentDir);
|
|
40617
40929
|
assertParentIdentity();
|
|
@@ -40622,7 +40934,7 @@ async function pullAppSourceUnlocked({
|
|
|
40622
40934
|
assertPullTargetIdentity(targetName, initialTargetIdentity);
|
|
40623
40935
|
if (!initialTargetIdentity.exists) {
|
|
40624
40936
|
try {
|
|
40625
|
-
|
|
40937
|
+
mkdirSync10(targetName);
|
|
40626
40938
|
} catch (error) {
|
|
40627
40939
|
if (error?.code === "EEXIST") {
|
|
40628
40940
|
throw usageError(`Space source pull target changed while the download was in progress: ${targetDir}`);
|
|
@@ -40640,25 +40952,25 @@ async function pullAppSourceUnlocked({
|
|
|
40640
40952
|
const targetRoot = ".";
|
|
40641
40953
|
assertPullStatePathSafe(targetRoot);
|
|
40642
40954
|
const preservedPaths = collectPullPreservedPaths(targetRoot);
|
|
40643
|
-
const transactionName = basename6(mkdtempSync2(
|
|
40955
|
+
const transactionName = basename6(mkdtempSync2(join17(".", ".notis-app-pull-")));
|
|
40644
40956
|
transactionDir = transactionName;
|
|
40645
|
-
transactionDisplayPath =
|
|
40646
|
-
const stageDir =
|
|
40647
|
-
const backupDir =
|
|
40648
|
-
const preservedDir =
|
|
40649
|
-
|
|
40650
|
-
|
|
40651
|
-
|
|
40957
|
+
transactionDisplayPath = join17(targetDir, transactionName);
|
|
40958
|
+
const stageDir = join17(transactionDir, "stage");
|
|
40959
|
+
const backupDir = join17(transactionDir, "backup");
|
|
40960
|
+
const preservedDir = join17(transactionDir, "preserved");
|
|
40961
|
+
mkdirSync10(stageDir, { recursive: true });
|
|
40962
|
+
mkdirSync10(backupDir, { recursive: true });
|
|
40963
|
+
mkdirSync10(preservedDir, { recursive: true });
|
|
40652
40964
|
extractTarGz(archiveBuffer, stageDir);
|
|
40653
40965
|
const stagedEntries = readdirSync6(stageDir);
|
|
40654
40966
|
if (stagedEntries.length === 0) {
|
|
40655
40967
|
throw usageError("The Space source archive did not contain any editable source files.");
|
|
40656
40968
|
}
|
|
40657
|
-
const previousStatePath =
|
|
40658
|
-
const backupStatePath =
|
|
40969
|
+
const previousStatePath = join17(targetRoot, SPACE_SOURCE_FILE);
|
|
40970
|
+
const backupStatePath = join17(backupDir, SPACE_SOURCE_FILE);
|
|
40659
40971
|
const hadPreviousState = existsSync13(previousStatePath);
|
|
40660
40972
|
if (hadPreviousState) {
|
|
40661
|
-
|
|
40973
|
+
mkdirSync10(dirname17(backupStatePath), { recursive: true });
|
|
40662
40974
|
cpSync2(previousStatePath, backupStatePath);
|
|
40663
40975
|
}
|
|
40664
40976
|
const movedPreserved = [];
|
|
@@ -40667,28 +40979,28 @@ async function pullAppSourceUnlocked({
|
|
|
40667
40979
|
const restoredPreserved = [];
|
|
40668
40980
|
try {
|
|
40669
40981
|
for (const relPath of preservedPaths) {
|
|
40670
|
-
const preservedPath =
|
|
40671
|
-
|
|
40672
|
-
|
|
40982
|
+
const preservedPath = join17(preservedDir, relPath);
|
|
40983
|
+
mkdirSync10(dirname17(preservedPath), { recursive: true });
|
|
40984
|
+
renameSync10(join17(targetRoot, relPath), preservedPath);
|
|
40673
40985
|
movedPreserved.push(relPath);
|
|
40674
40986
|
}
|
|
40675
40987
|
assertPullTargetIdentity(targetDir, activeTargetIdentity);
|
|
40676
40988
|
assertLockOwnership();
|
|
40677
40989
|
const managedTargetEntries = readdirSync6(targetRoot).filter((name) => name !== transactionName);
|
|
40678
40990
|
for (const name of managedTargetEntries) {
|
|
40679
|
-
|
|
40991
|
+
renameSync10(join17(targetRoot, name), join17(backupDir, name));
|
|
40680
40992
|
movedOriginal.push(name);
|
|
40681
40993
|
}
|
|
40682
40994
|
assertPullTargetIdentity(targetDir, activeTargetIdentity);
|
|
40683
40995
|
assertLockOwnership();
|
|
40684
40996
|
for (const name of stagedEntries) {
|
|
40685
|
-
|
|
40997
|
+
renameSync10(join17(stageDir, name), join17(targetRoot, name));
|
|
40686
40998
|
movedStaged.push(name);
|
|
40687
40999
|
}
|
|
40688
41000
|
assertPullTargetIdentity(targetDir, activeTargetIdentity);
|
|
40689
41001
|
assertLockOwnership();
|
|
40690
41002
|
for (const relPath of movedPreserved) {
|
|
40691
|
-
const targetPath =
|
|
41003
|
+
const targetPath = join17(targetRoot, relPath);
|
|
40692
41004
|
try {
|
|
40693
41005
|
lstatSync4(targetPath);
|
|
40694
41006
|
throw usageError(
|
|
@@ -40697,17 +41009,17 @@ async function pullAppSourceUnlocked({
|
|
|
40697
41009
|
} catch (error) {
|
|
40698
41010
|
if (error?.code !== "ENOENT") throw error;
|
|
40699
41011
|
}
|
|
40700
|
-
|
|
40701
|
-
|
|
41012
|
+
mkdirSync10(dirname17(targetPath), { recursive: true });
|
|
41013
|
+
renameSync10(join17(preservedDir, relPath), targetPath);
|
|
40702
41014
|
restoredPreserved.push(relPath);
|
|
40703
41015
|
}
|
|
40704
41016
|
assertPullTargetIdentity(targetDir, activeTargetIdentity);
|
|
40705
41017
|
assertLockOwnership();
|
|
40706
41018
|
withAppReleaseWorkspace(targetRoot, () => {
|
|
40707
|
-
const temporary = `.space-source-${
|
|
41019
|
+
const temporary = `.space-source-${randomUUID10()}.json`;
|
|
40708
41020
|
try {
|
|
40709
|
-
|
|
40710
|
-
|
|
41021
|
+
writeFileSync10(temporary, JSON.stringify({ ...sourceLink, revision: pulledVersion }), { flag: "wx", mode: 384 });
|
|
41022
|
+
renameSync10(temporary, basename6(SPACE_SOURCE_FILE));
|
|
40711
41023
|
} finally {
|
|
40712
41024
|
rmSync5(temporary, { force: true });
|
|
40713
41025
|
}
|
|
@@ -40717,20 +41029,20 @@ async function pullAppSourceUnlocked({
|
|
|
40717
41029
|
} catch (error) {
|
|
40718
41030
|
try {
|
|
40719
41031
|
for (const relPath of restoredPreserved.reverse()) {
|
|
40720
|
-
const preservedPath =
|
|
40721
|
-
|
|
40722
|
-
|
|
41032
|
+
const preservedPath = join17(preservedDir, relPath);
|
|
41033
|
+
mkdirSync10(dirname17(preservedPath), { recursive: true });
|
|
41034
|
+
renameSync10(join17(targetRoot, relPath), preservedPath);
|
|
40723
41035
|
}
|
|
40724
41036
|
for (const name of movedStaged.reverse()) {
|
|
40725
|
-
|
|
41037
|
+
renameSync10(join17(targetRoot, name), join17(stageDir, name));
|
|
40726
41038
|
}
|
|
40727
41039
|
for (const name of movedOriginal.reverse()) {
|
|
40728
|
-
|
|
41040
|
+
renameSync10(join17(backupDir, name), join17(targetRoot, name));
|
|
40729
41041
|
}
|
|
40730
41042
|
for (const relPath of movedPreserved.reverse()) {
|
|
40731
|
-
const targetPath =
|
|
40732
|
-
|
|
40733
|
-
|
|
41043
|
+
const targetPath = join17(targetRoot, relPath);
|
|
41044
|
+
mkdirSync10(dirname17(targetPath), { recursive: true });
|
|
41045
|
+
renameSync10(join17(preservedDir, relPath), targetPath);
|
|
40734
41046
|
}
|
|
40735
41047
|
if (hadPreviousState) {
|
|
40736
41048
|
cpSync2(backupStatePath, previousStatePath);
|
|
@@ -40782,7 +41094,7 @@ async function pullAppSourceUnlocked({
|
|
|
40782
41094
|
return { projectDir: targetDir, version: pulledVersion };
|
|
40783
41095
|
}
|
|
40784
41096
|
function readArtifactFiles(projectDir) {
|
|
40785
|
-
const outputDir =
|
|
41097
|
+
const outputDir = join17(projectDir, OUTPUT_DIR);
|
|
40786
41098
|
if (!existsSync13(outputDir)) {
|
|
40787
41099
|
throw usageError('No build output found. Run "notis spaces build" first.');
|
|
40788
41100
|
}
|
|
@@ -40790,12 +41102,12 @@ function readArtifactFiles(projectDir) {
|
|
|
40790
41102
|
function walk(dir, prefix) {
|
|
40791
41103
|
const entries = readdirSync6(dir, { withFileTypes: true });
|
|
40792
41104
|
for (const entry of entries) {
|
|
40793
|
-
const fullPath =
|
|
41105
|
+
const fullPath = join17(dir, entry.name);
|
|
40794
41106
|
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
40795
41107
|
if (entry.isDirectory()) {
|
|
40796
41108
|
walk(fullPath, relPath);
|
|
40797
41109
|
} else {
|
|
40798
|
-
files[relPath] =
|
|
41110
|
+
files[relPath] = readFileSync17(fullPath);
|
|
40799
41111
|
}
|
|
40800
41112
|
}
|
|
40801
41113
|
}
|
|
@@ -40803,7 +41115,7 @@ function readArtifactFiles(projectDir) {
|
|
|
40803
41115
|
return files;
|
|
40804
41116
|
}
|
|
40805
41117
|
function appFilesDigest(files) {
|
|
40806
|
-
return
|
|
41118
|
+
return createHash13("sha256").update(JSON.stringify(Object.keys(files).sort().map((key2) => [key2, files[key2]]))).digest("hex");
|
|
40807
41119
|
}
|
|
40808
41120
|
function withAppReleaseWorkspace(projectDir, operation, { create = false, expected = null } = {}) {
|
|
40809
41121
|
const canonicalProjectDir = expected?.projectDir || realpathSync2(projectDir);
|
|
@@ -40815,7 +41127,7 @@ function withAppReleaseWorkspace(projectDir, operation, { create = false, expect
|
|
|
40815
41127
|
assertPullTargetIdentity(".", projectIdentity);
|
|
40816
41128
|
let notisIdentity = capturePullTargetIdentity(NOTIS_DIR);
|
|
40817
41129
|
if (!notisIdentity.exists && create) {
|
|
40818
|
-
|
|
41130
|
+
mkdirSync10(NOTIS_DIR);
|
|
40819
41131
|
notisIdentity = capturePullTargetIdentity(NOTIS_DIR);
|
|
40820
41132
|
}
|
|
40821
41133
|
if (!notisIdentity.exists) throw usageError("No build workspace found. Run notis spaces build first.");
|
|
@@ -40825,7 +41137,7 @@ function withAppReleaseWorkspace(projectDir, operation, { create = false, expect
|
|
|
40825
41137
|
const value = operation({ projectDir: canonicalProjectDir, projectIdentity, notisIdentity });
|
|
40826
41138
|
assertPullTargetIdentity(".", notisIdentity);
|
|
40827
41139
|
assertPullTargetIdentity(canonicalProjectDir, projectIdentity);
|
|
40828
|
-
assertPullTargetIdentity(
|
|
41140
|
+
assertPullTargetIdentity(join17(canonicalProjectDir, NOTIS_DIR), notisIdentity);
|
|
40829
41141
|
return value;
|
|
40830
41142
|
} finally {
|
|
40831
41143
|
process.chdir(previousCwd);
|
|
@@ -40841,7 +41153,7 @@ function freezePinnedArtifactSnapshot(workspace, files, sourceFiles) {
|
|
|
40841
41153
|
}
|
|
40842
41154
|
const frozenName = mkdtempSync2("release-");
|
|
40843
41155
|
const frozenIdentity = capturePullTargetIdentity(frozenName);
|
|
40844
|
-
const frozenDir =
|
|
41156
|
+
const frozenDir = join17(workspace.projectDir, NOTIS_DIR, frozenName);
|
|
40845
41157
|
let closed = false;
|
|
40846
41158
|
const close = () => {
|
|
40847
41159
|
process.removeListener("exit", close);
|
|
@@ -40855,13 +41167,13 @@ function freezePinnedArtifactSnapshot(workspace, files, sourceFiles) {
|
|
|
40855
41167
|
function writeEntry(segments, content) {
|
|
40856
41168
|
const name = segments[0];
|
|
40857
41169
|
if (segments.length === 1) {
|
|
40858
|
-
|
|
41170
|
+
writeFileSync10(name, content, { flag: "wx" });
|
|
40859
41171
|
return;
|
|
40860
41172
|
}
|
|
40861
41173
|
const parentIdentity = capturePullTargetIdentity(".");
|
|
40862
41174
|
let identity = capturePullTargetIdentity(name);
|
|
40863
41175
|
if (!identity.exists) {
|
|
40864
|
-
|
|
41176
|
+
mkdirSync10(name);
|
|
40865
41177
|
identity = capturePullTargetIdentity(name);
|
|
40866
41178
|
}
|
|
40867
41179
|
process.chdir(name);
|
|
@@ -40913,7 +41225,7 @@ function selectedBuildName(key2) {
|
|
|
40913
41225
|
}
|
|
40914
41226
|
function saveSelectedBuild(projectDir, key2, release) {
|
|
40915
41227
|
return withAppReleaseWorkspace(projectDir, () => {
|
|
40916
|
-
const name = selectedBuildName(key2), temporary = `.${name}-${
|
|
41228
|
+
const name = selectedBuildName(key2), temporary = `.${name}-${randomUUID10()}`;
|
|
40917
41229
|
const snapshot = {
|
|
40918
41230
|
version: 1,
|
|
40919
41231
|
key: key2,
|
|
@@ -40923,13 +41235,13 @@ function saveSelectedBuild(projectDir, key2, release) {
|
|
|
40923
41235
|
artifact_hash: appFilesDigest(release.files)
|
|
40924
41236
|
};
|
|
40925
41237
|
try {
|
|
40926
|
-
|
|
40927
|
-
|
|
41238
|
+
writeFileSync10(temporary, JSON.stringify(snapshot), { flag: "wx", mode: 384 });
|
|
41239
|
+
renameSync10(temporary, name);
|
|
40928
41240
|
} finally {
|
|
40929
41241
|
rmSync5(temporary, { force: true });
|
|
40930
41242
|
}
|
|
40931
41243
|
removeSpaceImages(key2);
|
|
40932
|
-
return
|
|
41244
|
+
return join17(projectDir, NOTIS_DIR, name);
|
|
40933
41245
|
}, { create: true });
|
|
40934
41246
|
}
|
|
40935
41247
|
function prepareSelectedBuild(projectDir, key2, sourceFiles) {
|
|
@@ -40957,14 +41269,14 @@ function prepareSelectedBuild(projectDir, key2, sourceFiles) {
|
|
|
40957
41269
|
}
|
|
40958
41270
|
function saveSpaceVerification(projectDir, diagnostic) {
|
|
40959
41271
|
return withAppReleaseWorkspace(projectDir, (workspace) => {
|
|
40960
|
-
const name = `space-verification-${
|
|
40961
|
-
|
|
40962
|
-
return
|
|
41272
|
+
const name = `space-verification-${randomUUID10()}.json`;
|
|
41273
|
+
writeFileSync10(name, JSON.stringify(diagnostic, null, 2), { flag: "wx", mode: 384 });
|
|
41274
|
+
return join17(workspace.projectDir, ".notis", name);
|
|
40963
41275
|
});
|
|
40964
41276
|
}
|
|
40965
41277
|
function replaceVerifyImage(name, png) {
|
|
40966
41278
|
rmSync5(name, { force: true });
|
|
40967
|
-
if (png)
|
|
41279
|
+
if (png) writeFileSync10(name, png, { flag: "wx", mode: 384 });
|
|
40968
41280
|
}
|
|
40969
41281
|
var VERIFY_WIDTHS = [390, 1440];
|
|
40970
41282
|
var VERIFY_LOCALES = ["en", "fr"];
|
|
@@ -40977,7 +41289,7 @@ function pendingImageName(key2, width, locale) {
|
|
|
40977
41289
|
return `pending-${assertSpaceKey(key2, "Unsafe pending screenshot name.")}-${width}-${locale}.png`;
|
|
40978
41290
|
}
|
|
40979
41291
|
function clearSpaceScreenshots(projectDir, key2) {
|
|
40980
|
-
if (!isSpaceKey(key2) || !lstatSync4(
|
|
41292
|
+
if (!isSpaceKey(key2) || !lstatSync4(join17(projectDir, NOTIS_DIR), { throwIfNoEntry: false })) return;
|
|
40981
41293
|
withAppReleaseWorkspace(projectDir, () => removeSpaceImages(key2));
|
|
40982
41294
|
}
|
|
40983
41295
|
function removeSpaceImages(key2) {
|
|
@@ -40995,7 +41307,7 @@ function saveSpacePendingScreenshots(projectDir, key2, screenshots) {
|
|
|
40995
41307
|
const names = screenshots.map(({ width, locale }) => pendingImageName(key2, width, locale));
|
|
40996
41308
|
return withAppReleaseWorkspace(projectDir, (workspace) => screenshots.map(({ png }, index) => {
|
|
40997
41309
|
replaceVerifyImage(names[index], png);
|
|
40998
|
-
return
|
|
41310
|
+
return join17(workspace.projectDir, NOTIS_DIR, names[index]);
|
|
40999
41311
|
}));
|
|
41000
41312
|
}
|
|
41001
41313
|
function saveSpaceScreenshots(projectDir, key2, screenshots) {
|
|
@@ -41003,16 +41315,16 @@ function saveSpaceScreenshots(projectDir, key2, screenshots) {
|
|
|
41003
41315
|
const names = new Map([...kept.keys()].map((width) => [width, viewImageName(key2, width)]));
|
|
41004
41316
|
return withAppReleaseWorkspace(projectDir, (workspace) => [...kept].map(([width, { png }]) => {
|
|
41005
41317
|
replaceVerifyImage(names.get(width), png);
|
|
41006
|
-
return { width, path:
|
|
41318
|
+
return { width, path: join17(workspace.projectDir, NOTIS_DIR, names.get(width)) };
|
|
41007
41319
|
}));
|
|
41008
41320
|
}
|
|
41009
41321
|
function spacePublicationIntent(projectDir, identity, create = null) {
|
|
41010
|
-
const name = `space-publish-${
|
|
41322
|
+
const name = `space-publish-${createHash13("sha256").update(JSON.stringify(identity)).digest("hex")}.json`;
|
|
41011
41323
|
return withAppReleaseWorkspace(projectDir, () => {
|
|
41012
41324
|
if (create) {
|
|
41013
|
-
const temporary = `.${name}-${
|
|
41325
|
+
const temporary = `.${name}-${randomUUID10()}`;
|
|
41014
41326
|
try {
|
|
41015
|
-
|
|
41327
|
+
writeFileSync10(temporary, JSON.stringify(create), { flag: "wx", mode: 384 });
|
|
41016
41328
|
try {
|
|
41017
41329
|
linkSync(temporary, name);
|
|
41018
41330
|
} catch (error) {
|
|
@@ -41044,7 +41356,7 @@ function spaceStateFileName(name) {
|
|
|
41044
41356
|
}
|
|
41045
41357
|
function readSpaceStateFile(projectDir, name) {
|
|
41046
41358
|
spaceStateFileName(name);
|
|
41047
|
-
if (!existsSync13(
|
|
41359
|
+
if (!existsSync13(join17(resolve8(projectDir), NOTIS_DIR))) return null;
|
|
41048
41360
|
return withAppReleaseWorkspace(projectDir, () => {
|
|
41049
41361
|
let before;
|
|
41050
41362
|
try {
|
|
@@ -41065,14 +41377,14 @@ function readSpaceStateFile(projectDir, name) {
|
|
|
41065
41377
|
function writeSpaceStateFile(projectDir, name, value) {
|
|
41066
41378
|
spaceStateFileName(name);
|
|
41067
41379
|
return withAppReleaseWorkspace(projectDir, (workspace) => {
|
|
41068
|
-
const temporary = `.${name}-${
|
|
41380
|
+
const temporary = `.${name}-${randomUUID10()}`;
|
|
41069
41381
|
try {
|
|
41070
|
-
|
|
41071
|
-
|
|
41382
|
+
writeFileSync10(temporary, JSON.stringify(value, null, 2) + "\n", { flag: "wx", mode: 384 });
|
|
41383
|
+
renameSync10(temporary, name);
|
|
41072
41384
|
} finally {
|
|
41073
41385
|
rmSync5(temporary, { force: true });
|
|
41074
41386
|
}
|
|
41075
|
-
return
|
|
41387
|
+
return join17(workspace.projectDir, NOTIS_DIR, name);
|
|
41076
41388
|
}, { create: true });
|
|
41077
41389
|
}
|
|
41078
41390
|
function prepareAppRelease(projectDir) {
|
|
@@ -41584,8 +41896,8 @@ async function scaffoldSpaceCollection({ projectDir, name, databaseKey, path: pa
|
|
|
41584
41896
|
await scaffoldProject({ projectDir, appName: name });
|
|
41585
41897
|
syncSpaceSdk(projectDir, { log: () => {
|
|
41586
41898
|
} });
|
|
41587
|
-
|
|
41588
|
-
|
|
41899
|
+
mkdirSync11(join18(projectDir, "spaces", "collection"), { recursive: true });
|
|
41900
|
+
writeFileSync11(join18(projectDir, "notis.config.ts"), `import { defineSpaces } from '@notis/sdk/config';
|
|
41589
41901
|
export default defineSpaces({ spaces: { collection: { definition: 'spaces/collection/space.config.ts' } } });
|
|
41590
41902
|
`);
|
|
41591
41903
|
const definition = {
|
|
@@ -41611,11 +41923,11 @@ export default defineSpaces({ spaces: { collection: { definition: 'spaces/collec
|
|
|
41611
41923
|
delete: rowAction("LOCAL_NOTIS_DATABASE_DELETE", databaseKey)
|
|
41612
41924
|
}
|
|
41613
41925
|
};
|
|
41614
|
-
|
|
41926
|
+
writeFileSync11(join18(projectDir, "spaces/collection/space.config.ts"), `import { defineSpace } from '@notis/sdk/config';
|
|
41615
41927
|
export default defineSpace(${JSON.stringify(definition, null, 2)});
|
|
41616
41928
|
`);
|
|
41617
|
-
|
|
41618
|
-
|
|
41929
|
+
writeFileSync11(join18(projectDir, "spaces/collection/view.tsx"), collectionView(databaseKey));
|
|
41930
|
+
writeFileSync11(join18(projectDir, "spaces/collection/verification.json"), JSON.stringify({
|
|
41619
41931
|
actions: {},
|
|
41620
41932
|
shown: { items: [{ params: {}, result: { rows: [], has_more: false, schema_revision: 1 } }] }
|
|
41621
41933
|
}, null, 2) + "\n");
|
|
@@ -41688,15 +42000,15 @@ export default function CollectionView() {
|
|
|
41688
42000
|
var COLLECTION_VIEW = collectionView("items");
|
|
41689
42001
|
|
|
41690
42002
|
// src/runtime/space-platform.js
|
|
41691
|
-
import { existsSync as existsSync14, mkdirSync as
|
|
41692
|
-
import { dirname as
|
|
42003
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync12, readFileSync as readFileSync18, symlinkSync as symlinkSync2, writeFileSync as writeFileSync12 } from "node:fs";
|
|
42004
|
+
import { dirname as dirname19, join as join20, relative as relative5, resolve as resolve10 } from "node:path";
|
|
41693
42005
|
|
|
41694
42006
|
// src/runtime/space-source.js
|
|
41695
42007
|
import { createRequire as createRequire3 } from "node:module";
|
|
41696
42008
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
41697
|
-
import { dirname as
|
|
42009
|
+
import { dirname as dirname18, extname as extname2, join as join19, relative as relative4, resolve as resolve9, sep as sep3 } from "node:path";
|
|
41698
42010
|
init_errors();
|
|
41699
|
-
var CONFIG_FIELDS = /* @__PURE__ */ new Set(["name", "description", "icon", "accent", "entry", "layout", "readableContext", "resources", "actions", "navigation", "viewerReads", "cloudComputer", "agents", "collection", "sourceIncludes", "verificationFixtures", "editorsOnly", ...VIEW_DEFINITION_FIELDS]);
|
|
42011
|
+
var CONFIG_FIELDS = /* @__PURE__ */ new Set(["name", "description", "icon", "accent", "entry", "layout", "readableContext", "resources", "actions", "navigation", "viewerReads", "cloudComputer", "agents", "threadItems", "collection", "sourceIncludes", "verificationFixtures", "editorsOnly", ...VIEW_DEFINITION_FIELDS]);
|
|
41700
42012
|
var VIEWER_READ_FAMILIES = Object.freeze(["databases", "skills"]);
|
|
41701
42013
|
var WORKSPACE_INDEXES = /* @__PURE__ */ new Set(["notis.config.ts", "notis.config.js", "notis.config.mjs"]);
|
|
41702
42014
|
var ROOT_CONFIGS = [
|
|
@@ -41715,25 +42027,25 @@ var ROOT_CONFIGS = [
|
|
|
41715
42027
|
"tailwind.config.mjs"
|
|
41716
42028
|
];
|
|
41717
42029
|
function sourceCompiler(projectDir, files) {
|
|
41718
|
-
const require3 = createRequire3(
|
|
42030
|
+
const require3 = createRequire3(join19(projectDir, "package.json"));
|
|
41719
42031
|
let ts;
|
|
41720
42032
|
try {
|
|
41721
42033
|
ts = require3("typescript");
|
|
41722
42034
|
} catch {
|
|
41723
42035
|
throw usageError("Install this workspace's TypeScript dependency before packaging Space source.");
|
|
41724
42036
|
}
|
|
41725
|
-
const codeFiles = Object.keys(files).filter((path4) => /\.[cm]?[jt]sx?$/.test(path4)).map((path4) =>
|
|
42037
|
+
const codeFiles = Object.keys(files).filter((path4) => /\.[cm]?[jt]sx?$/.test(path4)).map((path4) => join19(projectDir, path4));
|
|
41726
42038
|
let source, checker, syntax, close = () => {
|
|
41727
42039
|
};
|
|
41728
42040
|
if (typeof ts.createProgram === "function") {
|
|
41729
42041
|
let options = { moduleResolution: ts.ModuleResolutionKind.Bundler, allowJs: true };
|
|
41730
42042
|
if (files["tsconfig.json"]) {
|
|
41731
|
-
const config = ts.readConfigFile(
|
|
42043
|
+
const config = ts.readConfigFile(join19(projectDir, "tsconfig.json"), ts.sys.readFile);
|
|
41732
42044
|
if (config.error) throw usageError("Fix tsconfig.json before building this Space.");
|
|
41733
42045
|
options = { ...options, ...ts.parseJsonConfigFileContent(config.config, ts.sys, projectDir).options, allowJs: true };
|
|
41734
42046
|
}
|
|
41735
42047
|
const program3 = ts.createProgram(codeFiles, options), projectChecker = program3.getTypeChecker();
|
|
41736
|
-
source = (file) => program3.getSourceFile(
|
|
42048
|
+
source = (file) => program3.getSourceFile(join19(projectDir, file));
|
|
41737
42049
|
checker = () => projectChecker;
|
|
41738
42050
|
syntax = ts.SyntaxKind;
|
|
41739
42051
|
} else {
|
|
@@ -41742,8 +42054,8 @@ function sourceCompiler(projectDir, files) {
|
|
|
41742
42054
|
const api2 = new API({ cwd: projectDir });
|
|
41743
42055
|
try {
|
|
41744
42056
|
const snapshot = api2.updateSnapshot({ openFiles: codeFiles });
|
|
41745
|
-
const project = (file) => snapshot.getDefaultProjectForFile(
|
|
41746
|
-
source = (file) => project(file)?.program.getSourceFile(
|
|
42057
|
+
const project = (file) => snapshot.getDefaultProjectForFile(join19(projectDir, file));
|
|
42058
|
+
source = (file) => project(file)?.program.getSourceFile(join19(projectDir, file));
|
|
41747
42059
|
checker = (file) => project(file)?.checker;
|
|
41748
42060
|
close = () => {
|
|
41749
42061
|
try {
|
|
@@ -41872,7 +42184,7 @@ async function loadSelectedSpace(projectDir, selectedKey) {
|
|
|
41872
42184
|
}
|
|
41873
42185
|
const resolveDefinitionPath = (value) => {
|
|
41874
42186
|
if (typeof value !== "string" || !value || value.startsWith("/") || value.includes("\\") || value.includes("\0")) throw usageError("Use a workspace-relative source path.");
|
|
41875
|
-
return localPath(relative4(projectDir, resolve9(projectDir,
|
|
42187
|
+
return localPath(relative4(projectDir, resolve9(projectDir, dirname18(definitionPath), value)).split(sep3).join("/"));
|
|
41876
42188
|
};
|
|
41877
42189
|
const entry = definition.entry ? resolveDefinitionPath(definition.entry) : null;
|
|
41878
42190
|
const layout = definition.layout ? resolveDefinitionPath(definition.layout) : null;
|
|
@@ -41913,6 +42225,7 @@ async function loadSelectedSpace(projectDir, selectedKey) {
|
|
|
41913
42225
|
if (definition.cloudComputer != null) validateCloudComputer(definition.cloudComputer);
|
|
41914
42226
|
if (definition.cloudComputer != null && !entry) throw usageError("A container has no page, so it cannot use the cloud computer.");
|
|
41915
42227
|
if (definition.agents != null) validateSpaceAgents(definition.agents, resources);
|
|
42228
|
+
if (definition.threadItems != null) validateThreadItems(definition.threadItems, definition.actions || {});
|
|
41916
42229
|
if (definition.collection && (resources[definition.collection.database]?.kind !== "database" || !definition.collection.titleProperty)) {
|
|
41917
42230
|
throw usageError("A collection needs a declared database binding and title property.");
|
|
41918
42231
|
}
|
|
@@ -41967,7 +42280,7 @@ function collectSelectedSpaceSource(projectDir, selection, { buildInputs = [] }
|
|
|
41967
42280
|
if (!specifier.startsWith(".")) return;
|
|
41968
42281
|
}
|
|
41969
42282
|
const raw = specifier.split(/[?#]/, 1)[0];
|
|
41970
|
-
const path4 = relative4(projectDir, resolve9(
|
|
42283
|
+
const path4 = relative4(projectDir, resolve9(dirname18(join19(projectDir, importer)), raw)).split(sep3).join("/");
|
|
41971
42284
|
const candidate = [path4, ...[".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".d.ts", "/index.ts", "/index.tsx", "/index.js"].map((suffix) => path4 + suffix)].find((name) => Object.hasOwn(files, name));
|
|
41972
42285
|
if (candidate) {
|
|
41973
42286
|
add(candidate);
|
|
@@ -42071,6 +42384,59 @@ function validateSpaceAgents(agents, resources = {}) {
|
|
|
42071
42384
|
}
|
|
42072
42385
|
}
|
|
42073
42386
|
}
|
|
42387
|
+
var THREAD_ITEM_FIELDS = ["label", "description", "inputs", "read", "title", "url", "states", "checks", "actions", "page"];
|
|
42388
|
+
var THREAD_ITEM_STATE_FIELDS = ["id", "label", "icon", "when", "needsYou", "final"];
|
|
42389
|
+
var THREAD_ITEM_ACTION_FIELDS = ["label", "tool", "arguments", "confirm", "states", "primary"];
|
|
42390
|
+
var REFUSED_ITEM_TOOL = /^(LOCAL_|COMPOSIO_|NOTIS_|CUSTOM_|MCP_)/;
|
|
42391
|
+
function threadItemLabel(value) {
|
|
42392
|
+
if (typeof value === "string") return value.trim().length > 0;
|
|
42393
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && typeof value.en === "string" && value.en.trim().length > 0 && Object.keys(value).every((name) => ["en", "fr"].includes(name) && typeof value[name] === "string" && value[name].trim());
|
|
42394
|
+
}
|
|
42395
|
+
function validateThreadItems(threadItems, actions = {}) {
|
|
42396
|
+
const kinds = threadItems && typeof threadItems === "object" && !Array.isArray(threadItems) ? Object.entries(threadItems) : null;
|
|
42397
|
+
if (!kinds || kinds.length < 1 || kinds.length > 8) throw usageError("Declare threadItems as 1 to 8 item kinds.");
|
|
42398
|
+
for (const [kind, spec] of kinds) {
|
|
42399
|
+
if (!/^[a-z][a-z0-9_]{0,39}$/.test(kind)) throw usageError("Each thread item kind needs a short id: lowercase letters, digits and _.");
|
|
42400
|
+
if (!spec || typeof spec !== "object" || Array.isArray(spec) || Object.keys(spec).some((name) => !THREAD_ITEM_FIELDS.includes(name))) {
|
|
42401
|
+
throw usageError(`Thread item ${kind} takes ${THREAD_ITEM_FIELDS.join(", ")} only.`);
|
|
42402
|
+
}
|
|
42403
|
+
if (!threadItemLabel(spec.label)) throw usageError(`Thread item ${kind} needs a label.`);
|
|
42404
|
+
if (spec.inputs?.type !== "object" || spec.inputs?.additionalProperties !== false || !spec.inputs.properties || !Array.isArray(spec.inputs.required) || !spec.inputs.required.length) {
|
|
42405
|
+
throw usageError(`Thread item ${kind} declares its inputs as a closed object with the fields an agent must give in required.`);
|
|
42406
|
+
}
|
|
42407
|
+
if (!spec.read || typeof spec.read.action !== "string" || !Object.hasOwn(actions, spec.read.action)) {
|
|
42408
|
+
throw usageError(`Thread item ${kind} reads through one of this Space's actions: read: { action: '<id>' }.`);
|
|
42409
|
+
}
|
|
42410
|
+
if (typeof spec.title !== "string" && !threadItemLabel(spec.title)) throw usageError(`Thread item ${kind} needs a title template.`);
|
|
42411
|
+
if (!Array.isArray(spec.states) || spec.states.length < 1 || spec.states.length > 12) {
|
|
42412
|
+
throw usageError(`Thread item ${kind} lists 1 to 12 states in the order they are checked.`);
|
|
42413
|
+
}
|
|
42414
|
+
const stateIds = /* @__PURE__ */ new Set();
|
|
42415
|
+
for (const state of spec.states) {
|
|
42416
|
+
if (!state || typeof state !== "object" || Object.keys(state).some((name) => !THREAD_ITEM_STATE_FIELDS.includes(name)) || typeof state.id !== "string" || !/^[a-z][a-z0-9_-]{0,39}$/.test(state.id) || stateIds.has(state.id)) {
|
|
42417
|
+
throw usageError(`Each state of thread item ${kind} has its own id and takes ${THREAD_ITEM_STATE_FIELDS.join(", ")} only.`);
|
|
42418
|
+
}
|
|
42419
|
+
stateIds.add(state.id);
|
|
42420
|
+
if (!threadItemLabel(state.label)) throw usageError(`State ${state.id} of thread item ${kind} needs a label.`);
|
|
42421
|
+
if (typeof state.icon !== "string" || !/^phosphor:[a-z0-9]+(-[a-z0-9]+)*$/.test(state.icon)) {
|
|
42422
|
+
throw usageError(`State ${state.id} of thread item ${kind} needs a Phosphor icon, written phosphor:<name>.`);
|
|
42423
|
+
}
|
|
42424
|
+
}
|
|
42425
|
+
if (spec.states.at(-1).when != null) throw usageError(`The last state of thread item ${kind} has no condition, so every item has a state.`);
|
|
42426
|
+
for (const [actionId, action] of Object.entries(spec.actions || {})) {
|
|
42427
|
+
if (!action || typeof action !== "object" || Object.keys(action).some((name) => !THREAD_ITEM_ACTION_FIELDS.includes(name))) {
|
|
42428
|
+
throw usageError(`Action ${actionId} of thread item ${kind} takes ${THREAD_ITEM_ACTION_FIELDS.join(", ")} only.`);
|
|
42429
|
+
}
|
|
42430
|
+
if (!threadItemLabel(action.label)) throw usageError(`Action ${actionId} of thread item ${kind} needs a label.`);
|
|
42431
|
+
if (typeof action.tool !== "string" || !/^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$/.test(action.tool) || REFUSED_ITEM_TOOL.test(action.tool)) {
|
|
42432
|
+
throw usageError(`Action ${actionId} of thread item ${kind} runs one connected app tool, such as GITHUB_MERGE_A_PULL_REQUEST.`);
|
|
42433
|
+
}
|
|
42434
|
+
if (action.states != null && (!Array.isArray(action.states) || action.states.some((id) => !stateIds.has(id)))) {
|
|
42435
|
+
throw usageError(`Action ${actionId} of thread item ${kind} lists states this item declares.`);
|
|
42436
|
+
}
|
|
42437
|
+
}
|
|
42438
|
+
}
|
|
42439
|
+
}
|
|
42074
42440
|
|
|
42075
42441
|
// src/runtime/space-platform.js
|
|
42076
42442
|
init_errors();
|
|
@@ -42100,6 +42466,8 @@ function generateSpaceManifest(selection) {
|
|
|
42100
42466
|
...definition.cloudComputer ? { cloud_computer: definition.cloudComputer } : {},
|
|
42101
42467
|
// Agents its database changes wake; absent when undeclared.
|
|
42102
42468
|
...definition.agents?.length ? { agents: definition.agents } : {},
|
|
42469
|
+
// Live items agents attach to threads; absent when undeclared.
|
|
42470
|
+
...definition.threadItems && Object.keys(definition.threadItems).length ? { thread_items: definition.threadItems } : {},
|
|
42103
42471
|
// Absent when nothing is editor-only (SPC-073: unmarked means public).
|
|
42104
42472
|
...editorsOnly ? { editors_only: editorsOnly } : {},
|
|
42105
42473
|
readable_context: definition.readableContext || "",
|
|
@@ -42112,18 +42480,18 @@ function generateSpaceManifest(selection) {
|
|
|
42112
42480
|
function prepareSelectedArtifact(projectDir, selection, { designBar = "enforce", log = null } = {}) {
|
|
42113
42481
|
validateProjectBoundary(projectDir);
|
|
42114
42482
|
validateProjectDesign(projectDir, { profile: "space", enforce: designBar !== "report", log });
|
|
42115
|
-
const entryPath =
|
|
42116
|
-
const manifestPath =
|
|
42117
|
-
|
|
42118
|
-
|
|
42483
|
+
const entryPath = join20(projectDir, ".notis/_entry.tsx");
|
|
42484
|
+
const manifestPath = join20(projectDir, ".notis/output/manifest.json");
|
|
42485
|
+
mkdirSync12(dirname19(entryPath), { recursive: true });
|
|
42486
|
+
mkdirSync12(dirname19(manifestPath), { recursive: true });
|
|
42119
42487
|
if (selection.entry) {
|
|
42120
|
-
const reference = (path4) => JSON.stringify("./" + relative5(
|
|
42488
|
+
const reference = (path4) => JSON.stringify("./" + relative5(dirname19(entryPath), join20(projectDir, path4)).replaceAll("\\", "/"));
|
|
42121
42489
|
const lines = [`export { default as SpaceView } from ${reference(selection.entry)};`];
|
|
42122
42490
|
if (selection.layout) lines.push(`export { default as __AppShell } from ${reference(selection.layout)};`);
|
|
42123
42491
|
if (selection.markdown) lines.push(`export { default as SpaceMarkdown } from ${reference(selection.markdown)};`);
|
|
42124
|
-
|
|
42492
|
+
writeFileSync12(entryPath, lines.join("\n") + "\n");
|
|
42125
42493
|
}
|
|
42126
|
-
|
|
42494
|
+
writeFileSync12(manifestPath, JSON.stringify(generateSpaceManifest(selection), null, 2) + "\n");
|
|
42127
42495
|
}
|
|
42128
42496
|
var SPACE_HOST_SDK_MODULES = Object.freeze(["@notis/sdk", "@notis/sdk/ui"]);
|
|
42129
42497
|
var SDK_IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s*)(["'])(@notis\/sdk(?:\/[^"'\s]*)?)\1/g;
|
|
@@ -42137,12 +42505,12 @@ function assertSpaceBundleUsesHostSdk(source) {
|
|
|
42137
42505
|
}
|
|
42138
42506
|
}
|
|
42139
42507
|
function finalizeSelectedArtifact(projectDir) {
|
|
42140
|
-
const manifestPath =
|
|
42141
|
-
const manifest = JSON.parse(
|
|
42142
|
-
if (manifest.bundle?.js) assertSpaceBundleUsesHostSdk(
|
|
42143
|
-
if (manifest.bundle?.css && !existsSync14(
|
|
42508
|
+
const manifestPath = join20(projectDir, ".notis/output/manifest.json");
|
|
42509
|
+
const manifest = JSON.parse(readFileSync18(manifestPath, "utf8"));
|
|
42510
|
+
if (manifest.bundle?.js) assertSpaceBundleUsesHostSdk(readFileSync18(join20(projectDir, ".notis/output", manifest.bundle.js), "utf8"));
|
|
42511
|
+
if (manifest.bundle?.css && !existsSync14(join20(projectDir, ".notis/output", manifest.bundle.css))) {
|
|
42144
42512
|
delete manifest.bundle.css;
|
|
42145
|
-
|
|
42513
|
+
writeFileSync12(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
|
|
42146
42514
|
}
|
|
42147
42515
|
}
|
|
42148
42516
|
async function buildSpaceRelease(projectDir, selectedKey, { stdio = "inherit", refreshSdk = true, runBuild, designBar = "enforce", designLog = null } = {}) {
|
|
@@ -42154,8 +42522,8 @@ async function buildSpaceRelease(projectDir, selectedKey, { stdio = "inherit", r
|
|
|
42154
42522
|
const staging = freezeSourceWorkspace(projectDir, sourceFiles);
|
|
42155
42523
|
let release;
|
|
42156
42524
|
try {
|
|
42157
|
-
if (existsSync14(
|
|
42158
|
-
symlinkSync2(
|
|
42525
|
+
if (existsSync14(join20(projectDir, "node_modules"))) {
|
|
42526
|
+
symlinkSync2(join20(projectDir, "node_modules"), join20(staging.projectDir, "node_modules"), process.platform === "win32" ? "junction" : "dir");
|
|
42159
42527
|
}
|
|
42160
42528
|
const frozenSelection = await loadSelectedSpace(staging.projectDir, selectedKey);
|
|
42161
42529
|
await buildArtifact(staging.projectDir, {
|
|
@@ -42213,19 +42581,19 @@ async function prepareSpaceRelease(projectDir, selectedKey) {
|
|
|
42213
42581
|
}
|
|
42214
42582
|
|
|
42215
42583
|
// src/runtime/space-verification.js
|
|
42216
|
-
import { createHash as
|
|
42217
|
-
import { existsSync as existsSync15, readFileSync as
|
|
42584
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
42585
|
+
import { existsSync as existsSync15, readFileSync as readFileSync19 } from "node:fs";
|
|
42218
42586
|
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
42219
42587
|
|
|
42220
42588
|
// src/runtime/space-test-server.js
|
|
42221
|
-
import { createHash as
|
|
42589
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
42222
42590
|
var import__ = __toESM(require__(), 1);
|
|
42223
42591
|
var import_ajv_formats2 = __toESM(require_dist(), 1);
|
|
42224
|
-
import { dirname as
|
|
42592
|
+
import { dirname as dirname20, join as join21, resolve as resolve11 } from "node:path";
|
|
42225
42593
|
import { isDeepStrictEqual } from "node:util";
|
|
42226
42594
|
import { fileURLToPath as fileURLToPath9 } from "node:url";
|
|
42227
42595
|
init_errors();
|
|
42228
|
-
var ROOT = resolve11(
|
|
42596
|
+
var ROOT = resolve11(dirname20(fileURLToPath9(import.meta.url)), "../..");
|
|
42229
42597
|
var MAX_SHOWN_FIXTURE_CASES = 256;
|
|
42230
42598
|
function object(value) {
|
|
42231
42599
|
return value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -42277,6 +42645,14 @@ function recordViewExample(operation, key2) {
|
|
|
42277
42645
|
return JSON.stringify({ operation, record_key: key2, result });
|
|
42278
42646
|
}
|
|
42279
42647
|
var VIEWER_READS = { list_databases: "databases", get_database: "databases", query_database: "databases", list_skills: "skills", get_skill: "skills" };
|
|
42648
|
+
function shownPage(result, options) {
|
|
42649
|
+
if (!object(options) || !object(result) || !Array.isArray(result.rows)) return result;
|
|
42650
|
+
const offset = Number.isSafeInteger(options.offset) && options.offset > 0 ? options.offset : 0;
|
|
42651
|
+
const size = Number.isSafeInteger(options.page_size) && options.page_size > 0 ? options.page_size : offset ? 100 : null;
|
|
42652
|
+
if (size === null) return result;
|
|
42653
|
+
result.rows = result.rows.slice(offset, offset + size);
|
|
42654
|
+
return result;
|
|
42655
|
+
}
|
|
42280
42656
|
function createSpaceFixtureEngine(release) {
|
|
42281
42657
|
const bodyTemplates = structuredClone(release.manifest.actions || {});
|
|
42282
42658
|
const bodyResources = structuredClone(release.manifest.resources || {});
|
|
@@ -42395,7 +42771,7 @@ function createSpaceFixtureEngine(release) {
|
|
|
42395
42771
|
}
|
|
42396
42772
|
return {
|
|
42397
42773
|
context: fixtures.context || {},
|
|
42398
|
-
digest:
|
|
42774
|
+
digest: createHash14("sha256").update(JSON.stringify(fixtures)).digest("hex"),
|
|
42399
42775
|
executeRecordView(operation, key2) {
|
|
42400
42776
|
const match = recordViews.find((value) => value.operation === operation && value.record_key === key2);
|
|
42401
42777
|
if (!match) {
|
|
@@ -42410,12 +42786,12 @@ function createSpaceFixtureEngine(release) {
|
|
|
42410
42786
|
if (!matched) throw usageError("Add an explicit synthetic document body fixture.");
|
|
42411
42787
|
return structuredClone(matched.result);
|
|
42412
42788
|
},
|
|
42413
|
-
executeShown(name, params) {
|
|
42789
|
+
executeShown(name, params, options = {}) {
|
|
42414
42790
|
if (!Object.hasOwn(declaredLists, name)) throw usageError("This view does not declare that list.");
|
|
42415
42791
|
if (!object(params)) throw usageError("List params must be an object.");
|
|
42416
42792
|
const matched = shownCases[name]?.find((entry) => isDeepStrictEqual(entry.params, params));
|
|
42417
42793
|
if (!matched) throw usageError(`Add an explicit synthetic shown fixture for ${name} and these params.`);
|
|
42418
|
-
return structuredClone(matched.result);
|
|
42794
|
+
return shownPage(structuredClone(matched.result), options);
|
|
42419
42795
|
},
|
|
42420
42796
|
executeViewerRead(operation, input) {
|
|
42421
42797
|
if (!Object.hasOwn(VIEWER_READS, operation) || !declaredReads.includes(VIEWER_READS[operation])) throw usageError("This Space does not declare that viewer read.");
|
|
@@ -42593,10 +42969,10 @@ async function loadSpaceVerificationRenderer() {
|
|
|
42593
42969
|
for (const root of candidates) {
|
|
42594
42970
|
const entry = new URL("src/index.js", root);
|
|
42595
42971
|
if (!existsSync15(fileURLToPath10(entry))) continue;
|
|
42596
|
-
const digest =
|
|
42972
|
+
const digest = createHash15("sha256");
|
|
42597
42973
|
for (const file of ["src/renderer.js", "src/dom.js", "src/pool.js", "src/skeleton.js", "dist/host.js", "dist/host.css", "dist/theme.css"]) {
|
|
42598
42974
|
digest.update(file);
|
|
42599
|
-
digest.update(
|
|
42975
|
+
digest.update(readFileSync19(new URL(file, root)));
|
|
42600
42976
|
}
|
|
42601
42977
|
return { ...await import(entry.href), rendererDigest: digest.digest("hex") };
|
|
42602
42978
|
}
|
|
@@ -42691,7 +43067,7 @@ async function verifySpaceRelease(release, {
|
|
|
42691
43067
|
mounted: true,
|
|
42692
43068
|
status: blocked.length ? "failed" : "passed",
|
|
42693
43069
|
loaded: true,
|
|
42694
|
-
markdown_sha256:
|
|
43070
|
+
markdown_sha256: createHash15("sha256").update(result2.markdown).digest("hex"),
|
|
42695
43071
|
screenshot_sha256: sha256(png),
|
|
42696
43072
|
screenshot_width: result2.screenshot.width,
|
|
42697
43073
|
screenshot_height: result2.screenshot.height,
|
|
@@ -42702,6 +43078,16 @@ async function verifySpaceRelease(release, {
|
|
|
42702
43078
|
const renders = observations.map((value, index) => {
|
|
42703
43079
|
if (value.status === "fulfilled") return value.value;
|
|
42704
43080
|
const width = brokers[index].width, shot = value.reason?.code === "render_not_ready" ? value.reason.screenshot : null;
|
|
43081
|
+
if (value.reason?.code === "render_view_failed") {
|
|
43082
|
+
return {
|
|
43083
|
+
width,
|
|
43084
|
+
mounted: false,
|
|
43085
|
+
status: "failed",
|
|
43086
|
+
error: "render_view_failed",
|
|
43087
|
+
loaded: false,
|
|
43088
|
+
message: `At ${width} px the view's code failed before it showed anything${value.reason.reason ? `: ${value.reason.reason}` : "."}`
|
|
43089
|
+
};
|
|
43090
|
+
}
|
|
42705
43091
|
if (!shot?.data_base64) return { width, mounted: false, status: "failed", error: value.reason?.code || "render_failed" };
|
|
42706
43092
|
const png = Buffer.from(shot.data_base64, "base64");
|
|
42707
43093
|
screenshots.push({ width, png });
|
|
@@ -42730,7 +43116,7 @@ async function verifySpaceRelease(release, {
|
|
|
42730
43116
|
...call.actionId ? { action_id: call.actionId } : {},
|
|
42731
43117
|
message: call.error
|
|
42732
43118
|
}])).values()].slice(0, 10);
|
|
42733
|
-
const notReady = renders.filter((value) => value.error === "render_not_ready").map((value) => ({ phase: "renderer", width: value.width, message: value.message }));
|
|
43119
|
+
const notReady = renders.filter((value) => value.error === "render_not_ready" || value.error === "render_view_failed").map((value) => ({ phase: "renderer", width: value.width, message: value.message }));
|
|
42734
43120
|
const result = {
|
|
42735
43121
|
...diagnostic,
|
|
42736
43122
|
status: passed ? "passed" : "failed",
|
|
@@ -42771,7 +43157,7 @@ async function verifySpaceRelease(release, {
|
|
|
42771
43157
|
var FIXTURE_FAILURE_GRACE_MS = 1500;
|
|
42772
43158
|
var READY_MARGIN_MS = 5e3;
|
|
42773
43159
|
var readyWait = (timeoutMs) => timeoutMs - READY_MARGIN_MS >= 1e3 ? timeoutMs - READY_MARGIN_MS : void 0;
|
|
42774
|
-
var sha256 = (bytes) =>
|
|
43160
|
+
var sha256 = (bytes) => createHash15("sha256").update(bytes).digest("hex");
|
|
42775
43161
|
var captureFailure = (width, locale, error) => ({
|
|
42776
43162
|
check: "capture_failed",
|
|
42777
43163
|
severity: "warning",
|
|
@@ -42900,14 +43286,14 @@ async function captureSpaceSkeleton({ library, pool: pool2, release, capabilitie
|
|
|
42900
43286
|
// src/runtime/space-database-structures.js
|
|
42901
43287
|
var import_parser = __toESM(require_lib(), 1);
|
|
42902
43288
|
init_errors();
|
|
42903
|
-
import { existsSync as existsSync16, readFileSync as
|
|
42904
|
-
import { dirname as
|
|
43289
|
+
import { existsSync as existsSync16, readFileSync as readFileSync20, realpathSync as realpathSync4, writeFileSync as writeFileSync13 } from "node:fs";
|
|
43290
|
+
import { dirname as dirname21, join as join22, relative as relative6, resolve as resolve12, sep as sep4 } from "node:path";
|
|
42905
43291
|
var nameOf = (node) => node?.type === "Identifier" ? node.name : node?.type === "StringLiteral" ? node.value : null;
|
|
42906
43292
|
function refreshSpaceAuthoring(projectDir, localKey, { databaseStructures, authoringOverrides } = {}) {
|
|
42907
43293
|
let rewritten = /* @__PURE__ */ new Map();
|
|
42908
43294
|
if (Object.keys(databaseStructures || {}).length) rewritten = planSpaceAuthoring(projectDir, localKey, { databaseStructures }, rewritten);
|
|
42909
43295
|
if (authoringOverrides) rewritten = planSpaceAuthoring(projectDir, localKey, { authoringOverrides }, rewritten);
|
|
42910
|
-
for (const [file, source] of rewritten)
|
|
43296
|
+
for (const [file, source] of rewritten) writeFileSync13(file, source);
|
|
42911
43297
|
return [...rewritten.keys()].map((file) => relative6(realpathSync4(projectDir), file).split(sep4).join("/"));
|
|
42912
43298
|
}
|
|
42913
43299
|
function planSpaceAuthoring(projectDir, localKey, { databaseStructures: structures, authoringOverrides: overrides }, staged) {
|
|
@@ -42917,7 +43303,7 @@ function planSpaceAuthoring(projectDir, localKey, { databaseStructures: structur
|
|
|
42917
43303
|
file = realpathSync4(file);
|
|
42918
43304
|
if (!file.startsWith(root + sep4) || file.includes(`${sep4}node_modules${sep4}`)) throw fail();
|
|
42919
43305
|
if (modules.has(file)) return modules.get(file);
|
|
42920
|
-
const source = staged.get(file) ??
|
|
43306
|
+
const source = staged.get(file) ?? readFileSync20(file, "utf8");
|
|
42921
43307
|
const ast = (0, import_parser.parse)(source, { sourceType: "module", plugins: ["typescript", "jsx"] });
|
|
42922
43308
|
const unit2 = { file, source, ast, bindings: /* @__PURE__ */ new Map(), exports: /* @__PURE__ */ new Map() };
|
|
42923
43309
|
modules.set(file, unit2);
|
|
@@ -42945,7 +43331,7 @@ function planSpaceAuthoring(projectDir, localKey, { databaseStructures: structur
|
|
|
42945
43331
|
}
|
|
42946
43332
|
function imported(reference) {
|
|
42947
43333
|
if (!reference.from?.startsWith(".")) throw fail();
|
|
42948
|
-
const base = resolve12(
|
|
43334
|
+
const base = resolve12(dirname21(reference.unit.file), reference.from);
|
|
42949
43335
|
const file = ["", ".ts", ".tsx", ".js", ".mjs", "/index.ts", "/index.js"].map((suffix) => base + suffix).find(existsSync16);
|
|
42950
43336
|
if (!file) throw fail();
|
|
42951
43337
|
return load(file);
|
|
@@ -42991,7 +43377,7 @@ function planSpaceAuthoring(projectDir, localKey, { databaseStructures: structur
|
|
|
42991
43377
|
if (value.node?.type !== "StringLiteral") throw fail();
|
|
42992
43378
|
return value.node.value;
|
|
42993
43379
|
}
|
|
42994
|
-
const indexFile = ["notis.config.ts", "notis.config.js", "notis.config.mjs"].map((file) =>
|
|
43380
|
+
const indexFile = ["notis.config.ts", "notis.config.js", "notis.config.mjs"].map((file) => join22(root, file)).find(existsSync16);
|
|
42995
43381
|
if (!indexFile) throw fail();
|
|
42996
43382
|
const index = load(indexFile);
|
|
42997
43383
|
const workspace = index.exports.get("default");
|
|
@@ -43114,10 +43500,10 @@ function planSpaceAuthoring(projectDir, localKey, { databaseStructures: structur
|
|
|
43114
43500
|
}
|
|
43115
43501
|
|
|
43116
43502
|
// src/runtime/space-lock.js
|
|
43117
|
-
import { createHash as
|
|
43118
|
-
import { existsSync as existsSync17, lstatSync as lstatSync5, mkdirSync as
|
|
43119
|
-
import { randomUUID as
|
|
43120
|
-
import { dirname as
|
|
43503
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
43504
|
+
import { existsSync as existsSync17, lstatSync as lstatSync5, mkdirSync as mkdirSync13, readdirSync as readdirSync7, readFileSync as readFileSync21, renameSync as renameSync11, rmSync as rmSync6, writeFileSync as writeFileSync14 } from "node:fs";
|
|
43505
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
43506
|
+
import { dirname as dirname22, join as join23, resolve as resolve13 } from "node:path";
|
|
43121
43507
|
init_errors();
|
|
43122
43508
|
var SPACE_LOCK_FILE = "space-lock.json";
|
|
43123
43509
|
var RESOURCES_FILE = "resources.json";
|
|
@@ -43171,12 +43557,12 @@ function writeSpaceLock(projectDir, lock) {
|
|
|
43171
43557
|
return writeSpaceStateFile(projectDir, SPACE_LOCK_FILE, lock);
|
|
43172
43558
|
}
|
|
43173
43559
|
function readResourceList(projectDir) {
|
|
43174
|
-
const path4 =
|
|
43560
|
+
const path4 = join23(resolve13(projectDir), RESOURCES_FILE);
|
|
43175
43561
|
if (!existsSync17(path4)) return null;
|
|
43176
43562
|
if (lstatSync5(path4).isSymbolicLink()) throw usageError(`${RESOURCES_FILE} must be a regular file.`);
|
|
43177
43563
|
let parsed;
|
|
43178
43564
|
try {
|
|
43179
|
-
parsed = JSON.parse(
|
|
43565
|
+
parsed = JSON.parse(readFileSync21(path4, "utf8"));
|
|
43180
43566
|
} catch {
|
|
43181
43567
|
throw usageError(`${RESOURCES_FILE} must be valid JSON.`);
|
|
43182
43568
|
}
|
|
@@ -43194,10 +43580,10 @@ function readResourceList(projectDir) {
|
|
|
43194
43580
|
}
|
|
43195
43581
|
function writeResourceList(projectDir, entries) {
|
|
43196
43582
|
const root = resolve13(projectDir);
|
|
43197
|
-
const temporary =
|
|
43583
|
+
const temporary = join23(root, `.${RESOURCES_FILE}-${randomUUID11()}`);
|
|
43198
43584
|
try {
|
|
43199
|
-
|
|
43200
|
-
|
|
43585
|
+
writeFileSync14(temporary, JSON.stringify(entries, null, 2) + "\n", { flag: "wx" });
|
|
43586
|
+
renameSync11(temporary, join23(root, RESOURCES_FILE));
|
|
43201
43587
|
} finally {
|
|
43202
43588
|
rmSync6(temporary, { force: true });
|
|
43203
43589
|
}
|
|
@@ -43206,19 +43592,19 @@ function walkSkillFolder(directory, prefix, files) {
|
|
|
43206
43592
|
for (const entry of readdirSync7(directory, { withFileTypes: true })) {
|
|
43207
43593
|
if (entry.isSymbolicLink() || excluded(entry.name)) continue;
|
|
43208
43594
|
const path4 = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
43209
|
-
if (entry.isDirectory()) walkSkillFolder(
|
|
43210
|
-
else if (entry.isFile()) files[path4] =
|
|
43595
|
+
if (entry.isDirectory()) walkSkillFolder(join23(directory, entry.name), path4, files);
|
|
43596
|
+
else if (entry.isFile()) files[path4] = readFileSync21(join23(directory, entry.name)).toString("base64");
|
|
43211
43597
|
}
|
|
43212
43598
|
}
|
|
43213
43599
|
function collectSkillFolders(projectDir) {
|
|
43214
|
-
const root =
|
|
43600
|
+
const root = join23(resolve13(projectDir), SKILLS_DIR);
|
|
43215
43601
|
const folders = {};
|
|
43216
43602
|
if (!existsSync17(root) || lstatSync5(root).isSymbolicLink() || !lstatSync5(root).isDirectory()) return folders;
|
|
43217
43603
|
for (const entry of readdirSync7(root, { withFileTypes: true })) {
|
|
43218
43604
|
if (entry.isSymbolicLink() || !entry.isDirectory()) continue;
|
|
43219
43605
|
if (!ALIAS.test(entry.name)) throw usageError(`${SKILLS_DIR}/${entry.name}: name the folder with the Skill alias (lowercase letters, digits, - or _).`);
|
|
43220
43606
|
const files = {};
|
|
43221
|
-
walkSkillFolder(
|
|
43607
|
+
walkSkillFolder(join23(root, entry.name), "", files);
|
|
43222
43608
|
if (!files["SKILL.md"]) throw usageError(`${SKILLS_DIR}/${entry.name} needs a SKILL.md.`);
|
|
43223
43609
|
folders[entry.name] = { files, digest: appFilesDigest(files) };
|
|
43224
43610
|
}
|
|
@@ -43229,7 +43615,7 @@ function skillFolderFiles(files) {
|
|
|
43229
43615
|
}
|
|
43230
43616
|
function writeSkillFolder(projectDir, alias, files, { sourceSnapshot } = {}) {
|
|
43231
43617
|
if (!ALIAS.test(alias)) throw usageError(`Unsafe Skill alias: ${alias}`);
|
|
43232
|
-
const root =
|
|
43618
|
+
const root = join23(resolve13(projectDir), SKILLS_DIR, alias);
|
|
43233
43619
|
const entries = Object.entries(files || {}).map(([path4, encoded]) => {
|
|
43234
43620
|
safeRelativePath(path4, `Skill ${alias}`);
|
|
43235
43621
|
return [path4, Buffer.from(encoded, "base64")];
|
|
@@ -43238,13 +43624,13 @@ function writeSkillFolder(projectDir, alias, files, { sourceSnapshot } = {}) {
|
|
|
43238
43624
|
const changed = () => usageError(`${SKILLS_DIR}/${alias} changed while pulling its current Skill. Keep these local files and pull into a new directory.`);
|
|
43239
43625
|
const readSnapshot = () => {
|
|
43240
43626
|
const current = {};
|
|
43241
|
-
if (!existsSync17(root) || lstatSync5(root).isSymbolicLink() || !lstatSync5(root).isDirectory() || lstatSync5(
|
|
43627
|
+
if (!existsSync17(root) || lstatSync5(root).isSymbolicLink() || !lstatSync5(root).isDirectory() || lstatSync5(dirname22(root)).isSymbolicLink()) throw changed();
|
|
43242
43628
|
const walk = (directory, prefix = "") => {
|
|
43243
43629
|
for (const entry of readdirSync7(directory, { withFileTypes: true })) {
|
|
43244
43630
|
if (entry.isSymbolicLink() || excluded(entry.name)) throw changed();
|
|
43245
43631
|
const path4 = prefix + entry.name;
|
|
43246
|
-
if (entry.isDirectory()) walk(
|
|
43247
|
-
else if (entry.isFile()) current[path4] =
|
|
43632
|
+
if (entry.isDirectory()) walk(join23(directory, entry.name), path4 + "/");
|
|
43633
|
+
else if (entry.isFile()) current[path4] = readFileSync21(join23(directory, entry.name)).toString("base64");
|
|
43248
43634
|
else throw changed();
|
|
43249
43635
|
}
|
|
43250
43636
|
};
|
|
@@ -43254,23 +43640,23 @@ function writeSkillFolder(projectDir, alias, files, { sourceSnapshot } = {}) {
|
|
|
43254
43640
|
const expected = appFilesDigest(sourceSnapshot);
|
|
43255
43641
|
if (appFilesDigest(readSnapshot()) !== expected) throw changed();
|
|
43256
43642
|
if (appFilesDigest(files) === expected) return;
|
|
43257
|
-
const staging =
|
|
43643
|
+
const staging = join23(resolve13(projectDir), ".notis", `skill-pull-${randomUUID11()}`);
|
|
43258
43644
|
const backup = `${staging}-previous`;
|
|
43259
|
-
|
|
43645
|
+
mkdirSync13(staging, { recursive: true });
|
|
43260
43646
|
let displaced = false;
|
|
43261
43647
|
try {
|
|
43262
43648
|
for (const [path4, bytes] of entries) {
|
|
43263
|
-
const target =
|
|
43264
|
-
|
|
43265
|
-
|
|
43649
|
+
const target = join23(staging, path4);
|
|
43650
|
+
mkdirSync13(dirname22(target), { recursive: true });
|
|
43651
|
+
writeFileSync14(target, bytes, { flag: "wx" });
|
|
43266
43652
|
}
|
|
43267
43653
|
if (appFilesDigest(readSnapshot()) !== expected) throw changed();
|
|
43268
|
-
|
|
43654
|
+
renameSync11(root, backup);
|
|
43269
43655
|
displaced = true;
|
|
43270
43656
|
try {
|
|
43271
|
-
|
|
43657
|
+
renameSync11(staging, root);
|
|
43272
43658
|
} catch (error) {
|
|
43273
|
-
|
|
43659
|
+
renameSync11(backup, root);
|
|
43274
43660
|
displaced = false;
|
|
43275
43661
|
throw error;
|
|
43276
43662
|
}
|
|
@@ -43283,10 +43669,10 @@ function writeSkillFolder(projectDir, alias, files, { sourceSnapshot } = {}) {
|
|
|
43283
43669
|
return;
|
|
43284
43670
|
}
|
|
43285
43671
|
for (const [path4, bytes] of entries) {
|
|
43286
|
-
const target =
|
|
43287
|
-
|
|
43672
|
+
const target = join23(root, path4);
|
|
43673
|
+
mkdirSync13(dirname22(target), { recursive: true });
|
|
43288
43674
|
try {
|
|
43289
|
-
|
|
43675
|
+
writeFileSync14(target, bytes, { flag: "wx" });
|
|
43290
43676
|
} catch (error) {
|
|
43291
43677
|
if (error?.code === "EEXIST") throw usageError(`${SKILLS_DIR}/${alias}/${path4} already exists in the pulled source; the Skill folder cannot be written over it.`);
|
|
43292
43678
|
throw error;
|
|
@@ -43383,7 +43769,7 @@ function computeSpaceSourceChanges({ lock, resources, folders, manifest }) {
|
|
|
43383
43769
|
skills: { edited: Object.keys(edits).sort(), created: Object.keys(creations).sort() },
|
|
43384
43770
|
links: { added: add.map((entry) => `${entry.alias} (${entry.kind})`), removed: remove.map((entry) => `${entry.kind} ${entry.resource_id}`) }
|
|
43385
43771
|
};
|
|
43386
|
-
return { changes, summary, fingerprint:
|
|
43772
|
+
return { changes, summary, fingerprint: createHash16("sha256").update(stableJson(changes)).digest("hex") };
|
|
43387
43773
|
}
|
|
43388
43774
|
function applyPublication({ lock, folders, result }) {
|
|
43389
43775
|
const applied = result?.applied;
|
|
@@ -43425,8 +43811,8 @@ function describeAppliedChanges(result) {
|
|
|
43425
43811
|
|
|
43426
43812
|
// src/command-specs/spaces.js
|
|
43427
43813
|
init_errors();
|
|
43428
|
-
import { existsSync as existsSync19, readFileSync as
|
|
43429
|
-
import { join as
|
|
43814
|
+
import { existsSync as existsSync19, readFileSync as readFileSync22 } from "node:fs";
|
|
43815
|
+
import { join as join25, resolve as resolve16 } from "node:path";
|
|
43430
43816
|
|
|
43431
43817
|
// src/command-specs/version-history.js
|
|
43432
43818
|
init_errors();
|
|
@@ -43448,7 +43834,7 @@ function versionName(options) {
|
|
|
43448
43834
|
}
|
|
43449
43835
|
|
|
43450
43836
|
// src/command-specs/spaces.js
|
|
43451
|
-
import { createHash as
|
|
43837
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
43452
43838
|
|
|
43453
43839
|
// src/command-specs/views.js
|
|
43454
43840
|
init_errors();
|
|
@@ -43456,7 +43842,7 @@ init_errors();
|
|
|
43456
43842
|
// src/runtime/view-render.js
|
|
43457
43843
|
import { existsSync as existsSync18 } from "node:fs";
|
|
43458
43844
|
import { mkdir as mkdir2, writeFile as writeFile2, unlink } from "node:fs/promises";
|
|
43459
|
-
import { resolve as resolve14, join as
|
|
43845
|
+
import { resolve as resolve14, join as join24 } from "node:path";
|
|
43460
43846
|
import { fileURLToPath as fileURLToPath11 } from "node:url";
|
|
43461
43847
|
init_errors();
|
|
43462
43848
|
async function rendererLibrary() {
|
|
@@ -43499,7 +43885,8 @@ async function renderViewWithCliRuntime({
|
|
|
43499
43885
|
message: error.message,
|
|
43500
43886
|
exitCode: EXIT_CODES.backend,
|
|
43501
43887
|
retryable: error.status >= 500 || error.status === 429,
|
|
43502
|
-
cause: error
|
|
43888
|
+
cause: error,
|
|
43889
|
+
details: typeof error.stage === "string" && /^[a-z_]{1,40}$/.test(error.stage) ? { stage: error.stage } : {}
|
|
43503
43890
|
});
|
|
43504
43891
|
throw error;
|
|
43505
43892
|
}
|
|
@@ -43512,7 +43899,7 @@ async function renderViewWithCliRuntime({
|
|
|
43512
43899
|
["screenshot", "view.png", result.screenshot ? Buffer.from(result.screenshot.data_base64, "base64") : void 0]
|
|
43513
43900
|
]) {
|
|
43514
43901
|
if (bytes === void 0) continue;
|
|
43515
|
-
const path4 =
|
|
43902
|
+
const path4 = join24(root, name);
|
|
43516
43903
|
await writeFile2(path4, bytes, { flag: "wx", mode: 384 });
|
|
43517
43904
|
created.push(path4);
|
|
43518
43905
|
artifacts[kind] = path4;
|
|
@@ -43526,7 +43913,7 @@ async function renderViewWithCliRuntime({
|
|
|
43526
43913
|
|
|
43527
43914
|
// src/command-specs/views.js
|
|
43528
43915
|
import { resolve as resolve15 } from "node:path";
|
|
43529
|
-
import { randomUUID as
|
|
43916
|
+
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
43530
43917
|
function viewRenderCommandSpec({ screenshotOnly = false } = {}) {
|
|
43531
43918
|
const command_path = screenshotOnly ? ["spaces", "screenshot"] : ["views", "render"];
|
|
43532
43919
|
return {
|
|
@@ -43552,7 +43939,7 @@ function viewRenderCommandSpec({ screenshotOnly = false } = {}) {
|
|
|
43552
43939
|
const width = ctx.options.width === void 0 ? 1440 : Number(ctx.options.width);
|
|
43553
43940
|
const viewAs = ctx.options.viewAs;
|
|
43554
43941
|
if (viewAs !== void 0 && viewAs !== "public") throw usageError("--view-as accepts only public.");
|
|
43555
|
-
const directory = resolve15(ctx.options.outputDir || `.notis/renders/${
|
|
43942
|
+
const directory = resolve15(ctx.options.outputDir || `.notis/renders/${randomUUID12()}`);
|
|
43556
43943
|
const controller = new AbortController(), cancel = () => controller.abort();
|
|
43557
43944
|
process.once("SIGINT", cancel);
|
|
43558
43945
|
process.once("SIGTERM", cancel);
|
|
@@ -43629,9 +44016,19 @@ var viewsCommandSpecs = [{
|
|
|
43629
44016
|
}, viewRenderCommandSpec()];
|
|
43630
44017
|
|
|
43631
44018
|
// src/command-specs/spaces.js
|
|
43632
|
-
function selected(ctx) {
|
|
43633
|
-
|
|
43634
|
-
|
|
44019
|
+
async function selected(ctx) {
|
|
44020
|
+
const directory = assertSourceRoot(resolveProjectDir(ctx.args.dir || "."));
|
|
44021
|
+
if (ctx.options.space) return { directory, key: ctx.options.space };
|
|
44022
|
+
const workspace = await loadAppConfig(directory);
|
|
44023
|
+
const keys = workspace && typeof workspace.spaces === "object" && workspace.spaces ? Object.keys(workspace.spaces) : [];
|
|
44024
|
+
if (keys.length === 1) return { directory, key: keys[0] };
|
|
44025
|
+
throw usageError(keys.length ? `Choose the Space with --space <key>: this workspace declares ${keys.join(", ")}.` : "Choose the independent Space with --space <key>.");
|
|
44026
|
+
}
|
|
44027
|
+
function destinationSpaceId(ctx, directory) {
|
|
44028
|
+
if (ctx.options.spaceId) return ctx.options.spaceId;
|
|
44029
|
+
const lock = readSpaceLock(directory);
|
|
44030
|
+
if (lock && lock.api_base === ctx.runtime.apiBase.replace(/\/$/, "")) return lock.space_id;
|
|
44031
|
+
throw usageError("Pass --space-id <id> for the existing Space.");
|
|
43635
44032
|
}
|
|
43636
44033
|
function requestId(ctx) {
|
|
43637
44034
|
const value = ctx.options.requestId || ctx.globalOptions.idempotencyKey;
|
|
@@ -43738,24 +44135,24 @@ function sameVerification(verification, body, sourceDigest) {
|
|
|
43738
44135
|
return verification?.valid === true && verification.space_id === body.space_id && verification.source_digest === sourceDigest && JSON.stringify(Object.entries(verification.reuse_grants || {}).sort()) === JSON.stringify(Object.entries(body.reuse_grants).sort()) && (verification.authorization_mode ?? "authorize_missing") === (body.authorization_mode ?? "authorize_missing");
|
|
43739
44136
|
}
|
|
43740
44137
|
async function sourceRelease(ctx, publish, stageOnly = false) {
|
|
43741
|
-
const { directory, key: key2 } = selected(ctx);
|
|
43742
|
-
|
|
44138
|
+
const { directory, key: key2 } = await selected(ctx);
|
|
44139
|
+
const spaceId = destinationSpaceId(ctx, directory);
|
|
43743
44140
|
const intentKey = publish ? requestId(ctx) : null;
|
|
43744
44141
|
clearSpaceScreenshots(directory, key2);
|
|
43745
44142
|
const release = await prepareSpaceRelease(directory, key2);
|
|
43746
44143
|
try {
|
|
43747
44144
|
if (publish) requireSpaceIcon(release.manifest, key2);
|
|
43748
|
-
const identity = [ctx.runtime.apiBase.replace(/\/$/, ""), ctx.runtime.profileName, key2,
|
|
44145
|
+
const identity = [ctx.runtime.apiBase.replace(/\/$/, ""), ctx.runtime.profileName, key2, spaceId, intentKey];
|
|
43749
44146
|
let verification = publish && !ctx.options.dryRun ? spacePublicationIntent(directory, identity) : null;
|
|
43750
44147
|
const local = intentChanges(
|
|
43751
44148
|
directory,
|
|
43752
|
-
|
|
44149
|
+
spaceId,
|
|
43753
44150
|
release.manifest,
|
|
43754
|
-
localSpaceChanges(directory,
|
|
44151
|
+
localSpaceChanges(directory, spaceId, release.manifest),
|
|
43755
44152
|
verification
|
|
43756
44153
|
);
|
|
43757
44154
|
const body = {
|
|
43758
|
-
space_id:
|
|
44155
|
+
space_id: spaceId,
|
|
43759
44156
|
manifest: release.manifest,
|
|
43760
44157
|
source_files: release.sourceFiles,
|
|
43761
44158
|
artifact_files: release.files,
|
|
@@ -43913,7 +44310,7 @@ async function materializeSpaceLinks(ctx, { projectDir, spaceId, sourceRevision
|
|
|
43913
44310
|
return { links: resourceEntries(list), skills: Object.keys(skills).sort(), skipped };
|
|
43914
44311
|
}
|
|
43915
44312
|
function refreshPulledSdk(projectDir) {
|
|
43916
|
-
if (!existsSync19(
|
|
44313
|
+
if (!existsSync19(join25(projectDir, "packages", "sdk", "package.json"))) return { sdk: null, notes: [], warnings: [] };
|
|
43917
44314
|
const messages = [];
|
|
43918
44315
|
let sdk = null;
|
|
43919
44316
|
try {
|
|
@@ -44348,7 +44745,7 @@ var spacesCommandSpecs = [
|
|
|
44348
44745
|
throw usageError("The server did not return a verified Space source snapshot.");
|
|
44349
44746
|
}
|
|
44350
44747
|
const archiveBuffer = Buffer.from(source.source_archive, "base64");
|
|
44351
|
-
if (archiveBuffer.toString("base64") !== source.source_archive ||
|
|
44748
|
+
if (archiveBuffer.toString("base64") !== source.source_archive || createHash17("sha256").update(archiveBuffer).digest("hex") !== source.archive_sha256) {
|
|
44352
44749
|
throw usageError("The downloaded Space source bytes do not match their fingerprint.");
|
|
44353
44750
|
}
|
|
44354
44751
|
sourceLink.source_digest = source.source_digest;
|
|
@@ -44377,8 +44774,8 @@ var spacesCommandSpecs = [
|
|
|
44377
44774
|
args_schema: {
|
|
44378
44775
|
arguments: [{ token: "[dir]", key: "dir", description: "Source workspace (default current directory)." }],
|
|
44379
44776
|
options: [
|
|
44380
|
-
{ flags: "--space <key>", description: "Exact source key from the workspace index." },
|
|
44381
|
-
{ flags: "--space-id <id>", description: "Exact existing destination Space." },
|
|
44777
|
+
{ flags: "--space <key>", description: "Exact source key from the workspace index. Optional when the workspace holds one Space." },
|
|
44778
|
+
{ flags: "--space-id <id>", description: "Exact existing destination Space. Optional in a pulled workspace: the Space it was pulled from." },
|
|
44382
44779
|
{ flags: "--reuse-grants <json>", description: "Explicit action-key to saved-grant-ID map. Otherwise your own connections are used." },
|
|
44383
44780
|
{ flags: "--reuse-grants-only", description: "Never authorize new actions. Reuse only the supplied saved grants; other declarations remain unavailable. Requires existing bound databases." },
|
|
44384
44781
|
...operation !== "verify" ? [requestOption, { flags: "--dry-run", description: "Validate without uploading or publishing." }] : []
|
|
@@ -44551,7 +44948,7 @@ var spacesCommandSpecs = [
|
|
|
44551
44948
|
return remote(ctx, "grant-authorize", { body: {
|
|
44552
44949
|
space_id: ctx.args.spaceId,
|
|
44553
44950
|
request_id: requestId(ctx),
|
|
44554
|
-
template: object3(
|
|
44951
|
+
template: object3(readFileSync22(resolve16(ctx.options.template), "utf8"), "--template"),
|
|
44555
44952
|
document_id: ctx.options.record,
|
|
44556
44953
|
dry_run: Boolean(ctx.options.dryRun)
|
|
44557
44954
|
} });
|
|
@@ -44741,7 +45138,7 @@ var spacesCommandSpecs = [
|
|
|
44741
45138
|
when_to_use: "Prepare a selected Space for verification without publishing it or changing siblings.",
|
|
44742
45139
|
args_schema: {
|
|
44743
45140
|
arguments: [{ token: "[dir]", key: "dir", description: "Source workspace (default current directory)." }],
|
|
44744
|
-
options: [{ flags: "--space <key>", description: "Exact source key from the workspace Space index." }]
|
|
45141
|
+
options: [{ flags: "--space <key>", description: "Exact source key from the workspace Space index. Optional when the workspace holds one Space." }]
|
|
44745
45142
|
},
|
|
44746
45143
|
examples: ["notis spaces build . --space overview"],
|
|
44747
45144
|
mutates: true,
|
|
@@ -44749,7 +45146,7 @@ var spacesCommandSpecs = [
|
|
|
44749
45146
|
require_auth: false,
|
|
44750
45147
|
backend_call: { type: "local", name: "space_build" },
|
|
44751
45148
|
async handler(ctx) {
|
|
44752
|
-
const { directory, key: key2 } = selected(ctx);
|
|
45149
|
+
const { directory, key: key2 } = await selected(ctx);
|
|
44753
45150
|
const result = await buildSpaceArtifact(directory, key2, { stdio: ctx.output.isMachineMode() ? "pipe" : "inherit" });
|
|
44754
45151
|
return ctx.output.emitSuccess({ command: "spaces build", data: result, humanSummary: `Built ${key2}; no Space was published.` });
|
|
44755
45152
|
}
|
|
@@ -44760,7 +45157,7 @@ var spacesCommandSpecs = [
|
|
|
44760
45157
|
when_to_use: "Read the selected source definition without loading sibling definitions or account resources.",
|
|
44761
45158
|
args_schema: {
|
|
44762
45159
|
arguments: [{ token: "[dir]", key: "dir", description: "Source workspace (default current directory)." }],
|
|
44763
|
-
options: [{ flags: "--space <key>", description: "Exact source key from the workspace Space index." }]
|
|
45160
|
+
options: [{ flags: "--space <key>", description: "Exact source key from the workspace Space index. Optional when the workspace holds one Space." }]
|
|
44764
45161
|
},
|
|
44765
45162
|
examples: ["notis spaces inspect . --space overview"],
|
|
44766
45163
|
mutates: false,
|
|
@@ -44768,7 +45165,7 @@ var spacesCommandSpecs = [
|
|
|
44768
45165
|
require_auth: false,
|
|
44769
45166
|
backend_call: { type: "local", name: "space_source_inspect" },
|
|
44770
45167
|
async handler(ctx) {
|
|
44771
|
-
const { directory, key: key2 } = selected(ctx);
|
|
45168
|
+
const { directory, key: key2 } = await selected(ctx);
|
|
44772
45169
|
const selection = await loadSelectedSpace(directory, key2);
|
|
44773
45170
|
return ctx.output.emitSuccess({
|
|
44774
45171
|
command: "spaces inspect",
|
|
@@ -44998,7 +45395,7 @@ var documentsCommandSpecs = [
|
|
|
44998
45395
|
|
|
44999
45396
|
// src/runtime/native-record-files.js
|
|
45000
45397
|
import { open } from "node:fs/promises";
|
|
45001
|
-
import { createHash as
|
|
45398
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
45002
45399
|
import { basename as basename7, extname as extname3 } from "node:path";
|
|
45003
45400
|
init_errors();
|
|
45004
45401
|
var MAX_BYTES = 8 * 1024 * 1024;
|
|
@@ -45047,7 +45444,7 @@ async function uploadNativeRecordFileWithCliRuntime({
|
|
|
45047
45444
|
} finally {
|
|
45048
45445
|
await handle.close();
|
|
45049
45446
|
}
|
|
45050
|
-
const digest =
|
|
45447
|
+
const digest = createHash18("sha256").update(data).digest("hex");
|
|
45051
45448
|
const body = {
|
|
45052
45449
|
protocol: 1,
|
|
45053
45450
|
target,
|
|
@@ -45106,13 +45503,13 @@ var filesCommandSpecs = [{
|
|
|
45106
45503
|
}];
|
|
45107
45504
|
|
|
45108
45505
|
// src/command-specs/cc.js
|
|
45109
|
-
import { randomUUID as
|
|
45506
|
+
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
45110
45507
|
import fs5 from "node:fs";
|
|
45111
45508
|
|
|
45112
45509
|
// src/runtime/cloud-transfer.js
|
|
45113
45510
|
init_errors();
|
|
45114
45511
|
init_profiles();
|
|
45115
|
-
import { createHash as
|
|
45512
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
45116
45513
|
import fs4 from "node:fs";
|
|
45117
45514
|
import fsp from "node:fs/promises";
|
|
45118
45515
|
import path3 from "node:path";
|
|
@@ -45169,7 +45566,7 @@ function manifestText(files) {
|
|
|
45169
45566
|
`).join("");
|
|
45170
45567
|
}
|
|
45171
45568
|
function digestOf(text2) {
|
|
45172
|
-
return
|
|
45569
|
+
return createHash19("sha256").update(text2).digest("hex");
|
|
45173
45570
|
}
|
|
45174
45571
|
function formatBytes(bytes) {
|
|
45175
45572
|
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
@@ -45227,7 +45624,7 @@ async function collectFiles(local, { followLinks = true } = {}) {
|
|
|
45227
45624
|
return { kind: "dir", files, skipped };
|
|
45228
45625
|
}
|
|
45229
45626
|
async function hashFile(abs) {
|
|
45230
|
-
const hash2 =
|
|
45627
|
+
const hash2 = createHash19("sha256");
|
|
45231
45628
|
await new Promise((resolve17, reject) => {
|
|
45232
45629
|
fs4.createReadStream(abs, { highWaterMark: 4 * 1024 * 1024 }).on("data", (data) => hash2.update(data)).on("error", reject).on("end", resolve17);
|
|
45233
45630
|
});
|
|
@@ -45576,7 +45973,7 @@ async function push(ctx, local, target, { streams = PARALLEL_STREAMS, followLink
|
|
|
45576
45973
|
await session.fetch(`f/${task.index}?offset=${offset}`, {
|
|
45577
45974
|
method: "PUT",
|
|
45578
45975
|
body: data,
|
|
45579
|
-
headers: { "x-notis-sha256":
|
|
45976
|
+
headers: { "x-notis-sha256": createHash19("sha256").update(data).digest("hex"), "content-type": "application/octet-stream" }
|
|
45580
45977
|
});
|
|
45581
45978
|
timings.large.bytes += task.bytes;
|
|
45582
45979
|
largeStarted.end = Date.now();
|
|
@@ -45762,7 +46159,7 @@ async function callShell(ctx, args, { mutating }) {
|
|
|
45762
46159
|
toolName: SANDBOX_SHELL_TOOL,
|
|
45763
46160
|
arguments_: args,
|
|
45764
46161
|
mutating,
|
|
45765
|
-
idempotencyKey: mutating ? nextIdempotencyKey(ctx.globalOptions) :
|
|
46162
|
+
idempotencyKey: mutating ? nextIdempotencyKey(ctx.globalOptions) : randomUUID13(),
|
|
45766
46163
|
sendIdempotencyKeyWhenReading: true
|
|
45767
46164
|
});
|
|
45768
46165
|
return { result, payload: extractToolResult(result.payload) || {} };
|
|
@@ -46131,31 +46528,31 @@ var ccCommandSpecs = [
|
|
|
46131
46528
|
// src/command-specs/computer.js
|
|
46132
46529
|
init_errors();
|
|
46133
46530
|
import { spawn as spawn4, spawnSync as spawnSync4 } from "node:child_process";
|
|
46134
|
-
import { randomUUID as
|
|
46135
|
-
import { existsSync as existsSync21, mkdirSync as
|
|
46531
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
46532
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync15, readFileSync as readFileSync24 } from "node:fs";
|
|
46136
46533
|
import { connect as netConnect } from "node:net";
|
|
46137
46534
|
init_computer_identity();
|
|
46138
46535
|
init_profiles();
|
|
46139
46536
|
|
|
46140
46537
|
// src/runtime/computer-ssh.js
|
|
46141
|
-
import { chmodSync as chmodSync2, existsSync as existsSync20, mkdirSync as
|
|
46538
|
+
import { chmodSync as chmodSync2, existsSync as existsSync20, mkdirSync as mkdirSync14, readFileSync as readFileSync23, renameSync as renameSync12, writeFileSync as writeFileSync15 } from "node:fs";
|
|
46142
46539
|
import { homedir as homedir11 } from "node:os";
|
|
46143
|
-
import { dirname as
|
|
46540
|
+
import { dirname as dirname23, join as join26 } from "node:path";
|
|
46144
46541
|
var SSH_HOST_ALIAS = "notis-computer";
|
|
46145
46542
|
var SSH_USER = "user";
|
|
46146
46543
|
var INCLUDE_MARKER = "# notis-computer-ssh";
|
|
46147
46544
|
var HOST_KEY_TYPE = /^(ssh-ed25519|ssh-rsa|ecdsa-sha2-nistp(256|384|521)|sk-ssh-ed25519@openssh\.com|sk-ecdsa-sha2-nistp256@openssh\.com|rsa-sha2-(256|512))$/;
|
|
46148
46545
|
function sshPaths(home = homedir11()) {
|
|
46149
|
-
const dir =
|
|
46546
|
+
const dir = join26(home, ".ssh", "notis");
|
|
46150
46547
|
return {
|
|
46151
|
-
sshDir:
|
|
46548
|
+
sshDir: join26(home, ".ssh"),
|
|
46152
46549
|
dir,
|
|
46153
|
-
userConfig:
|
|
46154
|
-
config:
|
|
46155
|
-
key:
|
|
46156
|
-
publicKey:
|
|
46157
|
-
proxy:
|
|
46158
|
-
knownHosts:
|
|
46550
|
+
userConfig: join26(home, ".ssh", "config"),
|
|
46551
|
+
config: join26(dir, "config"),
|
|
46552
|
+
key: join26(dir, "id_ed25519"),
|
|
46553
|
+
publicKey: join26(dir, "id_ed25519.pub"),
|
|
46554
|
+
proxy: join26(dir, "proxy"),
|
|
46555
|
+
knownHosts: join26(dir, "known_hosts")
|
|
46159
46556
|
};
|
|
46160
46557
|
}
|
|
46161
46558
|
function shellQuote2(value) {
|
|
@@ -46216,17 +46613,17 @@ function knownHostsText(hostKey) {
|
|
|
46216
46613
|
` : "";
|
|
46217
46614
|
}
|
|
46218
46615
|
function writeAtomic(path4, text2, mode) {
|
|
46219
|
-
|
|
46616
|
+
mkdirSync14(dirname23(path4), { recursive: true, mode: 448 });
|
|
46220
46617
|
const temp = `${path4}.${process.pid}.tmp`;
|
|
46221
|
-
|
|
46618
|
+
writeFileSync15(temp, text2, { mode });
|
|
46222
46619
|
chmodSync2(temp, mode);
|
|
46223
|
-
|
|
46620
|
+
renameSync12(temp, path4);
|
|
46224
46621
|
}
|
|
46225
46622
|
function writeSshFiles({ paths, nodePath, cliPath, profileName, configFile }) {
|
|
46226
|
-
|
|
46623
|
+
mkdirSync14(paths.sshDir, { recursive: true, mode: 448 });
|
|
46227
46624
|
writeAtomic(paths.config, sshConfigText(paths), 384);
|
|
46228
46625
|
writeAtomic(paths.proxy, proxyScriptText({ nodePath, cliPath, profileName, configFile }), 448);
|
|
46229
|
-
const existing = existsSync20(paths.userConfig) ?
|
|
46626
|
+
const existing = existsSync20(paths.userConfig) ? readFileSync23(paths.userConfig, "utf8") : "";
|
|
46230
46627
|
const next = withInclude(existing, paths);
|
|
46231
46628
|
if (next !== existing) writeAtomic(paths.userConfig, next, 384);
|
|
46232
46629
|
}
|
|
@@ -46252,10 +46649,10 @@ var MANAGE_TOOL = "LOCAL_NOTIS_MANAGE_CLOUD_COMPUTER";
|
|
|
46252
46649
|
var WAIT_TIMEOUT_MS = 24e4;
|
|
46253
46650
|
var PROXY_TIMEOUT_MS = 9e4;
|
|
46254
46651
|
function readPublicKey(paths) {
|
|
46255
|
-
return existsSync21(paths.publicKey) ?
|
|
46652
|
+
return existsSync21(paths.publicKey) ? readFileSync24(paths.publicKey, "utf8").trim() : "";
|
|
46256
46653
|
}
|
|
46257
46654
|
function makeKey(paths, deviceName) {
|
|
46258
|
-
|
|
46655
|
+
mkdirSync15(paths.dir, { recursive: true, mode: 448 });
|
|
46259
46656
|
const result = spawnSync4("ssh-keygen", [
|
|
46260
46657
|
"-q",
|
|
46261
46658
|
"-t",
|
|
@@ -46396,8 +46793,22 @@ var STATUS_LINES = {
|
|
|
46396
46793
|
moving: "Your Cloud Computer is moving to a bigger disk.",
|
|
46397
46794
|
none: "You have no Cloud Computer yet. It starts the first time Notis needs it."
|
|
46398
46795
|
};
|
|
46796
|
+
var MACHINE_LINES = {
|
|
46797
|
+
starting: "Your Cloud Computer is starting.",
|
|
46798
|
+
stopping: "Your Cloud Computer is finishing a stop. It starts again when Notis has work to do."
|
|
46799
|
+
};
|
|
46800
|
+
var AWAKE_IDLE = "Your Cloud Computer is awake, with nothing to do. It goes to sleep after its sleep time.";
|
|
46801
|
+
var AWAKE_ALWAYS_ON = "Your Cloud Computer is awake, with nothing to do. It stays on: always on is set.";
|
|
46802
|
+
function liveLine(computer) {
|
|
46803
|
+
if (computer.status === "stopped" && computer.machine_state === "awake") {
|
|
46804
|
+
return computer.sleep && computer.sleep.after_seconds === null ? AWAKE_ALWAYS_ON : AWAKE_IDLE;
|
|
46805
|
+
}
|
|
46806
|
+
return ["running", "stopped"].includes(computer.status) ? MACHINE_LINES[computer.machine_state] : null;
|
|
46807
|
+
}
|
|
46399
46808
|
function statusText(computer) {
|
|
46400
|
-
if (computer.status !== "not_responding")
|
|
46809
|
+
if (computer.status !== "not_responding") {
|
|
46810
|
+
return liveLine(computer) || STATUS_LINES[computer.status] || STATUS_LINES.none;
|
|
46811
|
+
}
|
|
46401
46812
|
const reason = computer.status_reason ? ` Reason: ${computer.status_reason}.` : "";
|
|
46402
46813
|
const saved = computer.last_saved_at ? ` Last saved ${computer.last_saved_at}.` : "";
|
|
46403
46814
|
return `Your Cloud Computer is not responding.${reason}${saved} Restart it with: notis computer restart`;
|
|
@@ -46405,7 +46816,7 @@ function statusText(computer) {
|
|
|
46405
46816
|
async function machineAction(ctx, action) {
|
|
46406
46817
|
const command = `computer ${action}`;
|
|
46407
46818
|
const callerKey = ctx.globalOptions.idempotencyKey;
|
|
46408
|
-
const first = await callComputer(ctx, MANAGE_TOOL, { action }, callerKey ||
|
|
46819
|
+
const first = await callComputer(ctx, MANAGE_TOOL, { action }, callerKey || randomUUID14());
|
|
46409
46820
|
const preview = findConfirmationPreview(first.payload);
|
|
46410
46821
|
if (!preview) {
|
|
46411
46822
|
throw new CliError({
|
|
@@ -46445,7 +46856,7 @@ ${reason}`
|
|
|
46445
46856
|
ctx,
|
|
46446
46857
|
MANAGE_TOOL,
|
|
46447
46858
|
decision.arguments,
|
|
46448
|
-
callerKey ? `${callerKey}.confirm` :
|
|
46859
|
+
callerKey ? `${callerKey}.confirm` : randomUUID14()
|
|
46449
46860
|
);
|
|
46450
46861
|
return ctx.output.emitSuccess({
|
|
46451
46862
|
command,
|
|
@@ -46467,7 +46878,7 @@ var computerCommandSpecs = [{
|
|
|
46467
46878
|
require_auth: true,
|
|
46468
46879
|
backend_call: { type: "tool", name: GET_TOOL },
|
|
46469
46880
|
async handler(ctx) {
|
|
46470
|
-
const { result, payload } = await callComputer(ctx, GET_TOOL, {},
|
|
46881
|
+
const { result, payload } = await callComputer(ctx, GET_TOOL, {}, randomUUID14());
|
|
46471
46882
|
const computer = payload.cloud_computer || {};
|
|
46472
46883
|
return ctx.output.emitSuccess({
|
|
46473
46884
|
command: "computer status",
|
|
@@ -46785,6 +47196,7 @@ ${lines.join("\n")}
|
|
|
46785
47196
|
init_errors();
|
|
46786
47197
|
|
|
46787
47198
|
// src/runtime/telemetry.js
|
|
47199
|
+
init_profiles();
|
|
46788
47200
|
var ERROR_CATEGORIES = /* @__PURE__ */ new Map([
|
|
46789
47201
|
[2, "usage"],
|
|
46790
47202
|
[3, "auth"],
|
|
@@ -46837,10 +47249,18 @@ async function reportCliCommand({
|
|
|
46837
47249
|
if (cliBackendKind(spec) !== "local" || !runtime?.jwt || !runtime?.apiBase || typeof fetchImpl !== "function") {
|
|
46838
47250
|
return false;
|
|
46839
47251
|
}
|
|
47252
|
+
if (runtime.credentialKind === "oauth" && oauthGrantOnRetiredAddress({
|
|
47253
|
+
oauth_issuer: runtime.oauthIssuer,
|
|
47254
|
+
oauth_resource: runtime.oauthResource,
|
|
47255
|
+
oauth_access_token: runtime.jwt
|
|
47256
|
+
})) {
|
|
47257
|
+
return false;
|
|
47258
|
+
}
|
|
47259
|
+
const apiBase = runtime.credentialKind === "oauth" && runtime.oauthApiBase || runtime.apiBase;
|
|
46840
47260
|
const controller = new AbortController();
|
|
46841
47261
|
const timeout = setTimeout(() => controller.abort(), 1500);
|
|
46842
47262
|
try {
|
|
46843
|
-
const response = await fetchImpl(`${
|
|
47263
|
+
const response = await fetchImpl(`${apiBase}/cli_telemetry`, {
|
|
46844
47264
|
method: "POST",
|
|
46845
47265
|
headers: {
|
|
46846
47266
|
Authorization: `Bearer ${runtime.jwt}`,
|
|
@@ -46869,8 +47289,8 @@ init_channel();
|
|
|
46869
47289
|
init_profiles();
|
|
46870
47290
|
function readCliVersion() {
|
|
46871
47291
|
try {
|
|
46872
|
-
const manifestPath =
|
|
46873
|
-
const version = JSON.parse(
|
|
47292
|
+
const manifestPath = join27(dirname24(fileURLToPath12(import.meta.url)), "..", "package.json");
|
|
47293
|
+
const version = JSON.parse(readFileSync25(manifestPath, "utf-8")).version;
|
|
46874
47294
|
if (typeof version === "string" && version.trim()) {
|
|
46875
47295
|
return version.trim();
|
|
46876
47296
|
}
|
|
@@ -47035,7 +47455,7 @@ function attachSpec(program3, parentMap, spec, specs, launchContext = {}) {
|
|
|
47035
47455
|
}
|
|
47036
47456
|
function createProgram(launchContext = {}) {
|
|
47037
47457
|
const program3 = new Command();
|
|
47038
|
-
program3.name("notis").description("Agent-first Notis CLI for Spaces and generic tool execution").version(CLI_VERSION).showHelpAfterError().option("--json", "Shortcut for --output json").option("--output <table|json|yaml|ndjson>", "Output mode override").option("--non-interactive", "Disable all interactive prompts").option("--quiet", "Suppress non-essential human output").option("--verbose", "Show extra human-readable diagnostics").option("--no-color", "Disable ANSI color output").option("--profile <name>", "CLI profile to run as (defaults to the active profile)").option("--api-base <url>", "Override the API base URL for this invocation").option("--timeout-ms <n>", "Time limit in milliseconds for each call, automatic retries included").option("--idempotency-key <key>", "Override the generated idempotency key for mutating commands").option("--no-retry", "Turn off automatic retries of interrupted calls that are safe to repeat (or set NOTIS_NO_RETRY=1)").addOption(new Option("--notis-managed-agent-hook").hideHelp());
|
|
47458
|
+
program3.name("notis").description("Agent-first Notis CLI for Spaces and generic tool execution").version(CLI_VERSION).showHelpAfterError().option("--json", "Shortcut for --output json").option("--output <table|json|yaml|ndjson>", "Output mode override").option("--non-interactive", "Disable all interactive prompts").option("--quiet", "Suppress non-essential human output").option("--verbose", "Show extra human-readable diagnostics").option("--no-color", "Disable ANSI color output").option("--profile <name>", "CLI profile to run as (defaults to the active profile)").option("--api-base <url>", "Override the API base URL for this invocation").option("--timeout-ms <n>", "Time limit in milliseconds for each call, automatic retries included").option("--idempotency-key <key>", "Override the generated idempotency key for mutating commands").option("--no-retry", "Turn off automatic retries of interrupted calls that are safe to repeat (or set NOTIS_NO_RETRY=1)").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)").option("--agent-id <id>", "Override the id this computer keeps for the agent name (generated on first use) (or set NOTIS_AGENT_ID)").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)").addOption(new Option("--notis-managed-agent-hook").hideHelp());
|
|
47039
47459
|
const parentMap = /* @__PURE__ */ new Map([["", program3]]);
|
|
47040
47460
|
for (const spec of COMMAND_SPECS) {
|
|
47041
47461
|
attachSpec(program3, parentMap, spec, COMMAND_SPECS, launchContext);
|