@notis_ai/cli 0.2.26 → 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/dist/agent-hooks/notis-agent-hook.mjs +82 -12
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/references/context.md +3 -0
- package/dist/sdk/src/components/NotisSelectionBoundary.tsx +79 -25
- package/dist/skill-sync/index.js +81 -11
- package/dist/skill-sync-worker.mjs +87 -12
- package/dist/space-harness/host.js +71 -71
- package/dist/space-sdk/dist/index.js +1 -1
- package/dist/space-sdk/src/components/NotisSelectionBoundary.d.ts +19 -2
- package/dist/space-sdk/src/tailwind-candidates.d.ts +7 -1
- package/dist/view-renderer/dist/host.js +124 -124
- package/dist/view-renderer/src/dom.js +15 -2
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +1 -1
- package/src/runtime/skill-sync/cloud-client.ts +98 -15
- package/src/runtime/skill-sync/index.ts +22 -3
- package/src/runtime/skill-sync/types.ts +4 -0
- package/src/skill-sync-worker.js +5 -1
|
@@ -10899,6 +10899,7 @@ __export(skill_sync_exports, {
|
|
|
10899
10899
|
fetchSyncSettings: () => fetchSyncSettings,
|
|
10900
10900
|
isolatedLinkOptions: () => isolatedLinkOptions,
|
|
10901
10901
|
materializeCloudSkillsForLocalShell: () => materializeCloudSkillsForLocalShell,
|
|
10902
|
+
pushChangedSkills: () => pushChangedSkills,
|
|
10902
10903
|
runSkillSync: () => runSkillSync,
|
|
10903
10904
|
shouldWriteCloudSkill: () => shouldWriteCloudSkill
|
|
10904
10905
|
});
|
|
@@ -11934,7 +11935,11 @@ async function requestJson(url, jwt, options = {}) {
|
|
|
11934
11935
|
});
|
|
11935
11936
|
if (!response.ok) {
|
|
11936
11937
|
const text2 = await response.text();
|
|
11937
|
-
throw new
|
|
11938
|
+
throw new SkillSyncHttpError(
|
|
11939
|
+
`${options.method || "POST"} ${url} \u2192 ${response.status}: ${text2}`,
|
|
11940
|
+
response.status,
|
|
11941
|
+
response.headers.get("content-type")
|
|
11942
|
+
);
|
|
11938
11943
|
}
|
|
11939
11944
|
return response.json();
|
|
11940
11945
|
}
|
|
@@ -11948,8 +11953,8 @@ async function pullSkills(serverUrl, jwt) {
|
|
|
11948
11953
|
body: { skill_sync_protocol: 2 }
|
|
11949
11954
|
});
|
|
11950
11955
|
}
|
|
11951
|
-
async function
|
|
11952
|
-
|
|
11956
|
+
async function skillPushPayload(skill) {
|
|
11957
|
+
return {
|
|
11953
11958
|
name: skill.name,
|
|
11954
11959
|
description: skill.description,
|
|
11955
11960
|
skill_md: skill.skillMd,
|
|
@@ -11962,13 +11967,57 @@ async function pushChangedSkills(serverUrl, jwt, changedSkills) {
|
|
|
11962
11967
|
display_name: skill.displayName,
|
|
11963
11968
|
native_scope: skill.nativeScope
|
|
11964
11969
|
} : {}
|
|
11965
|
-
}
|
|
11966
|
-
|
|
11967
|
-
|
|
11968
|
-
|
|
11969
|
-
|
|
11970
|
+
};
|
|
11971
|
+
}
|
|
11972
|
+
function pushBatches(payloads, maxBodyBytes) {
|
|
11973
|
+
const batches = [];
|
|
11974
|
+
let batch = [];
|
|
11975
|
+
let batchBytes = SYNC_PUSH_ENVELOPE_BYTES;
|
|
11976
|
+
for (const payload of payloads) {
|
|
11977
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
|
|
11978
|
+
if (batch.length > 0 && batchBytes + bytes > maxBodyBytes) {
|
|
11979
|
+
batches.push(batch);
|
|
11980
|
+
batch = [];
|
|
11981
|
+
batchBytes = SYNC_PUSH_ENVELOPE_BYTES;
|
|
11982
|
+
}
|
|
11983
|
+
batch.push(payload);
|
|
11984
|
+
batchBytes += bytes;
|
|
11985
|
+
}
|
|
11986
|
+
if (batch.length > 0) batches.push(batch);
|
|
11987
|
+
return batches;
|
|
11988
|
+
}
|
|
11989
|
+
function pushFailure(name, error) {
|
|
11990
|
+
if (error instanceof SkillSyncHttpError) {
|
|
11991
|
+
return {
|
|
11992
|
+
name,
|
|
11993
|
+
error: error.code === "edge_blocked" ? `Upload blocked before reaching Notis (HTTP ${error.status}); sync will retry` : `Upload failed (HTTP ${error.status}); sync will retry`,
|
|
11994
|
+
status: error.status,
|
|
11995
|
+
code: error.code
|
|
11996
|
+
};
|
|
11997
|
+
}
|
|
11998
|
+
const code = typeof error?.code === "string" ? error.code : "push_failed";
|
|
11999
|
+
return { name, error: "Upload failed; sync will retry", code };
|
|
12000
|
+
}
|
|
12001
|
+
async function pushChangedSkills(serverUrl, jwt, changedSkills, options = {}) {
|
|
12002
|
+
const payloadSkills = await Promise.all(changedSkills.map(skillPushPayload));
|
|
12003
|
+
const saved = [];
|
|
12004
|
+
const failed = [];
|
|
12005
|
+
for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
|
|
12006
|
+
try {
|
|
12007
|
+
const result = await requestJson(`${serverUrl}/portal_skills/sync-push`, jwt, {
|
|
12008
|
+
body: {
|
|
12009
|
+
skill_sync_protocol: 2,
|
|
12010
|
+
skills: batch
|
|
12011
|
+
}
|
|
12012
|
+
});
|
|
12013
|
+
saved.push(...result.skills || []);
|
|
12014
|
+
if (Array.isArray(result.failed)) failed.push(...result.failed);
|
|
12015
|
+
} catch (error) {
|
|
12016
|
+
if (error instanceof SkillSyncHttpError && error.status === 401) throw error;
|
|
12017
|
+
for (const payload of batch) failed.push(pushFailure(String(payload.name), error));
|
|
11970
12018
|
}
|
|
11971
|
-
}
|
|
12019
|
+
}
|
|
12020
|
+
return { skills: saved, ...failed.length ? { failed } : {} };
|
|
11972
12021
|
}
|
|
11973
12022
|
async function downloadSkillBundle(bundleUrl) {
|
|
11974
12023
|
const response = await fetch(bundleUrl, { signal: AbortSignal.timeout(9e4) });
|
|
@@ -12546,6 +12595,15 @@ function buildSyncState(pullResponse, localSkills, lastSyncedAt, verifiedAgentLi
|
|
|
12546
12595
|
skills
|
|
12547
12596
|
});
|
|
12548
12597
|
}
|
|
12598
|
+
function keepFailedPushesPending(state, previousState, failedPushes) {
|
|
12599
|
+
for (const { name } of failedPushes) {
|
|
12600
|
+
const row = state.skills[name];
|
|
12601
|
+
const previous = previousState.skills[name];
|
|
12602
|
+
if (!row || !previous || row.nativeReference || previous.nativeReference) continue;
|
|
12603
|
+
state.skills[name] = { ...row, folderHash: previous.folderHash };
|
|
12604
|
+
}
|
|
12605
|
+
return state;
|
|
12606
|
+
}
|
|
12549
12607
|
function buildLocalSymlinkCandidates(pullResponse, localSkills, previousState) {
|
|
12550
12608
|
const cloudSkillNames = new Set(
|
|
12551
12609
|
pullResponse.skills.map((skill) => skill.name)
|
|
@@ -12970,7 +13028,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
12970
13028
|
for (const failure of failedDownloads) delete verifiedLinks[failure.name];
|
|
12971
13029
|
const lastSyncedAt = pullResponse.last_synced_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
12972
13030
|
await deps.writeSyncState(
|
|
12973
|
-
buildSyncState(
|
|
13031
|
+
keepFailedPushesPending(buildSyncState(
|
|
12974
13032
|
pullResponse,
|
|
12975
13033
|
finalLocalSkills,
|
|
12976
13034
|
lastSyncedAt,
|
|
@@ -12979,7 +13037,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
12979
13037
|
collectAppliedCloudRevisions(pullResponse, previousState, writtenSkillNames),
|
|
12980
13038
|
collectAppliedFiles(pullResponse, previousState, appliedFilesByName),
|
|
12981
13039
|
previousState
|
|
12982
|
-
),
|
|
13040
|
+
), previousState, failedPushes),
|
|
12983
13041
|
syncPaths
|
|
12984
13042
|
);
|
|
12985
13043
|
return {
|
|
@@ -12999,7 +13057,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
12999
13057
|
failedPushes
|
|
13000
13058
|
};
|
|
13001
13059
|
}
|
|
13002
|
-
var DEFAULT_AGENT_TARGETS, NATIVE_IDENTITY_FILE, UUID, HOME_DIR, execFileAsync, NativeSkillIdentityError, AGENTS_DIR, LEGACY_AGENTS_SKILLS_DIR, NOTIS_SKILL_SYNC_ROOT, LEGACY_NOTIS_SYNC_STATE_PATH, AGENTS_SKILLS_DIR, SKILL_LOCK_PATH, DEFAULT_SYNC_STATE, EXCLUDED_TOP_LEVEL_ROOT_NAMES, DEFAULT_SYNC_PATHS, IGNORED_SKILL_DIRECTORIES, HOME_DIR2, EXTERNAL_AGENT_SKILL_DIRS, EXTERNAL_AGENTS, AGENT_FAILURE_LABELS, BASE_SKILL_NAMES2, DEFAULT_RUN_SKILL_SYNC_DEPS, MIRROR_ONLY_DEPS;
|
|
13060
|
+
var DEFAULT_AGENT_TARGETS, NATIVE_IDENTITY_FILE, UUID, HOME_DIR, execFileAsync, NativeSkillIdentityError, AGENTS_DIR, LEGACY_AGENTS_SKILLS_DIR, NOTIS_SKILL_SYNC_ROOT, LEGACY_NOTIS_SYNC_STATE_PATH, AGENTS_SKILLS_DIR, SKILL_LOCK_PATH, DEFAULT_SYNC_STATE, EXCLUDED_TOP_LEVEL_ROOT_NAMES, DEFAULT_SYNC_PATHS, IGNORED_SKILL_DIRECTORIES, SkillSyncHttpError, MAX_SYNC_PUSH_BODY_BYTES, SYNC_PUSH_ENVELOPE_BYTES, HOME_DIR2, EXTERNAL_AGENT_SKILL_DIRS, EXTERNAL_AGENTS, AGENT_FAILURE_LABELS, BASE_SKILL_NAMES2, DEFAULT_RUN_SKILL_SYNC_DEPS, MIRROR_ONLY_DEPS;
|
|
13003
13061
|
var init_skill_sync = __esm({
|
|
13004
13062
|
"dist/skill-sync/index.js"() {
|
|
13005
13063
|
DEFAULT_AGENT_TARGETS = {
|
|
@@ -13056,6 +13114,18 @@ var init_skill_sync = __esm({
|
|
|
13056
13114
|
gatherMetadataPath: path2.join(NOTIS_SKILL_SYNC_ROOT, "skill-gather-metadata.json")
|
|
13057
13115
|
};
|
|
13058
13116
|
IGNORED_SKILL_DIRECTORIES = /* @__PURE__ */ new Set(["__pycache__", ".pytest_cache"]);
|
|
13117
|
+
SkillSyncHttpError = class extends Error {
|
|
13118
|
+
status;
|
|
13119
|
+
code;
|
|
13120
|
+
constructor(message, status, contentType) {
|
|
13121
|
+
super(message);
|
|
13122
|
+
this.name = "SkillSyncHttpError";
|
|
13123
|
+
this.status = status;
|
|
13124
|
+
this.code = status === 403 && /text\/html/i.test(contentType || "") ? "edge_blocked" : `http_${status}`;
|
|
13125
|
+
}
|
|
13126
|
+
};
|
|
13127
|
+
MAX_SYNC_PUSH_BODY_BYTES = 2 * 1024 * 1024;
|
|
13128
|
+
SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
|
|
13059
13129
|
HOME_DIR2 = os2.homedir();
|
|
13060
13130
|
EXTERNAL_AGENT_SKILL_DIRS = {
|
|
13061
13131
|
claude_code: path22.join(HOME_DIR2, ".claude", "skills"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schema":1,"stamp":
|
|
1
|
+
{"schema":1,"stamp":1794314726,"commit":"7fda8d9020cc8bd18b3698e1ca4eb134d399b157"}
|
|
@@ -72,6 +72,9 @@ optional `quote`, `pending`, `error`, `className`) for image markers or custom l
|
|
|
72
72
|
Use `NotisSelectionBoundary` without the comment UI when only copy/paste provenance is
|
|
73
73
|
needed. It preserves ordinary clipboard text and source metadata so normal paste into
|
|
74
74
|
chat creates a selected-text pill. No special Paste as context action is required.
|
|
75
|
+
A `MarkdownEditor` inside the boundary is quoted the same way; inputs and textareas
|
|
76
|
+
keep plain copy. Without any boundary, copied view text still pastes as a quote
|
|
77
|
+
named after the Space; add a boundary to name the resource the text belongs to.
|
|
75
78
|
|
|
76
79
|
## Verify
|
|
77
80
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSProperties, ClipboardEvent, ReactNode } from 'react';
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
3
|
import { useNotisRuntime } from '../provider';
|
|
4
|
-
import type { ContextResource, ContextSelection } from '../runtime';
|
|
4
|
+
import type { ContextResource, ContextSelection, NotisRuntime } from '../runtime';
|
|
5
5
|
|
|
6
6
|
export const NOTIS_CONTEXT_CLIPBOARD_TYPE = 'application/x-notis-context+json';
|
|
7
7
|
|
|
@@ -18,6 +18,80 @@ function selectionId(): string {
|
|
|
18
18
|
: `selection-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** The selection's markup for other paste targets: hidden parts dropped, links made absolute. */
|
|
22
|
+
function selectionHtml(selection: Selection): string {
|
|
23
|
+
if (typeof document === 'undefined') return '';
|
|
24
|
+
const container = document.createElement('div');
|
|
25
|
+
for (let index = 0; index < selection.rangeCount; index += 1) container.appendChild(selection.getRangeAt(index).cloneContents());
|
|
26
|
+
container.querySelectorAll('[hidden],script,style,template').forEach(node => node.remove());
|
|
27
|
+
container.querySelectorAll('[href],[src]').forEach(node => {
|
|
28
|
+
for (const name of ['href', 'src']) {
|
|
29
|
+
const value = node.getAttribute(name);
|
|
30
|
+
if (value === null) continue;
|
|
31
|
+
try { node.setAttribute(name, new URL(value, document.baseURI).href); } catch { node.removeAttribute(name); }
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return container.innerHTML;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds the copied passage as a Notis quote to a copy event that started inside
|
|
39
|
+
* `event.currentTarget`, and returns that quote (null when nothing inside was
|
|
40
|
+
* copied). Text in a rich editor (a Space's MarkdownEditor, Skill and automation
|
|
41
|
+
* instructions) is quoted too: the editor already wrote its own formats, so they
|
|
42
|
+
* stay as written and the quote reads the editor's plain text. Form fields keep
|
|
43
|
+
* plain copy.
|
|
44
|
+
*/
|
|
45
|
+
export function addCopiedSelectionToClipboard(
|
|
46
|
+
event: ClipboardEvent<HTMLElement>,
|
|
47
|
+
context: Omit<ContextSelection, 'id' | 'text'> = {},
|
|
48
|
+
): ContextSelection | null {
|
|
49
|
+
const boundary = event.currentTarget;
|
|
50
|
+
const target = event.target as Element | null;
|
|
51
|
+
if (!event.clipboardData || target?.closest?.('input,textarea')) return null;
|
|
52
|
+
// An inner boundary already quoted this copy: its resource wins over an outer default.
|
|
53
|
+
if (event.clipboardData.getData(NOTIS_CONTEXT_CLIPBOARD_TYPE)) return null;
|
|
54
|
+
const scope = boundary.getRootNode() as ShadowRoot & { getSelection?: () => Selection | null };
|
|
55
|
+
const selection = scope?.getSelection?.() || window.getSelection();
|
|
56
|
+
if (!selection || !boundary.contains(selection.anchorNode) || !boundary.contains(selection.focusNode)) return null;
|
|
57
|
+
const editorWrote = event.nativeEvent?.defaultPrevented ?? event.defaultPrevented;
|
|
58
|
+
const wrotePlain = editorWrote ? event.clipboardData.getData('text/plain') : '';
|
|
59
|
+
// A handler that cancelled the copy and wrote nothing at all blocked it: quote nothing.
|
|
60
|
+
if (editorWrote && !wrotePlain && !event.clipboardData.getData('text/html')) return null;
|
|
61
|
+
const text = wrotePlain || selection.toString();
|
|
62
|
+
if (!text.trim()) return null;
|
|
63
|
+
|
|
64
|
+
const payload: ContextSelection = { ...context, id: selectionId(), text };
|
|
65
|
+
if (!editorWrote) {
|
|
66
|
+
// Keep the copied formatting (links, bold, tables) for every other paste target.
|
|
67
|
+
const html = selectionHtml(selection);
|
|
68
|
+
event.clipboardData.setData('text/plain', text);
|
|
69
|
+
if (html) event.clipboardData.setData('text/html', html);
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
}
|
|
72
|
+
event.clipboardData.setData(NOTIS_CONTEXT_CLIPBOARD_TYPE, JSON.stringify(payload));
|
|
73
|
+
return payload;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The Space-wide default every view gets from its host: text copied anywhere in
|
|
78
|
+
* the view quotes as the Space itself (its name on the pill, the view as source).
|
|
79
|
+
* A NotisSelectionBoundary inside the view quotes first and names its own resource.
|
|
80
|
+
*/
|
|
81
|
+
export function copySpaceSelection(event: ClipboardEvent<HTMLElement>, runtime: QuoteRuntime | null): void {
|
|
82
|
+
const source = runtime?.contextSource;
|
|
83
|
+
captureCopiedSelection(event, runtime, source ? { source, title: source.appName } : {});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
type QuoteRuntime = Pick<NotisRuntime, 'contextSource' | 'captureContextSelection'>;
|
|
87
|
+
|
|
88
|
+
/** Quotes a copy for the host chat; a public Site's runtime has no chat, so its copy stays the browser's own. */
|
|
89
|
+
function captureCopiedSelection(event: ClipboardEvent<HTMLElement>, runtime: QuoteRuntime | null, context: Omit<ContextSelection, 'id' | 'text'>): void {
|
|
90
|
+
if (!runtime?.captureContextSelection) return;
|
|
91
|
+
const payload = addCopiedSelectionToClipboard(event, context);
|
|
92
|
+
if (payload) runtime.captureContextSelection(payload);
|
|
93
|
+
}
|
|
94
|
+
|
|
21
95
|
/**
|
|
22
96
|
* Adds structured provenance to ordinary copied text. Pasting still works in
|
|
23
97
|
* every app because `text/plain` is preserved; Notis chat additionally reads
|
|
@@ -30,30 +104,10 @@ export function NotisSelectionBoundary({
|
|
|
30
104
|
style,
|
|
31
105
|
}: NotisSelectionBoundaryProps) {
|
|
32
106
|
const runtime = useNotisRuntime();
|
|
33
|
-
const onCopy = useCallback((event: ClipboardEvent<HTMLDivElement>) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const selection = scope?.getSelection?.() || window.getSelection();
|
|
38
|
-
const text = selection?.toString() ?? '';
|
|
39
|
-
if (
|
|
40
|
-
!text.trim()
|
|
41
|
-
|| !selection
|
|
42
|
-
|| !event.currentTarget.contains(selection.anchorNode)
|
|
43
|
-
|| !event.currentTarget.contains(selection.focusNode)
|
|
44
|
-
) return;
|
|
45
|
-
|
|
46
|
-
const payload: ContextSelection = {
|
|
47
|
-
id: selectionId(),
|
|
48
|
-
text,
|
|
49
|
-
...(runtime?.contextSource ? { source: runtime.contextSource } : {}),
|
|
50
|
-
...(resource ? { resource: { ...resource, snapshot: undefined } } : {}),
|
|
51
|
-
};
|
|
52
|
-
event.clipboardData.setData('text/plain', text);
|
|
53
|
-
event.clipboardData.setData(NOTIS_CONTEXT_CLIPBOARD_TYPE, JSON.stringify(payload));
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
runtime?.captureContextSelection?.(payload);
|
|
56
|
-
}, [resource, runtime]);
|
|
107
|
+
const onCopy = useCallback((event: ClipboardEvent<HTMLDivElement>) => captureCopiedSelection(event, runtime, {
|
|
108
|
+
...(runtime?.contextSource ? { source: runtime.contextSource } : {}),
|
|
109
|
+
...(resource ? { resource: { ...resource, snapshot: undefined } } : {}),
|
|
110
|
+
}), [resource, runtime]);
|
|
57
111
|
|
|
58
112
|
return <div className={className} style={style} onCopy={onCopy}>{children}</div>;
|
|
59
113
|
}
|
package/dist/skill-sync/index.js
CHANGED
|
@@ -1092,10 +1092,24 @@ async function requestJson(url, jwt, options = {}) {
|
|
|
1092
1092
|
});
|
|
1093
1093
|
if (!response.ok) {
|
|
1094
1094
|
const text = await response.text();
|
|
1095
|
-
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
|
+
);
|
|
1096
1100
|
}
|
|
1097
1101
|
return response.json();
|
|
1098
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
|
+
};
|
|
1099
1113
|
async function fetchSyncSettings(serverUrl, jwt) {
|
|
1100
1114
|
return requestJson(`${serverUrl}/portal_skills/sync-settings`, jwt, {
|
|
1101
1115
|
body: {}
|
|
@@ -1106,8 +1120,9 @@ async function pullSkills(serverUrl, jwt) {
|
|
|
1106
1120
|
body: { skill_sync_protocol: 2 }
|
|
1107
1121
|
});
|
|
1108
1122
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1123
|
+
var MAX_SYNC_PUSH_BODY_BYTES = 2 * 1024 * 1024;
|
|
1124
|
+
async function skillPushPayload(skill) {
|
|
1125
|
+
return {
|
|
1111
1126
|
name: skill.name,
|
|
1112
1127
|
description: skill.description,
|
|
1113
1128
|
skill_md: skill.skillMd,
|
|
@@ -1120,13 +1135,58 @@ async function pushChangedSkills(serverUrl, jwt, changedSkills) {
|
|
|
1120
1135
|
display_name: skill.displayName,
|
|
1121
1136
|
native_scope: skill.nativeScope
|
|
1122
1137
|
} : {}
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
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));
|
|
1128
1187
|
}
|
|
1129
|
-
}
|
|
1188
|
+
}
|
|
1189
|
+
return { skills: saved, ...failed.length ? { failed } : {} };
|
|
1130
1190
|
}
|
|
1131
1191
|
async function downloadSkillBundle(bundleUrl) {
|
|
1132
1192
|
const response = await fetch(bundleUrl, { signal: AbortSignal.timeout(9e4) });
|
|
@@ -1752,6 +1812,15 @@ function buildSyncState(pullResponse, localSkills, lastSyncedAt, verifiedAgentLi
|
|
|
1752
1812
|
skills
|
|
1753
1813
|
});
|
|
1754
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
|
+
}
|
|
1755
1824
|
function buildLocalSymlinkCandidates(pullResponse, localSkills, previousState) {
|
|
1756
1825
|
const cloudSkillNames = new Set(
|
|
1757
1826
|
pullResponse.skills.map((skill) => skill.name)
|
|
@@ -2176,7 +2245,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
2176
2245
|
for (const failure of failedDownloads) delete verifiedLinks[failure.name];
|
|
2177
2246
|
const lastSyncedAt = pullResponse.last_synced_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
2178
2247
|
await deps.writeSyncState(
|
|
2179
|
-
buildSyncState(
|
|
2248
|
+
keepFailedPushesPending(buildSyncState(
|
|
2180
2249
|
pullResponse,
|
|
2181
2250
|
finalLocalSkills,
|
|
2182
2251
|
lastSyncedAt,
|
|
@@ -2185,7 +2254,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
2185
2254
|
collectAppliedCloudRevisions(pullResponse, previousState, writtenSkillNames),
|
|
2186
2255
|
collectAppliedFiles(pullResponse, previousState, appliedFilesByName),
|
|
2187
2256
|
previousState
|
|
2188
|
-
),
|
|
2257
|
+
), previousState, failedPushes),
|
|
2189
2258
|
syncPaths
|
|
2190
2259
|
);
|
|
2191
2260
|
return {
|
|
@@ -2209,6 +2278,7 @@ export {
|
|
|
2209
2278
|
fetchSyncSettings,
|
|
2210
2279
|
isolatedLinkOptions,
|
|
2211
2280
|
materializeCloudSkillsForLocalShell,
|
|
2281
|
+
pushChangedSkills,
|
|
2212
2282
|
runSkillSync,
|
|
2213
2283
|
shouldWriteCloudSkill
|
|
2214
2284
|
};
|
|
@@ -2688,10 +2688,24 @@ async function requestJson(url, jwt, options = {}) {
|
|
|
2688
2688
|
});
|
|
2689
2689
|
if (!response.ok) {
|
|
2690
2690
|
const text = await response.text();
|
|
2691
|
-
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
|
+
);
|
|
2692
2696
|
}
|
|
2693
2697
|
return response.json();
|
|
2694
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
|
+
};
|
|
2695
2709
|
async function fetchSyncSettings(serverUrl, jwt) {
|
|
2696
2710
|
return requestJson(`${serverUrl}/portal_skills/sync-settings`, jwt, {
|
|
2697
2711
|
body: {}
|
|
@@ -2702,8 +2716,9 @@ async function pullSkills(serverUrl, jwt) {
|
|
|
2702
2716
|
body: { skill_sync_protocol: 2 }
|
|
2703
2717
|
});
|
|
2704
2718
|
}
|
|
2705
|
-
|
|
2706
|
-
|
|
2719
|
+
var MAX_SYNC_PUSH_BODY_BYTES = 2 * 1024 * 1024;
|
|
2720
|
+
async function skillPushPayload(skill) {
|
|
2721
|
+
return {
|
|
2707
2722
|
name: skill.name,
|
|
2708
2723
|
description: skill.description,
|
|
2709
2724
|
skill_md: skill.skillMd,
|
|
@@ -2716,13 +2731,58 @@ async function pushChangedSkills(serverUrl, jwt, changedSkills) {
|
|
|
2716
2731
|
display_name: skill.displayName,
|
|
2717
2732
|
native_scope: skill.nativeScope
|
|
2718
2733
|
} : {}
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
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));
|
|
2724
2783
|
}
|
|
2725
|
-
}
|
|
2784
|
+
}
|
|
2785
|
+
return { skills: saved, ...failed.length ? { failed } : {} };
|
|
2726
2786
|
}
|
|
2727
2787
|
async function downloadSkillBundle(bundleUrl) {
|
|
2728
2788
|
const response = await fetch(bundleUrl, { signal: AbortSignal.timeout(9e4) });
|
|
@@ -3337,6 +3397,15 @@ function buildSyncState(pullResponse, localSkills, lastSyncedAt, verifiedAgentLi
|
|
|
3337
3397
|
skills
|
|
3338
3398
|
});
|
|
3339
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
|
+
}
|
|
3340
3409
|
function buildLocalSymlinkCandidates(pullResponse, localSkills, previousState) {
|
|
3341
3410
|
const cloudSkillNames = new Set(
|
|
3342
3411
|
pullResponse.skills.map((skill) => skill.name)
|
|
@@ -3664,7 +3733,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
3664
3733
|
for (const failure of failedDownloads) delete verifiedLinks[failure.name];
|
|
3665
3734
|
const lastSyncedAt = pullResponse.last_synced_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
3666
3735
|
await deps.writeSyncState(
|
|
3667
|
-
buildSyncState(
|
|
3736
|
+
keepFailedPushesPending(buildSyncState(
|
|
3668
3737
|
pullResponse,
|
|
3669
3738
|
finalLocalSkills,
|
|
3670
3739
|
lastSyncedAt,
|
|
@@ -3673,7 +3742,7 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
3673
3742
|
collectAppliedCloudRevisions(pullResponse, previousState, writtenSkillNames),
|
|
3674
3743
|
collectAppliedFiles(pullResponse, previousState, appliedFilesByName),
|
|
3675
3744
|
previousState
|
|
3676
|
-
),
|
|
3745
|
+
), previousState, failedPushes),
|
|
3677
3746
|
syncPaths
|
|
3678
3747
|
);
|
|
3679
3748
|
return {
|
|
@@ -3937,7 +4006,13 @@ async function main(args = process.argv.slice(2), {
|
|
|
3937
4006
|
record(await run({ profile, apiBase, userId }));
|
|
3938
4007
|
} catch (error) {
|
|
3939
4008
|
const code = error.code || "sync_failed";
|
|
3940
|
-
|
|
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
|
+
});
|
|
3941
4016
|
process.exitCode = 1;
|
|
3942
4017
|
} finally {
|
|
3943
4018
|
clearTimeout(deadline);
|