skilld 2.0.0 → 2.1.0
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 +25 -0
- package/dist/_chunks/add.mjs +10 -9
- package/dist/_chunks/add.mjs.map +1 -1
- package/dist/_chunks/agent-prompt.mjs +4 -4
- package/dist/_chunks/agent-prompt.mjs.map +1 -1
- package/dist/_chunks/agent.mjs +288 -110
- package/dist/_chunks/agent.mjs.map +1 -1
- package/dist/_chunks/args.mjs +2 -2
- package/dist/_chunks/args.mjs.map +1 -1
- package/dist/_chunks/assemble.mjs +4 -4
- package/dist/_chunks/assemble.mjs.map +1 -1
- package/dist/_chunks/author.mjs +11 -11
- package/dist/_chunks/author.mjs.map +1 -1
- package/dist/_chunks/cache.mjs +21 -13
- package/dist/_chunks/cache.mjs.map +1 -1
- package/dist/_chunks/cache2.mjs +3 -3
- package/dist/_chunks/cache2.mjs.map +1 -1
- package/dist/_chunks/client.mjs +4 -3
- package/dist/_chunks/client.mjs.map +1 -1
- package/dist/_chunks/detect.mjs +1 -1
- package/dist/_chunks/detect.mjs.map +1 -1
- package/dist/_chunks/detect2.mjs +1 -1
- package/dist/_chunks/eject.mjs +7 -7
- package/dist/_chunks/eject.mjs.map +1 -1
- package/dist/_chunks/embedding-cache.mjs +1 -1
- package/dist/_chunks/embedding-cache2.mjs +2 -2
- package/dist/_chunks/embedding-cache2.mjs.map +1 -1
- package/dist/_chunks/env.mjs +1 -1
- package/dist/_chunks/env.mjs.map +1 -1
- package/dist/_chunks/install-many.mjs +19 -18
- package/dist/_chunks/install-many.mjs.map +1 -1
- package/dist/_chunks/install.mjs +33 -29
- package/dist/_chunks/install.mjs.map +1 -1
- package/dist/_chunks/intro.mjs +6 -6
- package/dist/_chunks/intro.mjs.map +1 -1
- package/dist/_chunks/list.mjs +5 -4
- package/dist/_chunks/list.mjs.map +1 -1
- package/dist/_chunks/lockfile.mjs +8 -6
- package/dist/_chunks/lockfile.mjs.map +1 -1
- package/dist/_chunks/login.mjs +7 -6
- package/dist/_chunks/login.mjs.map +1 -1
- package/dist/_chunks/logout.mjs +2 -2
- package/dist/_chunks/logout.mjs.map +1 -1
- package/dist/_chunks/map.mjs +1 -1
- package/dist/_chunks/map.mjs.map +1 -1
- package/dist/_chunks/markdown.mjs +2 -2
- package/dist/_chunks/markdown.mjs.map +1 -1
- package/dist/_chunks/menu.mjs +1 -1
- package/dist/_chunks/menu.mjs.map +1 -1
- package/dist/_chunks/model-picker.mjs +1 -1
- package/dist/_chunks/model-picker.mjs.map +1 -1
- package/dist/_chunks/monorepo.mjs +5 -4
- package/dist/_chunks/monorepo.mjs.map +1 -1
- package/dist/_chunks/package-json.mjs +7 -5
- package/dist/_chunks/package-json.mjs.map +1 -1
- package/dist/_chunks/paths.mjs +1 -1
- package/dist/_chunks/paths.mjs.map +1 -1
- package/dist/_chunks/pipeline.mjs +29 -25
- package/dist/_chunks/pipeline.mjs.map +1 -1
- package/dist/_chunks/pool.mjs +1 -1
- package/dist/_chunks/pool2.mjs +2 -2
- package/dist/_chunks/pool2.mjs.map +1 -1
- package/dist/_chunks/portable.mjs +7 -7
- package/dist/_chunks/portable.mjs.map +1 -1
- package/dist/_chunks/prepare-hook.mjs +1 -1
- package/dist/_chunks/prepare-hook2.mjs +3 -3
- package/dist/_chunks/prepare-hook2.mjs.map +1 -1
- package/dist/_chunks/prepare.mjs +17 -11
- package/dist/_chunks/prepare.mjs.map +1 -1
- package/dist/_chunks/prepare2.mjs +12 -10
- package/dist/_chunks/prepare2.mjs.map +1 -1
- package/dist/_chunks/prompts.mjs +8 -6
- package/dist/_chunks/prompts.mjs.map +1 -1
- package/dist/_chunks/pull.mjs +9 -8
- package/dist/_chunks/pull.mjs.map +1 -1
- package/dist/_chunks/regex.mjs +1 -1
- package/dist/_chunks/retriv.mjs +1 -1
- package/dist/_chunks/retriv2.mjs +2 -2
- package/dist/_chunks/retriv2.mjs.map +1 -1
- package/dist/_chunks/sanitize.mjs +1 -1
- package/dist/_chunks/sanitize.mjs.map +1 -1
- package/dist/_chunks/search-helpers.mjs +5 -5
- package/dist/_chunks/search-helpers.mjs.map +1 -1
- package/dist/_chunks/search-interactive.mjs +4 -4
- package/dist/_chunks/search-interactive.mjs.map +1 -1
- package/dist/_chunks/search.mjs +6 -6
- package/dist/_chunks/search.mjs.map +1 -1
- package/dist/_chunks/semver.mjs +111 -77
- package/dist/_chunks/semver.mjs.map +1 -1
- package/dist/_chunks/skill-installer.mjs +1 -1
- package/dist/_chunks/skill-installer2.mjs +26 -17
- package/dist/_chunks/skill-installer2.mjs.map +1 -1
- package/dist/_chunks/skills.mjs +7 -7
- package/dist/_chunks/skills.mjs.map +1 -1
- package/dist/_chunks/store.mjs +2 -2
- package/dist/_chunks/store.mjs.map +1 -1
- package/dist/_chunks/sync.mjs +25 -19
- package/dist/_chunks/sync.mjs.map +1 -1
- package/dist/_chunks/sync2.mjs +1 -1
- package/dist/_chunks/telemetry.mjs +3 -3
- package/dist/_chunks/telemetry.mjs.map +1 -1
- package/dist/_chunks/uninstall.mjs +31 -28
- package/dist/_chunks/uninstall.mjs.map +1 -1
- package/dist/_chunks/update.mjs +14 -13
- package/dist/_chunks/update.mjs.map +1 -1
- package/dist/_chunks/upload.mjs +13 -10
- package/dist/_chunks/upload.mjs.map +1 -1
- package/dist/_chunks/validate.mjs +1 -1
- package/dist/_chunks/validate.mjs.map +1 -1
- package/dist/_chunks/version.mjs +1 -1
- package/dist/_chunks/version.mjs.map +1 -1
- package/dist/_chunks/whoami.mjs +1 -1
- package/dist/_chunks/whoami.mjs.map +1 -1
- package/dist/_chunks/wizard.mjs +1 -1
- package/dist/_chunks/wizard2.mjs +8 -8
- package/dist/_chunks/wizard2.mjs.map +1 -1
- package/dist/_chunks/yaml.mjs +1 -1
- package/dist/_chunks/yaml.mjs.map +1 -1
- package/dist/cli-entry.d.mts +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +39 -35
- package/dist/cli.mjs.map +1 -1
- package/dist/prepare.d.mts +1 -1
- package/dist/prepare.mjs +6 -4
- package/dist/prepare.mjs.map +1 -1
- package/dist/retriv/worker.d.mts.map +1 -1
- package/dist/retriv/worker.mjs.map +1 -1
- package/package.json +23 -24
package/dist/_chunks/agent.mjs
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { detectInstalledAgents, targets } from "./detect.mjs";
|
|
2
|
+
import { SECTION_MERGE_ORDER, SECTION_OUTPUT_FILES, buildAllSectionPrompts, getSectionValidator, resolveSkilldCommand, wrapSection } from "./prompts.mjs";
|
|
3
|
+
import { CACHE_DIR, LLM_CACHE_DIR, PI_AI_AUTH_PATH, skillInternalDir, skillLogDir } from "./paths.mjs";
|
|
4
|
+
import { API_CHANGE_BULLET_RE, SECTION_HEADING_RE, SOURCE_LINK_RE, TRAILING_SLASH_RE as TRAILING_SLASH_RE$1 } from "./regex.mjs";
|
|
5
|
+
import { sanitizeMarkdown } from "./sanitize.mjs";
|
|
6
|
+
import { createReferenceCache, getSkillReferenceDirs } from "./cache.mjs";
|
|
7
7
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { promisify, styleText } from "node:util";
|
|
9
9
|
import { join } from "pathe";
|
|
10
10
|
import { exec, execFileSync, spawn } from "node:child_process";
|
|
11
11
|
import { isWindows } from "std-env";
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
|
-
import {
|
|
14
|
-
import { getOAuthApiKey, getOAuthProvider, getOAuthProviders } from "@earendil-works/pi-ai/oauth";
|
|
13
|
+
import { builtinModels, builtinProviders, getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
|
|
15
14
|
import { resolve as resolve$1 } from "node:path";
|
|
16
15
|
import { Type } from "typebox";
|
|
17
16
|
import { glob, readFile } from "node:fs/promises";
|
|
@@ -42,7 +41,7 @@ function compareVersions(a, b) {
|
|
|
42
41
|
}
|
|
43
42
|
function resolve$2(opts) {
|
|
44
43
|
const { provider, prefix, contains, exclude } = opts;
|
|
45
|
-
return
|
|
44
|
+
return getBuiltinModels(provider).filter((m) => isStableId(m.id)).filter((m) => m.id.startsWith(prefix)).filter((m) => !contains || m.id.includes(contains)).filter((m) => !exclude?.some((e) => m.id.includes(e))).sort((a, b) => compareVersions(a.id, b.id))[0];
|
|
46
45
|
}
|
|
47
46
|
function buildModelEntry(opts) {
|
|
48
47
|
const found = resolve$2(opts);
|
|
@@ -387,32 +386,181 @@ const adapter = {
|
|
|
387
386
|
buildArgs,
|
|
388
387
|
parseEvent
|
|
389
388
|
};
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
const OLLAMA_PREFIX = "ollama:";
|
|
390
|
+
function isOllamaModel(model) {
|
|
391
|
+
return model.startsWith(OLLAMA_PREFIX);
|
|
392
|
+
}
|
|
393
|
+
function parseOllamaModelId(model) {
|
|
394
|
+
return isOllamaModel(model) ? model.slice(7) : null;
|
|
395
|
+
}
|
|
396
|
+
const HAS_SCHEME_RE = /^https?:\/\//;
|
|
397
|
+
const TRAILING_SLASH_RE = /\/$/;
|
|
398
|
+
function ollamaHost() {
|
|
399
|
+
const raw = process.env.OLLAMA_HOST || "http://localhost:11434";
|
|
400
|
+
return (HAS_SCHEME_RE.test(raw) ? raw : `http://${raw}`).replace(TRAILING_SLASH_RE, "");
|
|
401
|
+
}
|
|
402
|
+
async function isCompletionModel(name) {
|
|
403
|
+
const res = await fetch(`${ollamaHost()}/api/show`, {
|
|
404
|
+
method: "POST",
|
|
405
|
+
headers: { "content-type": "application/json" },
|
|
406
|
+
body: JSON.stringify({ model: name }),
|
|
407
|
+
signal: AbortSignal.timeout(1500)
|
|
408
|
+
}).catch(() => null);
|
|
409
|
+
if (!res?.ok) return true;
|
|
410
|
+
const caps = (await res.json().catch(() => null))?.capabilities;
|
|
411
|
+
return !caps?.length || caps.includes("completion") || caps.includes("insert");
|
|
412
|
+
}
|
|
413
|
+
async function getAvailableOllamaModels() {
|
|
414
|
+
const res = await fetch(`${ollamaHost()}/api/tags`, { signal: AbortSignal.timeout(1500) }).catch(() => null);
|
|
415
|
+
if (!res?.ok) return [];
|
|
416
|
+
const data = await res.json().catch(() => null);
|
|
417
|
+
if (!data?.models?.length) return [];
|
|
418
|
+
return (await Promise.all(data.models.map(async (m) => {
|
|
419
|
+
if (!await isCompletionModel(m.name)) return null;
|
|
420
|
+
const params = m.details?.parameter_size;
|
|
421
|
+
const quant = m.details?.quantization_level;
|
|
422
|
+
const sizeGb = m.size ? `${(m.size / 1e9).toFixed(1)}GB` : void 0;
|
|
423
|
+
const detail = params ? `${params}${quant ? ` ${quant}` : ""}` : sizeGb;
|
|
424
|
+
return {
|
|
425
|
+
id: `ollama:${m.name}`,
|
|
426
|
+
name: m.name,
|
|
427
|
+
hint: detail ? `local · ${detail}` : "local"
|
|
428
|
+
};
|
|
429
|
+
}))).filter((m) => m !== null);
|
|
430
|
+
}
|
|
431
|
+
function ollamaExecutor(model) {
|
|
432
|
+
const modelId = parseOllamaModelId(model);
|
|
433
|
+
if (!modelId) return { error: `Not an Ollama model: ${model}` };
|
|
434
|
+
return {
|
|
435
|
+
cliCleanup: false,
|
|
436
|
+
run: async ({ section, prompt, timeout, onProgress }) => {
|
|
437
|
+
const ac = new AbortController();
|
|
438
|
+
const timer = setTimeout(() => ac.abort(), timeout);
|
|
439
|
+
onProgress?.({
|
|
440
|
+
chunk: "[ollama]",
|
|
441
|
+
type: "reasoning",
|
|
442
|
+
text: "",
|
|
443
|
+
reasoning: "Generating locally…",
|
|
444
|
+
section
|
|
445
|
+
});
|
|
446
|
+
const res = await fetch(`${ollamaHost()}/api/chat`, {
|
|
447
|
+
method: "POST",
|
|
448
|
+
headers: { "content-type": "application/json" },
|
|
449
|
+
body: JSON.stringify({
|
|
450
|
+
model: modelId,
|
|
451
|
+
messages: [{
|
|
452
|
+
role: "user",
|
|
453
|
+
content: prompt
|
|
454
|
+
}],
|
|
455
|
+
stream: true,
|
|
456
|
+
options: {
|
|
457
|
+
temperature: .2,
|
|
458
|
+
num_ctx: Number(process.env.OLLAMA_NUM_CTX) || 32768
|
|
459
|
+
}
|
|
460
|
+
}),
|
|
461
|
+
signal: ac.signal
|
|
462
|
+
}).catch((err) => ({
|
|
463
|
+
ok: false,
|
|
464
|
+
statusText: err.message,
|
|
465
|
+
body: null
|
|
466
|
+
}));
|
|
467
|
+
if (!res.ok || !res.body) {
|
|
468
|
+
clearTimeout(timer);
|
|
469
|
+
return {
|
|
470
|
+
text: "",
|
|
471
|
+
stderr: `Ollama request failed: ${res.statusText}. Is \`ollama serve\` running at ${ollamaHost()}?`,
|
|
472
|
+
exitCode: 1
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
let text = "";
|
|
476
|
+
let usage;
|
|
477
|
+
const drain = async () => {
|
|
478
|
+
const reader = res.body.getReader();
|
|
479
|
+
const decoder = new TextDecoder();
|
|
480
|
+
let buffer = "";
|
|
481
|
+
for (;;) {
|
|
482
|
+
const { done, value } = await reader.read();
|
|
483
|
+
if (done) break;
|
|
484
|
+
buffer += decoder.decode(value, { stream: true });
|
|
485
|
+
const lines = buffer.split("\n");
|
|
486
|
+
buffer = lines.pop() || "";
|
|
487
|
+
for (const line of lines) {
|
|
488
|
+
if (!line.trim()) continue;
|
|
489
|
+
const chunk = JSON.parse(line);
|
|
490
|
+
if (chunk.error) throw new Error(chunk.error);
|
|
491
|
+
const delta = chunk.message?.content;
|
|
492
|
+
if (delta) {
|
|
493
|
+
text += delta;
|
|
494
|
+
onProgress?.({
|
|
495
|
+
chunk: delta,
|
|
496
|
+
type: "text",
|
|
497
|
+
text,
|
|
498
|
+
reasoning: "",
|
|
499
|
+
section
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (chunk.done) usage = {
|
|
503
|
+
input: chunk.prompt_eval_count ?? 0,
|
|
504
|
+
output: chunk.eval_count ?? 0
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const streamError = await drain().then(() => void 0).catch((err) => err.message);
|
|
510
|
+
clearTimeout(timer);
|
|
511
|
+
if (streamError) return {
|
|
512
|
+
text: "",
|
|
513
|
+
stderr: `Ollama stream error: ${streamError}`,
|
|
514
|
+
exitCode: 1
|
|
515
|
+
};
|
|
516
|
+
if (!text.trim()) return {
|
|
517
|
+
text: "",
|
|
518
|
+
stderr: "Ollama returned no content",
|
|
519
|
+
exitCode: 1
|
|
520
|
+
};
|
|
521
|
+
return {
|
|
522
|
+
text: text.trim(),
|
|
523
|
+
usage,
|
|
524
|
+
cost: 0
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
const BLOCKED_OAUTH_PROVIDERS = /* @__PURE__ */ new Set([
|
|
393
530
|
"github-copilot",
|
|
394
531
|
"anthropic",
|
|
395
532
|
"openai-codex"
|
|
396
533
|
]);
|
|
397
534
|
const PI_AGENT_AUTH_PATH = join(process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent"), "auth.json");
|
|
398
535
|
const SKILLD_AUTH_PATH = PI_AI_AUTH_PATH;
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
536
|
+
function isObjectRecord(value) {
|
|
537
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
538
|
+
}
|
|
539
|
+
function isStringRecord(value) {
|
|
540
|
+
return isObjectRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
541
|
+
}
|
|
542
|
+
function isCredential(value) {
|
|
543
|
+
if (!isObjectRecord(value) || !("type" in value)) return false;
|
|
544
|
+
if (value.type === "oauth") return "refresh" in value && typeof value.refresh === "string" && "access" in value && typeof value.access === "string" && "expires" in value && typeof value.expires === "number";
|
|
545
|
+
if (value.type !== "api_key") return false;
|
|
546
|
+
return (!("key" in value) || value.key === void 0 || typeof value.key === "string") && (!("env" in value) || value.env === void 0 || isStringRecord(value.env));
|
|
547
|
+
}
|
|
403
548
|
function readAuthFile(path) {
|
|
404
549
|
if (!existsSync(path)) return {};
|
|
405
550
|
try {
|
|
406
|
-
|
|
551
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
552
|
+
if (!isObjectRecord(parsed)) return {};
|
|
553
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => isCredential(entry[1])));
|
|
407
554
|
} catch {
|
|
408
555
|
return {};
|
|
409
556
|
}
|
|
410
557
|
}
|
|
411
558
|
function loadAuth() {
|
|
412
559
|
const piAuth = readAuthFile(PI_AGENT_AUTH_PATH);
|
|
560
|
+
const skilldAuth = readAuthFile(SKILLD_AUTH_PATH);
|
|
413
561
|
return {
|
|
414
|
-
...
|
|
415
|
-
...
|
|
562
|
+
...piAuth,
|
|
563
|
+
...skilldAuth
|
|
416
564
|
};
|
|
417
565
|
}
|
|
418
566
|
function saveAuth(auth) {
|
|
@@ -422,58 +570,79 @@ function saveAuth(auth) {
|
|
|
422
570
|
});
|
|
423
571
|
writeFileSync(SKILLD_AUTH_PATH, JSON.stringify(auth, null, 2), { mode: 384 });
|
|
424
572
|
}
|
|
425
|
-
function
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
573
|
+
function createCredentialStore() {
|
|
574
|
+
const chains = /* @__PURE__ */ new Map();
|
|
575
|
+
return {
|
|
576
|
+
async read(providerId) {
|
|
577
|
+
return loadAuth()[providerId];
|
|
578
|
+
},
|
|
579
|
+
async list() {
|
|
580
|
+
return Object.entries(loadAuth()).map(([providerId, credential]) => ({
|
|
581
|
+
providerId,
|
|
582
|
+
type: credential.type
|
|
583
|
+
}));
|
|
584
|
+
},
|
|
585
|
+
async modify(providerId, update) {
|
|
586
|
+
let result;
|
|
587
|
+
const operation = (chains.get(providerId) ?? Promise.resolve()).then(async () => {
|
|
588
|
+
const current = loadAuth()[providerId];
|
|
589
|
+
const next = await update(current);
|
|
590
|
+
result = next ?? current;
|
|
591
|
+
if (next) {
|
|
592
|
+
const localAuth = readAuthFile(SKILLD_AUTH_PATH);
|
|
593
|
+
localAuth[providerId] = next;
|
|
594
|
+
saveAuth(localAuth);
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
chains.set(providerId, operation.then(() => void 0, () => void 0));
|
|
598
|
+
await operation;
|
|
599
|
+
return result;
|
|
600
|
+
},
|
|
601
|
+
async delete(providerId) {
|
|
602
|
+
const localAuth = readAuthFile(SKILLD_AUTH_PATH);
|
|
603
|
+
delete localAuth[providerId];
|
|
604
|
+
saveAuth(localAuth);
|
|
605
|
+
}
|
|
445
606
|
};
|
|
446
|
-
|
|
447
|
-
|
|
607
|
+
}
|
|
608
|
+
function createPiAiModels() {
|
|
609
|
+
return builtinModels({ credentials: createCredentialStore() });
|
|
448
610
|
}
|
|
449
611
|
function getOAuthProviderList() {
|
|
450
612
|
const auth = loadAuth();
|
|
451
|
-
return
|
|
452
|
-
id:
|
|
453
|
-
name:
|
|
454
|
-
loggedIn:
|
|
613
|
+
return builtinProviders().filter((provider) => provider.auth.oauth && !BLOCKED_OAUTH_PROVIDERS.has(provider.id)).map((provider) => ({
|
|
614
|
+
id: provider.id,
|
|
615
|
+
name: provider.auth.oauth?.name ?? provider.name,
|
|
616
|
+
loggedIn: auth[provider.id]?.type === "oauth"
|
|
455
617
|
}));
|
|
456
618
|
}
|
|
457
619
|
async function loginOAuthProvider(providerId, callbacks) {
|
|
458
|
-
const
|
|
459
|
-
if (!
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
620
|
+
const models = createPiAiModels();
|
|
621
|
+
if (!models.getProvider(providerId)?.auth.oauth || BLOCKED_OAUTH_PROVIDERS.has(providerId)) return false;
|
|
622
|
+
const notify = (event) => {
|
|
623
|
+
if (event.type === "auth_url") callbacks.onAuth(event.url, event.instructions);
|
|
624
|
+
else if (event.type === "device_code") {
|
|
625
|
+
if (callbacks.onDeviceCode) callbacks.onDeviceCode(event.userCode, event.verificationUri);
|
|
626
|
+
else callbacks.onAuth(event.verificationUri, `Enter code ${event.userCode}`);
|
|
627
|
+
} else callbacks.onProgress?.(event.message);
|
|
628
|
+
};
|
|
629
|
+
const prompt = async (input) => {
|
|
630
|
+
if (input.type !== "select") return callbacks.onPrompt(input.message, input.placeholder);
|
|
631
|
+
const options = input.options.map((option) => ({
|
|
632
|
+
id: option.id,
|
|
633
|
+
label: option.label
|
|
634
|
+
}));
|
|
635
|
+
return await callbacks.onSelect?.(input.message, options) ?? options[0]?.id ?? "";
|
|
636
|
+
};
|
|
637
|
+
const interaction = {
|
|
638
|
+
notify,
|
|
639
|
+
prompt
|
|
469
640
|
};
|
|
470
|
-
|
|
641
|
+
await models.login(providerId, "oauth", interaction);
|
|
471
642
|
return true;
|
|
472
643
|
}
|
|
473
|
-
function logoutOAuthProvider(providerId) {
|
|
474
|
-
|
|
475
|
-
delete auth[providerId];
|
|
476
|
-
saveAuth(auth);
|
|
644
|
+
async function logoutOAuthProvider(providerId) {
|
|
645
|
+
await createPiAiModels().logout(providerId);
|
|
477
646
|
}
|
|
478
647
|
function isPiAiModel(model) {
|
|
479
648
|
return model.startsWith("pi:");
|
|
@@ -510,42 +679,27 @@ const RECOMMENDED_MODELS = {
|
|
|
510
679
|
google: /flash/,
|
|
511
680
|
openai: /gpt-4\.1-mini/
|
|
512
681
|
};
|
|
513
|
-
function getAvailablePiAiModels() {
|
|
514
|
-
const
|
|
515
|
-
const auth = loadAuth();
|
|
682
|
+
async function getAvailablePiAiModels(models = createPiAiModels()) {
|
|
683
|
+
const modelsByProvider = Map.groupBy(await models.getAvailable(), (model) => model.provider);
|
|
516
684
|
const available = [];
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
else {
|
|
522
|
-
const oauthId = resolveOAuthProviderId(provider);
|
|
523
|
-
if (oauthId && auth[oauthId]) authSource = "oauth";
|
|
524
|
-
}
|
|
525
|
-
if (authSource === "none") continue;
|
|
526
|
-
const models = getModels(provider);
|
|
685
|
+
for (const [provider, providerModels] of modelsByProvider) {
|
|
686
|
+
const auth = await models.checkAuth(provider);
|
|
687
|
+
if (!auth) continue;
|
|
688
|
+
const authSource = auth.type === "oauth" ? "oauth" : "api-key";
|
|
527
689
|
const recPattern = RECOMMENDED_MODELS[provider];
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
for (const model of models) if (!isLegacyModel(model.id) && recPattern.test(model.id)) {
|
|
531
|
-
recModelId = model.id;
|
|
532
|
-
break;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
for (const model of models) {
|
|
690
|
+
const recModelId = recPattern ? providerModels.find((model) => !isLegacyModel(model.id) && recPattern.test(model.id))?.id : void 0;
|
|
691
|
+
for (const model of providerModels) {
|
|
536
692
|
if (model.contextWindow && model.contextWindow < MIN_CONTEXT_WINDOW) continue;
|
|
537
693
|
if (isLegacyModel(model.id)) continue;
|
|
538
694
|
const id = `pi:${provider}/${model.id}`;
|
|
539
695
|
const ctx = model.contextWindow ? ` · ${Math.round(model.contextWindow / 1e3)}k ctx` : "";
|
|
540
696
|
const cost = model.cost?.input ? ` · $${model.cost.input}/Mtok` : "";
|
|
541
|
-
const isRecommended = model.id === recModelId && !recommendedPicked.has(provider);
|
|
542
|
-
if (isRecommended) recommendedPicked.add(provider);
|
|
543
697
|
available.push({
|
|
544
698
|
id,
|
|
545
699
|
name: model.name || model.id,
|
|
546
700
|
hint: `${authSource === "oauth" ? "OAuth" : "API key"}${ctx}${cost}`,
|
|
547
701
|
authSource,
|
|
548
|
-
recommended:
|
|
702
|
+
recommended: model.id === recModelId
|
|
549
703
|
});
|
|
550
704
|
}
|
|
551
705
|
}
|
|
@@ -583,7 +737,7 @@ const TOOLS = [
|
|
|
583
737
|
parameters: Type.Object({ command: Type.String({ description: "Shell command to run" }) })
|
|
584
738
|
}
|
|
585
739
|
];
|
|
586
|
-
const SAFE_COMMANDS = new Set([
|
|
740
|
+
const SAFE_COMMANDS = /* @__PURE__ */ new Set([
|
|
587
741
|
"skilld",
|
|
588
742
|
"ls",
|
|
589
743
|
"cat",
|
|
@@ -591,7 +745,8 @@ const SAFE_COMMANDS = new Set([
|
|
|
591
745
|
]);
|
|
592
746
|
const SHELL_META_RE = /[;&|`$()<>]/;
|
|
593
747
|
function resolveSandboxedPath(p, skilldDir) {
|
|
594
|
-
const
|
|
748
|
+
const cleaned = String(p).replace(STATIC_REGEX_1$3, "./").replace(STATIC_REGEX_2$3, "./").replace(STATIC_REGEX_3$2, "");
|
|
749
|
+
const resolved = resolve$1(skilldDir, cleaned);
|
|
595
750
|
if (!resolved.startsWith(`${skilldDir}/`) && resolved !== skilldDir) throw new Error(`Path traversal blocked: ${p}`);
|
|
596
751
|
return resolved;
|
|
597
752
|
}
|
|
@@ -657,14 +812,16 @@ function executeTool(toolCall, skilldDir) {
|
|
|
657
812
|
else results.push(`./.skilld/${relPath}`);
|
|
658
813
|
}
|
|
659
814
|
};
|
|
660
|
-
const baseDir = pattern.split("*")[0]?.replace(TRAILING_SLASH_RE, "") ?? "";
|
|
815
|
+
const baseDir = pattern.split("*")[0]?.replace(TRAILING_SLASH_RE$1, "") ?? "";
|
|
661
816
|
walkDir(join(skilldDir, baseDir), baseDir);
|
|
662
817
|
const matched = results.filter((r) => globMatch(r.replace(STATIC_REGEX_1$3, ""), pattern));
|
|
663
818
|
return matched.length > 0 ? matched.join("\n") : `No files matching: ${args.pattern}`;
|
|
664
819
|
}
|
|
665
|
-
case "Write":
|
|
666
|
-
|
|
820
|
+
case "Write": {
|
|
821
|
+
const filePath = resolveSandboxedPath(args.path, skilldDir);
|
|
822
|
+
writeFileSync(filePath, sanitizeMarkdown(String(args.content)));
|
|
667
823
|
return "File written successfully.";
|
|
824
|
+
}
|
|
668
825
|
case "Bash": {
|
|
669
826
|
const cmd = String(args.command).trim();
|
|
670
827
|
const parts = cmd.split(STATIC_REGEX_5$2);
|
|
@@ -675,7 +832,7 @@ function executeTool(toolCall, skilldDir) {
|
|
|
675
832
|
cwd: skilldDir,
|
|
676
833
|
timeout: 15e3,
|
|
677
834
|
encoding: "utf-8",
|
|
678
|
-
maxBuffer:
|
|
835
|
+
maxBuffer: 524288
|
|
679
836
|
}).trim();
|
|
680
837
|
} catch (err) {
|
|
681
838
|
return `Error: ${err.message}`;
|
|
@@ -688,8 +845,9 @@ const SYSTEM_PROMPT = "You are a technical documentation expert generating SKILL
|
|
|
688
845
|
async function optimizeSectionPiAi(opts) {
|
|
689
846
|
const parsed = parsePiAiModelId(opts.model);
|
|
690
847
|
if (!parsed) throw new Error(`Invalid pi-ai model ID: ${opts.model}. Expected format: pi:provider/model-id`);
|
|
691
|
-
const
|
|
692
|
-
const
|
|
848
|
+
const models = opts.models ?? createPiAiModels();
|
|
849
|
+
const model = models.getModel(parsed.provider, parsed.modelId);
|
|
850
|
+
if (!model) throw new Error(`Unknown pi-ai model: ${parsed.provider}/${parsed.modelId}`);
|
|
693
851
|
const skilldDir = skillInternalDir(opts.skillDir);
|
|
694
852
|
const fullPrompt = opts.prompt;
|
|
695
853
|
opts.onProgress?.({
|
|
@@ -714,14 +872,14 @@ async function optimizeSectionPiAi(opts) {
|
|
|
714
872
|
let lastWriteContent = "";
|
|
715
873
|
for (let turn = 0; turn < 30; turn++) {
|
|
716
874
|
if (opts.signal?.aborted) throw new Error("pi-ai request timed out");
|
|
717
|
-
const eventStream = streamSimple(model, {
|
|
875
|
+
const eventStream = models.streamSimple(model, {
|
|
718
876
|
systemPrompt: SYSTEM_PROMPT,
|
|
719
877
|
messages,
|
|
720
878
|
tools: TOOLS
|
|
721
879
|
}, {
|
|
722
880
|
reasoning: turn === 0 ? "medium" : void 0,
|
|
723
881
|
maxTokens: 16384,
|
|
724
|
-
|
|
882
|
+
signal: opts.signal
|
|
725
883
|
});
|
|
726
884
|
let assistantMessage;
|
|
727
885
|
let turnText = "";
|
|
@@ -891,7 +1049,10 @@ function createToolProgress(log) {
|
|
|
891
1049
|
const shortened = shortenCommand(hint);
|
|
892
1050
|
emit(`${prefix}Running ${shortened.length > 50 ? `${shortened.slice(0, 47)}...` : shortened}`);
|
|
893
1051
|
}
|
|
894
|
-
} else
|
|
1052
|
+
} else {
|
|
1053
|
+
const path = shortenPath(hint || "...");
|
|
1054
|
+
emit(`${prefix}${verb} ${styleText("gray", path)}`);
|
|
1055
|
+
}
|
|
895
1056
|
}
|
|
896
1057
|
};
|
|
897
1058
|
}
|
|
@@ -932,10 +1093,12 @@ const CLI_MODELS = Object.fromEntries(Object.values(CLI_ADAPTERS).flatMap((adapt
|
|
|
932
1093
|
agentId: adapter.agentId
|
|
933
1094
|
}])));
|
|
934
1095
|
function getModelName(id) {
|
|
1096
|
+
if (isOllamaModel(id)) return parseOllamaModelId(id) ?? id;
|
|
935
1097
|
if (isPiAiModel(id)) return parsePiAiModelId(id)?.modelId ?? id;
|
|
936
1098
|
return CLI_MODELS[id]?.name ?? id;
|
|
937
1099
|
}
|
|
938
1100
|
function getModelLabel(id) {
|
|
1101
|
+
if (isOllamaModel(id)) return `Ollama · ${parseOllamaModelId(id) ?? id}`;
|
|
939
1102
|
if (isPiAiModel(id)) {
|
|
940
1103
|
const parsed = parsePiAiModelId(id);
|
|
941
1104
|
return parsed ? `${PI_PROVIDER_NAMES[parsed.provider] ?? parsed.provider} · ${parsed.modelId}` : id;
|
|
@@ -947,6 +1110,7 @@ function getModelLabel(id) {
|
|
|
947
1110
|
async function getAvailableModels() {
|
|
948
1111
|
const execAsync = promisify(exec);
|
|
949
1112
|
const lookupCmd = isWindows ? "where" : "which";
|
|
1113
|
+
const ollamaModelsPromise = getAvailableOllamaModels();
|
|
950
1114
|
const agentsWithCli = detectInstalledAgents().filter((id) => targets[id].cli);
|
|
951
1115
|
const cliChecks = await Promise.all(agentsWithCli.map(async (agentId) => {
|
|
952
1116
|
const cli = targets[agentId].cli;
|
|
@@ -972,10 +1136,10 @@ async function getAvailableModels() {
|
|
|
972
1136
|
vendorGroup: providerName
|
|
973
1137
|
};
|
|
974
1138
|
});
|
|
975
|
-
const piAiEntries = getAvailablePiAiModels().map((m) => {
|
|
1139
|
+
const piAiEntries = (await getAvailablePiAiModels()).map((m) => {
|
|
976
1140
|
const piProvider = parsePiAiModelId(m.id)?.provider ?? "pi-ai";
|
|
977
1141
|
const displayName = PI_PROVIDER_NAMES[piProvider] ?? piProvider;
|
|
978
|
-
const authLabel = m.authSource === "
|
|
1142
|
+
const authLabel = m.authSource === "api-key" ? "API key" : "OAuth";
|
|
979
1143
|
return {
|
|
980
1144
|
id: m.id,
|
|
981
1145
|
name: m.name,
|
|
@@ -988,7 +1152,21 @@ async function getAvailableModels() {
|
|
|
988
1152
|
vendorGroup: displayName
|
|
989
1153
|
};
|
|
990
1154
|
});
|
|
991
|
-
|
|
1155
|
+
const ollamaEntries = (await ollamaModelsPromise).map((m) => ({
|
|
1156
|
+
id: m.id,
|
|
1157
|
+
name: m.name,
|
|
1158
|
+
hint: m.hint,
|
|
1159
|
+
agentId: "ollama",
|
|
1160
|
+
agentName: "Ollama (local)",
|
|
1161
|
+
provider: "ollama",
|
|
1162
|
+
providerName: "Ollama (local)",
|
|
1163
|
+
vendorGroup: "Ollama"
|
|
1164
|
+
}));
|
|
1165
|
+
return [
|
|
1166
|
+
...cliModels,
|
|
1167
|
+
...piAiEntries,
|
|
1168
|
+
...ollamaEntries
|
|
1169
|
+
];
|
|
992
1170
|
}
|
|
993
1171
|
const NUXT_CONFIG_FILES = [
|
|
994
1172
|
"nuxt.config.ts",
|
|
@@ -1096,7 +1274,7 @@ async function detectImportedPackages(cwd = process.cwd()) {
|
|
|
1096
1274
|
};
|
|
1097
1275
|
}
|
|
1098
1276
|
}
|
|
1099
|
-
const NODE_BUILTINS = new Set([
|
|
1277
|
+
const NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
1100
1278
|
"assert",
|
|
1101
1279
|
"async_hooks",
|
|
1102
1280
|
"buffer",
|
|
@@ -1147,7 +1325,7 @@ function isNodeBuiltin(pkg) {
|
|
|
1147
1325
|
const base = pkg.startsWith("node:") ? pkg.slice(5) : pkg;
|
|
1148
1326
|
return NODE_BUILTINS.has(base.split("/")[0]);
|
|
1149
1327
|
}
|
|
1150
|
-
const DEFAULT_MAX_AGE =
|
|
1328
|
+
const DEFAULT_MAX_AGE = 6048e5;
|
|
1151
1329
|
function normalizePromptForHash(prompt) {
|
|
1152
1330
|
return prompt.replace(/\/[^\s`]*\.(?:claude|codex|gemini)\/skills\/[^\s/`]+/g, "<SKILL_DIR>");
|
|
1153
1331
|
}
|
|
@@ -1281,9 +1459,6 @@ function spawnCliAndStream(opts) {
|
|
|
1281
1459
|
case "done":
|
|
1282
1460
|
if (evt.usage) usage = evt.usage;
|
|
1283
1461
|
if (evt.cost != null) cost = evt.cost;
|
|
1284
|
-
break;
|
|
1285
|
-
case "error":
|
|
1286
|
-
case "noop": break;
|
|
1287
1462
|
}
|
|
1288
1463
|
}
|
|
1289
1464
|
proc.stdout.on("data", (chunk) => {
|
|
@@ -1341,8 +1516,9 @@ function cliExecutor(model) {
|
|
|
1341
1516
|
})
|
|
1342
1517
|
};
|
|
1343
1518
|
}
|
|
1344
|
-
function piAiExecutor(model) {
|
|
1345
|
-
|
|
1519
|
+
async function piAiExecutor(model) {
|
|
1520
|
+
const models = createPiAiModels();
|
|
1521
|
+
if (!new Set((await getAvailablePiAiModels(models)).map((m) => m.id)).has(model)) return { error: `Pi model unavailable or not authenticated: ${model}` };
|
|
1346
1522
|
return {
|
|
1347
1523
|
cliCleanup: false,
|
|
1348
1524
|
run: async ({ section, prompt, skillDir, timeout, onProgress }) => {
|
|
@@ -1355,7 +1531,8 @@ function piAiExecutor(model) {
|
|
|
1355
1531
|
skillDir,
|
|
1356
1532
|
model,
|
|
1357
1533
|
onProgress,
|
|
1358
|
-
signal: ac.signal
|
|
1534
|
+
signal: ac.signal,
|
|
1535
|
+
models
|
|
1359
1536
|
});
|
|
1360
1537
|
return {
|
|
1361
1538
|
text: result.text.trim(),
|
|
@@ -1374,7 +1551,8 @@ function piAiExecutor(model) {
|
|
|
1374
1551
|
}
|
|
1375
1552
|
};
|
|
1376
1553
|
}
|
|
1377
|
-
function selectExecutor(model) {
|
|
1554
|
+
async function selectExecutor(model) {
|
|
1555
|
+
if (isOllamaModel(model)) return ollamaExecutor(model);
|
|
1378
1556
|
return isPiAiModel(model) ? piAiExecutor(model) : cliExecutor(model);
|
|
1379
1557
|
}
|
|
1380
1558
|
const STATIC_REGEX_1 = /\b429\b/;
|
|
@@ -1435,7 +1613,7 @@ async function optimizeDocs(opts) {
|
|
|
1435
1613
|
wasOptimized: false,
|
|
1436
1614
|
error: "No valid sections to generate"
|
|
1437
1615
|
};
|
|
1438
|
-
const executorOrError = selectExecutor(model);
|
|
1616
|
+
const executorOrError = await selectExecutor(model);
|
|
1439
1617
|
if ("error" in executorOrError) return {
|
|
1440
1618
|
optimized: "",
|
|
1441
1619
|
wasOptimized: false,
|
|
@@ -1639,6 +1817,6 @@ function getRetryError(result) {
|
|
|
1639
1817
|
if (result.status === "rejected") return String(result.reason);
|
|
1640
1818
|
return result.value.error;
|
|
1641
1819
|
}
|
|
1642
|
-
export {
|
|
1820
|
+
export { cleanSectionOutput, createToolProgress, detectImportedPackages, getAvailableModels, getModelLabel, getModelName, getOAuthProviderList, loginOAuthProvider, logoutOAuthProvider, optimizeDocs };
|
|
1643
1821
|
|
|
1644
1822
|
//# sourceMappingURL=agent.mjs.map
|