@thinkingai/ae-cli 6.1.18 → 6.1.20
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 +97 -38
- package/README.zh.md +101 -38
- package/dist/{auth-ROB2EDYV.js → auth-FUM37MHF.js} +241 -126
- package/dist/{capability-DKMYUTLC.js → capability-AXFQW5WM.js} +49 -35
- package/dist/{chunk-JHENBQ5B.js → chunk-4P355ZWB.js} +70 -1
- package/dist/chunk-6ZIQV5GW.js +26 -0
- package/dist/{chunk-TUKQZTMI.js → chunk-7K24F7T2.js} +2 -0
- package/dist/{chunk-OO6XR6LK.js → chunk-AMBFK2K3.js} +2 -0
- package/dist/chunk-ATSM5XAW.js +623 -0
- package/dist/{chunk-4XXOWOTA.js → chunk-BBEFP4SB.js} +31 -38
- package/dist/{chunk-BYYS3ANB.js → chunk-CZU3V3DQ.js} +5 -15
- package/dist/{chunk-VTWMIC5L.js → chunk-E2JKXMVO.js} +2 -0
- package/dist/chunk-ECBLHAZO.js +15 -0
- package/dist/{sync-HKIOZXQE.js → chunk-I4WQAEYB.js} +31 -540
- package/dist/{chunk-DWO43OIB.js → chunk-JQ3ENZZH.js} +2 -0
- package/dist/chunk-LNZBEQXW.js +25216 -0
- package/dist/{chunk-ZQ47LWTI.js → chunk-QJQZH5GQ.js} +49 -79
- package/dist/{chunk-QZ3AS4KK.js → chunk-RSG4ONOI.js} +9 -8
- package/dist/{chunk-4NN5IWVN.js → chunk-T6OSFQZD.js} +2 -0
- package/dist/{chunk-Y3LOALAV.js → chunk-TAL6CZH6.js} +8 -7
- package/dist/{chunk-3KWQYGYI.js → chunk-TKHSULJT.js} +2 -0
- package/dist/chunk-VXNMYUXU.js +202 -0
- package/dist/{chunk-3FY3RJ26.js → chunk-WZ6YVQSF.js} +15 -14
- package/dist/{chunk-6EIJSNBD.js → chunk-Y74WTIKJ.js} +2 -0
- package/dist/{community-report-client-C7WDGET3.js → community-report-client-XXWGSBSD.js} +3 -4
- package/dist/{config-BMYZX2UE.js → config-EXUGQN5T.js} +10 -10
- package/dist/{data-integration-QEKDWQDY.js → data-integration-4NZ53OMT.js} +920 -97
- package/dist/index.js +56 -81
- package/dist/{local-data-upload-client-4YYHSYD6.js → local-data-upload-client-KYOKVYZV.js} +3 -4
- package/dist/{memory-I2WXDTV2.js → memory-ATNKZNW5.js} +6 -7
- package/dist/{metadata-I4C2EWUN.js → metadata-VZVC7YMH.js} +10 -11
- package/dist/{model-HLHIEFMU.js → model-E4JMQ4V2.js} +8 -9
- package/dist/{personal-semantic-preference-LIPACBDX.js → personal-semantic-preference-7S2SQ3UV.js} +9 -10
- package/dist/{project-semantic-RT3R2VQD.js → project-semantic-2SZP2OPO.js} +13 -14
- package/dist/sync-YV3E66IF.js +520 -0
- package/dist/{te-agent-BR6VDBNX.js → te-agent-JB5T3PO7.js} +396 -92
- package/dist/{te-analysis-7VUNUYWZ.js → te-analysis-3YJAAT2D.js} +196 -43
- package/dist/{te-community-5DMNKJWY.js → te-community-UDBI672N.js} +12 -34
- package/dist/{te-dataops-6P5IKWNJ.js → te-dataops-ZLYOCXZ4.js} +480 -81
- package/dist/{te-engage-KZPR5R22.js → te-engage-4XG6OJML.js} +88 -16
- package/dist/{te-experiment-6BITX4RD.js → te-experiment-VXUWPINJ.js} +83 -12
- package/dist/te-kb-WYQWHFSC.js +1732 -0
- package/dist/{te-system-FXITO2JG.js → te-system-7G6F2LJA.js} +569 -35
- package/dist/{te-team-ADOC2ROP.js → te-team-E7FBBXMQ.js} +8 -7
- package/dist/{update-YCYCKJOO.js → update-D47BUG25.js} +8 -8
- package/package.json +22 -10
- package/skills/ae-agent/SKILL.md +30 -13
- package/skills/ae-agent/references/agent-distribution.md +94 -0
- package/skills/ae-agent/references/approval-request.md +4 -0
- package/skills/ae-agent/references/command_index.md +9 -2
- package/skills/ae-agent/references/create-automation.md +20 -2
- package/skills/ae-agent/references/get-agent-context.md +70 -0
- package/skills/ae-agent/references/list-automations.md +18 -3
- package/skills/ae-agent/references/list-mcp-credentials.md +1 -1
- package/skills/ae-agent/references/mcp-token.md +3 -3
- package/skills/ae-agent/references/set-mcp-credential.md +0 -1
- package/skills/ae-agent/references/update-automation.md +18 -0
- package/skills/ae-analysis/SKILL.md +11 -2
- package/skills/ae-analysis/references/adhoc_run.md +2 -0
- package/skills/ae-analysis/references/ai_models.md +23 -3
- package/skills/ae-analysis/references/analysis_gateway_assets.md +3 -3
- package/skills/ae-analysis/references/audience_models.md +18 -0
- package/skills/ae-analysis/references/command_index.md +9 -9
- package/skills/ae-analysis/references/cross_source_config.md +84 -0
- package/skills/ae-analysis/references/dashboard_update.md +1 -1
- package/skills/ae-analysis/references/project_timezone_update.md +13 -4
- package/skills/ae-analysis/references/property_create.md +2 -0
- package/skills/ae-analysis/references/super_metadata_batch_create.md +2 -0
- package/skills/ae-analysis/references/user_cluster_models.md +2 -0
- package/skills/ae-analysis/references/user_cluster_update.md +8 -4
- package/skills/ae-analysis/references/user_tag_create.md +30 -2
- package/skills/ae-analysis/references/user_tag_models.md +17 -3
- package/skills/ae-analysis/references/user_tag_update.md +14 -2
- package/skills/ae-data-integration/SKILL.md +3 -1
- package/skills/ae-data-integration/references/dimension-routing.md +36 -0
- package/skills/ae-data-integration/references/error-handling.md +54 -1
- package/skills/ae-data-integration/references/local-analysis.md +2 -0
- package/skills/ae-data-integration/references/source-inspect.md +18 -2
- package/skills/ae-data-integration/references/tracking-plan.md +1 -1
- package/skills/ae-data-integration/references/transform.md +4 -2
- package/skills/ae-data-integration/references/ue-mapping.md +5 -2
- package/skills/ae-data-integration/references/ue-routing.md +40 -1
- package/skills/ae-dataops/SKILL.md +11 -1
- package/skills/ae-dataops/references/dataops-backfill.md +135 -0
- package/skills/ae-engage/SKILL.md +5 -0
- package/skills/ae-engage/references/build-task-save-guide.md +5 -1
- package/skills/ae-engage/references/save-flow.md +37 -1
- package/skills/ae-engage/references/save-task.md +6 -0
- package/skills/ae-experiment/SKILL.md +6 -2
- package/skills/ae-experiment/references/save_metric.md +20 -8
- package/skills/ae-generate-tracking-plan/SKILL.md +25 -13
- package/skills/ae-generate-tracking-plan/references/business-dimension-mapping.md +1 -1
- package/skills/ae-kb/SKILL.md +218 -36
- package/skills/ae-kb/references/query-workflow.md +59 -29
- package/skills/ae-kb/references/versions.md +46 -0
- package/skills/ae-system/SKILL.md +29 -31
- package/skills/ae-system/references/channel-management.md +303 -0
- package/skills/ae-use-agent/SKILL.md +42 -0
- package/skills/ae-use-agent/references/local-agent.md +114 -0
- package/dist/auth-GBMV6TEJ.js +0 -14
- package/dist/capability-HYVVPG25.js +0 -352
- package/dist/chunk-EFH4XWYC.js +0 -556
- package/dist/chunk-J2DEBMRF.js +0 -313
- package/dist/chunk-JRJY5DMJ.js +0 -71
- package/dist/chunk-OMPRXM3V.js +0 -349
- package/dist/chunk-QNOLN2LJ.js +0 -509
- package/dist/chunk-RJDU7NYP.js +0 -1198
- package/dist/chunk-RNAALWJK.js +0 -98
- package/dist/chunk-SERWF6G5.js +0 -13
- package/dist/chunk-UW5UN47B.js +0 -70
- package/dist/chunk-ZQKDZXDO.js +0 -317
- package/dist/client-L2YDMHQ6.js +0 -203
- package/dist/memory-3ORCR7JH.js +0 -893
- package/dist/metadata-VUOQJE26.js +0 -339
- package/dist/model-UGRDX4MW.js +0 -139
- package/dist/personal-semantic-preference-OEISBRHM.js +0 -239
- package/dist/project-semantic-FFPWFPIW.js +0 -1114
- package/dist/sync-TFHU2UTG.js +0 -10261
- package/dist/te-agent-VLYOV7S4.js +0 -3894
- package/dist/te-analysis-4YGQL5RC.js +0 -9357
- package/dist/te-community-ISDQWJU7.js +0 -1859
- package/dist/te-dataops-CVULXNVB.js +0 -2209
- package/dist/te-engage-N5WI32H6.js +0 -4898
- package/dist/te-experiment-UVR4HLND.js +0 -988
- package/dist/te-kb-RCLSSH2Q.js +0 -935
- package/dist/te-system-K2GYMCTB.js +0 -2213
- package/skills/ae-agent/references/auto-provision-mcp-credentials.md +0 -57
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
SKILL_MANIFEST_FILE,
|
|
4
|
+
assertValidMcpName,
|
|
5
|
+
assertValidSkillSlug,
|
|
6
|
+
describeSource,
|
|
7
|
+
getCurrentWorkspace,
|
|
8
|
+
readSkillManifestEntries,
|
|
9
|
+
scanMcps,
|
|
10
|
+
scanSkills,
|
|
11
|
+
splitPushableMcps,
|
|
12
|
+
writeSkillManifestEntries
|
|
13
|
+
} from "./chunk-JQ3ENZZH.js";
|
|
14
|
+
import {
|
|
15
|
+
MultiselectCancelled,
|
|
16
|
+
promptMultiselect,
|
|
17
|
+
promptSingleSelect
|
|
18
|
+
} from "./chunk-7K24F7T2.js";
|
|
19
|
+
import {
|
|
20
|
+
assertSkillDocumentSize
|
|
21
|
+
} from "./chunk-T6OSFQZD.js";
|
|
22
|
+
import {
|
|
23
|
+
require_lib
|
|
24
|
+
} from "./chunk-I4WQAEYB.js";
|
|
25
|
+
import {
|
|
26
|
+
TeAgentApiError,
|
|
27
|
+
TeAgentCredentialsError,
|
|
28
|
+
getSandboxSyncPullCandidates,
|
|
29
|
+
postSandboxSyncPull,
|
|
30
|
+
postToMainApp,
|
|
31
|
+
uploadToMainApp
|
|
32
|
+
} from "./chunk-BBEFP4SB.js";
|
|
33
|
+
import {
|
|
34
|
+
printError
|
|
35
|
+
} from "./chunk-CZU3V3DQ.js";
|
|
36
|
+
import "./chunk-Y74WTIKJ.js";
|
|
37
|
+
import "./chunk-ATSM5XAW.js";
|
|
38
|
+
import "./chunk-WZ6YVQSF.js";
|
|
39
|
+
import {
|
|
40
|
+
__toESM
|
|
41
|
+
} from "./chunk-4P355ZWB.js";
|
|
42
|
+
|
|
43
|
+
// src/commands/sync/index.ts
|
|
44
|
+
var import_jszip = __toESM(require_lib(), 1);
|
|
45
|
+
import Table from "cli-table3";
|
|
46
|
+
import { lstatSync, readFileSync as readFileSync2, readdirSync } from "fs";
|
|
47
|
+
import { join, relative } from "path";
|
|
48
|
+
|
|
49
|
+
// src/commands/sync/local-copy.ts
|
|
50
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
51
|
+
import path from "path";
|
|
52
|
+
var MCP_MANIFEST_FILE = ".mcp-manifest.json";
|
|
53
|
+
function isMcpScope(value) {
|
|
54
|
+
return value === "personal" || value === "company" || value === "system";
|
|
55
|
+
}
|
|
56
|
+
function uniqueMcpEntries(entries) {
|
|
57
|
+
const seen = /* @__PURE__ */ new Set();
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const entry of entries) {
|
|
60
|
+
if (seen.has(entry.name)) continue;
|
|
61
|
+
seen.add(entry.name);
|
|
62
|
+
out.push(entry);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
function readMcpManifestEntries(manifestPath) {
|
|
67
|
+
if (!existsSync(manifestPath)) return [];
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
71
|
+
} catch {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
if (!Array.isArray(parsed)) return [];
|
|
75
|
+
const entries = [];
|
|
76
|
+
for (const item of parsed) {
|
|
77
|
+
if (!item || typeof item !== "object") continue;
|
|
78
|
+
const entry = item;
|
|
79
|
+
if (typeof entry.name !== "string" || !isMcpScope(entry.scope)) continue;
|
|
80
|
+
entries.push({ name: entry.name, scope: entry.scope });
|
|
81
|
+
}
|
|
82
|
+
return uniqueMcpEntries(entries);
|
|
83
|
+
}
|
|
84
|
+
function writeMcpManifestEntries(manifestPath, entries) {
|
|
85
|
+
writeFileSync(
|
|
86
|
+
manifestPath,
|
|
87
|
+
JSON.stringify(uniqueMcpEntries(entries), null, 2) + "\n",
|
|
88
|
+
"utf8"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
function updateSkillManifestForSource(sourceDir, slug) {
|
|
92
|
+
assertValidSkillSlug(slug);
|
|
93
|
+
const sourceAbs = path.resolve(sourceDir);
|
|
94
|
+
if (!statSync(sourceAbs).isDirectory()) {
|
|
95
|
+
throw new Error(`Skill source path is not a directory: ${sourceDir}`);
|
|
96
|
+
}
|
|
97
|
+
const manifestPath = path.join(path.dirname(sourceAbs), SKILL_MANIFEST_FILE);
|
|
98
|
+
const manifest = readSkillManifestEntries(manifestPath);
|
|
99
|
+
const nextEntry = { dirName: slug, scope: "personal" };
|
|
100
|
+
const existingIndex = manifest.findIndex((entry) => entry.dirName === slug);
|
|
101
|
+
if (existingIndex >= 0 && manifest[existingIndex].scope === nextEntry.scope) {
|
|
102
|
+
return { manifestPath, changed: false };
|
|
103
|
+
}
|
|
104
|
+
const nextManifest = manifest.slice();
|
|
105
|
+
if (existingIndex >= 0) {
|
|
106
|
+
nextManifest[existingIndex] = nextEntry;
|
|
107
|
+
} else {
|
|
108
|
+
nextManifest.push(nextEntry);
|
|
109
|
+
}
|
|
110
|
+
writeSkillManifestEntries(manifestPath, nextManifest);
|
|
111
|
+
return { manifestPath, changed: true };
|
|
112
|
+
}
|
|
113
|
+
function updateMcpManifestForProjectSource(workspaceDir, name) {
|
|
114
|
+
assertValidMcpName(name);
|
|
115
|
+
const workspaceAbs = path.resolve(workspaceDir);
|
|
116
|
+
if (!statSync(workspaceAbs).isDirectory()) {
|
|
117
|
+
throw new Error(`MCP workspace path is not a directory: ${workspaceDir}`);
|
|
118
|
+
}
|
|
119
|
+
const manifestPath = path.join(workspaceAbs, MCP_MANIFEST_FILE);
|
|
120
|
+
const manifest = readMcpManifestEntries(manifestPath);
|
|
121
|
+
const nextEntry = { name, scope: "personal" };
|
|
122
|
+
const existingIndex = manifest.findIndex((entry) => entry.name === name);
|
|
123
|
+
if (existingIndex >= 0 && manifest[existingIndex].scope === nextEntry.scope) {
|
|
124
|
+
return { manifestPath, changed: false };
|
|
125
|
+
}
|
|
126
|
+
const nextManifest = manifest.slice();
|
|
127
|
+
if (existingIndex >= 0) {
|
|
128
|
+
nextManifest[existingIndex] = nextEntry;
|
|
129
|
+
} else {
|
|
130
|
+
nextManifest.push(nextEntry);
|
|
131
|
+
}
|
|
132
|
+
writeMcpManifestEntries(manifestPath, nextManifest);
|
|
133
|
+
return { manifestPath, changed: true };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/commands/sync/index.ts
|
|
137
|
+
function redactEnv(env) {
|
|
138
|
+
if (!env) return void 0;
|
|
139
|
+
const out = {};
|
|
140
|
+
for (const [k, v] of Object.entries(env)) {
|
|
141
|
+
if (/TOKEN|SECRET|KEY|PASSWORD/i.test(k)) {
|
|
142
|
+
out[k] = "***";
|
|
143
|
+
} else {
|
|
144
|
+
out[k] = v;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
var SOURCE_ORDER = {
|
|
150
|
+
global: 0,
|
|
151
|
+
workspace: 1,
|
|
152
|
+
project: 0,
|
|
153
|
+
local: 1,
|
|
154
|
+
user: 2
|
|
155
|
+
};
|
|
156
|
+
function skillToItem(s) {
|
|
157
|
+
return {
|
|
158
|
+
kind: "skill",
|
|
159
|
+
slug: s.slug,
|
|
160
|
+
scope: "personal",
|
|
161
|
+
source: s.source,
|
|
162
|
+
workspacePath: s.workspacePath,
|
|
163
|
+
event: "upsert",
|
|
164
|
+
dirPath: s.dirPath,
|
|
165
|
+
content: s.content,
|
|
166
|
+
checksum: s.checksum,
|
|
167
|
+
mtime: s.mtime
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function mcpToItem(m, includeSecrets) {
|
|
171
|
+
return {
|
|
172
|
+
kind: "mcp",
|
|
173
|
+
slug: m.slug,
|
|
174
|
+
scope: "personal",
|
|
175
|
+
source: m.source,
|
|
176
|
+
workspacePath: m.workspacePath,
|
|
177
|
+
workspaceDir: m.workspaceDir,
|
|
178
|
+
event: "upsert",
|
|
179
|
+
transport: m.transport,
|
|
180
|
+
url: m.url,
|
|
181
|
+
command: m.command,
|
|
182
|
+
args: m.args,
|
|
183
|
+
env: includeSecrets ? m.env : redactEnv(m.env),
|
|
184
|
+
headers: m.headers
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async function selectSkills() {
|
|
188
|
+
const all = scanSkills();
|
|
189
|
+
if (all.length === 0) {
|
|
190
|
+
process.stderr.write("No Skills found (scanned current workspace .claude/skills)\n");
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
all.sort((a, b) => {
|
|
194
|
+
if (a.source !== b.source) return SOURCE_ORDER[a.source] - SOURCE_ORDER[b.source];
|
|
195
|
+
return a.slug.localeCompare(b.slug);
|
|
196
|
+
});
|
|
197
|
+
const items = all.map((s) => ({
|
|
198
|
+
value: s,
|
|
199
|
+
label: s.slug,
|
|
200
|
+
group: describeSource(s),
|
|
201
|
+
hint: s.isSymlink ? "(symlink)" : void 0
|
|
202
|
+
}));
|
|
203
|
+
const picked = await promptMultiselect({
|
|
204
|
+
title: "Select Skills to push to the main app",
|
|
205
|
+
items
|
|
206
|
+
});
|
|
207
|
+
return picked.map(skillToItem);
|
|
208
|
+
}
|
|
209
|
+
async function selectMcps(includeSecrets) {
|
|
210
|
+
const all = scanMcps();
|
|
211
|
+
if (all.length === 0) {
|
|
212
|
+
process.stderr.write(
|
|
213
|
+
"No MCPs found (scanned current workspace .mcp.json / .claude/.claude.json and global ~/.claude.json)\n"
|
|
214
|
+
);
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
const { supported, unsupportedStdio } = splitPushableMcps(all);
|
|
218
|
+
if (unsupportedStdio.length > 0) {
|
|
219
|
+
const names = unsupportedStdio.map((m) => m.slug).sort().join(", ");
|
|
220
|
+
process.stderr.write(`ae-cli sync push only supports http/sse MCPs; skipped stdio MCPs: ${names}
|
|
221
|
+
`);
|
|
222
|
+
}
|
|
223
|
+
if (supported.length === 0) {
|
|
224
|
+
process.stderr.write("No syncable MCPs found. ae-cli sync push only supports http/sse.\n");
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
supported.sort((a, b) => {
|
|
228
|
+
if (a.source !== b.source) return SOURCE_ORDER[a.source] - SOURCE_ORDER[b.source];
|
|
229
|
+
return a.slug.localeCompare(b.slug);
|
|
230
|
+
});
|
|
231
|
+
const items = supported.map((m) => ({
|
|
232
|
+
value: m,
|
|
233
|
+
label: m.slug,
|
|
234
|
+
group: describeSource(m),
|
|
235
|
+
hint: m.hasSecrets && !includeSecrets ? "(env redacted)" : void 0
|
|
236
|
+
}));
|
|
237
|
+
const picked = await promptMultiselect({
|
|
238
|
+
title: "Select MCPs to push to the main app",
|
|
239
|
+
items
|
|
240
|
+
});
|
|
241
|
+
return picked.map((m) => mcpToItem(m, includeSecrets));
|
|
242
|
+
}
|
|
243
|
+
function renderResults(results) {
|
|
244
|
+
const table = new Table({
|
|
245
|
+
head: ["kind", "slug", "status", "message"],
|
|
246
|
+
wordWrap: true
|
|
247
|
+
});
|
|
248
|
+
for (const r of results) {
|
|
249
|
+
table.push([r.kind, r.slug, r.status, r.message ?? ""]);
|
|
250
|
+
}
|
|
251
|
+
process.stdout.write(table.toString() + "\n");
|
|
252
|
+
const failed = results.filter((r) => r.status === "failed").length;
|
|
253
|
+
if (failed > 0) {
|
|
254
|
+
process.stderr.write(`
|
|
255
|
+
\u2717 ${failed} item(s) failed
|
|
256
|
+
`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async function selectPullResources(args) {
|
|
260
|
+
const all = args.candidates.filter((candidate) => candidate.selected).sort((a, b) => {
|
|
261
|
+
const scopeOrder = {
|
|
262
|
+
system: 0,
|
|
263
|
+
company: 1,
|
|
264
|
+
personal: 2
|
|
265
|
+
};
|
|
266
|
+
const scopeDiff = scopeOrder[a.scope] - scopeOrder[b.scope];
|
|
267
|
+
return scopeDiff !== 0 ? scopeDiff : a.name.localeCompare(b.name);
|
|
268
|
+
});
|
|
269
|
+
if (all.length === 0) {
|
|
270
|
+
process.stderr.write(`${args.title}: no candidates available to sync
|
|
271
|
+
`);
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
const items = all.map((candidate) => ({
|
|
275
|
+
value: candidate,
|
|
276
|
+
label: `${candidate.name} ${candidate.scope}`,
|
|
277
|
+
preselected: true
|
|
278
|
+
}));
|
|
279
|
+
return promptMultiselect({ title: args.title, items });
|
|
280
|
+
}
|
|
281
|
+
function toHttpItems(items) {
|
|
282
|
+
return items.map((item) => {
|
|
283
|
+
if (item.kind === "skill") {
|
|
284
|
+
const { kind: _kind2, dirPath: _dirPath, ...rest2 } = item;
|
|
285
|
+
return rest2;
|
|
286
|
+
}
|
|
287
|
+
const { kind: _kind, workspaceDir: _workspaceDir, ...rest } = item;
|
|
288
|
+
return rest;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
async function pushItems(kind, items) {
|
|
292
|
+
if (items.length === 0) return { results: [] };
|
|
293
|
+
try {
|
|
294
|
+
const resp = await postToMainApp("/api/sandbox/sync/push", {
|
|
295
|
+
kind,
|
|
296
|
+
items: toHttpItems(items)
|
|
297
|
+
});
|
|
298
|
+
return { results: resp.results ?? [] };
|
|
299
|
+
} catch (err) {
|
|
300
|
+
if (err instanceof TeAgentApiError) {
|
|
301
|
+
return {
|
|
302
|
+
results: items.map((it) => ({
|
|
303
|
+
kind: it.kind,
|
|
304
|
+
slug: it.slug,
|
|
305
|
+
status: "failed",
|
|
306
|
+
message: `${err.code ?? err.status} ${err.message}`
|
|
307
|
+
}))
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
throw err;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function readSkillVersion(content) {
|
|
314
|
+
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---/.exec(content)?.[1];
|
|
315
|
+
if (!frontmatter) return void 0;
|
|
316
|
+
const matches = [...frontmatter.matchAll(/^version\s*:\s*(.+?)\s*(?:#.*)?$/gm)];
|
|
317
|
+
if (matches.length !== 1) return void 0;
|
|
318
|
+
const value = matches[0][1].trim().replace(/^(['"])(.*)\1$/, "$2");
|
|
319
|
+
return /^(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(value) ? value : void 0;
|
|
320
|
+
}
|
|
321
|
+
async function buildSkillZip(dirPath) {
|
|
322
|
+
const zip = new import_jszip.default();
|
|
323
|
+
const visit = (dir) => {
|
|
324
|
+
for (const name of readdirSync(dir)) {
|
|
325
|
+
if (name === ".DS_Store") continue;
|
|
326
|
+
const absolute = join(dir, name);
|
|
327
|
+
const stat = lstatSync(absolute);
|
|
328
|
+
if (stat.isSymbolicLink()) {
|
|
329
|
+
throw new Error(`Skill package contains a symlink: ${relative(dirPath, absolute)}`);
|
|
330
|
+
}
|
|
331
|
+
if (stat.isDirectory()) visit(absolute);
|
|
332
|
+
else if (stat.isFile()) {
|
|
333
|
+
const content = readFileSync2(absolute);
|
|
334
|
+
if (relative(dirPath, absolute).replaceAll("\\", "/") === "SKILL.md") {
|
|
335
|
+
assertSkillDocumentSize(content);
|
|
336
|
+
}
|
|
337
|
+
zip.file(relative(dirPath, absolute).replaceAll("\\", "/"), content);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
visit(dirPath);
|
|
342
|
+
return zip.generateAsync({ type: "nodebuffer", compression: "DEFLATE" });
|
|
343
|
+
}
|
|
344
|
+
var defaultPushSkillDependencies = {
|
|
345
|
+
upload: (path2, formData) => uploadToMainApp(path2, formData),
|
|
346
|
+
updateManifest: updateSkillManifestForSource
|
|
347
|
+
};
|
|
348
|
+
async function pushSkillItems(items, dependencies = defaultPushSkillDependencies) {
|
|
349
|
+
const results = [];
|
|
350
|
+
for (const item of items) {
|
|
351
|
+
try {
|
|
352
|
+
const buffer = await buildSkillZip(item.dirPath);
|
|
353
|
+
const formData = new FormData();
|
|
354
|
+
formData.append("file", new Blob([new Uint8Array(buffer)], { type: "application/zip" }), `${item.slug}.zip`);
|
|
355
|
+
formData.append("slug", item.slug);
|
|
356
|
+
formData.append("source", item.source);
|
|
357
|
+
if (item.workspacePath) formData.append("workspacePath", item.workspacePath);
|
|
358
|
+
const version = readSkillVersion(item.content);
|
|
359
|
+
if (version) formData.append("version", version);
|
|
360
|
+
const response = await dependencies.upload("/api/sandbox/sync/push/skill", formData);
|
|
361
|
+
dependencies.updateManifest(item.dirPath, item.slug);
|
|
362
|
+
results.push({
|
|
363
|
+
kind: "skill",
|
|
364
|
+
slug: item.slug,
|
|
365
|
+
status: "synced",
|
|
366
|
+
...!response.workspaceEnabled && item.source === "workspace" ? {
|
|
367
|
+
message: "Skill synced, but it was not enabled in the current workspace"
|
|
368
|
+
} : {}
|
|
369
|
+
});
|
|
370
|
+
} catch (err) {
|
|
371
|
+
const message = err instanceof TeAgentApiError ? `${err.code ?? err.status} ${err.message}` : err?.message ?? String(err);
|
|
372
|
+
results.push({
|
|
373
|
+
kind: "skill",
|
|
374
|
+
slug: item.slug,
|
|
375
|
+
status: "failed",
|
|
376
|
+
message
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return { results };
|
|
381
|
+
}
|
|
382
|
+
function updateSyncedProjectMcpManifest(mcpItems, resp) {
|
|
383
|
+
if (mcpItems.length === 0) return;
|
|
384
|
+
const bySlug = new Map(mcpItems.map((item) => [item.slug, item]));
|
|
385
|
+
for (const result of resp.results) {
|
|
386
|
+
if (result.kind !== "mcp" || result.status !== "synced") continue;
|
|
387
|
+
const item = bySlug.get(result.slug);
|
|
388
|
+
if (!item || item.source !== "project") continue;
|
|
389
|
+
if (!item.workspaceDir) {
|
|
390
|
+
result.status = "failed";
|
|
391
|
+
result.message = "Main app synced the MCP, but local MCP manifest update failed: missing workspaceDir";
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
try {
|
|
395
|
+
updateMcpManifestForProjectSource(item.workspaceDir, item.slug);
|
|
396
|
+
} catch (err) {
|
|
397
|
+
result.status = "failed";
|
|
398
|
+
result.message = `Main app synced the MCP, but local MCP manifest update failed: ${err?.message ?? String(err)}`;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
async function selectDirection(optsDirection) {
|
|
403
|
+
if (optsDirection === "push" || optsDirection === "pull") return optsDirection;
|
|
404
|
+
if (optsDirection) {
|
|
405
|
+
throw new Error("--direction must be push or pull");
|
|
406
|
+
}
|
|
407
|
+
return promptSingleSelect({
|
|
408
|
+
title: "Sync direction?",
|
|
409
|
+
items: [
|
|
410
|
+
{ value: "push", label: "Workspace -> Main app" },
|
|
411
|
+
{ value: "pull", label: "Main app -> Workspace" }
|
|
412
|
+
]
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
async function selectKind(optsKind) {
|
|
416
|
+
if (optsKind === "skill" || optsKind === "mcp" || optsKind === "both") return optsKind;
|
|
417
|
+
if (optsKind) {
|
|
418
|
+
throw new Error("--kind must be skill, mcp, or both");
|
|
419
|
+
}
|
|
420
|
+
return promptSingleSelect({
|
|
421
|
+
title: "Which resource type to sync?",
|
|
422
|
+
items: [
|
|
423
|
+
{ value: "skill", label: "Skills" },
|
|
424
|
+
{ value: "mcp", label: "MCPs" },
|
|
425
|
+
{ value: "both", label: "Skills + MCPs" }
|
|
426
|
+
]
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
async function runPush(kind, includeSecrets) {
|
|
430
|
+
const skillItems = kind !== "mcp" ? await selectSkills() : [];
|
|
431
|
+
const mcpItems = kind !== "skill" ? await selectMcps(includeSecrets) : [];
|
|
432
|
+
if (skillItems.length === 0 && mcpItems.length === 0) {
|
|
433
|
+
process.stderr.write("Nothing selected, exiting\n");
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
process.stderr.write(`Pushing ${skillItems.length} Skill(s) / ${mcpItems.length} MCP(s) ...
|
|
437
|
+
`);
|
|
438
|
+
const allResults = [];
|
|
439
|
+
if (skillItems.length > 0) {
|
|
440
|
+
const skillResp = await pushSkillItems(skillItems);
|
|
441
|
+
allResults.push(...skillResp.results);
|
|
442
|
+
}
|
|
443
|
+
if (mcpItems.length > 0) {
|
|
444
|
+
const mcpResp = await pushItems("mcp", mcpItems);
|
|
445
|
+
updateSyncedProjectMcpManifest(mcpItems, mcpResp);
|
|
446
|
+
allResults.push(...mcpResp.results);
|
|
447
|
+
}
|
|
448
|
+
renderResults(allResults);
|
|
449
|
+
}
|
|
450
|
+
function pullResultRows(resp) {
|
|
451
|
+
return (resp.results ?? []).map((result) => ({
|
|
452
|
+
kind: result.kind,
|
|
453
|
+
slug: result.name,
|
|
454
|
+
status: result.status,
|
|
455
|
+
message: result.message
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
async function runPull(kind) {
|
|
459
|
+
const workspace = getCurrentWorkspace();
|
|
460
|
+
if (!workspace) {
|
|
461
|
+
throw new Error("Current workspace not recognized; please run from within /home/ta/workspaces/<workspace>");
|
|
462
|
+
}
|
|
463
|
+
const candidates = await getSandboxSyncPullCandidates({
|
|
464
|
+
workspacePath: workspace.name,
|
|
465
|
+
kind
|
|
466
|
+
});
|
|
467
|
+
const skillItems = kind !== "mcp" ? await selectPullResources({
|
|
468
|
+
title: "Select Skills to sync to workspace",
|
|
469
|
+
candidates: (candidates.skills ?? []).filter((candidate) => candidate.scope !== "system")
|
|
470
|
+
}) : [];
|
|
471
|
+
const mcpItems = kind !== "skill" ? await selectPullResources({
|
|
472
|
+
title: "Select MCPs to sync to workspace",
|
|
473
|
+
candidates: candidates.mcp ?? []
|
|
474
|
+
}) : [];
|
|
475
|
+
if (skillItems.length === 0 && mcpItems.length === 0) {
|
|
476
|
+
process.stderr.write("Nothing selected, exiting\n");
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
process.stderr.write(`Syncing to workspace: ${skillItems.length} Skill(s) / ${mcpItems.length} MCP(s) ...
|
|
480
|
+
`);
|
|
481
|
+
const resp = await postSandboxSyncPull({
|
|
482
|
+
workspacePath: workspace.name,
|
|
483
|
+
kind,
|
|
484
|
+
skills: skillItems.map((item) => item.id),
|
|
485
|
+
mcp: mcpItems.map((item) => item.id)
|
|
486
|
+
});
|
|
487
|
+
renderResults(pullResultRows(resp));
|
|
488
|
+
}
|
|
489
|
+
function registerSync(program) {
|
|
490
|
+
program.command("sync").description("Sync Skills / MCPs between current workspace and te-claude main app").option("--direction <direction>", "push | pull (skip interactive direction picker)").option("--include-secrets", "Include MCP env secrets (TOKEN/SECRET/KEY) in push", false).option("--kind <kind>", "skill | mcp | both (skip interactive picker)").action(async (opts) => {
|
|
491
|
+
try {
|
|
492
|
+
const direction = await selectDirection(opts.direction);
|
|
493
|
+
const kind = await selectKind(opts.kind);
|
|
494
|
+
if (direction === "push") await runPush(kind, !!opts.includeSecrets);
|
|
495
|
+
else await runPull(kind);
|
|
496
|
+
} catch (err) {
|
|
497
|
+
if (err instanceof MultiselectCancelled) {
|
|
498
|
+
process.stderr.write("Cancelled\n");
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (err instanceof TeAgentCredentialsError) {
|
|
502
|
+
printError("config", err.message, err.hint);
|
|
503
|
+
process.exit(1);
|
|
504
|
+
}
|
|
505
|
+
if (err instanceof TeAgentApiError) {
|
|
506
|
+
printError("api", err.message, err.code);
|
|
507
|
+
process.exit(1);
|
|
508
|
+
}
|
|
509
|
+
const e = err;
|
|
510
|
+
printError("api", e?.message ?? String(err));
|
|
511
|
+
process.exit(1);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
export {
|
|
516
|
+
buildSkillZip,
|
|
517
|
+
pushSkillItems,
|
|
518
|
+
readSkillVersion,
|
|
519
|
+
registerSync
|
|
520
|
+
};
|