@notis_ai/cli 0.2.25 → 0.2.27
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 +186 -5
- package/config/notis_app_design_rules.json +36 -14
- package/config/portal-route-roots.json +1 -0
- package/dist/agent-hooks/notis-agent-hook.mjs +2866 -553
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/references/intelligence.md +1 -1
- package/dist/base-skills/notis-query/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-query/SKILL.md +0 -1
- package/dist/base-skills/notis-query/references/documents.md +7 -0
- package/dist/base-skills/notis-query/references/query.md +1 -0
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +96 -24
- package/dist/base-skills/notis-spaces/references/architecture.md +4 -3
- package/dist/base-skills/notis-spaces/references/context.md +3 -0
- package/dist/base-skills/notis-spaces/references/design.md +37 -18
- package/dist/base-skills/notis-spaces/references/reading.md +8 -1
- package/dist/base-skills/notis-spaces/references/reports.md +6 -6
- package/dist/base-skills/notis-spaces/references/sdk.md +71 -7
- package/dist/base-skills/notis-spaces/references/store.md +22 -13
- package/dist/base-skills/notis-spaces/references/views.md +99 -6
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/src/cloudComputerWords.ts +53 -0
- package/dist/sdk/src/components/Audience.tsx +76 -0
- package/dist/sdk/src/components/DocumentPage.tsx +15 -4
- package/dist/sdk/src/components/MarkdownEditor.tsx +44 -14
- package/dist/sdk/src/components/MultiSelectActionBar.tsx +16 -5
- package/dist/sdk/src/components/NotisSelectionBoundary.tsx +79 -25
- package/dist/sdk/src/components/Skeleton.tsx +162 -6
- package/dist/sdk/src/hooks/useAction.ts +12 -2
- package/dist/sdk/src/hooks/useAgentQueue.ts +125 -0
- package/dist/sdk/src/hooks/useCloudComputerJob.ts +142 -0
- package/dist/sdk/src/hooks/useCloudComputerService.ts +388 -0
- package/dist/sdk/src/hooks/useCloudComputerShell.ts +95 -7
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +40 -2
- package/dist/sdk/src/hooks/useItemThread.ts +58 -0
- package/dist/sdk/src/hooks/useMarqueeSelection.ts +6 -1
- package/dist/sdk/src/hooks/useNativeDocuments.ts +61 -8
- package/dist/sdk/src/hooks/useNotisNavigation.ts +31 -8
- package/dist/sdk/src/hooks/useQuery.ts +67 -10
- package/dist/sdk/src/hooks/useViewParams.ts +47 -11
- package/dist/sdk/src/index.ts +31 -4
- package/dist/sdk/src/interactions.ts +2 -0
- package/dist/sdk/src/nativeData.ts +2 -0
- package/dist/sdk/src/optimisticRows.ts +329 -0
- package/dist/sdk/src/perf.ts +188 -0
- package/dist/sdk/src/provider.tsx +2 -1
- package/dist/sdk/src/queryCache.ts +366 -17
- package/dist/sdk/src/runtime.ts +55 -4
- package/dist/sdk/src/skeleton.ts +103 -0
- package/dist/sdk/src/space.ts +662 -28
- package/dist/sdk/src/spacePublicUI.ts +36 -0
- package/dist/sdk/src/ui/engine/step.ts +54 -0
- package/dist/sdk/src/ui/icons.tsx +3 -1
- package/dist/sdk/src/words/shell.ts +1 -0
- package/dist/skill-sync/index.js +88 -13
- package/dist/skill-sync-worker.mjs +127 -38
- package/dist/space-harness/host.js +272 -105
- package/dist/space-sdk/dist/chunk-BWHAORT4.js +5 -0
- package/dist/space-sdk/dist/index.js +9 -4
- package/dist/space-sdk/dist/ui.js +12 -12
- package/dist/space-sdk/package.json +3 -0
- package/dist/space-sdk/src/cloudComputerWords.d.ts +34 -0
- package/dist/space-sdk/src/components/Audience.d.ts +46 -0
- package/dist/space-sdk/src/components/DocumentPage.d.ts +3 -1
- package/dist/space-sdk/src/components/MarkdownEditor.d.ts +21 -0
- package/dist/space-sdk/src/components/MultiSelectActionBar.d.ts +5 -1
- package/dist/space-sdk/src/components/NotisSelectionBoundary.d.ts +19 -2
- package/dist/space-sdk/src/components/Skeleton.d.ts +7 -2
- package/dist/space-sdk/src/hooks/useAction.d.ts +8 -1
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +61 -0
- package/dist/space-sdk/src/hooks/useCloudComputerJob.d.ts +35 -0
- package/dist/space-sdk/src/hooks/useCloudComputerService.d.ts +75 -0
- package/dist/space-sdk/src/hooks/useCloudComputerShell.d.ts +36 -3
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +6 -0
- package/dist/space-sdk/src/hooks/useItemThread.d.ts +32 -0
- package/dist/space-sdk/src/hooks/useMarqueeSelection.d.ts +2 -1
- package/dist/space-sdk/src/hooks/useNativeDocumentBody.d.ts +1 -0
- package/dist/space-sdk/src/hooks/useNativeDocuments.d.ts +20 -5
- package/dist/space-sdk/src/hooks/useNotisNavigation.d.ts +11 -2
- package/dist/space-sdk/src/hooks/useQuery.d.ts +24 -2
- package/dist/space-sdk/src/hooks/useViewParams.d.ts +2 -0
- package/dist/space-sdk/src/index.d.ts +24 -4
- package/dist/space-sdk/src/nativeData.d.ts +6 -0
- package/dist/space-sdk/src/queryCache.d.ts +97 -2
- package/dist/space-sdk/src/runtime.d.ts +53 -4
- package/dist/space-sdk/src/skeleton.d.ts +42 -0
- package/dist/space-sdk/src/space.ts +662 -28
- package/dist/space-sdk/src/tailwind-candidates.d.ts +761 -6
- package/dist/space-sdk/src/ui/cloud/CloudComputerFrame.d.ts +29 -0
- package/dist/space-sdk/src/ui/cloud/CloudComputerWaking.d.ts +20 -0
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +15 -2
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +50 -0
- package/dist/space-sdk/src/ui/comments/commentFiles.d.ts +64 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +49 -1
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +26 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +82 -0
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +34 -4
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +67 -0
- package/dist/space-sdk/src/ui/engine/index.d.ts +2 -2
- package/dist/space-sdk/src/ui/engine/step.d.ts +9 -0
- package/dist/space-sdk/src/ui/fields/fields.d.ts +2 -1
- package/dist/space-sdk/src/ui/index.d.ts +4 -0
- package/dist/space-sdk/src/ui/layout/Panels.d.ts +9 -2
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +42 -0
- package/dist/space-sdk/src/ui/layout/index.d.ts +2 -1
- package/dist/space-sdk/src/ui/layout/panelMath.d.ts +11 -2
- package/dist/space-sdk/src/ui/list/ListReader.d.ts +38 -7
- package/dist/space-sdk/src/ui/list/Row.d.ts +4 -0
- package/dist/space-sdk/src/ui/list/SelectionBar.d.ts +9 -4
- package/dist/space-sdk/src/ui/list/useListKeys.d.ts +4 -0
- package/dist/space-sdk/src/words/shell.ts +1 -0
- package/dist/view-renderer/dist/host.js +355 -188
- package/dist/view-renderer/dist/theme.css +1 -1
- package/dist/view-renderer/src/dom.js +15 -2
- package/dist/view-renderer/src/host.tsx +4 -1
- package/dist/view-renderer/src/index.js +3 -0
- package/dist/view-renderer/src/pool.js +8 -4
- package/dist/view-renderer/src/renderer.js +92 -23
- package/dist/view-renderer/src/skeleton.js +450 -0
- package/package.json +4 -4
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +8 -4
- package/skills/notis-onboarding/BRIEF.md +15 -9
- package/skills/notis-spaces/cli.md +43 -4
- package/src/command-specs/auth.js +5 -3
- package/src/command-specs/cc.js +410 -0
- package/src/command-specs/computer.js +320 -0
- package/src/command-specs/diagnostics.js +2 -13
- package/src/command-specs/documents.js +22 -4
- package/src/command-specs/index.js +7 -0
- package/src/command-specs/onboarding.js +127 -7
- package/src/command-specs/skills.js +2 -2
- package/src/command-specs/spaces.js +162 -30
- package/src/command-specs/tools.js +26 -8
- package/src/command-specs/views.js +4 -1
- package/src/runtime/agent-setup.js +20 -2
- package/src/runtime/app-boundary-validator.js +2 -1
- package/src/runtime/app-platform.js +13 -0
- package/src/runtime/auth-recovery.js +5 -0
- package/src/runtime/channel.js +16 -2
- package/src/runtime/cloud-transfer.js +587 -0
- package/src/runtime/computer-ssh.js +127 -0
- package/src/runtime/oauth.js +50 -4
- package/src/runtime/skill-sync/cloud-client.ts +98 -15
- package/src/runtime/skill-sync/index.ts +42 -4
- package/src/runtime/skill-sync/local-scanner.ts +1 -0
- package/src/runtime/skill-sync/types.ts +6 -0
- package/src/runtime/space-audience.js +94 -0
- package/src/runtime/space-collection-scaffold.js +2 -1
- package/src/runtime/space-fixture-broker.js +2 -1
- package/src/runtime/space-lock.js +1 -4
- package/src/runtime/space-platform.js +18 -2
- package/src/runtime/space-source.js +105 -7
- package/src/runtime/space-test-server.js +13 -2
- package/src/runtime/space-verification.js +99 -6
- package/src/runtime/space-view-manifest.js +22 -4
- package/src/runtime/sync-skills.js +24 -20
- package/src/runtime/transport.js +19 -0
- package/src/runtime/view-render.js +2 -2
- package/src/skill-sync-worker.js +5 -1
- package/template/.harness/index.html.tmpl +1 -1
- package/dist/skill-sync/index.js.map +0 -7
- package/dist/space-sdk/dist/chunk-SVZATGZB.js +0 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import type { NotisDocumentEditorProps, NotisDocumentPageProps, NotisRuntimeUI } from './runtime';
|
|
3
|
+
import type { SpacePublicRecordUI } from './space';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A DocumentPage `properties` choice with these editor-only properties left out. A chosen `include` list is filtered
|
|
7
|
+
* case-insensitively; otherwise they are excluded by name, which the host matches exactly, so the names passed are the
|
|
8
|
+
* declared ones plus the real names the page has seen in rows and schemas.
|
|
9
|
+
*/
|
|
10
|
+
export function publicDocumentPageProperties(option: NotisDocumentPageProps['properties'], names: readonly string[]): NotisDocumentPageProps['properties'] {
|
|
11
|
+
if (option === 'hidden' || !names.length) return option;
|
|
12
|
+
const hidden = new Set(names.map(name => name.toLowerCase()));
|
|
13
|
+
const chosen = option && option !== 'panel' ? option : {};
|
|
14
|
+
return { ...chosen,
|
|
15
|
+
...(chosen.include ? { include: chosen.include.filter(name => !hidden.has(name.toLowerCase())) } : {}),
|
|
16
|
+
exclude: [...new Set([...(chosen.exclude ?? []), ...names])] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The host record components while an editor views the Space as the public. They read and write with the editor's
|
|
21
|
+
* authority, so what they draw is held to the public floor here: a document page leaves the editor-only properties
|
|
22
|
+
* out, a document editor shows no properties, and the properties form (which cannot leave single properties out) is
|
|
23
|
+
* not drawn. The title stays: the host does not say which column is the record's title.
|
|
24
|
+
*/
|
|
25
|
+
export const publicRecordUI: SpacePublicRecordUI = (ui, columns): NotisRuntimeUI => {
|
|
26
|
+
const { DocumentPage, DocumentEditor } = ui;
|
|
27
|
+
return { ...ui,
|
|
28
|
+
DocumentPage: DocumentPage ? function PublicDocumentPage(props: NotisDocumentPageProps) {
|
|
29
|
+
return createElement(DocumentPage, { ...props, properties: publicDocumentPageProperties(props.properties, columns()) });
|
|
30
|
+
} : undefined,
|
|
31
|
+
DocumentEditor: DocumentEditor ? function PublicDocumentEditor(props: NotisDocumentEditorProps) {
|
|
32
|
+
return createElement(DocumentEditor, { ...props, showProperties: false });
|
|
33
|
+
} : undefined,
|
|
34
|
+
RecordProperties: undefined,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface StepOptions {
|
|
2
|
+
/** Wrap from the last item to the first (and back). Default true. */
|
|
3
|
+
wrap?: boolean;
|
|
4
|
+
/** The key is held (`event.repeat`): never wrap, stop at the edge. */
|
|
5
|
+
repeat?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Next cursor id for J/K stepping. Wraps only on a fresh press, so holding J stops at the last row instead of
|
|
10
|
+
* spinning back to the top. No cursor: J lands on the first item, K on the last.
|
|
11
|
+
*/
|
|
12
|
+
export function stepCursor(ids: readonly string[], cursor: string | null | undefined, delta: number,
|
|
13
|
+
options: StepOptions = {}): string | null {
|
|
14
|
+
if (!ids.length) return null;
|
|
15
|
+
const { wrap = true, repeat = false } = options;
|
|
16
|
+
const index = cursor == null ? -1 : ids.indexOf(cursor);
|
|
17
|
+
if (index === -1) return delta >= 0 ? ids[0]! : ids[ids.length - 1]!;
|
|
18
|
+
let next = index + delta;
|
|
19
|
+
if (next < 0 || next >= ids.length) {
|
|
20
|
+
if (wrap && !repeat) next = ((next % ids.length) + ids.length) % ids.length;
|
|
21
|
+
else next = Math.max(0, Math.min(ids.length - 1, next));
|
|
22
|
+
}
|
|
23
|
+
return ids[next]!;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The way the cursor last moved through a list. A removal continues that way (iOS Photos). */
|
|
27
|
+
export type TravelDirection = 'next' | 'previous';
|
|
28
|
+
|
|
29
|
+
/** The way a move from `from` to `to` went in `ids`; null when either is not in the list or nothing moved. */
|
|
30
|
+
export function travelBetween(ids: readonly string[], from: string | null | undefined,
|
|
31
|
+
to: string | null | undefined): TravelDirection | null {
|
|
32
|
+
if (from == null || to == null || from === to) return null;
|
|
33
|
+
const a = ids.indexOf(from);
|
|
34
|
+
const b = ids.indexOf(to);
|
|
35
|
+
if (a === -1 || b === -1) return null;
|
|
36
|
+
return b > a ? 'next' : 'previous';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The id that takes `gone`'s place after it left `previous` (`now` holds the ids still listed): the nearest one still
|
|
41
|
+
* there in the travel direction, else the nearest the other way. Null when none is left.
|
|
42
|
+
*/
|
|
43
|
+
export function continuationOf(previous: readonly string[], now: readonly string[] | ReadonlySet<string>,
|
|
44
|
+
gone: string, direction: TravelDirection = 'next'): string | null {
|
|
45
|
+
const present = now instanceof Set ? now : new Set(now as readonly string[]);
|
|
46
|
+
const index = previous.indexOf(gone);
|
|
47
|
+
if (index === -1) return null;
|
|
48
|
+
const scan = (delta: number) => {
|
|
49
|
+
for (let i = index + delta; i >= 0 && i < previous.length; i += delta) if (present.has(previous[i]!)) return previous[i]!;
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
const first = direction === 'next' ? 1 : -1;
|
|
53
|
+
return scan(first) ?? scan(-first);
|
|
54
|
+
}
|
|
@@ -47,7 +47,8 @@ const SHAPES: Record<string, Shape> = {
|
|
|
47
47
|
hourglass: <path {...S} d="M4 2.5h8M4 13.5h8M5 2.5c0 3 6 3.5 6 5.5s-6 2.5-6 5.5M11 2.5c0 3-6 3.5-6 5.5s6 2.5 6 5.5" />,
|
|
48
48
|
'arrow-counter-clockwise': <path {...S} d="M4.5 6H2V3.5M2.3 6A6 6 0 112 9" />,
|
|
49
49
|
'arrow-clockwise': <path {...S} d="M11.5 6H14V3.5M13.7 6A6 6 0 1 0 14 9" />,
|
|
50
|
-
'arrows-
|
|
50
|
+
'arrows-left-right': <path {...S} d="M11 2.5l2.5 2.5L11 7.5M13.5 5h-11M5 8.5L2.5 11 5 13.5M2.5 11h11" />,
|
|
51
|
+
'arrows-clockwise':<path {...S} d="M3 6a5.4 5.4 0 0110 0M13 3v3h-3M13 10a5.4 5.4 0 01-10 0M3 13v-3h3" />,
|
|
51
52
|
plus: <path {...S} d="M8 3v10M3 8h10" />,
|
|
52
53
|
'circle-dashed': <circle {...S} cx="8" cy="8" r="6" strokeDasharray="2.2 2.2" />,
|
|
53
54
|
circle: <circle {...S} cx="8" cy="8" r="6" />,
|
|
@@ -61,6 +62,7 @@ const SHAPES: Record<string, Shape> = {
|
|
|
61
62
|
'magnifying-glass-plus': <path {...S} d="M7 12A5 5 0 107 2a5 5 0 000 10zM10.6 10.6L14 14M5 7h4M7 5v4" />,
|
|
62
63
|
'magnifying-glass-minus': <path {...S} d="M7 12A5 5 0 107 2a5 5 0 000 10zM10.6 10.6L14 14M5 7h4" />,
|
|
63
64
|
'download-simple': <path {...S} d="M8 2.5v7.5M4.5 6.5L8 10l3.5-3.5M2.5 10v3a.5.5 0 00.5.5h10a.5.5 0 00.5-.5v-3" />,
|
|
65
|
+
info: <g {...S}><circle cx="8" cy="8" r="6.5" /><path d="M8 7.5V11M8 5.25v.01" /></g>,
|
|
64
66
|
link: <path {...S} d="M6.8 9.2l2.4-2.4M7.6 4.6l1.2-1.2a2.8 2.8 0 014 4l-1.2 1.2M8.4 11.4l-1.2 1.2a2.8 2.8 0 01-4-4l1.2-1.2" />,
|
|
65
67
|
file: <path {...S} d="M9.5 2H4a.5.5 0 00-.5.5v11a.5.5 0 00.5.5h8a.5.5 0 00.5-.5V5zM9.5 2v3h3" />,
|
|
66
68
|
'file-image': <g {...S}><path d="M9.5 2H4a.5.5 0 00-.5.5v11a.5.5 0 00.5.5h8a.5.5 0 00.5-.5V5zM9.5 2v3h3" /><path d="M3.5 12l3-3 2 2 1.5-1.5 2.5 2.5" /><circle cx="6.5" cy="6.75" r=".75" /></g>,
|
|
@@ -23,6 +23,7 @@ export const SHELL_WORDS = Object.freeze({
|
|
|
23
23
|
tryAgain: { en: 'Try again', fr: 'Réessayer' },
|
|
24
24
|
selectedOne: { en: '1 selected', fr: '1 sélectionné' },
|
|
25
25
|
selectedMany: { en: '{n} selected', fr: '{n} sélectionnés' },
|
|
26
|
+
moreNotLoaded: { en: 'more not loaded', fr: 'suite non chargée' },
|
|
26
27
|
sidePeek: { en: 'Side peek', fr: 'Aperçu latéral' },
|
|
27
28
|
centerPeek: { en: 'Center peek', fr: 'Aperçu centré' },
|
|
28
29
|
fullPage: { en: 'Full page', fr: 'Pleine page' },
|
package/dist/skill-sync/index.js
CHANGED
|
@@ -660,6 +660,7 @@ async function scanLocalSkills(paths = DEFAULT_SYNC_PATHS) {
|
|
|
660
660
|
nativeScope: identity.scope,
|
|
661
661
|
nativeBaseFolderHash: identity.folderHash,
|
|
662
662
|
nativeFilesCurrent: current,
|
|
663
|
+
nativeManagedFiles: [...Object.keys(identity.files), NATIVE_IDENTITY_FILE].sort(),
|
|
663
664
|
displayName: editedName && editedName !== identity.frontmatterName ? editedName : identity.displayName
|
|
664
665
|
});
|
|
665
666
|
}
|
|
@@ -1091,10 +1092,24 @@ async function requestJson(url, jwt, options = {}) {
|
|
|
1091
1092
|
});
|
|
1092
1093
|
if (!response.ok) {
|
|
1093
1094
|
const text = await response.text();
|
|
1094
|
-
throw new
|
|
1095
|
+
throw new SkillSyncHttpError(
|
|
1096
|
+
`${options.method || "POST"} ${url} \u2192 ${response.status}: ${text}`,
|
|
1097
|
+
response.status,
|
|
1098
|
+
response.headers.get("content-type")
|
|
1099
|
+
);
|
|
1095
1100
|
}
|
|
1096
1101
|
return response.json();
|
|
1097
1102
|
}
|
|
1103
|
+
var SkillSyncHttpError = class extends Error {
|
|
1104
|
+
status;
|
|
1105
|
+
code;
|
|
1106
|
+
constructor(message, status, contentType) {
|
|
1107
|
+
super(message);
|
|
1108
|
+
this.name = "SkillSyncHttpError";
|
|
1109
|
+
this.status = status;
|
|
1110
|
+
this.code = status === 403 && /text\/html/i.test(contentType || "") ? "edge_blocked" : `http_${status}`;
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1098
1113
|
async function fetchSyncSettings(serverUrl, jwt) {
|
|
1099
1114
|
return requestJson(`${serverUrl}/portal_skills/sync-settings`, jwt, {
|
|
1100
1115
|
body: {}
|
|
@@ -1105,8 +1120,9 @@ async function pullSkills(serverUrl, jwt) {
|
|
|
1105
1120
|
body: { skill_sync_protocol: 2 }
|
|
1106
1121
|
});
|
|
1107
1122
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1123
|
+
var MAX_SYNC_PUSH_BODY_BYTES = 2 * 1024 * 1024;
|
|
1124
|
+
async function skillPushPayload(skill) {
|
|
1125
|
+
return {
|
|
1110
1126
|
name: skill.name,
|
|
1111
1127
|
description: skill.description,
|
|
1112
1128
|
skill_md: skill.skillMd,
|
|
@@ -1119,13 +1135,58 @@ async function pushChangedSkills(serverUrl, jwt, changedSkills) {
|
|
|
1119
1135
|
display_name: skill.displayName,
|
|
1120
1136
|
native_scope: skill.nativeScope
|
|
1121
1137
|
} : {}
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
var SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
|
|
1141
|
+
function pushBatches(payloads, maxBodyBytes) {
|
|
1142
|
+
const batches = [];
|
|
1143
|
+
let batch = [];
|
|
1144
|
+
let batchBytes = SYNC_PUSH_ENVELOPE_BYTES;
|
|
1145
|
+
for (const payload of payloads) {
|
|
1146
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
|
|
1147
|
+
if (batch.length > 0 && batchBytes + bytes > maxBodyBytes) {
|
|
1148
|
+
batches.push(batch);
|
|
1149
|
+
batch = [];
|
|
1150
|
+
batchBytes = SYNC_PUSH_ENVELOPE_BYTES;
|
|
1151
|
+
}
|
|
1152
|
+
batch.push(payload);
|
|
1153
|
+
batchBytes += bytes;
|
|
1154
|
+
}
|
|
1155
|
+
if (batch.length > 0) batches.push(batch);
|
|
1156
|
+
return batches;
|
|
1157
|
+
}
|
|
1158
|
+
function pushFailure(name, error) {
|
|
1159
|
+
if (error instanceof SkillSyncHttpError) {
|
|
1160
|
+
return {
|
|
1161
|
+
name,
|
|
1162
|
+
error: error.code === "edge_blocked" ? `Upload blocked before reaching Notis (HTTP ${error.status}); sync will retry` : `Upload failed (HTTP ${error.status}); sync will retry`,
|
|
1163
|
+
status: error.status,
|
|
1164
|
+
code: error.code
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
const code = typeof error?.code === "string" ? error.code : "push_failed";
|
|
1168
|
+
return { name, error: "Upload failed; sync will retry", code };
|
|
1169
|
+
}
|
|
1170
|
+
async function pushChangedSkills(serverUrl, jwt, changedSkills, options = {}) {
|
|
1171
|
+
const payloadSkills = await Promise.all(changedSkills.map(skillPushPayload));
|
|
1172
|
+
const saved = [];
|
|
1173
|
+
const failed = [];
|
|
1174
|
+
for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
|
|
1175
|
+
try {
|
|
1176
|
+
const result = await requestJson(`${serverUrl}/portal_skills/sync-push`, jwt, {
|
|
1177
|
+
body: {
|
|
1178
|
+
skill_sync_protocol: 2,
|
|
1179
|
+
skills: batch
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
saved.push(...result.skills || []);
|
|
1183
|
+
if (Array.isArray(result.failed)) failed.push(...result.failed);
|
|
1184
|
+
} catch (error) {
|
|
1185
|
+
if (error instanceof SkillSyncHttpError && error.status === 401) throw error;
|
|
1186
|
+
for (const payload of batch) failed.push(pushFailure(String(payload.name), error));
|
|
1127
1187
|
}
|
|
1128
|
-
}
|
|
1188
|
+
}
|
|
1189
|
+
return { skills: saved, ...failed.length ? { failed } : {} };
|
|
1129
1190
|
}
|
|
1130
1191
|
async function downloadSkillBundle(bundleUrl) {
|
|
1131
1192
|
const response = await fetch(bundleUrl, { signal: AbortSignal.timeout(9e4) });
|
|
@@ -1751,6 +1812,15 @@ function buildSyncState(pullResponse, localSkills, lastSyncedAt, verifiedAgentLi
|
|
|
1751
1812
|
skills
|
|
1752
1813
|
});
|
|
1753
1814
|
}
|
|
1815
|
+
function keepFailedPushesPending(state, previousState, failedPushes) {
|
|
1816
|
+
for (const { name } of failedPushes) {
|
|
1817
|
+
const row = state.skills[name];
|
|
1818
|
+
const previous = previousState.skills[name];
|
|
1819
|
+
if (!row || !previous || row.nativeReference || previous.nativeReference) continue;
|
|
1820
|
+
state.skills[name] = { ...row, folderHash: previous.folderHash };
|
|
1821
|
+
}
|
|
1822
|
+
return state;
|
|
1823
|
+
}
|
|
1754
1824
|
function buildLocalSymlinkCandidates(pullResponse, localSkills, previousState) {
|
|
1755
1825
|
const cloudSkillNames = new Set(
|
|
1756
1826
|
pullResponse.skills.map((skill) => skill.name)
|
|
@@ -1795,6 +1865,11 @@ function applyLegacyFirstRunState(localSkills, scopedState, legacyState) {
|
|
|
1795
1865
|
skills: migratedSkills
|
|
1796
1866
|
};
|
|
1797
1867
|
}
|
|
1868
|
+
function previouslyAppliedFiles(skill, local, previousState) {
|
|
1869
|
+
const recorded = previousNativeState(previousState, skill)?.appliedFiles;
|
|
1870
|
+
if (recorded || !isNativeSkill(skill) || !local?.nativeManagedFiles) return recorded;
|
|
1871
|
+
return local.nativeFilesCurrent === true && local.cloudId === skill.id && local.folderHash === local.nativeBaseFolderHash ? local.nativeManagedFiles : void 0;
|
|
1872
|
+
}
|
|
1798
1873
|
async function writePulledSkillsToScopedMirror(pullResponse, localSkills, previousState, syncPaths, deps, failures = [], writtenSkillNames = /* @__PURE__ */ new Set(), appliedFilesByName = {}, acknowledgedNative = /* @__PURE__ */ new Map()) {
|
|
1799
1874
|
const localSkillMap = toSkillMap(localSkills);
|
|
1800
1875
|
const warnSkillSync = (message, error) => {
|
|
@@ -1816,7 +1891,7 @@ async function writePulledSkillsToScopedMirror(pullResponse, localSkills, previo
|
|
|
1816
1891
|
writeCloudSkillToDisk: (skill, bundleBytes) => deps.writeCloudSkillToDisk(skill, bundleBytes, syncPaths, {
|
|
1817
1892
|
// What the last write put there. Everything else in the folder was
|
|
1818
1893
|
// produced locally and survives this one.
|
|
1819
|
-
previouslyApplied:
|
|
1894
|
+
previouslyApplied: previouslyAppliedFiles(skill, local, previousState),
|
|
1820
1895
|
...isNativeSkill(skill) && local ? { expectedFolderHash: local.folderHash } : {},
|
|
1821
1896
|
...legacyBaseline ? { legacyBaseline } : {}
|
|
1822
1897
|
}),
|
|
@@ -2170,7 +2245,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
2170
2245
|
for (const failure of failedDownloads) delete verifiedLinks[failure.name];
|
|
2171
2246
|
const lastSyncedAt = pullResponse.last_synced_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
2172
2247
|
await deps.writeSyncState(
|
|
2173
|
-
buildSyncState(
|
|
2248
|
+
keepFailedPushesPending(buildSyncState(
|
|
2174
2249
|
pullResponse,
|
|
2175
2250
|
finalLocalSkills,
|
|
2176
2251
|
lastSyncedAt,
|
|
@@ -2179,7 +2254,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
2179
2254
|
collectAppliedCloudRevisions(pullResponse, previousState, writtenSkillNames),
|
|
2180
2255
|
collectAppliedFiles(pullResponse, previousState, appliedFilesByName),
|
|
2181
2256
|
previousState
|
|
2182
|
-
),
|
|
2257
|
+
), previousState, failedPushes),
|
|
2183
2258
|
syncPaths
|
|
2184
2259
|
);
|
|
2185
2260
|
return {
|
|
@@ -2203,7 +2278,7 @@ export {
|
|
|
2203
2278
|
fetchSyncSettings,
|
|
2204
2279
|
isolatedLinkOptions,
|
|
2205
2280
|
materializeCloudSkillsForLocalShell,
|
|
2281
|
+
pushChangedSkills,
|
|
2206
2282
|
runSkillSync,
|
|
2207
2283
|
shouldWriteCloudSkill
|
|
2208
2284
|
};
|
|
2209
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -6,7 +6,7 @@ import { join as join8 } from "node:path";
|
|
|
6
6
|
|
|
7
7
|
// src/runtime/profiles.js
|
|
8
8
|
import {
|
|
9
|
-
existsSync as
|
|
9
|
+
existsSync as existsSync3,
|
|
10
10
|
mkdirSync as mkdirSync2,
|
|
11
11
|
readFileSync as readFileSync2,
|
|
12
12
|
renameSync as renameSync2,
|
|
@@ -153,6 +153,8 @@ function withConfigFileWriteLock(configFile, callback) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// src/runtime/channel.js
|
|
156
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
157
|
+
import { isAbsolute } from "node:path";
|
|
156
158
|
var RELEASE_CHANNELS = ["stable", "nightly"];
|
|
157
159
|
var CHANNEL_TAGS = { stable: "latest", nightly: "nightly" };
|
|
158
160
|
var API_HOST_CHANNELS = {
|
|
@@ -179,8 +181,14 @@ function channelFromApiBase(apiBase) {
|
|
|
179
181
|
function packageTagForChannel(channel) {
|
|
180
182
|
return CHANNEL_TAGS[channel] || CHANNEL_TAGS.stable;
|
|
181
183
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
var CLI_LAUNCHER_ENV = "NOTIS_CLI_LAUNCHER";
|
|
185
|
+
function installedLauncher(env = process.env) {
|
|
186
|
+
const value = env[CLI_LAUNCHER_ENV];
|
|
187
|
+
if (typeof value !== "string" || !isAbsolute(value) || !existsSync2(value)) return null;
|
|
188
|
+
return /^[A-Za-z0-9_./-]+$/.test(value) ? value : `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
189
|
+
}
|
|
190
|
+
function cliCommandForChannel(channel, env = process.env) {
|
|
191
|
+
return installedLauncher(env) || `npx --package ${CLI_PACKAGE_NAME}@${packageTagForChannel(channel)} -- notis`;
|
|
184
192
|
}
|
|
185
193
|
function pinnedReleaseChannel(profile = {}) {
|
|
186
194
|
if (profile.beta === true) return "nightly";
|
|
@@ -353,7 +361,7 @@ function findUp(filename, startDir = process.cwd(), boundary = null) {
|
|
|
353
361
|
const root = parse(current).root;
|
|
354
362
|
while (true) {
|
|
355
363
|
const candidate = join2(current, filename);
|
|
356
|
-
if (
|
|
364
|
+
if (existsSync3(candidate)) {
|
|
357
365
|
return candidate;
|
|
358
366
|
}
|
|
359
367
|
if (current === root || current === boundary) {
|
|
@@ -437,7 +445,7 @@ function resolveConfigFile() {
|
|
|
437
445
|
}
|
|
438
446
|
function loadConfig() {
|
|
439
447
|
const configFile = resolveConfigFile();
|
|
440
|
-
if (!
|
|
448
|
+
if (!existsSync3(configFile)) {
|
|
441
449
|
return normalizeConfig({});
|
|
442
450
|
}
|
|
443
451
|
try {
|
|
@@ -1466,7 +1474,7 @@ function lockIsStale() {
|
|
|
1466
1474
|
return false;
|
|
1467
1475
|
}
|
|
1468
1476
|
}
|
|
1469
|
-
async function acquireRefreshLock(runtime, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS) {
|
|
1477
|
+
async function acquireRefreshLock(runtime, staleAccessToken, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS) {
|
|
1470
1478
|
mkdirSync4(join4(homedir3(), ".notis"), { recursive: true });
|
|
1471
1479
|
const deadline = Date.now() + waitMs;
|
|
1472
1480
|
for (; ; ) {
|
|
@@ -1476,7 +1484,7 @@ async function acquireRefreshLock(runtime, waitMs = OAUTH_REFRESH_LOCK_WAIT_MS)
|
|
|
1476
1484
|
} catch (error) {
|
|
1477
1485
|
if (error?.code !== "EEXIST") throw error;
|
|
1478
1486
|
const profile = getProfile(loadConfig(), runtime.profileName);
|
|
1479
|
-
if (profile.oauth_access_token && profile.oauth_access_token !==
|
|
1487
|
+
if (profile.oauth_access_token && profile.oauth_access_token !== staleAccessToken && !credentialIsExpired({ credentialKind: "oauth" }, profile)) {
|
|
1480
1488
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
1481
1489
|
return false;
|
|
1482
1490
|
}
|
|
@@ -1509,6 +1517,7 @@ function keepLockFoldersFresh(paths) {
|
|
|
1509
1517
|
return () => clearInterval(interval);
|
|
1510
1518
|
}
|
|
1511
1519
|
async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOptions = {}) {
|
|
1520
|
+
const staleAccessToken = runtime.oauthAccessToken;
|
|
1512
1521
|
const globalLock = await acquireListenerGlobalLock({ waitMs: OAUTH_REFRESH_LOCK_WAIT_MS });
|
|
1513
1522
|
let profileLock = null;
|
|
1514
1523
|
let ownsLock = false;
|
|
@@ -1517,13 +1526,13 @@ async function refreshOAuthCredential(runtime, fetchImpl = fetch, tokenRequestOp
|
|
|
1517
1526
|
let metadata = null;
|
|
1518
1527
|
try {
|
|
1519
1528
|
profileLock = await acquireListenerStartLock(runtime);
|
|
1520
|
-
ownsLock = await acquireRefreshLock(runtime);
|
|
1529
|
+
ownsLock = await acquireRefreshLock(runtime, staleAccessToken);
|
|
1521
1530
|
if (!ownsLock) return true;
|
|
1522
1531
|
stopTouchingLocks = keepLockFoldersFresh([profileLock, oauthLockDir()]);
|
|
1523
1532
|
const config = loadConfig();
|
|
1524
1533
|
const profile = getProfile(config, runtime.profileName);
|
|
1525
1534
|
assertOAuthApiTarget(runtime, profile);
|
|
1526
|
-
if (profile.oauth_access_token && profile.oauth_access_token !==
|
|
1535
|
+
if (profile.oauth_access_token && profile.oauth_access_token !== staleAccessToken && !credentialIsExpired({ credentialKind: "oauth" }, profile)) {
|
|
1527
1536
|
updateRuntimeFromOAuthProfile(runtime, profile);
|
|
1528
1537
|
return true;
|
|
1529
1538
|
}
|
|
@@ -2250,6 +2259,7 @@ async function scanLocalSkills(paths = DEFAULT_SYNC_PATHS) {
|
|
|
2250
2259
|
nativeScope: identity.scope,
|
|
2251
2260
|
nativeBaseFolderHash: identity.folderHash,
|
|
2252
2261
|
nativeFilesCurrent: current,
|
|
2262
|
+
nativeManagedFiles: [...Object.keys(identity.files), NATIVE_IDENTITY_FILE].sort(),
|
|
2253
2263
|
displayName: editedName && editedName !== identity.frontmatterName ? editedName : identity.displayName
|
|
2254
2264
|
});
|
|
2255
2265
|
}
|
|
@@ -2678,10 +2688,24 @@ async function requestJson(url, jwt, options = {}) {
|
|
|
2678
2688
|
});
|
|
2679
2689
|
if (!response.ok) {
|
|
2680
2690
|
const text = await response.text();
|
|
2681
|
-
throw new
|
|
2691
|
+
throw new SkillSyncHttpError(
|
|
2692
|
+
`${options.method || "POST"} ${url} \u2192 ${response.status}: ${text}`,
|
|
2693
|
+
response.status,
|
|
2694
|
+
response.headers.get("content-type")
|
|
2695
|
+
);
|
|
2682
2696
|
}
|
|
2683
2697
|
return response.json();
|
|
2684
2698
|
}
|
|
2699
|
+
var SkillSyncHttpError = class extends Error {
|
|
2700
|
+
status;
|
|
2701
|
+
code;
|
|
2702
|
+
constructor(message, status, contentType) {
|
|
2703
|
+
super(message);
|
|
2704
|
+
this.name = "SkillSyncHttpError";
|
|
2705
|
+
this.status = status;
|
|
2706
|
+
this.code = status === 403 && /text\/html/i.test(contentType || "") ? "edge_blocked" : `http_${status}`;
|
|
2707
|
+
}
|
|
2708
|
+
};
|
|
2685
2709
|
async function fetchSyncSettings(serverUrl, jwt) {
|
|
2686
2710
|
return requestJson(`${serverUrl}/portal_skills/sync-settings`, jwt, {
|
|
2687
2711
|
body: {}
|
|
@@ -2692,8 +2716,9 @@ async function pullSkills(serverUrl, jwt) {
|
|
|
2692
2716
|
body: { skill_sync_protocol: 2 }
|
|
2693
2717
|
});
|
|
2694
2718
|
}
|
|
2695
|
-
|
|
2696
|
-
|
|
2719
|
+
var MAX_SYNC_PUSH_BODY_BYTES = 2 * 1024 * 1024;
|
|
2720
|
+
async function skillPushPayload(skill) {
|
|
2721
|
+
return {
|
|
2697
2722
|
name: skill.name,
|
|
2698
2723
|
description: skill.description,
|
|
2699
2724
|
skill_md: skill.skillMd,
|
|
@@ -2706,13 +2731,58 @@ async function pushChangedSkills(serverUrl, jwt, changedSkills) {
|
|
|
2706
2731
|
display_name: skill.displayName,
|
|
2707
2732
|
native_scope: skill.nativeScope
|
|
2708
2733
|
} : {}
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2736
|
+
var SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
|
|
2737
|
+
function pushBatches(payloads, maxBodyBytes) {
|
|
2738
|
+
const batches = [];
|
|
2739
|
+
let batch = [];
|
|
2740
|
+
let batchBytes = SYNC_PUSH_ENVELOPE_BYTES;
|
|
2741
|
+
for (const payload of payloads) {
|
|
2742
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
|
|
2743
|
+
if (batch.length > 0 && batchBytes + bytes > maxBodyBytes) {
|
|
2744
|
+
batches.push(batch);
|
|
2745
|
+
batch = [];
|
|
2746
|
+
batchBytes = SYNC_PUSH_ENVELOPE_BYTES;
|
|
2747
|
+
}
|
|
2748
|
+
batch.push(payload);
|
|
2749
|
+
batchBytes += bytes;
|
|
2750
|
+
}
|
|
2751
|
+
if (batch.length > 0) batches.push(batch);
|
|
2752
|
+
return batches;
|
|
2753
|
+
}
|
|
2754
|
+
function pushFailure(name, error) {
|
|
2755
|
+
if (error instanceof SkillSyncHttpError) {
|
|
2756
|
+
return {
|
|
2757
|
+
name,
|
|
2758
|
+
error: error.code === "edge_blocked" ? `Upload blocked before reaching Notis (HTTP ${error.status}); sync will retry` : `Upload failed (HTTP ${error.status}); sync will retry`,
|
|
2759
|
+
status: error.status,
|
|
2760
|
+
code: error.code
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
const code = typeof error?.code === "string" ? error.code : "push_failed";
|
|
2764
|
+
return { name, error: "Upload failed; sync will retry", code };
|
|
2765
|
+
}
|
|
2766
|
+
async function pushChangedSkills(serverUrl, jwt, changedSkills, options = {}) {
|
|
2767
|
+
const payloadSkills = await Promise.all(changedSkills.map(skillPushPayload));
|
|
2768
|
+
const saved = [];
|
|
2769
|
+
const failed = [];
|
|
2770
|
+
for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
|
|
2771
|
+
try {
|
|
2772
|
+
const result = await requestJson(`${serverUrl}/portal_skills/sync-push`, jwt, {
|
|
2773
|
+
body: {
|
|
2774
|
+
skill_sync_protocol: 2,
|
|
2775
|
+
skills: batch
|
|
2776
|
+
}
|
|
2777
|
+
});
|
|
2778
|
+
saved.push(...result.skills || []);
|
|
2779
|
+
if (Array.isArray(result.failed)) failed.push(...result.failed);
|
|
2780
|
+
} catch (error) {
|
|
2781
|
+
if (error instanceof SkillSyncHttpError && error.status === 401) throw error;
|
|
2782
|
+
for (const payload of batch) failed.push(pushFailure(String(payload.name), error));
|
|
2714
2783
|
}
|
|
2715
|
-
}
|
|
2784
|
+
}
|
|
2785
|
+
return { skills: saved, ...failed.length ? { failed } : {} };
|
|
2716
2786
|
}
|
|
2717
2787
|
async function downloadSkillBundle(bundleUrl) {
|
|
2718
2788
|
const response = await fetch(bundleUrl, { signal: AbortSignal.timeout(9e4) });
|
|
@@ -3327,6 +3397,15 @@ function buildSyncState(pullResponse, localSkills, lastSyncedAt, verifiedAgentLi
|
|
|
3327
3397
|
skills
|
|
3328
3398
|
});
|
|
3329
3399
|
}
|
|
3400
|
+
function keepFailedPushesPending(state, previousState, failedPushes) {
|
|
3401
|
+
for (const { name } of failedPushes) {
|
|
3402
|
+
const row = state.skills[name];
|
|
3403
|
+
const previous = previousState.skills[name];
|
|
3404
|
+
if (!row || !previous || row.nativeReference || previous.nativeReference) continue;
|
|
3405
|
+
state.skills[name] = { ...row, folderHash: previous.folderHash };
|
|
3406
|
+
}
|
|
3407
|
+
return state;
|
|
3408
|
+
}
|
|
3330
3409
|
function buildLocalSymlinkCandidates(pullResponse, localSkills, previousState) {
|
|
3331
3410
|
const cloudSkillNames = new Set(
|
|
3332
3411
|
pullResponse.skills.map((skill) => skill.name)
|
|
@@ -3371,6 +3450,11 @@ function applyLegacyFirstRunState(localSkills, scopedState, legacyState) {
|
|
|
3371
3450
|
skills: migratedSkills
|
|
3372
3451
|
};
|
|
3373
3452
|
}
|
|
3453
|
+
function previouslyAppliedFiles(skill, local, previousState) {
|
|
3454
|
+
const recorded = previousNativeState(previousState, skill)?.appliedFiles;
|
|
3455
|
+
if (recorded || !isNativeSkill(skill) || !local?.nativeManagedFiles) return recorded;
|
|
3456
|
+
return local.nativeFilesCurrent === true && local.cloudId === skill.id && local.folderHash === local.nativeBaseFolderHash ? local.nativeManagedFiles : void 0;
|
|
3457
|
+
}
|
|
3374
3458
|
async function writePulledSkillsToScopedMirror(pullResponse, localSkills, previousState, syncPaths, deps, failures = [], writtenSkillNames = /* @__PURE__ */ new Set(), appliedFilesByName = {}, acknowledgedNative = /* @__PURE__ */ new Map()) {
|
|
3375
3459
|
const localSkillMap = toSkillMap(localSkills);
|
|
3376
3460
|
const warnSkillSync = (message, error) => {
|
|
@@ -3392,7 +3476,7 @@ async function writePulledSkillsToScopedMirror(pullResponse, localSkills, previo
|
|
|
3392
3476
|
writeCloudSkillToDisk: (skill, bundleBytes) => deps.writeCloudSkillToDisk(skill, bundleBytes, syncPaths, {
|
|
3393
3477
|
// What the last write put there. Everything else in the folder was
|
|
3394
3478
|
// produced locally and survives this one.
|
|
3395
|
-
previouslyApplied:
|
|
3479
|
+
previouslyApplied: previouslyAppliedFiles(skill, local, previousState),
|
|
3396
3480
|
...isNativeSkill(skill) && local ? { expectedFolderHash: local.folderHash } : {},
|
|
3397
3481
|
...legacyBaseline ? { legacyBaseline } : {}
|
|
3398
3482
|
}),
|
|
@@ -3649,7 +3733,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
3649
3733
|
for (const failure of failedDownloads) delete verifiedLinks[failure.name];
|
|
3650
3734
|
const lastSyncedAt = pullResponse.last_synced_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
3651
3735
|
await deps.writeSyncState(
|
|
3652
|
-
buildSyncState(
|
|
3736
|
+
keepFailedPushesPending(buildSyncState(
|
|
3653
3737
|
pullResponse,
|
|
3654
3738
|
finalLocalSkills,
|
|
3655
3739
|
lastSyncedAt,
|
|
@@ -3658,7 +3742,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
3658
3742
|
collectAppliedCloudRevisions(pullResponse, previousState, writtenSkillNames),
|
|
3659
3743
|
collectAppliedFiles(pullResponse, previousState, appliedFilesByName),
|
|
3660
3744
|
previousState
|
|
3661
|
-
),
|
|
3745
|
+
), previousState, failedPushes),
|
|
3662
3746
|
syncPaths
|
|
3663
3747
|
);
|
|
3664
3748
|
return {
|
|
@@ -3750,11 +3834,20 @@ async function quarantineStaleLock(lockDirectory, snapshot) {
|
|
|
3750
3834
|
throw error;
|
|
3751
3835
|
}
|
|
3752
3836
|
}
|
|
3753
|
-
async function
|
|
3754
|
-
const
|
|
3755
|
-
const
|
|
3756
|
-
await
|
|
3757
|
-
await
|
|
3837
|
+
async function publishOwnedLock(lockDirectory, owner) {
|
|
3838
|
+
const quarantineRoot = join7(dirname7(lockDirectory), ".stale-operation-locks");
|
|
3839
|
+
const staging = join7(quarantineRoot, `staging.${owner.id}`);
|
|
3840
|
+
await mkdir(quarantineRoot, { recursive: true, mode: 448 });
|
|
3841
|
+
await mkdir(staging, { mode: 448 });
|
|
3842
|
+
try {
|
|
3843
|
+
await writeFile(join7(staging, "owner"), JSON.stringify(owner), { mode: 384 });
|
|
3844
|
+
await rename(staging, lockDirectory);
|
|
3845
|
+
} catch (error) {
|
|
3846
|
+
await rm(staging, { recursive: true, force: true });
|
|
3847
|
+
const held = ["EEXIST", "ENOTEMPTY"].includes(error?.code) || error?.code === "EPERM" && await lockSnapshot(lockDirectory) !== null;
|
|
3848
|
+
if (held) throw Object.assign(new Error("Lock held."), { code: "EEXIST" });
|
|
3849
|
+
throw error;
|
|
3850
|
+
}
|
|
3758
3851
|
}
|
|
3759
3852
|
async function releaseOwnedLock(lockDirectory, ownerId) {
|
|
3760
3853
|
const owner = await lockSnapshot(lockDirectory);
|
|
@@ -3783,17 +3876,7 @@ async function withSkillSyncLock(callback, {
|
|
|
3783
3876
|
await mkdir(dirname7(lockDirectory), { recursive: true, mode: 448 });
|
|
3784
3877
|
for (; ; ) {
|
|
3785
3878
|
try {
|
|
3786
|
-
await
|
|
3787
|
-
try {
|
|
3788
|
-
await writeLockOwnerAtomically(lockDirectory, {
|
|
3789
|
-
id: ownerId,
|
|
3790
|
-
pid: process.pid,
|
|
3791
|
-
at: now()
|
|
3792
|
-
});
|
|
3793
|
-
} catch (error) {
|
|
3794
|
-
await rm(lockDirectory, { recursive: true, force: true });
|
|
3795
|
-
throw error;
|
|
3796
|
-
}
|
|
3879
|
+
await publishOwnedLock(lockDirectory, { id: ownerId, pid: process.pid, at: now() });
|
|
3797
3880
|
break;
|
|
3798
3881
|
} catch (error) {
|
|
3799
3882
|
if (error?.code !== "EEXIST") throw error;
|
|
@@ -3923,7 +4006,13 @@ async function main(args = process.argv.slice(2), {
|
|
|
3923
4006
|
record(await run({ profile, apiBase, userId }));
|
|
3924
4007
|
} catch (error) {
|
|
3925
4008
|
const code = error.code || "sync_failed";
|
|
3926
|
-
|
|
4009
|
+
const httpStatus = Number.isInteger(error.status) ? { http_status: error.status } : {};
|
|
4010
|
+
record({
|
|
4011
|
+
status: "error",
|
|
4012
|
+
code,
|
|
4013
|
+
...httpStatus,
|
|
4014
|
+
...REJECTED_SIGN_IN_CODES.has(code) && signIn ? { sign_in: signIn } : {}
|
|
4015
|
+
});
|
|
3927
4016
|
process.exitCode = 1;
|
|
3928
4017
|
} finally {
|
|
3929
4018
|
clearTimeout(deadline);
|