@notis_ai/cli 0.2.32 → 0.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -11
- package/dist/agent-hooks/notis-agent-hook.mjs +4407 -905
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +7 -3
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +5 -3
- package/dist/base-skills/notis-spaces/references/comments.md +102 -0
- package/dist/base-skills/notis-spaces/references/context.md +20 -19
- package/dist/base-skills/notis-spaces/references/design.md +3 -2
- package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
- package/dist/base-skills/notis-spaces/references/store.md +24 -1
- package/dist/sdk/src/components/NotisSelectionBoundary.tsx +13 -5
- package/dist/sdk/src/components/SelectionActionBar.tsx +45 -8
- package/dist/sdk/src/components/SpaceTextComments.tsx +293 -0
- package/dist/sdk/src/components/selectionRange.ts +65 -0
- package/dist/sdk/src/config.ts +3 -1
- package/dist/sdk/src/functions.ts +218 -0
- package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +66 -9
- package/dist/sdk/src/hooks/useConnection.ts +102 -0
- package/dist/sdk/src/hooks/useFunction.ts +42 -0
- package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
- package/dist/sdk/src/index.ts +16 -4
- package/dist/sdk/src/interactions/shortcuts.tsx +6 -1
- package/dist/sdk/src/interactions/swipeDownToDismiss.ts +158 -0
- package/dist/sdk/src/interactions/textBoxTwoState.ts +174 -0
- package/dist/sdk/src/interactions.ts +17 -0
- package/dist/sdk/src/runtime.ts +16 -1
- package/dist/sdk/src/space.ts +401 -33
- package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
- package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
- package/dist/skill-sync/index.js +262 -31
- package/dist/skill-sync-worker.mjs +515 -127
- package/dist/space-harness/host.js +389 -154
- package/dist/space-sdk/dist/chunk-3NPBCE6E.js +3 -0
- package/dist/space-sdk/dist/index.js +3 -3
- package/dist/space-sdk/dist/ui.js +16 -11
- package/dist/space-sdk/src/config.ts +3 -1
- package/dist/space-sdk/src/functions.ts +218 -0
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +7 -0
- package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
- package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
- package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
- package/dist/space-sdk/src/index.d.ts +10 -4
- package/dist/space-sdk/src/interactions/shortcuts.d.ts +5 -0
- package/dist/space-sdk/src/runtime.d.ts +14 -1
- package/dist/space-sdk/src/space.ts +401 -33
- package/dist/space-sdk/src/tailwind-candidates.d.ts +400 -204
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +90 -15
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +4 -1
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +4 -2
- package/dist/space-sdk/src/ui/comments/commentDrafts.d.ts +63 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +59 -88
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +32 -1
- package/dist/space-sdk/src/ui/comments/handover.d.ts +34 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
- package/dist/space-sdk/src/ui/comments/hostPanel.d.ts +113 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +7 -2
- package/dist/space-sdk/src/ui/comments/paneOutlet.d.ts +33 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +71 -27
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
- package/dist/space-sdk/src/ui/comments/reviewRun.d.ts +190 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +116 -77
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
- package/dist/space-sdk/src/ui/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
- package/dist/view-renderer/dist/host.js +450 -215
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
- package/skills/notis-spaces/cli.md +3 -3
- package/src/cli.js +2 -1
- package/src/command-specs/index.js +3 -0
- package/src/command-specs/repository-secrets.js +171 -0
- package/src/command-specs/spaces.js +3 -3
- package/src/runtime/agent-credential.js +175 -0
- package/src/runtime/agent-identity.js +95 -19
- package/src/runtime/app-platform.js +8 -0
- package/src/runtime/auth-recovery.js +14 -0
- package/src/runtime/profiles.js +74 -2
- package/src/runtime/skill-sync/cloud-client.ts +33 -3
- package/src/runtime/skill-sync/index.ts +4 -3
- package/src/runtime/skill-sync/symlink-manager.ts +354 -35
- package/src/runtime/skill-sync/types.ts +14 -2
- package/src/runtime/space-functions.js +213 -0
- package/src/runtime/space-platform.js +12 -3
- package/src/runtime/space-source.js +116 -13
- package/src/runtime/space-test-server.js +22 -4
- package/src/runtime/space-verification.js +3 -1
- package/src/runtime/transport.js +15 -0
- package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
- package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
- package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
// src/skill-sync-worker.js
|
|
2
|
-
import { createHash as
|
|
3
|
-
import { mkdirSync as
|
|
2
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
3
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync6, renameSync as renameSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
4
4
|
import { homedir as homedir5 } from "node:os";
|
|
5
|
-
import { join as
|
|
5
|
+
import { join as join9 } from "node:path";
|
|
6
6
|
|
|
7
7
|
// src/runtime/profiles.js
|
|
8
|
-
import {
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
9
10
|
import {
|
|
10
11
|
existsSync as existsSync3,
|
|
11
|
-
mkdirSync as
|
|
12
|
-
readFileSync as
|
|
13
|
-
renameSync as
|
|
14
|
-
writeFileSync as
|
|
12
|
+
mkdirSync as mkdirSync3,
|
|
13
|
+
readFileSync as readFileSync3,
|
|
14
|
+
renameSync as renameSync3,
|
|
15
|
+
writeFileSync as writeFileSync3
|
|
15
16
|
} from "node:fs";
|
|
16
17
|
import { homedir as homedir2 } from "node:os";
|
|
17
|
-
import { dirname as
|
|
18
|
+
import { dirname as dirname3, join as join3, parse, resolve as resolve2 } from "node:path";
|
|
18
19
|
|
|
19
20
|
// src/runtime/errors.js
|
|
20
21
|
var EXIT_CODES = {
|
|
@@ -343,12 +344,45 @@ function resolveRetryEnabled(globalOptions = {}, env = process.env) {
|
|
|
343
344
|
var AGENT_IDENTITY_ENV = {
|
|
344
345
|
name: "NOTIS_AGENT_NAME",
|
|
345
346
|
id: "NOTIS_AGENT_ID",
|
|
346
|
-
thread: "NOTIS_AGENT_THREAD"
|
|
347
|
+
thread: "NOTIS_AGENT_THREAD",
|
|
348
|
+
threadName: "NOTIS_AGENT_THREAD_NAME",
|
|
349
|
+
harness: "NOTIS_AGENT_HARNESS"
|
|
347
350
|
};
|
|
348
351
|
var AGENT_NAME_MIN = 3;
|
|
349
352
|
var AGENT_NAME_LIMIT = 60;
|
|
350
353
|
var BAND_NAME_EXAMPLE = "fred-and-the-machine";
|
|
351
354
|
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}`;
|
|
355
|
+
var RESERVED_BASES = [
|
|
356
|
+
"claude",
|
|
357
|
+
"claude-code",
|
|
358
|
+
"codex",
|
|
359
|
+
"cursor",
|
|
360
|
+
"cursor-agent",
|
|
361
|
+
"gemini",
|
|
362
|
+
"notis",
|
|
363
|
+
"t3",
|
|
364
|
+
"t3-code",
|
|
365
|
+
"opencode",
|
|
366
|
+
"agent",
|
|
367
|
+
"assistant",
|
|
368
|
+
"bot"
|
|
369
|
+
];
|
|
370
|
+
var RESERVED_AGENT_NAMES = Object.freeze(new Set(
|
|
371
|
+
RESERVED_BASES.flatMap((base) => [base, `${base}-cli`, `${base}-agent`])
|
|
372
|
+
));
|
|
373
|
+
function detectAgentHarness(env = process.env) {
|
|
374
|
+
const set = (name) => typeof env[name] === "string" && env[name].trim() !== "";
|
|
375
|
+
if (set("CLAUDECODE") || set("CLAUDE_CODE_ENTRYPOINT") || set("CLAUDE_CODE_SESSION_ID")) return "claude_code";
|
|
376
|
+
if (Object.keys(env).some((key) => key.startsWith("CODEX_") && key !== "CODEX_HOME" && set(key))) return "codex";
|
|
377
|
+
if (set("CURSOR_AGENT")) return "cursor_agent";
|
|
378
|
+
if (set("GEMINI_CLI")) return "gemini";
|
|
379
|
+
if (set("OPENCODE")) return "opencode";
|
|
380
|
+
const named = String(env.AI_AGENT ?? "").toLowerCase();
|
|
381
|
+
if (named.startsWith("claude")) return "claude_code";
|
|
382
|
+
if (named.startsWith("codex")) return "codex";
|
|
383
|
+
if (named.startsWith("cursor")) return "cursor_agent";
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
352
386
|
function pick(flag, variable) {
|
|
353
387
|
if (typeof flag === "string") return flag;
|
|
354
388
|
return typeof variable === "string" ? variable : void 0;
|
|
@@ -359,13 +393,89 @@ function readAgentIdentity(globalOptions = {}, env = process.env) {
|
|
|
359
393
|
id: pick(globalOptions.agentId, env[AGENT_IDENTITY_ENV.id]),
|
|
360
394
|
thread: pick(globalOptions.agentThread, env[AGENT_IDENTITY_ENV.thread])
|
|
361
395
|
};
|
|
362
|
-
|
|
396
|
+
const threadName = pick(globalOptions.agentThreadName, env[AGENT_IDENTITY_ENV.threadName]);
|
|
397
|
+
if (threadName !== void 0) raw.threadName = threadName;
|
|
398
|
+
if (!Object.values(raw).some((value) => typeof value === "string" && value.trim())) return null;
|
|
399
|
+
const harness = pick(void 0, env[AGENT_IDENTITY_ENV.harness]) ?? detectAgentHarness(env);
|
|
400
|
+
return harness ? { ...raw, harness } : raw;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/runtime/agent-credential.js
|
|
404
|
+
import { createHash } from "node:crypto";
|
|
405
|
+
import {
|
|
406
|
+
chmodSync,
|
|
407
|
+
mkdirSync as mkdirSync2,
|
|
408
|
+
readdirSync,
|
|
409
|
+
readFileSync as readFileSync2,
|
|
410
|
+
renameSync as renameSync2,
|
|
411
|
+
unlinkSync,
|
|
412
|
+
writeFileSync as writeFileSync2
|
|
413
|
+
} from "node:fs";
|
|
414
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
415
|
+
var MANAGED_AGENT_TYPE = "notis_managed_agent";
|
|
416
|
+
var AGENT_CLAIM = "notis_agent";
|
|
417
|
+
var CACHE_DIRNAME = "agent-credentials";
|
|
418
|
+
var AGENT_RENEW_WINDOW_SECONDS = 60 * 60;
|
|
419
|
+
var RENEW_TIMEOUT_MS = 15e3;
|
|
420
|
+
function nowSeconds() {
|
|
421
|
+
return Math.floor(Date.now() / 1e3);
|
|
422
|
+
}
|
|
423
|
+
function unverifiedPayload(jwt) {
|
|
424
|
+
if (typeof jwt !== "string" || !jwt) return null;
|
|
425
|
+
try {
|
|
426
|
+
const parts = jwt.split(".");
|
|
427
|
+
if (parts.length !== 3) return null;
|
|
428
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
|
|
429
|
+
return payload && typeof payload === "object" ? payload : null;
|
|
430
|
+
} catch {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function agentCredentialExpiry(jwt) {
|
|
435
|
+
const payload = unverifiedPayload(jwt);
|
|
436
|
+
if (!payload || payload.type !== MANAGED_AGENT_TYPE || !payload[AGENT_CLAIM] || typeof payload[AGENT_CLAIM] !== "object" || typeof payload.exp !== "number") {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
return payload.exp;
|
|
440
|
+
}
|
|
441
|
+
function cacheDirectory(configFile) {
|
|
442
|
+
return join2(dirname2(configFile), CACHE_DIRNAME);
|
|
443
|
+
}
|
|
444
|
+
function agentCredentialCacheFile(configFile, envJwt) {
|
|
445
|
+
return join2(cacheDirectory(configFile), `${createHash("sha256").update(envJwt).digest("hex")}.json`);
|
|
446
|
+
}
|
|
447
|
+
function readCachedToken(configFile, envJwt) {
|
|
448
|
+
try {
|
|
449
|
+
const cached = JSON.parse(readFileSync2(agentCredentialCacheFile(configFile, envJwt), "utf-8"));
|
|
450
|
+
const token = typeof cached?.token === "string" ? cached.token : null;
|
|
451
|
+
if (!token || agentCredentialExpiry(token) === null || unverifiedPayload(token).sub !== unverifiedPayload(envJwt).sub) {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
return token;
|
|
455
|
+
} catch {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function selectAgentCredential(envJwt, { configFile, now = nowSeconds() } = {}) {
|
|
460
|
+
const envExpiry = agentCredentialExpiry(envJwt);
|
|
461
|
+
if (envExpiry === null) return null;
|
|
462
|
+
const cached = configFile ? readCachedToken(configFile, envJwt) : null;
|
|
463
|
+
const cachedExpiry = cached ? agentCredentialExpiry(cached) : null;
|
|
464
|
+
if (cached && cachedExpiry > now && cachedExpiry > envExpiry) {
|
|
465
|
+
return { jwt: cached };
|
|
466
|
+
}
|
|
467
|
+
return { jwt: envJwt };
|
|
363
468
|
}
|
|
469
|
+
var AGENT_RENEW_REQUEST = Object.freeze({
|
|
470
|
+
path: "/cli_tools",
|
|
471
|
+
body: Object.freeze({ operation: "renew_agent_credential" }),
|
|
472
|
+
timeoutMs: RENEW_TIMEOUT_MS
|
|
473
|
+
});
|
|
364
474
|
|
|
365
475
|
// src/runtime/profiles.js
|
|
366
|
-
var CONFIG_DIR =
|
|
367
|
-
var CONFIG_FILE =
|
|
368
|
-
var WORKSPACE_DIR =
|
|
476
|
+
var CONFIG_DIR = join3(homedir2(), ".notis");
|
|
477
|
+
var CONFIG_FILE = join3(CONFIG_DIR, "config.json");
|
|
478
|
+
var WORKSPACE_DIR = join3(CONFIG_DIR, "workspace");
|
|
369
479
|
var DEFAULT_API_BASE = currentApiOrigin("stable");
|
|
370
480
|
var NIGHTLY_API_BASE = currentApiOrigin("nightly");
|
|
371
481
|
var DEFAULT_PROFILE = "default";
|
|
@@ -379,8 +489,9 @@ var LEGACY_DESKTOP_PROFILE_KEYS = [
|
|
|
379
489
|
"desktop_app_name",
|
|
380
490
|
"desktop_pid"
|
|
381
491
|
];
|
|
382
|
-
var WORKTREE_RUNTIME_FILENAME =
|
|
383
|
-
var
|
|
492
|
+
var WORKTREE_RUNTIME_FILENAME = join3(".context", "notis-runtime.json");
|
|
493
|
+
var WORKTREE_RUNTIME_SECRETS_FILENAME = "notis-runtime-secrets.json";
|
|
494
|
+
var WORKTREE_ROUTING_FILENAME = join3(".context", "notis-routing.json");
|
|
384
495
|
var LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
385
496
|
function clone(value) {
|
|
386
497
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -460,7 +571,7 @@ function normalizeConfig(rawConfig = {}) {
|
|
|
460
571
|
}
|
|
461
572
|
function readJsonFile(path3) {
|
|
462
573
|
try {
|
|
463
|
-
return JSON.parse(
|
|
574
|
+
return JSON.parse(readFileSync3(path3, "utf-8"));
|
|
464
575
|
} catch {
|
|
465
576
|
return null;
|
|
466
577
|
}
|
|
@@ -469,14 +580,14 @@ function findUp(filename, startDir = process.cwd(), boundary = null) {
|
|
|
469
580
|
let current = resolve2(startDir);
|
|
470
581
|
const root = parse(current).root;
|
|
471
582
|
while (true) {
|
|
472
|
-
const candidate =
|
|
583
|
+
const candidate = join3(current, filename);
|
|
473
584
|
if (existsSync3(candidate)) {
|
|
474
585
|
return candidate;
|
|
475
586
|
}
|
|
476
587
|
if (current === root || current === boundary) {
|
|
477
588
|
return null;
|
|
478
589
|
}
|
|
479
|
-
current =
|
|
590
|
+
current = dirname3(current);
|
|
480
591
|
}
|
|
481
592
|
}
|
|
482
593
|
function processIsAlive(pid) {
|
|
@@ -490,12 +601,47 @@ function processIsAlive(pid) {
|
|
|
490
601
|
return error?.code === "EPERM";
|
|
491
602
|
}
|
|
492
603
|
}
|
|
604
|
+
var RUNTIME_API_PROBE_TIMEOUT_MS = 1500;
|
|
605
|
+
var RUNTIME_API_PROBE_SOURCE = `
|
|
606
|
+
const target = process.argv[1].replace(/\\/+$/, '') + '/openapi.json';
|
|
607
|
+
fetch(target, { redirect: 'manual', signal: AbortSignal.timeout(${RUNTIME_API_PROBE_TIMEOUT_MS}) })
|
|
608
|
+
.then((response) => {
|
|
609
|
+
response.body?.cancel().catch(() => {});
|
|
610
|
+
process.exit(response.ok ? 0 : 1);
|
|
611
|
+
})
|
|
612
|
+
.catch(() => process.exit(1));
|
|
613
|
+
`;
|
|
614
|
+
var runtimeApiProbeResults = /* @__PURE__ */ new Map();
|
|
615
|
+
function localRuntimeApiAnswers(apiBase) {
|
|
616
|
+
if (runtimeApiProbeResults.has(apiBase)) {
|
|
617
|
+
return runtimeApiProbeResults.get(apiBase);
|
|
618
|
+
}
|
|
619
|
+
let answered = false;
|
|
620
|
+
try {
|
|
621
|
+
const probe = spawnSync(process.execPath, ["-e", RUNTIME_API_PROBE_SOURCE, apiBase], {
|
|
622
|
+
env: { PATH: process.env.PATH || "" },
|
|
623
|
+
stdio: "ignore",
|
|
624
|
+
timeout: RUNTIME_API_PROBE_TIMEOUT_MS + 2500
|
|
625
|
+
});
|
|
626
|
+
answered = probe.status === 0;
|
|
627
|
+
} catch {
|
|
628
|
+
answered = false;
|
|
629
|
+
}
|
|
630
|
+
runtimeApiProbeResults.set(apiBase, answered);
|
|
631
|
+
return answered;
|
|
632
|
+
}
|
|
633
|
+
function devRuntimeIsAlive(pid, apiBase) {
|
|
634
|
+
if (processIsAlive(pid)) {
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
return Number.isInteger(pid) && pid > 0 && localRuntimeApiAnswers(apiBase);
|
|
638
|
+
}
|
|
493
639
|
function resolveWorktreeRuntime(startDir = process.cwd()) {
|
|
494
640
|
if (process.env.NODE_ENV === "test" && process.env.NOTIS_TEST_DISABLE_WORKTREE_ROUTING === "1") {
|
|
495
641
|
return null;
|
|
496
642
|
}
|
|
497
643
|
const routingPath = findUp(WORKTREE_ROUTING_FILENAME, startDir);
|
|
498
|
-
const boundary = routingPath ?
|
|
644
|
+
const boundary = routingPath ? dirname3(dirname3(routingPath)) : null;
|
|
499
645
|
const runtimePath = findUp(WORKTREE_RUNTIME_FILENAME, startDir, boundary);
|
|
500
646
|
const routing = routingPath ? readJsonFile(routingPath) : null;
|
|
501
647
|
if (!runtimePath) {
|
|
@@ -516,12 +662,14 @@ function resolveWorktreeRuntime(startDir = process.cwd()) {
|
|
|
516
662
|
return null;
|
|
517
663
|
}
|
|
518
664
|
const runtime = readJsonFile(runtimePath);
|
|
665
|
+
const secrets = readJsonFile(join3(dirname3(runtimePath), WORKTREE_RUNTIME_SECRETS_FILENAME));
|
|
666
|
+
const sessionSecrets = secrets && runtime && secrets.dev_session_id === runtime.dev_session_id ? secrets : null;
|
|
519
667
|
const apiBase = typeof runtime?.api_base === "string" ? runtime.api_base.replace(/\/+$/, "") : "";
|
|
520
668
|
const profile = typeof runtime?.profile === "string" ? runtime.profile.trim() : "";
|
|
521
|
-
const devAccessToken = typeof runtime?.dev_access_token === "string" ? runtime.dev_access_token.trim() : "";
|
|
669
|
+
const devAccessToken = typeof sessionSecrets?.dev_access_token === "string" && sessionSecrets.dev_access_token.trim() ? sessionSecrets.dev_access_token.trim() : typeof runtime?.dev_access_token === "string" ? runtime.dev_access_token.trim() : "";
|
|
522
670
|
const desktopDeepLinkScheme = typeof runtime?.desktop_deep_link_scheme === "string" ? runtime.desktop_deep_link_scheme.trim() : "";
|
|
523
671
|
const pid = Number(runtime?.dev_pid);
|
|
524
|
-
if (runtime?.mode !== "local-only" || !isLocalApiBase(apiBase) || !profile || !devAccessToken || !
|
|
672
|
+
if (runtime?.mode !== "local-only" || !isLocalApiBase(apiBase) || !profile || !devAccessToken || !devRuntimeIsAlive(pid, apiBase)) {
|
|
525
673
|
return {
|
|
526
674
|
unavailable: new CliError({
|
|
527
675
|
code: "dev_runtime_unavailable",
|
|
@@ -558,7 +706,7 @@ function loadConfig() {
|
|
|
558
706
|
return normalizeConfig({});
|
|
559
707
|
}
|
|
560
708
|
try {
|
|
561
|
-
return normalizeConfig(JSON.parse(
|
|
709
|
+
return normalizeConfig(JSON.parse(readFileSync3(configFile, "utf-8")));
|
|
562
710
|
} catch {
|
|
563
711
|
return normalizeConfig({});
|
|
564
712
|
}
|
|
@@ -566,7 +714,7 @@ function loadConfig() {
|
|
|
566
714
|
function writeConfig(configFile, config) {
|
|
567
715
|
let rawConfig = null;
|
|
568
716
|
try {
|
|
569
|
-
rawConfig = JSON.parse(
|
|
717
|
+
rawConfig = JSON.parse(readFileSync3(configFile, "utf-8"));
|
|
570
718
|
} catch {
|
|
571
719
|
}
|
|
572
720
|
const normalized = normalizeConfig(config);
|
|
@@ -584,10 +732,10 @@ function writeConfig(configFile, config) {
|
|
|
584
732
|
writeRawConfig(configFile, persisted);
|
|
585
733
|
}
|
|
586
734
|
function writeRawConfig(configFile, config) {
|
|
587
|
-
|
|
735
|
+
mkdirSync3(dirname3(configFile), { recursive: true });
|
|
588
736
|
const temporaryFile = `${configFile}.${process.pid}.${Date.now()}.tmp`;
|
|
589
|
-
|
|
590
|
-
|
|
737
|
+
writeFileSync3(temporaryFile, JSON.stringify(config, null, 2), { mode: 384 });
|
|
738
|
+
renameSync3(temporaryFile, configFile);
|
|
591
739
|
}
|
|
592
740
|
function withConfigWriteLock(callback) {
|
|
593
741
|
return withConfigFileWriteLock(resolveConfigFile(), callback);
|
|
@@ -692,9 +840,9 @@ function oauthGrantOnRetiredAddress(profile = {}) {
|
|
|
692
840
|
return isOnRetiredApiHost(profile.oauth_issuer) || isOnRetiredApiHost(getOAuthResource(profile));
|
|
693
841
|
}
|
|
694
842
|
function refreshTokenFingerprint(refreshToken) {
|
|
695
|
-
return
|
|
843
|
+
return createHash2("sha256").update(String(refreshToken)).digest("hex").slice(0, 32);
|
|
696
844
|
}
|
|
697
|
-
function oauthGrantIsDead(profile = {},
|
|
845
|
+
function oauthGrantIsDead(profile = {}, nowSeconds2 = Math.floor(Date.now() / 1e3)) {
|
|
698
846
|
if (oauthGrantOnRetiredAddress(profile)) return true;
|
|
699
847
|
const refreshToken = profile.oauth_refresh_token;
|
|
700
848
|
if (!refreshToken) return false;
|
|
@@ -704,7 +852,7 @@ function oauthGrantIsDead(profile = {}, nowSeconds = Math.floor(Date.now() / 1e3
|
|
|
704
852
|
if (profile.oauth_refresh_expiry_from_server !== true) return false;
|
|
705
853
|
const refreshExpiry = Number(profile.oauth_refresh_expires_at);
|
|
706
854
|
const accessExpiry = Number(profile.oauth_access_expires_at);
|
|
707
|
-
return Number.isFinite(refreshExpiry) && refreshExpiry <=
|
|
855
|
+
return Number.isFinite(refreshExpiry) && refreshExpiry <= nowSeconds2 && Number.isFinite(accessExpiry) && accessExpiry <= nowSeconds2;
|
|
708
856
|
}
|
|
709
857
|
function resolveDefaultLiveApiBase(profile = {}) {
|
|
710
858
|
const channel = pinnedReleaseChannel(profile) || (isLiveApiBase(profile.api_base) ? channelFromProfile({ api_base: profile.api_base }) : null);
|
|
@@ -850,6 +998,7 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
850
998
|
const oauthJwt = profile.oauth_access_token;
|
|
851
999
|
let jwt;
|
|
852
1000
|
let credentialKind;
|
|
1001
|
+
let agentEnvJwt = null;
|
|
853
1002
|
if (requireAuth && !devRuntime && devJwt && !oauthJwt && !process.env.NOTIS_JWT) {
|
|
854
1003
|
throw new CliError({
|
|
855
1004
|
code: "dev_runtime_unavailable",
|
|
@@ -868,6 +1017,14 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
868
1017
|
} else if (envJwt) {
|
|
869
1018
|
jwt = envJwt;
|
|
870
1019
|
credentialKind = "env";
|
|
1020
|
+
try {
|
|
1021
|
+
const selected = selectAgentCredential(envJwt, { configFile: resolveConfigFile() });
|
|
1022
|
+
if (selected) {
|
|
1023
|
+
jwt = selected.jwt;
|
|
1024
|
+
agentEnvJwt = envJwt;
|
|
1025
|
+
}
|
|
1026
|
+
} catch {
|
|
1027
|
+
}
|
|
871
1028
|
} else if (oauthJwt && !credentialIsExpired({ credentialKind: "oauth", jwt: oauthJwt }, profile)) {
|
|
872
1029
|
jwt = oauthJwt;
|
|
873
1030
|
credentialKind = "oauth";
|
|
@@ -936,6 +1093,8 @@ function resolveRuntimeProfile(globalOptions = {}, {
|
|
|
936
1093
|
jwt,
|
|
937
1094
|
credentialKind,
|
|
938
1095
|
credentialSource: credentialKind,
|
|
1096
|
+
// The NOTIS_JWT of a managed agent credential, set only when `jwt` may be renewed (agent-credential.js).
|
|
1097
|
+
agentEnvJwt,
|
|
939
1098
|
oauthAccessToken: profile.oauth_access_token,
|
|
940
1099
|
oauthRefreshToken: profile.oauth_refresh_token,
|
|
941
1100
|
oauthAccessExpiresAt: profile.oauth_access_expires_at,
|
|
@@ -986,16 +1145,16 @@ function getJwtSubject(jwt) {
|
|
|
986
1145
|
return null;
|
|
987
1146
|
}
|
|
988
1147
|
}
|
|
989
|
-
function credentialIsExpired(runtime, profile = {},
|
|
1148
|
+
function credentialIsExpired(runtime, profile = {}, nowSeconds2 = Math.floor(Date.now() / 1e3)) {
|
|
990
1149
|
const credentialKind = runtime?.credentialKind || (runtime?.credentialSource === "env" ? "env" : null);
|
|
991
1150
|
switch (credentialKind) {
|
|
992
1151
|
case "oauth": {
|
|
993
1152
|
const expiration = Number(profile.oauth_access_expires_at);
|
|
994
|
-
return !Number.isFinite(expiration) || expiration <=
|
|
1153
|
+
return !Number.isFinite(expiration) || expiration <= nowSeconds2 || oauthGrantIsDead(profile, nowSeconds2);
|
|
995
1154
|
}
|
|
996
1155
|
case "env": {
|
|
997
1156
|
const expiration = getJwtExpiration(runtime?.jwt);
|
|
998
|
-
return expiration !== null && expiration <=
|
|
1157
|
+
return expiration !== null && expiration <= nowSeconds2;
|
|
999
1158
|
}
|
|
1000
1159
|
case "worktree": {
|
|
1001
1160
|
const rawExpiration = profile.dev_access_expires_at ?? getJwtExpiration(runtime?.jwt);
|
|
@@ -1003,7 +1162,7 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds = Math.floor(Date
|
|
|
1003
1162
|
return true;
|
|
1004
1163
|
}
|
|
1005
1164
|
const expiration = Number(rawExpiration);
|
|
1006
|
-
return !Number.isFinite(expiration) || expiration <=
|
|
1165
|
+
return !Number.isFinite(expiration) || expiration <= nowSeconds2;
|
|
1007
1166
|
}
|
|
1008
1167
|
default:
|
|
1009
1168
|
return true;
|
|
@@ -1012,39 +1171,39 @@ function credentialIsExpired(runtime, profile = {}, nowSeconds = Math.floor(Date
|
|
|
1012
1171
|
|
|
1013
1172
|
// src/runtime/oauth.js
|
|
1014
1173
|
import {
|
|
1015
|
-
createHash as
|
|
1174
|
+
createHash as createHash3,
|
|
1016
1175
|
randomBytes,
|
|
1017
1176
|
timingSafeEqual
|
|
1018
1177
|
} from "node:crypto";
|
|
1019
1178
|
import { subscribe, unsubscribe } from "node:diagnostics_channel";
|
|
1020
1179
|
import {
|
|
1021
|
-
mkdirSync as
|
|
1022
|
-
readdirSync,
|
|
1023
|
-
readFileSync as
|
|
1024
|
-
renameSync as
|
|
1180
|
+
mkdirSync as mkdirSync5,
|
|
1181
|
+
readdirSync as readdirSync2,
|
|
1182
|
+
readFileSync as readFileSync5,
|
|
1183
|
+
renameSync as renameSync5,
|
|
1025
1184
|
rmdirSync,
|
|
1026
1185
|
rmSync as rmSync2,
|
|
1027
1186
|
statSync as statSync2,
|
|
1028
1187
|
utimesSync,
|
|
1029
|
-
writeFileSync as
|
|
1188
|
+
writeFileSync as writeFileSync5
|
|
1030
1189
|
} from "node:fs";
|
|
1031
1190
|
import { homedir as homedir3 } from "node:os";
|
|
1032
|
-
import { basename, dirname as
|
|
1191
|
+
import { basename, dirname as dirname5, join as join5 } from "node:path";
|
|
1033
1192
|
import { fileURLToPath } from "node:url";
|
|
1034
1193
|
import { createInterface } from "node:readline/promises";
|
|
1035
1194
|
|
|
1036
1195
|
// src/runtime/computer-identity.js
|
|
1037
1196
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
1038
1197
|
import { execFileSync } from "node:child_process";
|
|
1039
|
-
import { mkdirSync as
|
|
1198
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync4, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1040
1199
|
import { hostname as osHostname } from "node:os";
|
|
1041
|
-
import { dirname as
|
|
1200
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
1042
1201
|
var COMPUTER_IDENTITY_VERSION = 1;
|
|
1043
1202
|
var COMPUTER_NAME_MAX_LENGTH = 64;
|
|
1044
1203
|
var COMPUTER_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
1045
1204
|
var FALLBACK_COMPUTER_NAME = "Computer";
|
|
1046
1205
|
function computerIdentityFile(configFile = resolveCliConfigFile()) {
|
|
1047
|
-
return
|
|
1206
|
+
return join4(dirname4(configFile), "computer.json");
|
|
1048
1207
|
}
|
|
1049
1208
|
function normalizeComputerName(value) {
|
|
1050
1209
|
if (typeof value !== "string") return null;
|
|
@@ -1082,7 +1241,7 @@ function defaultComputerName(options = {}) {
|
|
|
1082
1241
|
function parseIdentityFile(file) {
|
|
1083
1242
|
let raw;
|
|
1084
1243
|
try {
|
|
1085
|
-
raw = JSON.parse(
|
|
1244
|
+
raw = JSON.parse(readFileSync4(file, "utf8"));
|
|
1086
1245
|
} catch {
|
|
1087
1246
|
return null;
|
|
1088
1247
|
}
|
|
@@ -1098,16 +1257,16 @@ function validStored(raw) {
|
|
|
1098
1257
|
};
|
|
1099
1258
|
}
|
|
1100
1259
|
function writeIdentityFile(file, stored) {
|
|
1101
|
-
|
|
1260
|
+
mkdirSync4(dirname4(file), { recursive: true });
|
|
1102
1261
|
const contents = {
|
|
1103
1262
|
version: COMPUTER_IDENTITY_VERSION,
|
|
1104
1263
|
computer_id: stored.computerId,
|
|
1105
1264
|
...stored.name ? { name: stored.name } : {}
|
|
1106
1265
|
};
|
|
1107
1266
|
const temporaryFile = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
1108
|
-
|
|
1267
|
+
writeFileSync4(temporaryFile, `${JSON.stringify(contents, null, 2)}
|
|
1109
1268
|
`, { mode: 384 });
|
|
1110
|
-
|
|
1269
|
+
renameSync4(temporaryFile, file);
|
|
1111
1270
|
}
|
|
1112
1271
|
function withIdentity(stored, options) {
|
|
1113
1272
|
const defaultName = defaultComputerName(options);
|
|
@@ -1139,7 +1298,7 @@ function readComputerIdentity(options = {}) {
|
|
|
1139
1298
|
|
|
1140
1299
|
// src/runtime/oauth.js
|
|
1141
1300
|
function oauthLockDir() {
|
|
1142
|
-
return
|
|
1301
|
+
return join5(homedir3(), ".notis", "oauth.lock");
|
|
1143
1302
|
}
|
|
1144
1303
|
var DEFAULT_REFRESH_EXPIRES_IN = 30 * 24 * 60 * 60;
|
|
1145
1304
|
var PENDING_LOGIN_TTL_SECONDS = 30 * 60;
|
|
@@ -1446,7 +1605,7 @@ var LISTENER_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
|
1446
1605
|
var LISTENER_START_LOCK_STALE_MS = LISTENER_HANDSHAKE_TIMEOUT_MS * 2;
|
|
1447
1606
|
var LISTENER_GLOBAL_LOCK_HEARTBEAT_MS = 5e3;
|
|
1448
1607
|
function listenerStateFile(runtime) {
|
|
1449
|
-
const profileKey =
|
|
1608
|
+
const profileKey = createHash3("sha256").update(String(runtime.profileName || "default")).digest("hex").slice(0, 16);
|
|
1450
1609
|
return `${resolveConfigFile()}.login-listener.${profileKey}`;
|
|
1451
1610
|
}
|
|
1452
1611
|
function listenerStartLockDir(runtime) {
|
|
@@ -1456,11 +1615,11 @@ function listenerGlobalLockDir() {
|
|
|
1456
1615
|
return `${resolveConfigFile()}.oauth-listener-global.lock`;
|
|
1457
1616
|
}
|
|
1458
1617
|
function listenerGlobalLockOwnerFile(lockDir) {
|
|
1459
|
-
return
|
|
1618
|
+
return join5(lockDir, "owner.json");
|
|
1460
1619
|
}
|
|
1461
1620
|
function readListenerGlobalLockOwner(lockDir) {
|
|
1462
1621
|
try {
|
|
1463
|
-
return JSON.parse(
|
|
1622
|
+
return JSON.parse(readFileSync5(listenerGlobalLockOwnerFile(lockDir), "utf-8"));
|
|
1464
1623
|
} catch {
|
|
1465
1624
|
return null;
|
|
1466
1625
|
}
|
|
@@ -1468,7 +1627,7 @@ function readListenerGlobalLockOwner(lockDir) {
|
|
|
1468
1627
|
function writeListenerGlobalLockOwner(lock) {
|
|
1469
1628
|
const current = readListenerGlobalLockOwner(lock.lockDir);
|
|
1470
1629
|
if (current && current.owner_token !== lock.ownerToken) return false;
|
|
1471
|
-
|
|
1630
|
+
writeFileSync5(listenerGlobalLockOwnerFile(lock.lockDir), JSON.stringify({
|
|
1472
1631
|
owner_token: lock.ownerToken,
|
|
1473
1632
|
owner_pid: process.pid,
|
|
1474
1633
|
updated_at: Date.now()
|
|
@@ -1489,7 +1648,7 @@ function listenerGlobalLockIsStale(lockDir, staleMs) {
|
|
|
1489
1648
|
function retireStaleListenerGlobalLock(lockDir) {
|
|
1490
1649
|
const retiredDir = `${lockDir}.stale-${process.pid}-${base64url(randomBytes(8))}`;
|
|
1491
1650
|
try {
|
|
1492
|
-
|
|
1651
|
+
renameSync5(lockDir, retiredDir);
|
|
1493
1652
|
} catch {
|
|
1494
1653
|
return false;
|
|
1495
1654
|
}
|
|
@@ -1498,11 +1657,11 @@ function retireStaleListenerGlobalLock(lockDir) {
|
|
|
1498
1657
|
}
|
|
1499
1658
|
async function acquireListenerStartLock(runtime) {
|
|
1500
1659
|
const lockDir = listenerStartLockDir(runtime);
|
|
1501
|
-
|
|
1660
|
+
mkdirSync5(dirname5(lockDir), { recursive: true });
|
|
1502
1661
|
const deadline = Date.now() + LISTENER_START_LOCK_STALE_MS * 2;
|
|
1503
1662
|
for (; ; ) {
|
|
1504
1663
|
try {
|
|
1505
|
-
|
|
1664
|
+
mkdirSync5(lockDir);
|
|
1506
1665
|
return lockDir;
|
|
1507
1666
|
} catch (error) {
|
|
1508
1667
|
if (error?.code !== "EEXIST") throw error;
|
|
@@ -1536,11 +1695,11 @@ async function acquireListenerGlobalLock({
|
|
|
1536
1695
|
heartbeatMs = LISTENER_GLOBAL_LOCK_HEARTBEAT_MS
|
|
1537
1696
|
} = {}) {
|
|
1538
1697
|
const lockDir = listenerGlobalLockDir();
|
|
1539
|
-
|
|
1698
|
+
mkdirSync5(dirname5(lockDir), { recursive: true });
|
|
1540
1699
|
const deadline = Date.now() + waitMs;
|
|
1541
1700
|
for (; ; ) {
|
|
1542
1701
|
try {
|
|
1543
|
-
|
|
1702
|
+
mkdirSync5(lockDir);
|
|
1544
1703
|
const lock = {
|
|
1545
1704
|
lockDir,
|
|
1546
1705
|
ownerToken: base64url(randomBytes(24)),
|
|
@@ -1577,14 +1736,14 @@ function releaseListenerGlobalLock(lock) {
|
|
|
1577
1736
|
if (owner?.owner_token !== lock.ownerToken) return;
|
|
1578
1737
|
const releasedDir = `${lock.lockDir}.released-${process.pid}-${lock.ownerToken}`;
|
|
1579
1738
|
try {
|
|
1580
|
-
|
|
1739
|
+
renameSync5(lock.lockDir, releasedDir);
|
|
1581
1740
|
} catch {
|
|
1582
1741
|
return;
|
|
1583
1742
|
}
|
|
1584
1743
|
const movedOwner = readListenerGlobalLockOwner(releasedDir);
|
|
1585
1744
|
if (movedOwner?.owner_token !== lock.ownerToken) {
|
|
1586
1745
|
try {
|
|
1587
|
-
|
|
1746
|
+
renameSync5(releasedDir, lock.lockDir);
|
|
1588
1747
|
} catch {
|
|
1589
1748
|
}
|
|
1590
1749
|
return;
|
|
@@ -1651,11 +1810,11 @@ function lockIsStale() {
|
|
|
1651
1810
|
}
|
|
1652
1811
|
}
|
|
1653
1812
|
async function acquireRefreshLock(runtime, staleAccessToken, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS) {
|
|
1654
|
-
|
|
1813
|
+
mkdirSync5(join5(homedir3(), ".notis"), { recursive: true });
|
|
1655
1814
|
const deadline = Date.now() + waitMs;
|
|
1656
1815
|
for (; ; ) {
|
|
1657
1816
|
try {
|
|
1658
|
-
|
|
1817
|
+
mkdirSync5(oauthLockDir());
|
|
1659
1818
|
return true;
|
|
1660
1819
|
} catch (error) {
|
|
1661
1820
|
if (error?.code !== "EEXIST") throw error;
|
|
@@ -1789,8 +1948,8 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
1789
1948
|
// dist/skill-sync/index.js
|
|
1790
1949
|
import { createHash as createHash4 } from "node:crypto";
|
|
1791
1950
|
import { promises as fs3 } from "node:fs";
|
|
1792
|
-
import { dirname as
|
|
1793
|
-
import { createHash as
|
|
1951
|
+
import { dirname as dirname6, join as join6 } from "node:path";
|
|
1952
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
1794
1953
|
import { createHash as createHash22 } from "crypto";
|
|
1795
1954
|
import { execFile } from "child_process";
|
|
1796
1955
|
import { promises as fs } from "fs";
|
|
@@ -1857,7 +2016,7 @@ function assertNativePull(response) {
|
|
|
1857
2016
|
}
|
|
1858
2017
|
}
|
|
1859
2018
|
function nativeFileDigest(bytes) {
|
|
1860
|
-
return
|
|
2019
|
+
return createHash5("sha256").update(bytes).digest("hex");
|
|
1861
2020
|
}
|
|
1862
2021
|
function nativeFrontmatterName(markdown) {
|
|
1863
2022
|
const header = markdown.match(/^---\s*\n([\s\S]*?)\n---/);
|
|
@@ -2864,6 +3023,20 @@ async function skillPushPayload(skill) {
|
|
|
2864
3023
|
};
|
|
2865
3024
|
}
|
|
2866
3025
|
var SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
|
|
3026
|
+
var SERVER_REQUEST_BODY_MAX_BYTES = 64 * 1024 * 1024;
|
|
3027
|
+
var MAX_SYNC_PUSH_SKILL_BYTES = SERVER_REQUEST_BODY_MAX_BYTES - SYNC_PUSH_ENVELOPE_BYTES;
|
|
3028
|
+
function mib(bytes) {
|
|
3029
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
3030
|
+
}
|
|
3031
|
+
function tooLargeFailure(name, sizeBytes, limitBytes) {
|
|
3032
|
+
return {
|
|
3033
|
+
name,
|
|
3034
|
+
error: `Skill is too large to sync (${mib(sizeBytes)}, the limit is ${mib(limitBytes)}); remove large files from its folder to sync it`,
|
|
3035
|
+
code: "skill_too_large",
|
|
3036
|
+
size_bytes: sizeBytes,
|
|
3037
|
+
limit_bytes: limitBytes
|
|
3038
|
+
};
|
|
3039
|
+
}
|
|
2867
3040
|
function pushBatches(payloads, maxBodyBytes) {
|
|
2868
3041
|
const batches = [];
|
|
2869
3042
|
let batch = [];
|
|
@@ -2894,9 +3067,15 @@ function pushFailure(name, error) {
|
|
|
2894
3067
|
return { name, error: "Upload failed; sync will retry", code };
|
|
2895
3068
|
}
|
|
2896
3069
|
async function pushChangedSkills(serverUrl, jwt, changedSkills, options = {}) {
|
|
2897
|
-
const
|
|
3070
|
+
const maxSkillBytes = options.maxSkillBytes ?? MAX_SYNC_PUSH_SKILL_BYTES;
|
|
2898
3071
|
const saved = [];
|
|
2899
3072
|
const failed = [];
|
|
3073
|
+
const payloadSkills = [];
|
|
3074
|
+
for (const payload of await Promise.all(changedSkills.map(skillPushPayload))) {
|
|
3075
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
|
|
3076
|
+
if (bytes > maxSkillBytes) failed.push(tooLargeFailure(String(payload.name), bytes, maxSkillBytes));
|
|
3077
|
+
else payloadSkills.push(payload);
|
|
3078
|
+
}
|
|
2900
3079
|
for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
|
|
2901
3080
|
try {
|
|
2902
3081
|
const result = await requestJson(`${serverUrl}/portal_skills/sync-push`, jwt, {
|
|
@@ -2999,6 +3178,9 @@ async function removeForeignAccountSymlinks(skillsDir, options = {}) {
|
|
|
2999
3178
|
}
|
|
3000
3179
|
return removed;
|
|
3001
3180
|
}
|
|
3181
|
+
var BASE_SKILL_LINK_NAMES = /* @__PURE__ */ new Set(["notis-spaces", "notis-query", "notis-cli"]);
|
|
3182
|
+
var NATIVE_FOLDER_NAME = /^native-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
3183
|
+
var READABLE_SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3002
3184
|
function managedSkillRoots(skillsDir, legacyGlobalSkillsDir = LEGACY_AGENTS_SKILLS_DIR) {
|
|
3003
3185
|
const resolvedSkillsDir = path2.resolve(skillsDir);
|
|
3004
3186
|
const scopedUsersRoot = path2.dirname(path2.dirname(resolvedSkillsDir));
|
|
@@ -3013,6 +3195,9 @@ function managedSkillRoots(skillsDir, legacyGlobalSkillsDir = LEGACY_AGENTS_SKIL
|
|
|
3013
3195
|
}
|
|
3014
3196
|
return roots;
|
|
3015
3197
|
}
|
|
3198
|
+
function isUnderManagedRoot(resolvedTarget, managedRoots) {
|
|
3199
|
+
return managedRoots.some((root) => resolvedTarget === root || resolvedTarget.startsWith(`${root}${path2.sep}`));
|
|
3200
|
+
}
|
|
3016
3201
|
async function isManagedSymlink(linkPath, managedRoots) {
|
|
3017
3202
|
try {
|
|
3018
3203
|
const stats = await fs2.lstat(linkPath);
|
|
@@ -3021,7 +3206,7 @@ async function isManagedSymlink(linkPath, managedRoots) {
|
|
|
3021
3206
|
}
|
|
3022
3207
|
const target = await fs2.readlink(linkPath);
|
|
3023
3208
|
const resolvedTarget = path2.resolve(path2.dirname(linkPath), target);
|
|
3024
|
-
return
|
|
3209
|
+
return isUnderManagedRoot(resolvedTarget, managedRoots);
|
|
3025
3210
|
} catch (error) {
|
|
3026
3211
|
if (error?.code === "ENOENT") return false;
|
|
3027
3212
|
throw error;
|
|
@@ -3053,7 +3238,7 @@ function defaultAgentSkillDirs(skillsDir) {
|
|
|
3053
3238
|
...EXTERNAL_AGENT_SKILL_DIRS
|
|
3054
3239
|
};
|
|
3055
3240
|
}
|
|
3056
|
-
async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, failures, agent) {
|
|
3241
|
+
async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, failures, agent, movedTargets = /* @__PURE__ */ new Set()) {
|
|
3057
3242
|
let removed = 0;
|
|
3058
3243
|
try {
|
|
3059
3244
|
await fs2.mkdir(agentDir, { recursive: true });
|
|
@@ -3061,7 +3246,7 @@ async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRo
|
|
|
3061
3246
|
for (const entry of existingEntries) {
|
|
3062
3247
|
const entryPath = path2.join(agentDir, entry.name);
|
|
3063
3248
|
try {
|
|
3064
|
-
if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots)) {
|
|
3249
|
+
if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots) && !(movedTargets.size > 0 && movedTargets.has(path2.resolve(agentDir, await fs2.readlink(entryPath))))) {
|
|
3065
3250
|
await fs2.unlink(entryPath);
|
|
3066
3251
|
removed += 1;
|
|
3067
3252
|
}
|
|
@@ -3084,15 +3269,174 @@ async function removeAllSymlinksForSkill(skillName, skillsDir = LEGACY_AGENTS_SK
|
|
|
3084
3269
|
const agentDirs = /* @__PURE__ */ new Set([...Object.values(agentSkillDirs), legacyGlobalSkillsDir]);
|
|
3085
3270
|
const expectedTarget = path2.resolve(skillsDir, safeName(skillName, skillsDir));
|
|
3086
3271
|
for (const agentDir of agentDirs) {
|
|
3087
|
-
const
|
|
3088
|
-
const
|
|
3272
|
+
const linkName = safeName(skillName, agentDir);
|
|
3273
|
+
const linkPath = path2.join(agentDir, linkName);
|
|
3274
|
+
const owned = options.ownership === "exact-skill-dir" ? await isManagedSymlink(linkPath, [expectedTarget]) : await isManagedSymlink(linkPath, managedRoots) && !await linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir);
|
|
3089
3275
|
if (owned) {
|
|
3090
3276
|
await fs2.unlink(linkPath);
|
|
3091
3277
|
removed += 1;
|
|
3092
3278
|
}
|
|
3279
|
+
if (path2.resolve(agentDir) !== path2.resolve(skillsDir)) {
|
|
3280
|
+
try {
|
|
3281
|
+
removed += await removeLinksToTarget(agentDir, expectedTarget, /* @__PURE__ */ new Set([linkName]));
|
|
3282
|
+
} catch (error) {
|
|
3283
|
+
console.warn(`[skill-sync] Could not list ${agentDir} to remove the links to "${skillName}": ${error.message}`);
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
return removed;
|
|
3288
|
+
}
|
|
3289
|
+
async function linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir) {
|
|
3290
|
+
try {
|
|
3291
|
+
const resolved = path2.resolve(path2.dirname(linkPath), await fs2.readlink(linkPath));
|
|
3292
|
+
if (resolved === expectedTarget || path2.dirname(resolved) !== path2.resolve(skillsDir)) return false;
|
|
3293
|
+
return (await fs2.stat(resolved)).isDirectory();
|
|
3294
|
+
} catch {
|
|
3295
|
+
return false;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
async function hasLinkToTarget(agentDir, targetPath) {
|
|
3299
|
+
let entries;
|
|
3300
|
+
try {
|
|
3301
|
+
entries = await fs2.readdir(agentDir, { withFileTypes: true });
|
|
3302
|
+
} catch {
|
|
3303
|
+
return true;
|
|
3304
|
+
}
|
|
3305
|
+
for (const entry of entries) {
|
|
3306
|
+
if (!entry.isSymbolicLink()) continue;
|
|
3307
|
+
try {
|
|
3308
|
+
if (path2.resolve(agentDir, await fs2.readlink(path2.join(agentDir, entry.name))) === targetPath) return true;
|
|
3309
|
+
} catch {
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
return false;
|
|
3313
|
+
}
|
|
3314
|
+
async function linkNamesByTarget(agentDir, targets) {
|
|
3315
|
+
const names = /* @__PURE__ */ new Map();
|
|
3316
|
+
let entries;
|
|
3317
|
+
try {
|
|
3318
|
+
entries = await fs2.readdir(agentDir, { withFileTypes: true });
|
|
3319
|
+
} catch (error) {
|
|
3320
|
+
if (error?.code === "ENOENT") return names;
|
|
3321
|
+
throw error;
|
|
3322
|
+
}
|
|
3323
|
+
for (const entry of entries) {
|
|
3324
|
+
if (!entry.isSymbolicLink()) continue;
|
|
3325
|
+
try {
|
|
3326
|
+
const resolved = path2.resolve(agentDir, await fs2.readlink(path2.join(agentDir, entry.name)));
|
|
3327
|
+
if (targets.has(resolved)) names.set(resolved, [...names.get(resolved) ?? [], entry.name]);
|
|
3328
|
+
} catch (error) {
|
|
3329
|
+
if (error?.code !== "ENOENT") throw error;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
return names;
|
|
3333
|
+
}
|
|
3334
|
+
async function unlinkIfTarget(agentDir, names, targetPath) {
|
|
3335
|
+
let removed = 0;
|
|
3336
|
+
for (const name of names) {
|
|
3337
|
+
const entryPath = path2.join(agentDir, name);
|
|
3338
|
+
try {
|
|
3339
|
+
if ((await fs2.lstat(entryPath)).isSymbolicLink() && path2.resolve(agentDir, await fs2.readlink(entryPath)) === targetPath) {
|
|
3340
|
+
await fs2.unlink(entryPath);
|
|
3341
|
+
removed += 1;
|
|
3342
|
+
}
|
|
3343
|
+
} catch (error) {
|
|
3344
|
+
if (error?.code !== "ENOENT") throw error;
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
return removed;
|
|
3348
|
+
}
|
|
3349
|
+
async function removeLinksToTarget(agentDir, targetPath, keepNames) {
|
|
3350
|
+
let entries;
|
|
3351
|
+
try {
|
|
3352
|
+
entries = await fs2.readdir(agentDir, { withFileTypes: true });
|
|
3353
|
+
} catch (error) {
|
|
3354
|
+
if (error?.code === "ENOENT") return 0;
|
|
3355
|
+
throw error;
|
|
3356
|
+
}
|
|
3357
|
+
const keep = new Set([...keepNames].map((name) => name.toLowerCase()));
|
|
3358
|
+
let removed = 0;
|
|
3359
|
+
for (const entry of entries) {
|
|
3360
|
+
if (!entry.isSymbolicLink() || keep.has(entry.name.toLowerCase())) continue;
|
|
3361
|
+
const entryPath = path2.join(agentDir, entry.name);
|
|
3362
|
+
try {
|
|
3363
|
+
const resolved = path2.resolve(agentDir, await fs2.readlink(entryPath));
|
|
3364
|
+
if (resolved !== targetPath) continue;
|
|
3365
|
+
await fs2.unlink(entryPath);
|
|
3366
|
+
removed += 1;
|
|
3367
|
+
} catch (error) {
|
|
3368
|
+
if (error?.code !== "ENOENT") throw error;
|
|
3369
|
+
}
|
|
3093
3370
|
}
|
|
3094
3371
|
return removed;
|
|
3095
3372
|
}
|
|
3373
|
+
async function readableNativeLinkName(skill, folderName, skillsDir) {
|
|
3374
|
+
if (!isNativeSkill(skill)) return null;
|
|
3375
|
+
let markdown = "";
|
|
3376
|
+
try {
|
|
3377
|
+
markdown = await fs2.readFile(path2.join(skillsDir, folderName, "SKILL.md"), "utf8");
|
|
3378
|
+
} catch {
|
|
3379
|
+
}
|
|
3380
|
+
const name = [nativeFrontmatterName(markdown), nativeFrontmatterName(skill.skill_md || ""), skill.display_name || ""].map((value) => value.trim()).find(Boolean);
|
|
3381
|
+
if (!name || name === folderName || name.length > 64 || !READABLE_SKILL_NAME.test(name) || NATIVE_FOLDER_NAME.test(name) || BASE_SKILL_LINK_NAMES.has(name)) {
|
|
3382
|
+
return null;
|
|
3383
|
+
}
|
|
3384
|
+
return name;
|
|
3385
|
+
}
|
|
3386
|
+
async function readableLinkAvailable(linkPath, targetPath, managedRoots, ownsWholeFolder) {
|
|
3387
|
+
let stats;
|
|
3388
|
+
try {
|
|
3389
|
+
stats = await fs2.lstat(linkPath);
|
|
3390
|
+
} catch (error) {
|
|
3391
|
+
return error?.code === "ENOENT";
|
|
3392
|
+
}
|
|
3393
|
+
if (!stats.isSymbolicLink()) return false;
|
|
3394
|
+
try {
|
|
3395
|
+
const resolved = path2.resolve(path2.dirname(linkPath), await fs2.readlink(linkPath));
|
|
3396
|
+
if (resolved === path2.resolve(targetPath)) return true;
|
|
3397
|
+
return ownsWholeFolder && isUnderManagedRoot(resolved, managedRoots);
|
|
3398
|
+
} catch {
|
|
3399
|
+
return false;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
async function planAgentLinkNames(candidates, agentDir, skillsDir, managedRoots, ownsWholeFolder) {
|
|
3403
|
+
const reserved = new Set(
|
|
3404
|
+
candidates.filter((candidate) => !candidate.readableName).map((candidate) => candidate.folderName.toLowerCase())
|
|
3405
|
+
);
|
|
3406
|
+
const readableCounts = /* @__PURE__ */ new Map();
|
|
3407
|
+
for (const { readableName } of candidates) {
|
|
3408
|
+
if (!readableName) continue;
|
|
3409
|
+
const key = readableName.toLowerCase();
|
|
3410
|
+
readableCounts.set(key, (readableCounts.get(key) ?? 0) + 1);
|
|
3411
|
+
}
|
|
3412
|
+
const available = /* @__PURE__ */ new Map();
|
|
3413
|
+
for (; ; ) {
|
|
3414
|
+
const plan = /* @__PURE__ */ new Map();
|
|
3415
|
+
const owners = /* @__PURE__ */ new Map();
|
|
3416
|
+
for (const { folderName, readableName } of candidates) {
|
|
3417
|
+
let linkName = folderName;
|
|
3418
|
+
if (readableName) {
|
|
3419
|
+
const key = readableName.toLowerCase();
|
|
3420
|
+
if (!reserved.has(key) && readableCounts.get(key) === 1) {
|
|
3421
|
+
if (!available.has(folderName)) {
|
|
3422
|
+
available.set(folderName, await readableLinkAvailable(
|
|
3423
|
+
path2.join(agentDir, readableName),
|
|
3424
|
+
path2.join(skillsDir, folderName),
|
|
3425
|
+
managedRoots,
|
|
3426
|
+
ownsWholeFolder
|
|
3427
|
+
));
|
|
3428
|
+
}
|
|
3429
|
+
if (available.get(folderName)) linkName = readableName;
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
plan.set(linkName, folderName);
|
|
3433
|
+
owners.set(linkName.toLowerCase(), (owners.get(linkName.toLowerCase()) ?? 0) + 1);
|
|
3434
|
+
}
|
|
3435
|
+
const collisions = [...owners].filter(([name, count]) => count > 1 && !reserved.has(name)).map(([name]) => name);
|
|
3436
|
+
if (collisions.length === 0) return plan;
|
|
3437
|
+
for (const name of collisions) reserved.add(name);
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3096
3440
|
async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir = LEGACY_AGENTS_SKILLS_DIR, options = {}) {
|
|
3097
3441
|
const agentSkillDirs = { ...defaultAgentSkillDirs(skillsDir), ...options.agentSkillDirs };
|
|
3098
3442
|
const deletions = [];
|
|
@@ -3117,7 +3461,8 @@ async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir
|
|
|
3117
3461
|
continue;
|
|
3118
3462
|
}
|
|
3119
3463
|
const previous = previousState.skills[skill.name];
|
|
3120
|
-
|
|
3464
|
+
const verified = previous?.verifiedAgentLinks?.[agent];
|
|
3465
|
+
if (!previous || previous.cloudId !== skill.id || !verified || !skill.updated_at || previous.cloudUpdatedAt !== skill.updated_at) {
|
|
3121
3466
|
continue;
|
|
3122
3467
|
}
|
|
3123
3468
|
const cloudTargets = normalizeAgentTargets(skill.agent_targets);
|
|
@@ -3125,17 +3470,19 @@ async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir
|
|
|
3125
3470
|
if (!cloudTargets[agent] || !previousTargets[agent]) {
|
|
3126
3471
|
continue;
|
|
3127
3472
|
}
|
|
3128
|
-
let
|
|
3473
|
+
let linkName;
|
|
3474
|
+
let folderName;
|
|
3129
3475
|
try {
|
|
3130
|
-
|
|
3476
|
+
folderName = safeName(skill.name, skillsDir);
|
|
3477
|
+
linkName = safeName(typeof verified === "string" ? verified : folderName, agentDir);
|
|
3131
3478
|
} catch {
|
|
3132
3479
|
continue;
|
|
3133
3480
|
}
|
|
3134
|
-
const linkPath = path2.join(agentDir,
|
|
3481
|
+
const linkPath = path2.join(agentDir, linkName);
|
|
3135
3482
|
try {
|
|
3136
3483
|
await fs2.lstat(linkPath);
|
|
3137
3484
|
} catch (error) {
|
|
3138
|
-
if (error?.code === "ENOENT") {
|
|
3485
|
+
if (error?.code === "ENOENT" && !await hasLinkToTarget(agentDir, path2.resolve(skillsDir, folderName))) {
|
|
3139
3486
|
deletions.push({ skillId: skill.id, skillName: skill.name, agent });
|
|
3140
3487
|
}
|
|
3141
3488
|
}
|
|
@@ -3155,11 +3502,12 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
3155
3502
|
const agentSkillDirs = { ...defaultAgentSkillDirs(skillsDir), ...options.agentSkillDirs };
|
|
3156
3503
|
const legacyGlobalSkillsDir = options.legacyGlobalSkillsDir || LEGACY_AGENTS_SKILLS_DIR;
|
|
3157
3504
|
const managedRoots = managedSkillRoots(skillsDir, legacyGlobalSkillsDir);
|
|
3505
|
+
const ownsWholeFolder = options.removeUndesired !== false;
|
|
3158
3506
|
const desiredByAgent = {
|
|
3159
|
-
notis: /* @__PURE__ */ new
|
|
3160
|
-
claude_code: /* @__PURE__ */ new
|
|
3161
|
-
cursor: /* @__PURE__ */ new
|
|
3162
|
-
codex: /* @__PURE__ */ new
|
|
3507
|
+
notis: /* @__PURE__ */ new Map(),
|
|
3508
|
+
claude_code: /* @__PURE__ */ new Map(),
|
|
3509
|
+
cursor: /* @__PURE__ */ new Map(),
|
|
3510
|
+
codex: /* @__PURE__ */ new Map()
|
|
3163
3511
|
};
|
|
3164
3512
|
for (const skill of skills) {
|
|
3165
3513
|
if (skill.status !== "active") {
|
|
@@ -3167,17 +3515,20 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
3167
3515
|
}
|
|
3168
3516
|
const safeSkillName = safeName(skill.name, skillsDir);
|
|
3169
3517
|
const targets = normalizeAgentTargets(skill.agent_targets);
|
|
3170
|
-
|
|
3171
|
-
desiredByAgent.
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
desiredByAgent.claude_code.add(safeSkillName);
|
|
3175
|
-
}
|
|
3176
|
-
if (targets.cursor) {
|
|
3177
|
-
desiredByAgent.cursor.add(safeSkillName);
|
|
3518
|
+
for (const agent of Object.keys(desiredByAgent)) {
|
|
3519
|
+
if (targets[agent] && !desiredByAgent[agent].has(safeSkillName)) {
|
|
3520
|
+
desiredByAgent[agent].set(safeSkillName, skill);
|
|
3521
|
+
}
|
|
3178
3522
|
}
|
|
3179
|
-
|
|
3180
|
-
|
|
3523
|
+
}
|
|
3524
|
+
const readableNames = /* @__PURE__ */ new Map();
|
|
3525
|
+
for (const [folderName, skill] of [
|
|
3526
|
+
...desiredByAgent.claude_code,
|
|
3527
|
+
...desiredByAgent.cursor,
|
|
3528
|
+
...desiredByAgent.codex
|
|
3529
|
+
]) {
|
|
3530
|
+
if (!readableNames.has(folderName)) {
|
|
3531
|
+
readableNames.set(folderName, await readableNativeLinkName(skill, folderName, skillsDir));
|
|
3181
3532
|
}
|
|
3182
3533
|
}
|
|
3183
3534
|
for (const [agent, agentDir] of Object.entries(agentSkillDirs)) {
|
|
@@ -3191,13 +3542,39 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
3191
3542
|
result.failures.push({ name: agentFolderFailureName(agent), error: `Could not create agent skills directory (${error.message})` });
|
|
3192
3543
|
continue;
|
|
3193
3544
|
}
|
|
3194
|
-
const
|
|
3195
|
-
|
|
3196
|
-
|
|
3545
|
+
const external = EXTERNAL_AGENTS.includes(agent);
|
|
3546
|
+
const linkPlan = await planAgentLinkNames(
|
|
3547
|
+
[...desiredByAgent[agent].keys()].map((folderName) => ({
|
|
3548
|
+
folderName,
|
|
3549
|
+
readableName: external ? readableNames.get(folderName) ?? null : null
|
|
3550
|
+
})),
|
|
3551
|
+
agentDir,
|
|
3552
|
+
skillsDir,
|
|
3553
|
+
managedRoots,
|
|
3554
|
+
ownsWholeFolder
|
|
3555
|
+
);
|
|
3556
|
+
const movedTargets = new Set(external ? [...linkPlan.values()].filter((name) => isNativeSkill(desiredByAgent[agent].get(name))).map((name) => path2.resolve(skillsDir, name)) : []);
|
|
3557
|
+
if (ownsWholeFolder) {
|
|
3558
|
+
result.removed += await removeUndesiredManagedSymlinks(
|
|
3559
|
+
agentDir,
|
|
3560
|
+
new Set(linkPlan.keys()),
|
|
3561
|
+
managedRoots,
|
|
3562
|
+
result.failures,
|
|
3563
|
+
agent,
|
|
3564
|
+
movedTargets
|
|
3565
|
+
);
|
|
3566
|
+
}
|
|
3567
|
+
let namesByTarget = /* @__PURE__ */ new Map();
|
|
3568
|
+
if (movedTargets.size > 0) {
|
|
3569
|
+
try {
|
|
3570
|
+
namesByTarget = await linkNamesByTarget(agentDir, movedTargets);
|
|
3571
|
+
} catch (error) {
|
|
3572
|
+
result.failures.push({ name: agentFolderFailureName(agent), error: `Could not read agent skills directory (${error.message})` });
|
|
3573
|
+
}
|
|
3197
3574
|
}
|
|
3198
|
-
for (const skillName of
|
|
3575
|
+
for (const [linkName, skillName] of linkPlan) {
|
|
3199
3576
|
const targetPath = path2.join(skillsDir, skillName);
|
|
3200
|
-
const linkPath = path2.join(agentDir, safeName(
|
|
3577
|
+
const linkPath = path2.join(agentDir, safeName(linkName, agentDir));
|
|
3201
3578
|
try {
|
|
3202
3579
|
if (!(await fs2.stat(path2.join(targetPath, "SKILL.md"))).isFile()) throw new Error("Missing SKILL.md");
|
|
3203
3580
|
} catch {
|
|
@@ -3225,7 +3602,18 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
3225
3602
|
result.skipped += 1;
|
|
3226
3603
|
}
|
|
3227
3604
|
if (syncOutcome !== "blocked") {
|
|
3228
|
-
result.verifiedAgentLinks[skillName] = {
|
|
3605
|
+
result.verifiedAgentLinks[skillName] = {
|
|
3606
|
+
...result.verifiedAgentLinks[skillName],
|
|
3607
|
+
[agent]: linkName === skillName ? true : linkName
|
|
3608
|
+
};
|
|
3609
|
+
const otherNames = (namesByTarget.get(path2.resolve(targetPath)) ?? []).filter((name) => name.toLowerCase() !== linkName.toLowerCase());
|
|
3610
|
+
if (otherNames.length > 0) {
|
|
3611
|
+
try {
|
|
3612
|
+
result.removed += await unlinkIfTarget(agentDir, otherNames, path2.resolve(targetPath));
|
|
3613
|
+
} catch (error) {
|
|
3614
|
+
result.failures.push({ name: skillName, error: `${agentFailureLabel(agent)}: could not remove skill link (${error.message})` });
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3229
3617
|
}
|
|
3230
3618
|
}
|
|
3231
3619
|
}
|
|
@@ -3331,7 +3719,7 @@ var MIRROR_ONLY_DEPS = {
|
|
|
3331
3719
|
syncSymlinks: async () => ({ linked: 0, removed: 0, skipped: 0, verifiedAgentLinks: {} })
|
|
3332
3720
|
};
|
|
3333
3721
|
async function forgetOtherAccountsAgentLinks(paths) {
|
|
3334
|
-
const usersDir =
|
|
3722
|
+
const usersDir = dirname6(dirname6(paths.syncStatePath));
|
|
3335
3723
|
let entries;
|
|
3336
3724
|
try {
|
|
3337
3725
|
entries = await fs3.readdir(usersDir, { withFileTypes: true });
|
|
@@ -3340,7 +3728,7 @@ async function forgetOtherAccountsAgentLinks(paths) {
|
|
|
3340
3728
|
}
|
|
3341
3729
|
for (const entry of entries) {
|
|
3342
3730
|
if (!entry.isDirectory()) continue;
|
|
3343
|
-
const statePath =
|
|
3731
|
+
const statePath = join6(usersDir, entry.name, ".notis-sync.json");
|
|
3344
3732
|
if (statePath === paths.syncStatePath) continue;
|
|
3345
3733
|
let state = null;
|
|
3346
3734
|
try {
|
|
@@ -3365,15 +3753,15 @@ async function forgetOtherAccountsAgentLinks(paths) {
|
|
|
3365
3753
|
}
|
|
3366
3754
|
function isolatedLinkOptions(paths) {
|
|
3367
3755
|
if (!paths.isolatedNamespace && !paths.homeDir) return void 0;
|
|
3368
|
-
const root = paths.isolatedNamespace ?
|
|
3756
|
+
const root = paths.isolatedNamespace ? join6(paths.syncRoot, "environments", paths.isolatedNamespace, "agents") : paths.homeDir;
|
|
3369
3757
|
return {
|
|
3370
3758
|
agentSkillDirs: {
|
|
3371
3759
|
notis: paths.skillsDir,
|
|
3372
|
-
claude_code:
|
|
3373
|
-
cursor:
|
|
3374
|
-
codex:
|
|
3760
|
+
claude_code: join6(root, ".claude", "skills"),
|
|
3761
|
+
cursor: join6(root, ".cursor", "skills"),
|
|
3762
|
+
codex: join6(root, ".codex", "skills")
|
|
3375
3763
|
},
|
|
3376
|
-
legacyGlobalSkillsDir:
|
|
3764
|
+
legacyGlobalSkillsDir: join6(root, ".agents", "skills")
|
|
3377
3765
|
};
|
|
3378
3766
|
}
|
|
3379
3767
|
function assertSyncEnvironment(pull, settings) {
|
|
@@ -3869,13 +4257,13 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
3869
4257
|
}
|
|
3870
4258
|
|
|
3871
4259
|
// src/runtime/sync-skills.js
|
|
3872
|
-
import { createHash as
|
|
4260
|
+
import { createHash as createHash6, randomUUID as randomUUID3 } from "node:crypto";
|
|
3873
4261
|
import { mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3874
4262
|
import { homedir as homedir4 } from "node:os";
|
|
3875
|
-
import { dirname as
|
|
4263
|
+
import { dirname as dirname8, join as join8 } from "node:path";
|
|
3876
4264
|
|
|
3877
4265
|
// src/runtime/base-skills.js
|
|
3878
|
-
import { dirname as
|
|
4266
|
+
import { dirname as dirname7, join as join7, relative, resolve as resolve3 } from "node:path";
|
|
3879
4267
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3880
4268
|
var BASE_SKILL_NAMES2 = Object.freeze([
|
|
3881
4269
|
"notis-spaces",
|
|
@@ -3883,7 +4271,7 @@ var BASE_SKILL_NAMES2 = Object.freeze([
|
|
|
3883
4271
|
"notis-cli"
|
|
3884
4272
|
]);
|
|
3885
4273
|
var RETIRED_BASE_SKILL_NAMES = Object.freeze(["notis-apps", "notis-reports"]);
|
|
3886
|
-
var HERE =
|
|
4274
|
+
var HERE = dirname7(fileURLToPath2(import.meta.url));
|
|
3887
4275
|
|
|
3888
4276
|
// src/runtime/sync-skills.js
|
|
3889
4277
|
var DEFAULT_LOCK_TIMEOUT_MS = 3e4;
|
|
@@ -3892,7 +4280,7 @@ var DEFAULT_LOCK_POLL_MS = 50;
|
|
|
3892
4280
|
async function lockSnapshot(lockDirectory) {
|
|
3893
4281
|
try {
|
|
3894
4282
|
const [raw, metadata] = await Promise.all([
|
|
3895
|
-
readFile(
|
|
4283
|
+
readFile(join8(lockDirectory, "owner"), "utf8").catch(() => ""),
|
|
3896
4284
|
stat(lockDirectory)
|
|
3897
4285
|
]);
|
|
3898
4286
|
let owner = {};
|
|
@@ -3928,11 +4316,11 @@ function delay(milliseconds) {
|
|
|
3928
4316
|
return new Promise((resolve4) => setTimeout(resolve4, milliseconds));
|
|
3929
4317
|
}
|
|
3930
4318
|
async function quarantineStaleLock(lockDirectory, snapshot) {
|
|
3931
|
-
const quarantineRoot =
|
|
3932
|
-
const snapshotToken =
|
|
4319
|
+
const quarantineRoot = join8(dirname8(lockDirectory), ".stale-operation-locks");
|
|
4320
|
+
const snapshotToken = createHash6("sha256").update(JSON.stringify(snapshot)).digest("hex");
|
|
3933
4321
|
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
3934
4322
|
try {
|
|
3935
|
-
await rename(lockDirectory,
|
|
4323
|
+
await rename(lockDirectory, join8(quarantineRoot, snapshotToken));
|
|
3936
4324
|
return true;
|
|
3937
4325
|
} catch (error) {
|
|
3938
4326
|
if (["EEXIST", "ENOTEMPTY", "ENOENT"].includes(error?.code)) return false;
|
|
@@ -3940,12 +4328,12 @@ async function quarantineStaleLock(lockDirectory, snapshot) {
|
|
|
3940
4328
|
}
|
|
3941
4329
|
}
|
|
3942
4330
|
async function publishOwnedLock(lockDirectory, owner) {
|
|
3943
|
-
const quarantineRoot =
|
|
3944
|
-
const staging =
|
|
4331
|
+
const quarantineRoot = join8(dirname8(lockDirectory), ".stale-operation-locks");
|
|
4332
|
+
const staging = join8(quarantineRoot, `staging.${owner.id}`);
|
|
3945
4333
|
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
3946
4334
|
await mkdir(staging, { mode: 448 });
|
|
3947
4335
|
try {
|
|
3948
|
-
await writeFile(
|
|
4336
|
+
await writeFile(join8(staging, "owner"), JSON.stringify(owner), { mode: 384 });
|
|
3949
4337
|
await rename(staging, lockDirectory);
|
|
3950
4338
|
} catch (error) {
|
|
3951
4339
|
await rm(staging, { recursive: true, force: true });
|
|
@@ -3957,8 +4345,8 @@ async function publishOwnedLock(lockDirectory, owner) {
|
|
|
3957
4345
|
async function releaseOwnedLock(lockDirectory, ownerId) {
|
|
3958
4346
|
const owner = await lockSnapshot(lockDirectory);
|
|
3959
4347
|
if (owner?.id !== ownerId) return;
|
|
3960
|
-
const quarantineRoot =
|
|
3961
|
-
const releasedDirectory =
|
|
4348
|
+
const quarantineRoot = join8(dirname8(lockDirectory), ".stale-operation-locks");
|
|
4349
|
+
const releasedDirectory = join8(quarantineRoot, `released.${ownerId}`);
|
|
3962
4350
|
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
3963
4351
|
try {
|
|
3964
4352
|
await rename(lockDirectory, releasedDirectory);
|
|
@@ -3975,10 +4363,10 @@ async function withSkillSyncLock(callback, {
|
|
|
3975
4363
|
pollMs = DEFAULT_LOCK_POLL_MS,
|
|
3976
4364
|
now = () => Date.now()
|
|
3977
4365
|
} = {}) {
|
|
3978
|
-
const lockDirectory =
|
|
4366
|
+
const lockDirectory = join8(home, ".notis", "skills", ".operation-lock");
|
|
3979
4367
|
const ownerId = `${process.pid}.${randomUUID3()}`;
|
|
3980
4368
|
const deadline = now() + timeoutMs;
|
|
3981
|
-
await mkdir(
|
|
4369
|
+
await mkdir(dirname8(lockDirectory), { recursive: true, mode: 448 });
|
|
3982
4370
|
for (; ; ) {
|
|
3983
4371
|
try {
|
|
3984
4372
|
await publishOwnedLock(lockDirectory, { id: ownerId, pid: process.pid, at: now() });
|
|
@@ -4004,7 +4392,7 @@ async function withSkillSyncLock(callback, {
|
|
|
4004
4392
|
let heartbeatInFlight = Promise.resolve();
|
|
4005
4393
|
const refreshHeartbeat = async () => {
|
|
4006
4394
|
if (heartbeatStopped) return;
|
|
4007
|
-
const temporaryOwnerPath =
|
|
4395
|
+
const temporaryOwnerPath = join8(lockDirectory, `.owner.${ownerId}.tmp`);
|
|
4008
4396
|
await writeFile(
|
|
4009
4397
|
temporaryOwnerPath,
|
|
4010
4398
|
JSON.stringify({ id: ownerId, pid: process.pid, at: now() }),
|
|
@@ -4015,7 +4403,7 @@ async function withSkillSyncLock(callback, {
|
|
|
4015
4403
|
await rm(temporaryOwnerPath, { force: true });
|
|
4016
4404
|
return;
|
|
4017
4405
|
}
|
|
4018
|
-
await rename(temporaryOwnerPath,
|
|
4406
|
+
await rename(temporaryOwnerPath, join8(lockDirectory, "owner"));
|
|
4019
4407
|
};
|
|
4020
4408
|
const heartbeat = setInterval(() => {
|
|
4021
4409
|
heartbeatInFlight = heartbeatInFlight.then(refreshHeartbeat).catch(() => void 0);
|
|
@@ -4048,7 +4436,7 @@ function currentCliProfile() {
|
|
|
4048
4436
|
function signInFingerprint(profileName, config = loadConfig()) {
|
|
4049
4437
|
const profile = getProfile(config, profileName);
|
|
4050
4438
|
if (!profile.oauth_client_id && !profile.oauth_access_expires_at) return null;
|
|
4051
|
-
return
|
|
4439
|
+
return createHash7("sha256").update(JSON.stringify([
|
|
4052
4440
|
profile.oauth_issuer ?? null,
|
|
4053
4441
|
profile.oauth_client_id ?? null,
|
|
4054
4442
|
profile.oauth_user_id ?? null,
|
|
@@ -4080,7 +4468,7 @@ async function runAutomaticSkillSync({ profile, apiBase, userId }, {
|
|
|
4080
4468
|
}
|
|
4081
4469
|
function readStatus(target) {
|
|
4082
4470
|
try {
|
|
4083
|
-
return JSON.parse(
|
|
4471
|
+
return JSON.parse(readFileSync6(target, "utf8"));
|
|
4084
4472
|
} catch {
|
|
4085
4473
|
return null;
|
|
4086
4474
|
}
|
|
@@ -4092,13 +4480,13 @@ async function main(args = process.argv.slice(2), {
|
|
|
4092
4480
|
deadlineMs = 24e4
|
|
4093
4481
|
} = {}) {
|
|
4094
4482
|
const [profile, apiBase, userId] = args;
|
|
4095
|
-
const root =
|
|
4096
|
-
const target =
|
|
4483
|
+
const root = join9(home, ".notis", "skills", "service");
|
|
4484
|
+
const target = join9(root, "status.json");
|
|
4097
4485
|
const record = (value) => {
|
|
4098
|
-
|
|
4486
|
+
mkdirSync6(root, { recursive: true, mode: 448 });
|
|
4099
4487
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
4100
|
-
|
|
4101
|
-
|
|
4488
|
+
writeFileSync6(temporary, JSON.stringify({ ...value, profile, at: (/* @__PURE__ */ new Date()).toISOString() }, null, 2), { mode: 384 });
|
|
4489
|
+
renameSync6(temporary, target);
|
|
4102
4490
|
};
|
|
4103
4491
|
let signIn = null;
|
|
4104
4492
|
try {
|