@notis_ai/cli 0.2.29 → 0.2.31
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 +26 -8
- package/dist/agent-hooks/notis-agent-hook.mjs +38399 -10883
- 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-cli/references/native-databases.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/references/query.md +6 -4
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +8 -3
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -1
- package/dist/base-skills/notis-spaces/references/design.md +7 -1
- package/dist/base-skills/notis-spaces/references/fixtures.md +27 -2
- package/dist/base-skills/notis-spaces/references/release.md +6 -5
- package/dist/base-skills/notis-spaces/references/sdk.md +172 -48
- package/dist/base-skills/notis-spaces/references/troubleshooting.md +3 -0
- package/dist/base-skills/notis-spaces/references/views.md +20 -0
- package/dist/sdk/src/hooks/useNativeDocuments.ts +50 -12
- package/dist/sdk/src/hooks/useThreadItem.ts +56 -0
- package/dist/sdk/src/index.ts +7 -2
- package/dist/sdk/src/runtime.ts +8 -1
- package/dist/sdk/src/space.ts +233 -1
- package/dist/sdk/src/tailwind.ts +53 -3
- package/dist/sdk/src/ui/icons.tsx +1 -0
- package/dist/sdk/src/words/types.ts +28 -0
- package/dist/skill-sync/index.js +10 -90
- package/dist/skill-sync-worker.mjs +232 -120
- package/dist/space-harness/host.js +309 -96
- package/dist/space-sdk/dist/chunk-3DFOGU26.js +3 -0
- package/dist/space-sdk/dist/index.js +4 -2
- package/dist/space-sdk/dist/ui.js +19 -14
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +23 -0
- package/dist/space-sdk/src/hooks/useThreadItem.d.ts +28 -0
- package/dist/space-sdk/src/index.d.ts +4 -2
- package/dist/space-sdk/src/runtime.d.ts +8 -1
- package/dist/space-sdk/src/space.ts +233 -1
- package/dist/space-sdk/src/tailwind-candidates.d.ts +765 -16
- package/dist/space-sdk/src/tailwind.ts +53 -3
- package/dist/space-sdk/src/ui/actions/useToast.d.ts +2 -0
- package/dist/space-sdk/src/ui/blocks/DataTable.d.ts +19 -4
- package/dist/space-sdk/src/ui/blocks/Meter.d.ts +12 -3
- package/dist/space-sdk/src/ui/blocks/Tabs.d.ts +7 -1
- package/dist/space-sdk/src/ui/blocks/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/charts/CalendarHeatmap.d.ts +69 -0
- package/dist/space-sdk/src/ui/charts/Chart.d.ts +18 -3
- package/dist/space-sdk/src/ui/charts/chartData.d.ts +19 -0
- package/dist/space-sdk/src/ui/charts/heatmapData.d.ts +81 -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 +6 -3
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +6 -1
- package/dist/space-sdk/src/ui/list/Row.d.ts +11 -1
- package/dist/space-sdk/src/ui/overlay/Tooltip.d.ts +8 -2
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +2 -0
- package/dist/space-sdk/src/ui/period/dateWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/period/periods.d.ts +15 -2
- package/dist/space-sdk/src/ui/styles.d.ts +27 -5
- package/dist/space-sdk/src/words/types.ts +28 -0
- package/dist/view-renderer/dist/host.js +379 -166
- package/dist/view-renderer/src/dom.js +3 -2
- package/dist/view-renderer/src/errors.js +9 -0
- package/dist/view-renderer/src/host.tsx +18 -8
- package/dist/view-renderer/src/remote-broker.js +3 -1
- package/dist/view-renderer/src/renderer.js +87 -17
- package/dist/view-renderer/src/skeleton.js +70 -18
- package/package.json +5 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -1
- package/skills/notis-query/cli.md +3 -0
- 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 +101 -31
- package/src/command-specs/tools.js +3 -0
- package/src/runtime/agent-identity.js +187 -0
- package/src/runtime/api-hosts.generated.js +35 -0
- package/src/runtime/api-hosts.js +109 -0
- package/src/runtime/app-platform.js +68 -24
- package/src/runtime/channel.js +3 -7
- package/src/runtime/http-agent.js +53 -0
- package/src/runtime/native-record-files.js +11 -0
- package/src/runtime/oauth.js +97 -5
- package/src/runtime/profiles.js +200 -41
- package/src/runtime/skill-sync/cloud-client.ts +0 -10
- package/src/runtime/skill-sync/index.ts +13 -15
- package/src/runtime/skill-sync/local-scanner.ts +0 -67
- package/src/runtime/skill-sync/types.ts +1 -0
- package/src/runtime/skill-sync/write-cloud-skill.ts +7 -23
- package/src/runtime/skill-sync-service.js +4 -5
- package/src/runtime/space-dependencies.js +66 -0
- package/src/runtime/space-fixture-broker.js +23 -8
- package/src/runtime/space-platform.js +49 -3
- package/src/runtime/space-source.js +76 -2
- package/src/runtime/space-test-server.js +125 -10
- package/src/runtime/space-verification.js +106 -42
- package/src/runtime/space-view-manifest.js +38 -5
- package/src/runtime/telemetry.js +14 -1
- package/src/runtime/transport.js +31 -4
- package/src/runtime/upsell.js +3 -6
- package/src/runtime/view-render.js +6 -1
- package/src/skill-sync-worker.js +13 -2
- package/src/space-harness-host.ts +6 -3
- package/template/tailwind.config.ts +2 -35
- package/dist/space-sdk/dist/chunk-BFGB6XXC.js +0 -5
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { CHANNEL_HOSTNAMES, CHANNEL_ORIGINS } from './api-hosts.generated.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retired API names the CLI keeps knowing after the server list drops them. A
|
|
5
|
+
* retired name stays listed after its domain is removed: profiles that stored
|
|
6
|
+
* it keep being recognised and renamed to the channel's current API (CLI-037),
|
|
7
|
+
* and sign-ins recorded on it are known to be spent (CLI-038, CLI-039).
|
|
8
|
+
*/
|
|
9
|
+
const CLI_RETIRED_API_HOSTS = {
|
|
10
|
+
nightly: ['api-beta.notis.ai'],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The live Notis APIs, one row per release channel: the API's current name,
|
|
15
|
+
* the names it answered on before (retired), and the channel's Portal.
|
|
16
|
+
*
|
|
17
|
+
* Every CLI list of live API hosts derives from this table. The current and
|
|
18
|
+
* retired names come from api-hosts.generated.js, written by
|
|
19
|
+
* scripts/generate_channel_hosts.py from server/lib/release_channels.py
|
|
20
|
+
* (CHANNEL_ORIGINS, _LEGACY_HOSTNAMES): edit the server list and regenerate.
|
|
21
|
+
* CLI_RETIRED_API_HOSTS adds the retired names only the CLI still needs.
|
|
22
|
+
*/
|
|
23
|
+
const CHANNEL_APIS = channelApis(CHANNEL_HOSTNAMES, CHANNEL_ORIGINS);
|
|
24
|
+
|
|
25
|
+
/** The CHANNEL_APIS rows of a generated host table, with the CLI's own retired names added. */
|
|
26
|
+
export function channelApis(channelHostnames, channelOrigins) {
|
|
27
|
+
return Object.fromEntries(Object.entries(channelHostnames).map(([channel, surfaces]) => {
|
|
28
|
+
const [current, ...legacy] = surfaces.api;
|
|
29
|
+
const retired = [...new Set([...legacy, ...(CLI_RETIRED_API_HOSTS[channel] || [])])].filter(host => host !== current);
|
|
30
|
+
return [channel, { current, retired, portal: channelOrigins[channel].portal }];
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const HOST_ROWS = Object.entries(CHANNEL_APIS).flatMap(([channel, row]) => [
|
|
35
|
+
{ host: row.current, channel, current: true },
|
|
36
|
+
...row.retired.map(host => ({ host, channel, current: false })),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
/** Every live API hostname, current names first. */
|
|
40
|
+
export const LIVE_API_HOSTS = [
|
|
41
|
+
...HOST_ROWS.filter(row => row.current),
|
|
42
|
+
...HOST_ROWS.filter(row => !row.current),
|
|
43
|
+
].map(row => row.host);
|
|
44
|
+
|
|
45
|
+
/** Every live API origin (`https://<host>`), current names first. */
|
|
46
|
+
export const LIVE_API_ORIGINS = LIVE_API_HOSTS.map(host => `https://${host}`);
|
|
47
|
+
|
|
48
|
+
/** The channel a live API hostname serves, else null. */
|
|
49
|
+
export function channelForApiHost(hostname) {
|
|
50
|
+
return HOST_ROWS.find(row => row.host === hostname)?.channel || null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Portal of the channel a live API hostname serves, else null. */
|
|
54
|
+
export function portalOriginForApiHost(hostname) {
|
|
55
|
+
const channel = channelForApiHost(hostname);
|
|
56
|
+
return channel ? CHANNEL_APIS[channel].portal : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The current API origin of a channel (`https://api-nightly.notis.ai`). */
|
|
60
|
+
export function currentApiOrigin(channel) {
|
|
61
|
+
return `https://${CHANNEL_APIS[channel].current}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Whether a hostname is a retired name of a live API. */
|
|
65
|
+
export function isRetiredApiHost(hostname) {
|
|
66
|
+
return HOST_ROWS.some(row => row.host === hostname && !row.current);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parsedHttps(value) {
|
|
70
|
+
if (typeof value !== 'string' || !value) return null;
|
|
71
|
+
try {
|
|
72
|
+
const parsed = new URL(value);
|
|
73
|
+
return parsed.protocol === 'https:' ? parsed : null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Whether a value is exactly a live API origin: `https://<live host>` with at
|
|
81
|
+
* most a trailing slash, no port, path, query or fragment.
|
|
82
|
+
*/
|
|
83
|
+
export function isLiveApiOrigin(value) {
|
|
84
|
+
const parsed = parsedHttps(value);
|
|
85
|
+
return Boolean(parsed)
|
|
86
|
+
&& LIVE_API_HOSTS.includes(parsed.hostname)
|
|
87
|
+
&& !parsed.port
|
|
88
|
+
&& /^\/*$/.test(parsed.pathname)
|
|
89
|
+
&& !parsed.search
|
|
90
|
+
&& !parsed.hash;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The current origin for a value that is exactly a retired API origin
|
|
95
|
+
* (`https://api-beta.notis.ai` -> `https://api-nightly.notis.ai`), else null.
|
|
96
|
+
* An address with a port, path or query is not the retired API and is left
|
|
97
|
+
* to the caller as stored.
|
|
98
|
+
*/
|
|
99
|
+
export function renamedRetiredApiOrigin(value) {
|
|
100
|
+
if (!isLiveApiOrigin(value)) return null;
|
|
101
|
+
const { hostname } = new URL(value);
|
|
102
|
+
return isRetiredApiHost(hostname) ? currentApiOrigin(channelForApiHost(hostname)) : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Whether a URL of any shape points at a retired API name over HTTPS. */
|
|
106
|
+
export function isOnRetiredApiHost(value) {
|
|
107
|
+
const parsed = parsedHttps(value);
|
|
108
|
+
return Boolean(parsed) && isRetiredApiHost(parsed.hostname);
|
|
109
|
+
}
|
|
@@ -2039,15 +2039,45 @@ function replaceVerifyImage(name, png) {
|
|
|
2039
2039
|
if (png) writeFileSync(name, png, { flag: 'wx', mode: 0o600 });
|
|
2040
2040
|
}
|
|
2041
2041
|
|
|
2042
|
-
const VERIFY_WIDTHS = [390, 1440], VERIFY_LOCALES = ['en', 'fr'];
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2042
|
+
export const VERIFY_WIDTHS = [390, 1440], VERIFY_LOCALES = ['en', 'fr'];
|
|
2043
|
+
// A fixture context's name (space-test-server.js checks fixtures with it): it joins the image name only when the
|
|
2044
|
+
// fixtures declare several, after a dot, which no Space key has, so `view-a.b-...` is never Space `a-b`'s image.
|
|
2045
|
+
export const VERIFY_CONTEXT_NAME = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
2046
|
+
function contextPart(context, message) {
|
|
2047
|
+
if (context === undefined) return '';
|
|
2048
|
+
if (typeof context !== 'string' || !VERIFY_CONTEXT_NAME.test(context)) throw usageError(message);
|
|
2049
|
+
return `.${context}`;
|
|
2047
2050
|
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
+
/**
|
|
2052
|
+
* Each Space's verify images carry its key, so two Spaces verified from one folder never share a file:
|
|
2053
|
+
* `view-<key>[.<context>]-<width>-<locale>.png`.
|
|
2054
|
+
*/
|
|
2055
|
+
function viewImageName(key, width, locale, context) {
|
|
2056
|
+
if (!VERIFY_WIDTHS.includes(width) || !VERIFY_LOCALES.includes(locale)) throw usageError('Unsafe screenshot name.');
|
|
2057
|
+
return `view-${assertSpaceKey(key, 'Unsafe screenshot name.')}${contextPart(context, 'Unsafe screenshot name.')}-${width}-${locale}.png`;
|
|
2058
|
+
}
|
|
2059
|
+
/** `pending-<key>[.<context>][.reader]-<width>-<locale>.png`; `reader` is an opened item's loading state. */
|
|
2060
|
+
function pendingImageName(key, width, locale, { context, state } = {}) {
|
|
2061
|
+
if (!VERIFY_WIDTHS.includes(width) || !VERIFY_LOCALES.includes(locale) || (state !== undefined && state !== 'reader')) {
|
|
2062
|
+
throw usageError('Unsafe pending screenshot name.');
|
|
2063
|
+
}
|
|
2064
|
+
return `pending-${assertSpaceKey(key, 'Unsafe pending screenshot name.')}${contextPart(context, 'Unsafe pending screenshot name.')}${state ? `.${state}` : ''}-${width}-${locale}.png`;
|
|
2065
|
+
}
|
|
2066
|
+
// The names of the images the last verify of a Space wrote: names carrying a context cannot be listed in advance, and
|
|
2067
|
+
// matching them by pattern could take another Space's images whose key starts with this one's.
|
|
2068
|
+
const imageIndexName = key => `verify-images-${key}.json`;
|
|
2069
|
+
function readImageIndex(key) {
|
|
2070
|
+
const name = imageIndexName(key), stat = lstatSync(name, { throwIfNoEntry: false });
|
|
2071
|
+
if (!stat?.isFile() || stat.size > 64 * 1024) return [];
|
|
2072
|
+
try {
|
|
2073
|
+
const names = JSON.parse(readFileSync(name, 'utf8'));
|
|
2074
|
+
const own = new RegExp(`^(?:view|pending)-${key}(?:\\.[a-z0-9_-]+){0,2}-(?:390|1440)-(?:en|fr)\\.png$`);
|
|
2075
|
+
return Array.isArray(names) ? names.filter(value => typeof value === 'string' && own.test(value)) : [];
|
|
2076
|
+
} catch { return []; }
|
|
2077
|
+
}
|
|
2078
|
+
function recordImages(key, names) {
|
|
2079
|
+
const known = [...new Set([...readImageIndex(key), ...names])];
|
|
2080
|
+
replaceVerifyImage(imageIndexName(key), Buffer.from(JSON.stringify(known)));
|
|
2051
2081
|
}
|
|
2052
2082
|
|
|
2053
2083
|
/**
|
|
@@ -2063,39 +2093,53 @@ export function clearSpaceScreenshots(projectDir, key) {
|
|
|
2063
2093
|
|
|
2064
2094
|
/** Remove one Space's verify images, and the unnamed ones, from the pinned .notis directory (the working directory). */
|
|
2065
2095
|
function removeSpaceImages(key) {
|
|
2096
|
+
for (const name of readImageIndex(key)) replaceVerifyImage(name);
|
|
2097
|
+
replaceVerifyImage(imageIndexName(key));
|
|
2066
2098
|
for (const width of VERIFY_WIDTHS) {
|
|
2067
|
-
|
|
2099
|
+
// Names of older CLIs: one view image per width, with and without the key.
|
|
2100
|
+
replaceVerifyImage(`view-${key}-${width}.png`);
|
|
2068
2101
|
replaceVerifyImage(`view-${width}.png`);
|
|
2069
2102
|
for (const locale of VERIFY_LOCALES) {
|
|
2103
|
+
replaceVerifyImage(viewImageName(key, width, locale));
|
|
2070
2104
|
replaceVerifyImage(pendingImageName(key, width, locale));
|
|
2105
|
+
replaceVerifyImage(pendingImageName(key, width, locale, { state: 'reader' }));
|
|
2071
2106
|
replaceVerifyImage(`pending-${width}-${locale}.png`);
|
|
2072
2107
|
}
|
|
2073
2108
|
}
|
|
2074
2109
|
}
|
|
2075
2110
|
|
|
2076
|
-
/**
|
|
2111
|
+
/**
|
|
2112
|
+
* The loading-state screenshots of the last verify, `pending-<key>[.<context>][.reader]-<width>-<locale>.png` beside
|
|
2113
|
+
* the diagnostic.
|
|
2114
|
+
*/
|
|
2077
2115
|
export function saveSpacePendingScreenshots(projectDir, key, screenshots) {
|
|
2078
2116
|
if (!screenshots?.length) return [];
|
|
2079
2117
|
// Every name is checked before any file is written.
|
|
2080
|
-
const names = screenshots.map(({ width, locale }) => pendingImageName(key, width, locale));
|
|
2081
|
-
return withAppReleaseWorkspace(projectDir, (workspace) =>
|
|
2082
|
-
|
|
2083
|
-
return
|
|
2084
|
-
|
|
2118
|
+
const names = screenshots.map(({ width, locale, context, state }) => pendingImageName(key, width, locale, { context, state }));
|
|
2119
|
+
return withAppReleaseWorkspace(projectDir, (workspace) => {
|
|
2120
|
+
recordImages(key, names);
|
|
2121
|
+
return screenshots.map(({ png }, index) => {
|
|
2122
|
+
replaceVerifyImage(names[index], png);
|
|
2123
|
+
return join(workspace.projectDir, NOTIS_DIR, names[index]);
|
|
2124
|
+
});
|
|
2125
|
+
});
|
|
2085
2126
|
}
|
|
2086
2127
|
|
|
2087
2128
|
/**
|
|
2088
|
-
* The screenshots of the last verify, `view-<key>-<
|
|
2089
|
-
* its data (or of what it showed when it had not).
|
|
2129
|
+
* The screenshots of the last verify, `view-<key>[.<context>]-<width>-<locale>.png` beside the diagnostic, taken once
|
|
2130
|
+
* the view had loaded its data (or of what it showed when it had not). Each comes back with its width, locale and
|
|
2131
|
+
* context and the path it was saved at.
|
|
2090
2132
|
*/
|
|
2091
2133
|
export function saveSpaceScreenshots(projectDir, key, screenshots) {
|
|
2092
|
-
// One image per width, every name checked before any file is written.
|
|
2093
|
-
const kept = new Map((screenshots || []).map(value => [value.width, value]));
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2134
|
+
// One image per width, locale and context, every name checked before any file is written.
|
|
2135
|
+
const kept = new Map((screenshots || []).map(value => [viewImageName(key, value.width, value.locale || 'en', value.context), value]));
|
|
2136
|
+
return withAppReleaseWorkspace(projectDir, (workspace) => {
|
|
2137
|
+
recordImages(key, [...kept.keys()]);
|
|
2138
|
+
return [...kept].map(([name, { width, locale = 'en', context, png }]) => {
|
|
2139
|
+
replaceVerifyImage(name, png);
|
|
2140
|
+
return { width, locale, ...(context ? { context } : {}), path: join(workspace.projectDir, NOTIS_DIR, name) };
|
|
2141
|
+
});
|
|
2142
|
+
});
|
|
2099
2143
|
}
|
|
2100
2144
|
|
|
2101
2145
|
/** Retain the original CAS after an uncertain publish response, across CLI exits. */
|
package/src/runtime/channel.js
CHANGED
|
@@ -12,16 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
import { existsSync } from 'node:fs';
|
|
14
14
|
import { isAbsolute } from 'node:path';
|
|
15
|
+
import { channelForApiHost } from './api-hosts.js';
|
|
15
16
|
|
|
16
17
|
export const RELEASE_CHANNELS = ['stable', 'nightly'];
|
|
17
18
|
// Keep equal to the dist-tags in scripts/release-channels.cjs (a test checks).
|
|
18
19
|
const CHANNEL_TAGS = { stable: 'latest', nightly: 'nightly' };
|
|
19
|
-
// Live API hosts and the channel each one serves.
|
|
20
|
-
const API_HOST_CHANNELS = {
|
|
21
|
-
'api.notis.ai': 'stable',
|
|
22
|
-
'api-beta.notis.ai': 'nightly',
|
|
23
|
-
'api-nightly.notis.ai': 'nightly',
|
|
24
|
-
};
|
|
25
20
|
export const CLI_PACKAGE_NAME = '@notis_ai/cli';
|
|
26
21
|
// Set on the child so a build that disagrees about its own channel — a bad
|
|
27
22
|
// version string, a half-published tag — cannot bounce the process forever.
|
|
@@ -49,7 +44,8 @@ export function normalizeReleaseChannel(value) {
|
|
|
49
44
|
export function channelFromApiBase(apiBase) {
|
|
50
45
|
if (typeof apiBase !== 'string' || !apiBase) return null;
|
|
51
46
|
try {
|
|
52
|
-
|
|
47
|
+
// The live API hosts and the channel each one serves (api-hosts.js).
|
|
48
|
+
return channelForApiHost(new URL(apiBase).hostname);
|
|
53
49
|
} catch {
|
|
54
50
|
// A malformed endpoint says nothing about the channel.
|
|
55
51
|
return null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's fetch gives up on any answer that takes longer than 300 s to start (headersTimeout) or
|
|
3
|
+
* pauses longer than 300 s mid-body (bodyTimeout), and reports it as a bare "fetch failed". The
|
|
4
|
+
* CLI already bounds every request with its own AbortSignal (--timeout-ms, or a longer limit a
|
|
5
|
+
* command sets), so these requests go through an agent without those two hidden limits: the
|
|
6
|
+
* caller's signal is the one deadline, and its timeout message is the one a user reads.
|
|
7
|
+
*
|
|
8
|
+
* Only pass this dispatcher with a signal that ends the request.
|
|
9
|
+
*/
|
|
10
|
+
let agent;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Node's own fetch sends through HTTP_PROXY / HTTPS_PROXY (and honours NO_PROXY) only when its env
|
|
14
|
+
* proxy is on (NODE_USE_ENV_PROXY=1 or --use-env-proxy). A plain Agent would connect directly, so
|
|
15
|
+
* that case keeps the proxy with undici's EnvHttpProxyAgent, which reads the same variables.
|
|
16
|
+
*/
|
|
17
|
+
export function nodeEnvProxyEnabled(env = process.env, execArgv = process.execArgv) {
|
|
18
|
+
// As Node decides: the last --use-env-proxy / --no-use-env-proxy wins (NODE_OPTIONS, then the command line),
|
|
19
|
+
// and without either flag only NODE_USE_ENV_PROXY=1 turns it on.
|
|
20
|
+
const flags = [...String(env.NODE_OPTIONS || '').split(/\s+/), ...execArgv]
|
|
21
|
+
.filter(flag => flag === '--use-env-proxy' || flag === '--no-use-env-proxy');
|
|
22
|
+
return flags.length ? flags.at(-1) === '--use-env-proxy' : env.NODE_USE_ENV_PROXY === '1';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function deadlineDispatcher() {
|
|
26
|
+
if (agent === undefined) {
|
|
27
|
+
try {
|
|
28
|
+
const { Agent, EnvHttpProxyAgent } = await import('undici');
|
|
29
|
+
const options = { headersTimeout: 0, bodyTimeout: 0 };
|
|
30
|
+
agent = nodeEnvProxyEnabled() ? new EnvHttpProxyAgent(options) : new Agent(options);
|
|
31
|
+
} catch {
|
|
32
|
+
// A checkout whose dependencies predate undici keeps Node's default agent and its 300 s limits.
|
|
33
|
+
agent = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return agent ?? undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// A connect timeout is undici's own 10 s, not a slow answer: it stays a network_error naming UND_ERR_CONNECT_TIMEOUT.
|
|
40
|
+
const TIMEOUT_CODES = new Set(['UND_ERR_HEADERS_TIMEOUT', 'UND_ERR_BODY_TIMEOUT']);
|
|
41
|
+
|
|
42
|
+
/** The network code under fetch's bare "fetch failed" (ECONNRESET, ENOTFOUND, UND_ERR_SOCKET, ...), when there is one. */
|
|
43
|
+
export function networkCauseCode(error) {
|
|
44
|
+
for (let value = error, depth = 0; value && depth < 4; value = value.cause, depth += 1) {
|
|
45
|
+
if (typeof value.code === 'string' && value.code) return value.code;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** True when the transport itself stopped waiting for an answer (not our own AbortSignal). */
|
|
51
|
+
export function isTransportTimeout(error) {
|
|
52
|
+
return TIMEOUT_CODES.has(networkCauseCode(error));
|
|
53
|
+
}
|
|
@@ -6,6 +6,16 @@ import { usageError } from './errors.js';
|
|
|
6
6
|
|
|
7
7
|
const MAX_BYTES = 8 * 1024 * 1024;
|
|
8
8
|
const UUID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i;
|
|
9
|
+
// Same rule as the server (server/lib/env_file_names.py): env files hold secrets and are never stored.
|
|
10
|
+
export const ENV_FILE_MESSAGE = 'Env files (.env, .env.*, *.env) hold secrets such as API keys and are never stored. '
|
|
11
|
+
+ 'Nothing was uploaded. Share the setting names without their values instead.';
|
|
12
|
+
|
|
13
|
+
/** Whether a file name or path names a developer env file: server/lib/env_file_names.py's rule, kept the same. */
|
|
14
|
+
export function isEnvFileName(value) {
|
|
15
|
+
const name = String(value || '').replace(/\\/g, '/').replace(/\/+$/, '').split('/').pop().trim().toLowerCase();
|
|
16
|
+
return /^\.env(?:[._-][\s\S]*|rc)?$/.test(name) || name.endsWith('.env');
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
const MIME = { '.html': 'text/html', '.htm': 'text/html', '.txt': 'text/plain', '.md': 'text/markdown',
|
|
10
20
|
'.json': 'application/json', '.pdf': 'application/pdf', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp' };
|
|
11
21
|
|
|
@@ -17,6 +27,7 @@ export async function uploadNativeRecordFileWithCliRuntime({ runtime, target, re
|
|
|
17
27
|
|| !target || typeof target !== 'object' || Array.isArray(target) || !filePath) {
|
|
18
28
|
throw usageError('Choose a local file, native target, record key, schema revision and stable request ID.');
|
|
19
29
|
}
|
|
30
|
+
if (isEnvFileName(filePath) || isEnvFileName(name)) throw usageError(ENV_FILE_MESSAGE);
|
|
20
31
|
const handle = await open(filePath, 'r');
|
|
21
32
|
let data;
|
|
22
33
|
try {
|
package/src/runtime/oauth.js
CHANGED
|
@@ -24,6 +24,7 @@ import { createInterface } from 'node:readline/promises';
|
|
|
24
24
|
|
|
25
25
|
import { CliError, EXIT_CODES, usageError } from './errors.js';
|
|
26
26
|
import { readComputerIdentity } from './computer-identity.js';
|
|
27
|
+
import { isOnRetiredApiHost, renamedRetiredApiOrigin } from './api-hosts.js';
|
|
27
28
|
import { getAuthRecovery, getRetryRecovery, quoteShellArgument } from './auth-recovery.js';
|
|
28
29
|
import {
|
|
29
30
|
channelFromApiBase,
|
|
@@ -37,7 +38,11 @@ import {
|
|
|
37
38
|
getOAuthApiBase,
|
|
38
39
|
getOAuthResource,
|
|
39
40
|
getProfile,
|
|
41
|
+
signedOutRoute,
|
|
40
42
|
loadConfig,
|
|
43
|
+
oauthGrantIsDead,
|
|
44
|
+
oauthGrantOnRetiredAddress,
|
|
45
|
+
refreshTokenFingerprint,
|
|
41
46
|
resolveConfigFile,
|
|
42
47
|
updateConfig,
|
|
43
48
|
} from './profiles.js';
|
|
@@ -348,6 +353,26 @@ function readRefreshAnswer(runtime, { response, text }) {
|
|
|
348
353
|
return payload;
|
|
349
354
|
}
|
|
350
355
|
|
|
356
|
+
// The server refused this refresh token for good: remember which one, so the
|
|
357
|
+
// profile routes like a signed-out one (oauthGrantIsDead) until a new grant
|
|
358
|
+
// replaces it. Best effort; the refusal itself is still reported.
|
|
359
|
+
function recordRefusedRefreshToken(runtime, refreshToken) {
|
|
360
|
+
if (!refreshToken) return;
|
|
361
|
+
try {
|
|
362
|
+
updateConfig((latest) => {
|
|
363
|
+
const current = latest.profiles?.[runtime.profileName];
|
|
364
|
+
if (!current || current.oauth_refresh_token !== refreshToken) return latest;
|
|
365
|
+
latest.profiles[runtime.profileName] = {
|
|
366
|
+
...current,
|
|
367
|
+
oauth_refresh_rejected_for: refreshTokenFingerprint(refreshToken),
|
|
368
|
+
};
|
|
369
|
+
return latest;
|
|
370
|
+
});
|
|
371
|
+
} catch {
|
|
372
|
+
// The refusal is reported either way; the next refresh records it again.
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
351
376
|
async function persistRefreshedSignIn(runtime, metadata, tokenResponse) {
|
|
352
377
|
let lastError = null;
|
|
353
378
|
for (const delay of [0, ...OAUTH_REFRESH_SAVE_RETRY_DELAYS_MS]) {
|
|
@@ -626,7 +651,8 @@ function connectedCallbackHtml({ portalOrigin }) {
|
|
|
626
651
|
transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
|
|
627
652
|
}
|
|
628
653
|
.button:hover { transform: translateY(-1px); border-color: #454b57; background: #1b1e24; }
|
|
629
|
-
.button:focus-visible {
|
|
654
|
+
.button:focus-visible { border-color: var(--focus); }
|
|
655
|
+
@media (forced-colors: none) { :focus, :focus-visible { outline: none; } }
|
|
630
656
|
.button-primary { border-color: var(--primary); background: var(--primary); color: var(--primary-ink); }
|
|
631
657
|
.button-primary:hover { border-color: #fff; background: #fff; }
|
|
632
658
|
.helper { margin: 12px 0 0; color: #777f8d; font-size: 0.78rem; line-height: 1.45; }
|
|
@@ -1030,6 +1056,10 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
1030
1056
|
const now = Math.floor(Date.now() / 1000);
|
|
1031
1057
|
const payload = decodeJwtPayload(tokenResponse.access_token);
|
|
1032
1058
|
const oauthApiBase = (metadata.apiBase || runtime.apiBase || '').replace(/\/+$/, '');
|
|
1059
|
+
const refreshExpiryFromServer = Boolean(tokenResponse.refresh_token)
|
|
1060
|
+
&& tokenResponse.refresh_expires_in !== null
|
|
1061
|
+
&& tokenResponse.refresh_expires_in !== ''
|
|
1062
|
+
&& Number.isFinite(Number(tokenResponse.refresh_expires_in));
|
|
1033
1063
|
const config = updateConfig((latest) => {
|
|
1034
1064
|
const next = ensureProfile(latest, runtime.profileName);
|
|
1035
1065
|
const profile = next.profiles[runtime.profileName];
|
|
@@ -1052,8 +1082,14 @@ function persistOAuthTokenResponse(runtime, metadata, tokenResponse) {
|
|
|
1052
1082
|
oauth_access_token: tokenResponse.access_token,
|
|
1053
1083
|
oauth_refresh_token: tokenResponse.refresh_token || profile.oauth_refresh_token,
|
|
1054
1084
|
oauth_access_expires_at: now + Number(tokenResponse.expires_in || 0),
|
|
1055
|
-
oauth_refresh_expires_at:
|
|
1056
|
-
|
|
1085
|
+
oauth_refresh_expires_at: now + (
|
|
1086
|
+
refreshExpiryFromServer ? Number(tokenResponse.refresh_expires_in) : DEFAULT_REFRESH_EXPIRES_IN
|
|
1087
|
+
),
|
|
1088
|
+
// Only an expiry the server sent for the refresh token it sent may later
|
|
1089
|
+
// prove the grant dead (oauthGrantIsDead); the default above is a guess.
|
|
1090
|
+
oauth_refresh_expiry_from_server: refreshExpiryFromServer || undefined,
|
|
1091
|
+
// A new grant or a renewed one is no longer the token the server refused.
|
|
1092
|
+
oauth_refresh_rejected_for: undefined,
|
|
1057
1093
|
oauth_client_id: metadata.clientId,
|
|
1058
1094
|
oauth_issuer: metadata.issuer,
|
|
1059
1095
|
oauth_scopes: String(tokenResponse.scope || '').split(/\s+/).filter(Boolean),
|
|
@@ -2029,7 +2065,8 @@ function updateRuntimeFromOAuthProfile(runtime, profile) {
|
|
|
2029
2065
|
}
|
|
2030
2066
|
|
|
2031
2067
|
function assertOAuthApiTarget(runtime, profile) {
|
|
2032
|
-
const requestedApiBase =
|
|
2068
|
+
const requestedApiBase = renamedRetiredApiOrigin(runtime.requestedApiBase)
|
|
2069
|
+
|| String(runtime.requestedApiBase || '').replace(/\/+$/, '');
|
|
2033
2070
|
const oauthApiBase = getOAuthApiBase(profile);
|
|
2034
2071
|
if (requestedApiBase && oauthApiBase && requestedApiBase !== oauthApiBase) {
|
|
2035
2072
|
throw oauthError(
|
|
@@ -2039,12 +2076,34 @@ function assertOAuthApiTarget(runtime, profile) {
|
|
|
2039
2076
|
}
|
|
2040
2077
|
}
|
|
2041
2078
|
|
|
2079
|
+
/**
|
|
2080
|
+
* A grant minted while the nightly API answered as api-beta.notis.ai
|
|
2081
|
+
* (oauthGrantOnRetiredAddress) is refused by the nightly service and its
|
|
2082
|
+
* refresh endpoint is the retired domain, so it is never refreshed or sent:
|
|
2083
|
+
* the person is told to sign in again, which starts on stable and follows the
|
|
2084
|
+
* account (CLI-035, CLI-038).
|
|
2085
|
+
*/
|
|
2086
|
+
function retiredAddressGrantError(runtime, profile) {
|
|
2087
|
+
const { hints } = getAuthRecovery(runtime);
|
|
2088
|
+
const retiredHost = [profile.oauth_issuer, getOAuthResource(profile)]
|
|
2089
|
+
.filter(isOnRetiredApiHost)
|
|
2090
|
+
.map(value => new URL(value).hostname)[0];
|
|
2091
|
+
return oauthError(
|
|
2092
|
+
'oauth_grant_retired_address',
|
|
2093
|
+
`This sign-in was made on ${retiredHost}, a retired address of Notis that no longer accepts it. `
|
|
2094
|
+
+ `Sign in again: ${hints[0].command}`,
|
|
2095
|
+
hints,
|
|
2096
|
+
{ retired_host: retiredHost },
|
|
2097
|
+
);
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2042
2100
|
export async function ensureFreshOAuthCredential(runtime, fetchImpl = fetch) {
|
|
2043
2101
|
if (runtime.credentialKind !== 'oauth') {
|
|
2044
2102
|
return Boolean(runtime.jwt);
|
|
2045
2103
|
}
|
|
2046
2104
|
|
|
2047
2105
|
const profile = getProfile(loadConfig(), runtime.profileName);
|
|
2106
|
+
if (oauthGrantOnRetiredAddress(profile)) throw retiredAddressGrantError(runtime, profile);
|
|
2048
2107
|
assertOAuthApiTarget(runtime, profile);
|
|
2049
2108
|
if (!credentialIsExpired({ credentialKind: 'oauth' }, profile)) {
|
|
2050
2109
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
@@ -2322,6 +2381,8 @@ export async function loginWithOAuth(
|
|
|
2322
2381
|
if (
|
|
2323
2382
|
storedProfile.oauth_access_token
|
|
2324
2383
|
&& !credentialIsExpired({ credentialKind: 'oauth' }, storedProfile)
|
|
2384
|
+
// A grant the server refused is no sign-in to confirm.
|
|
2385
|
+
&& !oauthGrantIsDead(storedProfile)
|
|
2325
2386
|
) {
|
|
2326
2387
|
assertOAuthApiTarget(runtime, storedProfile);
|
|
2327
2388
|
updateRuntimeFromOAuthProfile(runtime, storedProfile);
|
|
@@ -2788,6 +2849,9 @@ export async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRe
|
|
|
2788
2849
|
stopTouchingLocks = keepLockFoldersFresh([profileLock, oauthLockDir()]);
|
|
2789
2850
|
const config = loadConfig();
|
|
2790
2851
|
const profile = getProfile(config, runtime.profileName);
|
|
2852
|
+
// Checked before the API target: a retired grant's own address is the
|
|
2853
|
+
// retired one, and nothing is sent with it (CLI-038).
|
|
2854
|
+
if (oauthGrantOnRetiredAddress(profile)) throw retiredAddressGrantError(runtime, profile);
|
|
2791
2855
|
assertOAuthApiTarget(runtime, profile);
|
|
2792
2856
|
if (
|
|
2793
2857
|
profile.oauth_access_token
|
|
@@ -2834,7 +2898,15 @@ export async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRe
|
|
|
2834
2898
|
failure.cause,
|
|
2835
2899
|
);
|
|
2836
2900
|
}
|
|
2837
|
-
|
|
2901
|
+
let rotatedResponse;
|
|
2902
|
+
try {
|
|
2903
|
+
rotatedResponse = readRefreshAnswer(runtime, answer);
|
|
2904
|
+
} catch (refusal) {
|
|
2905
|
+
if (refusal?.code === 'invalid_grant') {
|
|
2906
|
+
recordRefusedRefreshToken(runtime, profile.oauth_refresh_token);
|
|
2907
|
+
}
|
|
2908
|
+
throw refusal;
|
|
2909
|
+
}
|
|
2838
2910
|
const updated = await persistRefreshedSignIn(runtime, metadata, rotatedResponse);
|
|
2839
2911
|
updateRuntimeFromOAuthProfile(runtime, updated);
|
|
2840
2912
|
return true;
|
|
@@ -2928,6 +3000,9 @@ export async function logoutOAuth(runtime, { allProfiles = false } = {}, fetchIm
|
|
|
2928
3000
|
revocationToken
|
|
2929
3001
|
&& profile.oauth_client_id
|
|
2930
3002
|
&& profile.oauth_issuer
|
|
3003
|
+
// The nightly service no longer knows a grant minted on its retired
|
|
3004
|
+
// name, and that name's domain is gone (CLI-038).
|
|
3005
|
+
&& !oauthGrantOnRetiredAddress(profile)
|
|
2931
3006
|
) {
|
|
2932
3007
|
try {
|
|
2933
3008
|
const metadata = storedOAuthMetadata(runtime, profile);
|
|
@@ -2953,12 +3028,29 @@ export async function logoutOAuth(runtime, { allProfiles = false } = {}, fetchIm
|
|
|
2953
3028
|
// A named pending login has no stored profile yet. Cancelling it must
|
|
2954
3029
|
// not create an empty profile as a side effect of logout.
|
|
2955
3030
|
if (!current) return latest;
|
|
3031
|
+
// Signing an account out forgets the route learned from it
|
|
3032
|
+
// (CLI-034, signedOutRoute). A profile with no grant, or one still
|
|
3033
|
+
// holding a worktree credential, keeps its route.
|
|
3034
|
+
const signsOutAccount = Boolean(
|
|
3035
|
+
(current.oauth_access_token
|
|
3036
|
+
|| current.oauth_refresh_token
|
|
3037
|
+
|| current.oauth_client_id
|
|
3038
|
+
|| current.oauth_issuer
|
|
3039
|
+
|| current.oauth_resource
|
|
3040
|
+
|| current.oauth_user_id)
|
|
3041
|
+
&& !current.dev_access_token
|
|
3042
|
+
);
|
|
2956
3043
|
latest.profiles[profileName] = {
|
|
2957
3044
|
...current,
|
|
3045
|
+
...(signsOutAccount
|
|
3046
|
+
? { api_base: undefined, release_channel: undefined, ...signedOutRoute(current) }
|
|
3047
|
+
: {}),
|
|
2958
3048
|
oauth_access_token: undefined,
|
|
2959
3049
|
oauth_refresh_token: undefined,
|
|
2960
3050
|
oauth_access_expires_at: undefined,
|
|
2961
3051
|
oauth_refresh_expires_at: undefined,
|
|
3052
|
+
oauth_refresh_expiry_from_server: undefined,
|
|
3053
|
+
oauth_refresh_rejected_for: undefined,
|
|
2962
3054
|
oauth_client_id: undefined,
|
|
2963
3055
|
oauth_issuer: undefined,
|
|
2964
3056
|
oauth_api_base: undefined,
|