@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
|
@@ -5,6 +5,7 @@ import { homedir as homedir5 } from "node:os";
|
|
|
5
5
|
import { join as join8 } from "node:path";
|
|
6
6
|
|
|
7
7
|
// src/runtime/profiles.js
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
8
9
|
import {
|
|
9
10
|
existsSync as existsSync3,
|
|
10
11
|
mkdirSync as mkdirSync2,
|
|
@@ -155,13 +156,56 @@ function withConfigFileWriteLock(configFile, callback) {
|
|
|
155
156
|
// src/runtime/channel.js
|
|
156
157
|
import { existsSync as existsSync2 } from "node:fs";
|
|
157
158
|
import { isAbsolute } from "node:path";
|
|
159
|
+
|
|
160
|
+
// src/runtime/api-hosts.js
|
|
161
|
+
var CHANNEL_APIS = {
|
|
162
|
+
stable: { current: "api.notis.ai", retired: [], portal: "https://app.notis.ai" },
|
|
163
|
+
nightly: { current: "api-nightly.notis.ai", retired: ["api-beta.notis.ai"], portal: "https://app-nightly.notis.ai" }
|
|
164
|
+
};
|
|
165
|
+
var HOST_ROWS = Object.entries(CHANNEL_APIS).flatMap(([channel, row]) => [
|
|
166
|
+
{ host: row.current, channel, current: true },
|
|
167
|
+
...row.retired.map((host) => ({ host, channel, current: false }))
|
|
168
|
+
]);
|
|
169
|
+
var LIVE_API_HOSTS = [
|
|
170
|
+
...HOST_ROWS.filter((row) => row.current),
|
|
171
|
+
...HOST_ROWS.filter((row) => !row.current)
|
|
172
|
+
].map((row) => row.host);
|
|
173
|
+
var LIVE_API_ORIGINS = LIVE_API_HOSTS.map((host) => `https://${host}`);
|
|
174
|
+
function channelForApiHost(hostname) {
|
|
175
|
+
return HOST_ROWS.find((row) => row.host === hostname)?.channel || null;
|
|
176
|
+
}
|
|
177
|
+
function currentApiOrigin(channel) {
|
|
178
|
+
return `https://${CHANNEL_APIS[channel].current}`;
|
|
179
|
+
}
|
|
180
|
+
function isRetiredApiHost(hostname) {
|
|
181
|
+
return HOST_ROWS.some((row) => row.host === hostname && !row.current);
|
|
182
|
+
}
|
|
183
|
+
function parsedHttps(value) {
|
|
184
|
+
if (typeof value !== "string" || !value) return null;
|
|
185
|
+
try {
|
|
186
|
+
const parsed = new URL(value);
|
|
187
|
+
return parsed.protocol === "https:" ? parsed : null;
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function isLiveApiOrigin(value) {
|
|
193
|
+
const parsed = parsedHttps(value);
|
|
194
|
+
return Boolean(parsed) && LIVE_API_HOSTS.includes(parsed.hostname) && !parsed.port && /^\/*$/.test(parsed.pathname) && !parsed.search && !parsed.hash;
|
|
195
|
+
}
|
|
196
|
+
function renamedRetiredApiOrigin(value) {
|
|
197
|
+
if (!isLiveApiOrigin(value)) return null;
|
|
198
|
+
const { hostname } = new URL(value);
|
|
199
|
+
return isRetiredApiHost(hostname) ? currentApiOrigin(channelForApiHost(hostname)) : null;
|
|
200
|
+
}
|
|
201
|
+
function isOnRetiredApiHost(value) {
|
|
202
|
+
const parsed = parsedHttps(value);
|
|
203
|
+
return Boolean(parsed) && isRetiredApiHost(parsed.hostname);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/runtime/channel.js
|
|
158
207
|
var RELEASE_CHANNELS = ["stable", "nightly"];
|
|
159
208
|
var CHANNEL_TAGS = { stable: "latest", nightly: "nightly" };
|
|
160
|
-
var API_HOST_CHANNELS = {
|
|
161
|
-
"api.notis.ai": "stable",
|
|
162
|
-
"api-beta.notis.ai": "nightly",
|
|
163
|
-
"api-nightly.notis.ai": "nightly"
|
|
164
|
-
};
|
|
165
209
|
var CLI_PACKAGE_NAME = "@notis_ai/cli";
|
|
166
210
|
function isReleaseChannel(value) {
|
|
167
211
|
return RELEASE_CHANNELS.includes(value);
|
|
@@ -173,7 +217,7 @@ function normalizeReleaseChannel(value) {
|
|
|
173
217
|
function channelFromApiBase(apiBase) {
|
|
174
218
|
if (typeof apiBase !== "string" || !apiBase) return null;
|
|
175
219
|
try {
|
|
176
|
-
return
|
|
220
|
+
return channelForApiHost(new URL(apiBase).hostname);
|
|
177
221
|
} catch {
|
|
178
222
|
return null;
|
|
179
223
|
}
|
|
@@ -258,12 +302,35 @@ function resolveRetryEnabled(globalOptions = {}, env = process.env) {
|
|
|
258
302
|
return FALSE_VALUES.has(String(raw).trim().toLowerCase());
|
|
259
303
|
}
|
|
260
304
|
|
|
305
|
+
// src/runtime/agent-identity.js
|
|
306
|
+
var AGENT_IDENTITY_ENV = {
|
|
307
|
+
name: "NOTIS_AGENT_NAME",
|
|
308
|
+
id: "NOTIS_AGENT_ID",
|
|
309
|
+
thread: "NOTIS_AGENT_THREAD"
|
|
310
|
+
};
|
|
311
|
+
var AGENT_NAME_MIN = 3;
|
|
312
|
+
var AGENT_NAME_LIMIT = 60;
|
|
313
|
+
var BAND_NAME_EXAMPLE = "fred-and-the-machine";
|
|
314
|
+
var 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}`;
|
|
315
|
+
function pick(flag, variable) {
|
|
316
|
+
if (typeof flag === "string") return flag;
|
|
317
|
+
return typeof variable === "string" ? variable : void 0;
|
|
318
|
+
}
|
|
319
|
+
function readAgentIdentity(globalOptions = {}, env = process.env) {
|
|
320
|
+
const raw = {
|
|
321
|
+
name: pick(globalOptions.agentName, env[AGENT_IDENTITY_ENV.name]),
|
|
322
|
+
id: pick(globalOptions.agentId, env[AGENT_IDENTITY_ENV.id]),
|
|
323
|
+
thread: pick(globalOptions.agentThread, env[AGENT_IDENTITY_ENV.thread])
|
|
324
|
+
};
|
|
325
|
+
return Object.values(raw).some((value) => typeof value === "string" && value.trim()) ? raw : null;
|
|
326
|
+
}
|
|
327
|
+
|
|
261
328
|
// src/runtime/profiles.js
|
|
262
329
|
var CONFIG_DIR = join2(homedir2(), ".notis");
|
|
263
330
|
var CONFIG_FILE = join2(CONFIG_DIR, "config.json");
|
|
264
331
|
var WORKSPACE_DIR = join2(CONFIG_DIR, "workspace");
|
|
265
|
-
var DEFAULT_API_BASE = "
|
|
266
|
-
var NIGHTLY_API_BASE = "
|
|
332
|
+
var DEFAULT_API_BASE = currentApiOrigin("stable");
|
|
333
|
+
var NIGHTLY_API_BASE = currentApiOrigin("nightly");
|
|
267
334
|
var DEFAULT_PROFILE = "default";
|
|
268
335
|
var PROFILE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
269
336
|
var LEGACY_DESKTOP_PROFILE_KEYS = [
|
|
@@ -277,8 +344,7 @@ var LEGACY_DESKTOP_PROFILE_KEYS = [
|
|
|
277
344
|
];
|
|
278
345
|
var WORKTREE_RUNTIME_FILENAME = join2(".context", "notis-runtime.json");
|
|
279
346
|
var WORKTREE_ROUTING_FILENAME = join2(".context", "notis-routing.json");
|
|
280
|
-
var LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"]);
|
|
281
|
-
var LIVE_API_HOSTS = /* @__PURE__ */ new Set(["api.notis.ai", "api-nightly.notis.ai", "api-beta.notis.ai"]);
|
|
347
|
+
var LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
282
348
|
function clone(value) {
|
|
283
349
|
return JSON.parse(JSON.stringify(value));
|
|
284
350
|
}
|
|
@@ -318,6 +384,12 @@ function normalizeProfile(rawProfile = {}) {
|
|
|
318
384
|
oauth_refresh_token: typeof raw.oauth_refresh_token === "string" ? raw.oauth_refresh_token : void 0,
|
|
319
385
|
oauth_access_expires_at: typeof raw.oauth_access_expires_at === "number" ? raw.oauth_access_expires_at : void 0,
|
|
320
386
|
oauth_refresh_expires_at: typeof raw.oauth_refresh_expires_at === "number" ? raw.oauth_refresh_expires_at : void 0,
|
|
387
|
+
// True only when the token answer carried `refresh_expires_in`; otherwise
|
|
388
|
+
// oauth_refresh_expires_at is the CLI's own guess and proves nothing.
|
|
389
|
+
oauth_refresh_expiry_from_server: raw.oauth_refresh_expiry_from_server === true ? true : void 0,
|
|
390
|
+
// A fingerprint of the refresh token the sign-in server refused with
|
|
391
|
+
// `invalid_grant` (oauthGrantIsDead).
|
|
392
|
+
oauth_refresh_rejected_for: typeof raw.oauth_refresh_rejected_for === "string" ? raw.oauth_refresh_rejected_for : void 0,
|
|
321
393
|
oauth_client_id: typeof raw.oauth_client_id === "string" ? raw.oauth_client_id : void 0,
|
|
322
394
|
oauth_issuer: typeof raw.oauth_issuer === "string" ? raw.oauth_issuer : void 0,
|
|
323
395
|
oauth_api_base: typeof raw.oauth_api_base === "string" ? raw.oauth_api_base : void 0,
|
|
@@ -561,11 +633,42 @@ function isLiveApiBase(value) {
|
|
|
561
633
|
}
|
|
562
634
|
try {
|
|
563
635
|
const parsed = new URL(value);
|
|
564
|
-
return parsed.protocol === "https:" && LIVE_API_HOSTS.
|
|
636
|
+
return parsed.protocol === "https:" && LIVE_API_HOSTS.includes(parsed.hostname);
|
|
565
637
|
} catch {
|
|
566
638
|
return false;
|
|
567
639
|
}
|
|
568
640
|
}
|
|
641
|
+
function routingProfile(profile = {}, env = process.env) {
|
|
642
|
+
if (holdsAccount(profile) || env.NOTIS_JWT) return profile;
|
|
643
|
+
const apiBase = profile.api_base;
|
|
644
|
+
const local = isLocalApiBase(apiBase);
|
|
645
|
+
if (apiBase && !local && !isLiveApiBase(apiBase)) return profile;
|
|
646
|
+
const { api_base: _apiBase, oauth_api_base: _oauthApiBase, release_channel: _releaseChannel, ...rest } = profile;
|
|
647
|
+
return local ? { ...rest, api_base: apiBase } : rest;
|
|
648
|
+
}
|
|
649
|
+
function holdsAccount(profile = {}) {
|
|
650
|
+
if (profile.dev_access_token) return true;
|
|
651
|
+
return Boolean(profile.oauth_access_token || profile.oauth_refresh_token) && !oauthGrantIsDead(profile);
|
|
652
|
+
}
|
|
653
|
+
function oauthGrantOnRetiredAddress(profile = {}) {
|
|
654
|
+
if (!profile.oauth_access_token && !profile.oauth_refresh_token) return false;
|
|
655
|
+
return isOnRetiredApiHost(profile.oauth_issuer) || isOnRetiredApiHost(getOAuthResource(profile));
|
|
656
|
+
}
|
|
657
|
+
function refreshTokenFingerprint(refreshToken) {
|
|
658
|
+
return createHash("sha256").update(String(refreshToken)).digest("hex").slice(0, 32);
|
|
659
|
+
}
|
|
660
|
+
function oauthGrantIsDead(profile = {}, nowSeconds = Math.floor(Date.now() / 1e3)) {
|
|
661
|
+
if (oauthGrantOnRetiredAddress(profile)) return true;
|
|
662
|
+
const refreshToken = profile.oauth_refresh_token;
|
|
663
|
+
if (!refreshToken) return false;
|
|
664
|
+
if (typeof profile.oauth_refresh_rejected_for === "string" && profile.oauth_refresh_rejected_for === refreshTokenFingerprint(refreshToken)) {
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
if (profile.oauth_refresh_expiry_from_server !== true) return false;
|
|
668
|
+
const refreshExpiry = Number(profile.oauth_refresh_expires_at);
|
|
669
|
+
const accessExpiry = Number(profile.oauth_access_expires_at);
|
|
670
|
+
return Number.isFinite(refreshExpiry) && refreshExpiry <= nowSeconds && Number.isFinite(accessExpiry) && accessExpiry <= nowSeconds;
|
|
671
|
+
}
|
|
569
672
|
function resolveDefaultLiveApiBase(profile = {}) {
|
|
570
673
|
const channel = pinnedReleaseChannel(profile) || (isLiveApiBase(profile.api_base) ? channelFromProfile({ api_base: profile.api_base }) : null);
|
|
571
674
|
return channel === "nightly" ? NIGHTLY_API_BASE : DEFAULT_API_BASE;
|
|
@@ -578,10 +681,12 @@ function getApiBase(config, profileName, override) {
|
|
|
578
681
|
if (env) {
|
|
579
682
|
return env;
|
|
580
683
|
}
|
|
581
|
-
|
|
684
|
+
return storedApiBase(routingProfile(getProfile(config, profileName)));
|
|
685
|
+
}
|
|
686
|
+
function storedApiBase(profile = {}) {
|
|
582
687
|
const profileApiBase = profile.api_base;
|
|
583
688
|
if (typeof profileApiBase === "string" && profileApiBase && !isLocalApiBase(profileApiBase)) {
|
|
584
|
-
return profileApiBase.replace(/\/+$/, "");
|
|
689
|
+
return renamedRetiredApiOrigin(profileApiBase) || profileApiBase.replace(/\/+$/, "");
|
|
585
690
|
}
|
|
586
691
|
return resolveDefaultLiveApiBase(profile);
|
|
587
692
|
}
|
|
@@ -661,7 +766,7 @@ function getOAuthResource(profile = {}) {
|
|
|
661
766
|
}
|
|
662
767
|
function getOAuthApiBase(profile = {}) {
|
|
663
768
|
if (typeof profile.oauth_api_base === "string" && profile.oauth_api_base) {
|
|
664
|
-
return profile.oauth_api_base.replace(/\/+$/, "");
|
|
769
|
+
return renamedRetiredApiOrigin(profile.oauth_api_base) || profile.oauth_api_base.replace(/\/+$/, "");
|
|
665
770
|
}
|
|
666
771
|
const resource = getOAuthResource(profile);
|
|
667
772
|
if (resource?.endsWith("/cli")) {
|
|
@@ -735,8 +840,8 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
735
840
|
}
|
|
736
841
|
const oauthApiBase = getOAuthApiBase(profile);
|
|
737
842
|
const oauthResource = getOAuthResource(profile);
|
|
738
|
-
const normalizedRequestedApiBase = requestedApiBase ? requestedApiBase.replace(/\/+$/, "") : null;
|
|
739
|
-
if (requireAuth && credentialKind === "oauth" && normalizedRequestedApiBase && oauthApiBase && normalizedRequestedApiBase !== oauthApiBase) {
|
|
843
|
+
const normalizedRequestedApiBase = requestedApiBase ? renamedRetiredApiOrigin(requestedApiBase) || requestedApiBase.replace(/\/+$/, "") : null;
|
|
844
|
+
if (requireAuth && credentialKind === "oauth" && !oauthGrantOnRetiredAddress(profile) && normalizedRequestedApiBase && oauthApiBase && normalizedRequestedApiBase !== oauthApiBase) {
|
|
740
845
|
throw new CliError({
|
|
741
846
|
code: "oauth_api_target_mismatch",
|
|
742
847
|
message: `The OAuth credential for profile ${profileName} belongs to ${oauthApiBase}, not ${normalizedRequestedApiBase}`,
|
|
@@ -752,7 +857,7 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
752
857
|
}]
|
|
753
858
|
});
|
|
754
859
|
}
|
|
755
|
-
if (credentialKind === "oauth" && oauthApiBase && !requestedApiBase) {
|
|
860
|
+
if (credentialKind === "oauth" && oauthApiBase && !requestedApiBase && !oauthGrantIsDead(profile)) {
|
|
756
861
|
apiBase = oauthApiBase;
|
|
757
862
|
}
|
|
758
863
|
const agentMode = isAgentMode(globalOptions);
|
|
@@ -787,7 +892,7 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
787
892
|
// Which published build serves this profile. Carried on the runtime so
|
|
788
893
|
// every recovery hint prints the command that will actually run.
|
|
789
894
|
channel: devRuntime ? null : channelFromProfile(
|
|
790
|
-
globalOptions.apiBase || process.env.NOTIS_API_BASE ? { api_base: apiBase } : { ...profile, api_base: apiBase }
|
|
895
|
+
globalOptions.apiBase || process.env.NOTIS_API_BASE ? { api_base: apiBase } : { ...routingProfile(profile), api_base: apiBase }
|
|
791
896
|
),
|
|
792
897
|
apiBase,
|
|
793
898
|
requestedApiBase: normalizedRequestedApiBase,
|
|
@@ -810,6 +915,8 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
810
915
|
timeoutMs,
|
|
811
916
|
// Automatic retries of interrupted calls that are safe to repeat.
|
|
812
917
|
retry: resolveRetryEnabled(globalOptions),
|
|
918
|
+
// The agent this run declares (--agent-name / NOTIS_AGENT_NAME, ...), checked and sent by httpRequest.
|
|
919
|
+
agentIdentity: readAgentIdentity(globalOptions),
|
|
813
920
|
debugEntitlementOverride,
|
|
814
921
|
worktreeRuntime: devRuntime,
|
|
815
922
|
detachedWorktreeRuntime: devRuntime ? null : worktreeRuntime,
|
|
@@ -847,7 +954,7 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds = Math.floor(Date
|
|
|
847
954
|
switch (credentialKind) {
|
|
848
955
|
case "oauth": {
|
|
849
956
|
const expiration = Number(profile.oauth_access_expires_at);
|
|
850
|
-
return !Number.isFinite(expiration) || expiration <= nowSeconds;
|
|
957
|
+
return !Number.isFinite(expiration) || expiration <= nowSeconds || oauthGrantIsDead(profile, nowSeconds);
|
|
851
958
|
}
|
|
852
959
|
case "env": {
|
|
853
960
|
const expiration = getJwtExpiration(runtime?.jwt);
|
|
@@ -868,7 +975,7 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds = Math.floor(Date
|
|
|
868
975
|
|
|
869
976
|
// src/runtime/oauth.js
|
|
870
977
|
import {
|
|
871
|
-
createHash,
|
|
978
|
+
createHash as createHash2,
|
|
872
979
|
randomBytes,
|
|
873
980
|
timingSafeEqual
|
|
874
981
|
} from "node:crypto";
|
|
@@ -1196,6 +1303,21 @@ function readRefreshAnswer(runtime, { response, text }) {
|
|
|
1196
1303
|
}
|
|
1197
1304
|
return payload;
|
|
1198
1305
|
}
|
|
1306
|
+
function recordRefusedRefreshToken(runtime, refreshToken) {
|
|
1307
|
+
if (!refreshToken) return;
|
|
1308
|
+
try {
|
|
1309
|
+
updateConfig((latest) => {
|
|
1310
|
+
const current = latest.profiles?.[runtime.profileName];
|
|
1311
|
+
if (!current || current.oauth_refresh_token !== refreshToken) return latest;
|
|
1312
|
+
latest.profiles[runtime.profileName] = {
|
|
1313
|
+
...current,
|
|
1314
|
+
oauth_refresh_rejected_for: refreshTokenFingerprint(refreshToken)
|
|
1315
|
+
};
|
|
1316
|
+
return latest;
|
|
1317
|
+
});
|
|
1318
|
+
} catch {
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1199
1321
|
async function persistRefreshedSignIn(runtime, metadata, tokenResponse) {
|
|
1200
1322
|
let lastError = null;
|
|
1201
1323
|
for (const delay2 of [0, ...OAUTH_REFRESH_SAVE_RETRY_DELAYS_MS]) {
|
|
@@ -1246,6 +1368,7 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
1246
1368
|
const now = Math.floor(Date.now() / 1e3);
|
|
1247
1369
|
const payload = decodeJwtPayload(tokenResponse.access_token);
|
|
1248
1370
|
const oauthApiBase = (metadata.apiBase || runtime.apiBase || "").replace(/\/+$/, "");
|
|
1371
|
+
const refreshExpiryFromServer = Boolean(tokenResponse.refresh_token) && tokenResponse.refresh_expires_in !== null && tokenResponse.refresh_expires_in !== "" && Number.isFinite(Number(tokenResponse.refresh_expires_in));
|
|
1249
1372
|
const config = updateConfig((latest) => {
|
|
1250
1373
|
const next = ensureProfile(latest, runtime.profileName);
|
|
1251
1374
|
const profile = next.profiles[runtime.profileName];
|
|
@@ -1266,7 +1389,12 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
1266
1389
|
oauth_access_token: tokenResponse.access_token,
|
|
1267
1390
|
oauth_refresh_token: tokenResponse.refresh_token || profile.oauth_refresh_token,
|
|
1268
1391
|
oauth_access_expires_at: now + Number(tokenResponse.expires_in || 0),
|
|
1269
|
-
oauth_refresh_expires_at: now + Number(tokenResponse.refresh_expires_in
|
|
1392
|
+
oauth_refresh_expires_at: now + (refreshExpiryFromServer ? Number(tokenResponse.refresh_expires_in) : DEFAULT_REFRESH_EXPIRES_IN),
|
|
1393
|
+
// Only an expiry the server sent for the refresh token it sent may later
|
|
1394
|
+
// prove the grant dead (oauthGrantIsDead); the default above is a guess.
|
|
1395
|
+
oauth_refresh_expiry_from_server: refreshExpiryFromServer || void 0,
|
|
1396
|
+
// A new grant or a renewed one is no longer the token the server refused.
|
|
1397
|
+
oauth_refresh_rejected_for: void 0,
|
|
1270
1398
|
oauth_client_id: metadata.clientId,
|
|
1271
1399
|
oauth_issuer: metadata.issuer,
|
|
1272
1400
|
oauth_scopes: String(tokenResponse.scope || "").split(/\s+/).filter(Boolean),
|
|
@@ -1281,7 +1409,7 @@ var LISTENER_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
|
1281
1409
|
var LISTENER_START_LOCK_STALE_MS = LISTENER_HANDSHAKE_TIMEOUT_MS * 2;
|
|
1282
1410
|
var LISTENER_GLOBAL_LOCK_HEARTBEAT_MS = 5e3;
|
|
1283
1411
|
function listenerStateFile(runtime) {
|
|
1284
|
-
const profileKey =
|
|
1412
|
+
const profileKey = createHash2("sha256").update(String(runtime.profileName || "default")).digest("hex").slice(0, 16);
|
|
1285
1413
|
return `${resolveConfigFile()}.login-listener.${profileKey}`;
|
|
1286
1414
|
}
|
|
1287
1415
|
function listenerStartLockDir(runtime) {
|
|
@@ -1446,7 +1574,7 @@ function updateRuntimeFromOAuthProfile(runtime, profile) {
|
|
|
1446
1574
|
}
|
|
1447
1575
|
}
|
|
1448
1576
|
function assertOAuthApiTarget(runtime, profile) {
|
|
1449
|
-
const requestedApiBase = String(runtime.requestedApiBase || "").replace(/\/+$/, "");
|
|
1577
|
+
const requestedApiBase = renamedRetiredApiOrigin(runtime.requestedApiBase) || String(runtime.requestedApiBase || "").replace(/\/+$/, "");
|
|
1450
1578
|
const oauthApiBase = getOAuthApiBase(profile);
|
|
1451
1579
|
if (requestedApiBase && oauthApiBase && requestedApiBase !== oauthApiBase) {
|
|
1452
1580
|
throw oauthError(
|
|
@@ -1455,11 +1583,22 @@ function assertOAuthApiTarget(runtime, profile) {
|
|
|
1455
1583
|
);
|
|
1456
1584
|
}
|
|
1457
1585
|
}
|
|
1586
|
+
function retiredAddressGrantError(runtime, profile) {
|
|
1587
|
+
const { hints } = getAuthRecovery(runtime);
|
|
1588
|
+
const retiredHost = [profile.oauth_issuer, getOAuthResource(profile)].filter(isOnRetiredApiHost).map((value) => new URL(value).hostname)[0];
|
|
1589
|
+
return oauthError(
|
|
1590
|
+
"oauth_grant_retired_address",
|
|
1591
|
+
`This sign-in was made on ${retiredHost}, a retired address of Notis that no longer accepts it. Sign in again: ${hints[0].command}`,
|
|
1592
|
+
hints,
|
|
1593
|
+
{ retired_host: retiredHost }
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1458
1596
|
async function ensureFreshOAuthCredential(runtime, fetchImpl = fetch) {
|
|
1459
1597
|
if (runtime.credentialKind !== "oauth") {
|
|
1460
1598
|
return Boolean(runtime.jwt);
|
|
1461
1599
|
}
|
|
1462
1600
|
const profile = getProfile(loadConfig(), runtime.profileName);
|
|
1601
|
+
if (oauthGrantOnRetiredAddress(profile)) throw retiredAddressGrantError(runtime, profile);
|
|
1463
1602
|
assertOAuthApiTarget(runtime, profile);
|
|
1464
1603
|
if (!credentialIsExpired({ credentialKind: "oauth" }, profile)) {
|
|
1465
1604
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -1531,6 +1670,7 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
1531
1670
|
stopTouchingLocks = keepLockFoldersFresh([profileLock, oauthLockDir()]);
|
|
1532
1671
|
const config = loadConfig();
|
|
1533
1672
|
const profile = getProfile(config, runtime.profileName);
|
|
1673
|
+
if (oauthGrantOnRetiredAddress(profile)) throw retiredAddressGrantError(runtime, profile);
|
|
1534
1674
|
assertOAuthApiTarget(runtime, profile);
|
|
1535
1675
|
if (profile.oauth_access_token && profile.oauth_access_token !== staleAccessToken && !credentialIsExpired({ credentialKind: "oauth" }, profile)) {
|
|
1536
1676
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -1568,7 +1708,15 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
1568
1708
|
failure.cause
|
|
1569
1709
|
);
|
|
1570
1710
|
}
|
|
1571
|
-
|
|
1711
|
+
let rotatedResponse;
|
|
1712
|
+
try {
|
|
1713
|
+
rotatedResponse = readRefreshAnswer(runtime, answer);
|
|
1714
|
+
} catch (refusal) {
|
|
1715
|
+
if (refusal?.code === "invalid_grant") {
|
|
1716
|
+
recordRefusedRefreshToken(runtime, profile.oauth_refresh_token);
|
|
1717
|
+
}
|
|
1718
|
+
throw refusal;
|
|
1719
|
+
}
|
|
1572
1720
|
const updated = await persistRefreshedSignIn(runtime, metadata, rotatedResponse);
|
|
1573
1721
|
updateRuntimeFromOAuthProfile(runtime, updated);
|
|
1574
1722
|
return true;
|
|
@@ -1605,14 +1753,14 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
1605
1753
|
import { createHash as createHash4 } from "node:crypto";
|
|
1606
1754
|
import { promises as fs3 } from "node:fs";
|
|
1607
1755
|
import { dirname as dirname5, join as join5 } from "node:path";
|
|
1608
|
-
import { createHash as
|
|
1756
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1609
1757
|
import { createHash as createHash22 } from "crypto";
|
|
1610
1758
|
import { execFile } from "child_process";
|
|
1611
1759
|
import { promises as fs } from "fs";
|
|
1612
1760
|
import os from "os";
|
|
1613
1761
|
import path from "path";
|
|
1614
1762
|
import { promisify } from "util";
|
|
1615
|
-
import { createHash as
|
|
1763
|
+
import { createHash as createHash32 } from "node:crypto";
|
|
1616
1764
|
import { promises as fs2 } from "fs";
|
|
1617
1765
|
import os2 from "os";
|
|
1618
1766
|
import path2 from "path";
|
|
@@ -1672,7 +1820,7 @@ function assertNativePull(response) {
|
|
|
1672
1820
|
}
|
|
1673
1821
|
}
|
|
1674
1822
|
function nativeFileDigest(bytes) {
|
|
1675
|
-
return
|
|
1823
|
+
return createHash3("sha256").update(bytes).digest("hex");
|
|
1676
1824
|
}
|
|
1677
1825
|
function nativeFrontmatterName(markdown) {
|
|
1678
1826
|
const header = markdown.match(/^---\s*\n([\s\S]*?)\n---/);
|
|
@@ -2802,7 +2950,7 @@ async function updateAgentTargets(serverUrl, jwt, skillId, targets, expectedUpda
|
|
|
2802
2950
|
revision: native.settingsRevision,
|
|
2803
2951
|
patch: { agent_targets: Object.fromEntries(Object.entries(targets).sort(([a], [b]) => a.localeCompare(b))) }
|
|
2804
2952
|
};
|
|
2805
|
-
const requestId = "sync-settings-" +
|
|
2953
|
+
const requestId = "sync-settings-" + createHash32("sha256").update(JSON.stringify(payload)).digest("hex");
|
|
2806
2954
|
const saved = await requestJson(
|
|
2807
2955
|
`${serverUrl}/portal_skills/native-settings`,
|
|
2808
2956
|
jwt,
|
|
@@ -3927,7 +4075,12 @@ async function withSkillSyncLock(callback, {
|
|
|
3927
4075
|
}
|
|
3928
4076
|
|
|
3929
4077
|
// src/skill-sync-worker.js
|
|
3930
|
-
var REJECTED_SIGN_IN_CODES = /* @__PURE__ */ new Set([
|
|
4078
|
+
var REJECTED_SIGN_IN_CODES = /* @__PURE__ */ new Set([
|
|
4079
|
+
"invalid_grant",
|
|
4080
|
+
"invalid_client",
|
|
4081
|
+
"unauthorized_client",
|
|
4082
|
+
"oauth_grant_retired_address"
|
|
4083
|
+
]);
|
|
3931
4084
|
function currentCliProfile() {
|
|
3932
4085
|
try {
|
|
3933
4086
|
return getCurrentProfileName(loadConfig());
|
|
@@ -3955,7 +4108,9 @@ async function runAutomaticSkillSync({ profile, apiBase, userId }, {
|
|
|
3955
4108
|
currentProfile = currentCliProfile
|
|
3956
4109
|
} = {}) {
|
|
3957
4110
|
const runtime = resolveRuntime({ profile }, { requireAuth: true });
|
|
3958
|
-
|
|
4111
|
+
const current = (value) => renamedRetiredApiOrigin(value) || value;
|
|
4112
|
+
const boundApiBase = current(apiBase);
|
|
4113
|
+
if (runtime.credentialKind !== "oauth" || current(runtime.oauthApiBase || runtime.apiBase) !== boundApiBase || runtime.oauthUserId !== userId) throw new Error("Automatic skill sync account changed; run notis skills sync to rebind");
|
|
3959
4114
|
await refresh(runtime);
|
|
3960
4115
|
const saved = await settings(runtime.apiBase, runtime.jwt);
|
|
3961
4116
|
if (saved.user_id !== userId) throw new Error("Automatic skill sync identity mismatch");
|