@shunagent/shun 0.1.145 → 0.1.146
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 +54 -1
- package/dist/cli.js +166 -93
- package/package.json +15 -6
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
Shun brings streaming conversations, coding tools, Agent Skills, and plugins to
|
|
8
8
|
your terminal. Connect a local model server or a hosted model provider.
|
|
9
9
|
|
|
10
|
+

|
|
11
|
+
|
|
10
12
|
## Install
|
|
11
13
|
|
|
12
14
|
Requires **Node.js 22.19 or newer** on macOS, Linux, or Windows.
|
|
@@ -17,7 +19,10 @@ shun
|
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
Alternatively, use `pnpm add -g @shunagent/shun` or `bun add -g @shunagent/shun`.
|
|
20
|
-
The terminal app can run without Shun Desktop.
|
|
22
|
+
The terminal app can run without Shun Desktop. Browser, PDF, and image-processing
|
|
23
|
+
components download automatically when first needed and are reused from your
|
|
24
|
+
local Shun profile. Basic conversations do not install these components.
|
|
25
|
+
Standalone Browser Preview also downloads its testing browser on first use.
|
|
21
26
|
|
|
22
27
|
## Start a conversation
|
|
23
28
|
|
|
@@ -46,6 +51,54 @@ finished conversation to the welcome screen. At the welcome screen, press it
|
|
|
46
51
|
twice to exit. Ctrl+D on an empty prompt detaches from Shun. Exiting the terminal
|
|
47
52
|
does not stop background tasks; use `/stop` to stop the current run.
|
|
48
53
|
|
|
54
|
+
## Command reference
|
|
55
|
+
|
|
56
|
+
### In your shell
|
|
57
|
+
|
|
58
|
+
| Command | What it does |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `shun` | Start a new conversation without choosing a project. |
|
|
61
|
+
| `shun .` or `shun <folder>` | Start in the current directory or a chosen project. |
|
|
62
|
+
| `shun -c` / `--continue` | Continue the most recent conversation in the selected project scope. |
|
|
63
|
+
| `shun -r` / `--resume` | Search and choose a saved conversation. |
|
|
64
|
+
| `shun --session <id>` | Reopen a specific conversation; `--task` is an alias. |
|
|
65
|
+
| `shun run "message" --workspace <folder>` | Send a message and stream the answer to standard output. |
|
|
66
|
+
| `shun run "message" --task <id>` | Continue a saved conversation without opening the TUI. |
|
|
67
|
+
| `shun tasks` | Print conversation IDs, running status, and titles. |
|
|
68
|
+
| `shun service status` | Check whether the local background service is running. |
|
|
69
|
+
| `shun service stop` | Stop the service when its tasks are idle. |
|
|
70
|
+
| `shun desktop` | Open Shun Desktop. |
|
|
71
|
+
| `shun desktop --install` | Download and verify the Desktop installer. |
|
|
72
|
+
| `shun --help` / `-h` | Show commands and their descriptions. |
|
|
73
|
+
| `shun --version` / `-v` | Print the installed CLI version. |
|
|
74
|
+
|
|
75
|
+
### Inside a conversation
|
|
76
|
+
|
|
77
|
+
Type `/` for searchable suggestions, or `/help` for the command picker.
|
|
78
|
+
|
|
79
|
+
| Command | What it does |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `/connect` | Add a model provider connection. |
|
|
82
|
+
| `/providers` | Manage provider credentials, settings, and connection tests. |
|
|
83
|
+
| `/model` | Choose the provider and model for this conversation. |
|
|
84
|
+
| `/new [folder]` | Start a new conversation, retaining the current project unless a folder is supplied. |
|
|
85
|
+
| `/new --no-workspace` | Start a new conversation without a project. |
|
|
86
|
+
| `/clear` | Start fresh; preserve the previous conversation in history. |
|
|
87
|
+
| `/resume` | Find and reopen a conversation, initially scoped to the current project. |
|
|
88
|
+
| `/tasks` | Browse conversations across projects. |
|
|
89
|
+
| `/session` | Show this conversation's ID and project. |
|
|
90
|
+
| `/name <title>` | Rename this conversation. |
|
|
91
|
+
| `/trust` | Review project configuration trust. |
|
|
92
|
+
| `/paste` | Attach an image from the local clipboard. |
|
|
93
|
+
| `/attach <path>` | Attach an image file, for example `/attach /tmp/screenshot.png`. |
|
|
94
|
+
| `/images` | Preview or remove images attached to your next message. |
|
|
95
|
+
| `/processes` | Inspect output from or stop task-owned background processes. |
|
|
96
|
+
| `/skills` | Enable, disable, or install Agent Skills. |
|
|
97
|
+
| `/desktop` | Open this conversation in Shun Desktop. |
|
|
98
|
+
| `/stop` | Stop the current generation. |
|
|
99
|
+
| `/quit` | Exit the terminal interface; background tasks can continue. |
|
|
100
|
+
| `/help` | Browse command descriptions and insert a selected command. |
|
|
101
|
+
|
|
49
102
|
## Images
|
|
50
103
|
|
|
51
104
|
On macOS, use **Cmd+V**. If iTerm2 asks how to paste an image, choose **Save to
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { spawn, execFile } from "node:child_process";
|
|
2
|
+
import { access, mkdir, mkdtemp, writeFile, rename, rm, readFile, lstat, copyFile, readdir, stat, realpath, open, appendFile, cp, chmod, unlink } from "node:fs/promises";
|
|
3
3
|
import { createHash, randomUUID, randomBytes, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { homedir, tmpdir, platform } from "node:os";
|
|
5
|
-
import { resolve, join, dirname, basename, sep, relative, extname, win32,
|
|
5
|
+
import { resolve, join, dirname, delimiter, basename, sep, relative, extname, win32, isAbsolute } from "node:path";
|
|
6
6
|
import { createServer, request } from "node:http";
|
|
7
7
|
import { createConnection } from "node:net";
|
|
8
8
|
import { ProjectTrustStore, SettingsManager, DefaultResourceLoader, loadSkillsFromDir, DefaultPackageManager, loadSkills, createAgentSession, ModelRuntime, SessionManager, defineTool, CONFIG_DIR_NAME, createBashToolDefinition, createLocalBashOperations, truncateTail, createEditToolDefinition, withFileMutationQueue, hasTrustRequiringProjectResources } from "@earendil-works/pi-coding-agent";
|
|
@@ -15,15 +15,33 @@ import { constants, existsSync, mkdirSync, openSync, closeSync, rmSync, readFile
|
|
|
15
15
|
import { createProvider } from "@earendil-works/pi-ai";
|
|
16
16
|
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
17
17
|
import { unzipSync, gunzipSync } from "fflate";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
18
20
|
import "typebox/value";
|
|
19
|
-
import puppeteer from "puppeteer-core";
|
|
20
|
-
import { PUPPETEER_REVISIONS } from "puppeteer-core/internal/revisions.js";
|
|
21
|
-
import { computeExecutablePath, Browser, install } from "@puppeteer/browsers";
|
|
22
21
|
import { StringDecoder } from "node:string_decoder";
|
|
23
22
|
import { createTwoFilesPatch } from "diff";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
23
|
import { truncateToWidth, stripTerminalSequences, Markdown, TuiMainScreen, ProcessTerminal, Container, Text, matchesKey, Editor, CombinedAutocompleteProvider, Spacer, SelectList, Input, Image } from "@earendil-works/pi-tui";
|
|
26
|
-
|
|
24
|
+
const slashCommands = [
|
|
25
|
+
["help", "Show available commands"],
|
|
26
|
+
["connect", "Connect a model provider"],
|
|
27
|
+
["providers", "Manage model providers"],
|
|
28
|
+
["model", "Choose a model"],
|
|
29
|
+
["resume", "Resume a conversation"],
|
|
30
|
+
["session", "Show this conversation"],
|
|
31
|
+
["name", "Rename this conversation"],
|
|
32
|
+
["tasks", "Browse conversations"],
|
|
33
|
+
["new", "Start a new conversation"],
|
|
34
|
+
["clear", "Start fresh; keep previous conversations"],
|
|
35
|
+
["trust", "Manage project trust"],
|
|
36
|
+
["paste", "Attach an image from the clipboard"],
|
|
37
|
+
["attach", "Attach an image file"],
|
|
38
|
+
["images", "Preview or remove attached images"],
|
|
39
|
+
["processes", "Manage background processes"],
|
|
40
|
+
["skills", "Manage Agent Skills"],
|
|
41
|
+
["desktop", "Open this conversation in Shun"],
|
|
42
|
+
["stop", "Stop the current task"],
|
|
43
|
+
["quit", "Exit the terminal"]
|
|
44
|
+
].map(([name, description]) => ({ name, description }));
|
|
27
45
|
function agentRuntimeHome(homeDirectory, override = "") {
|
|
28
46
|
const root = resolve(override || join(homeDirectory, ".shun"));
|
|
29
47
|
return {
|
|
@@ -886,6 +904,74 @@ function contentWindow(content, maxChars, offset, knownHasMore = false) {
|
|
|
886
904
|
const value = content.slice(offset, offset + maxChars), end = offset + value.length, hasMore = knownHasMore || end < content.length;
|
|
887
905
|
return { content_offset: offset, content_end: end, content_characters: content.length, returned_characters: value.length, truncated: offset > 0 || hasMore, has_more: hasMore, content: value };
|
|
888
906
|
}
|
|
907
|
+
const modules = {
|
|
908
|
+
"pdfjs-dist/legacy/build/pdf.mjs": { group: "pdf", packages: ["pdfjs-dist@6.2.108"] },
|
|
909
|
+
"@napi-rs/canvas": { group: "images", packages: ["@napi-rs/canvas@1.0.6"] },
|
|
910
|
+
"puppeteer-core": { group: "browser", packages: ["puppeteer-core@25.16.0", "@puppeteer/browsers@3.2.6"] },
|
|
911
|
+
"puppeteer-core/internal/revisions.js": { group: "browser", packages: ["puppeteer-core@25.16.0", "@puppeteer/browsers@3.2.6"] },
|
|
912
|
+
"@puppeteer/browsers": { group: "browser", packages: ["puppeteer-core@25.16.0", "@puppeteer/browsers@3.2.6"] }
|
|
913
|
+
};
|
|
914
|
+
const pending = /* @__PURE__ */ new Map();
|
|
915
|
+
async function installPackages(directory, packages) {
|
|
916
|
+
const bundled = join(dirname(process.execPath), "npm", "bin", "npm-cli.js");
|
|
917
|
+
const candidates = [
|
|
918
|
+
bundled,
|
|
919
|
+
join(dirname(process.execPath), "node_modules/npm/bin/npm-cli.js"),
|
|
920
|
+
...process.platform === "win32" ? (process.env.PATH || "").split(delimiter).filter(Boolean).map((path) => join(path, "node_modules/npm/bin/npm-cli.js")) : []
|
|
921
|
+
];
|
|
922
|
+
let npmCli;
|
|
923
|
+
for (const candidate of candidates) if (await access(candidate).then(() => true).catch(() => false)) {
|
|
924
|
+
npmCli = candidate;
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
if (process.platform === "win32" && !npmCli) throw Error("Install Node.js with npm to enable this optional capability.");
|
|
928
|
+
const args2 = ["install", "--prefix", directory, "--registry=https://registry.npmjs.org", "--ignore-scripts", "--no-audit", "--no-fund", "--save-exact", ...packages];
|
|
929
|
+
await new Promise((resolve2, reject) => {
|
|
930
|
+
const executable = npmCli ? process.execPath : "npm";
|
|
931
|
+
const commandArgs = npmCli ? [npmCli, ...args2] : args2;
|
|
932
|
+
const child = spawn(executable, commandArgs, { stdio: ["ignore", "ignore", "pipe"], timeout: 18e4, windowsHide: true });
|
|
933
|
+
let error = "";
|
|
934
|
+
child.stderr.on("data", (chunk) => {
|
|
935
|
+
error = (error + chunk.toString()).slice(-2e3);
|
|
936
|
+
});
|
|
937
|
+
child.once("error", () => reject(Error("Could not install this optional capability. Install Node.js with npm and try again.")));
|
|
938
|
+
child.once("exit", (code) => code === 0 ? resolve2() : reject(Error(`Optional capability installation failed. Retry when npm can reach the registry. ${error.replace(/https?:\/\/\S+/g, "[registry]")}`)));
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
async function capabilityDirectory(specifier, root = join(hostPaths().root, "capabilities"), install = installPackages) {
|
|
942
|
+
const spec = modules[specifier];
|
|
943
|
+
if (!spec) throw Error("Unknown optional capability.");
|
|
944
|
+
const key = `${spec.group}-${spec.packages.join("-").replace(/[^a-zA-Z0-9.-]/g, "_")}`;
|
|
945
|
+
const directory = join(root, key), marker = join(directory, ".ready");
|
|
946
|
+
if (await access(marker).then(() => true).catch(() => false)) return directory;
|
|
947
|
+
let work = pending.get(directory);
|
|
948
|
+
if (!work) {
|
|
949
|
+
work = (async () => {
|
|
950
|
+
await mkdir(root, { recursive: true, mode: 448 });
|
|
951
|
+
const temporary = await mkdtemp(join(root, ".install-"));
|
|
952
|
+
try {
|
|
953
|
+
await writeFile(join(temporary, "package.json"), JSON.stringify({ private: true, name: `shun-${spec.group}-capability`, version: "1.0.0" }));
|
|
954
|
+
await install(temporary, spec.packages);
|
|
955
|
+
await writeFile(join(temporary, ".ready"), "ready\n");
|
|
956
|
+
try {
|
|
957
|
+
await rename(temporary, directory);
|
|
958
|
+
} catch (error) {
|
|
959
|
+
if (!await access(marker).then(() => true).catch(() => false)) throw error;
|
|
960
|
+
}
|
|
961
|
+
return directory;
|
|
962
|
+
} finally {
|
|
963
|
+
await rm(temporary, { recursive: true, force: true });
|
|
964
|
+
}
|
|
965
|
+
})().finally(() => pending.delete(directory));
|
|
966
|
+
pending.set(directory, work);
|
|
967
|
+
}
|
|
968
|
+
return work;
|
|
969
|
+
}
|
|
970
|
+
async function loadCapabilityModule(specifier) {
|
|
971
|
+
const directory = await capabilityDirectory(specifier);
|
|
972
|
+
const require2 = createRequire(join(directory, "package.json"));
|
|
973
|
+
return import(pathToFileURL(require2.resolve(specifier)).href);
|
|
974
|
+
}
|
|
889
975
|
function clean$4(value) {
|
|
890
976
|
return String(value || "").replace(/\s+/g, " ").trim();
|
|
891
977
|
}
|
|
@@ -960,7 +1046,7 @@ function pdfPageText(value) {
|
|
|
960
1046
|
const pdfJsParser = {
|
|
961
1047
|
id: "pdfjs",
|
|
962
1048
|
async read(bytes, options) {
|
|
963
|
-
const pdfjs = await
|
|
1049
|
+
const pdfjs = await loadCapabilityModule("pdfjs-dist/legacy/build/pdf.mjs");
|
|
964
1050
|
const loading = pdfjs.getDocument({ data: new Uint8Array(bytes), useWorkerFetch: false, useSystemFonts: true });
|
|
965
1051
|
const document2 = await loading.promise;
|
|
966
1052
|
try {
|
|
@@ -1121,8 +1207,8 @@ ${query}`), cached = this.cache.get(key), now = this.now();
|
|
|
1121
1207
|
fillSlots();
|
|
1122
1208
|
}
|
|
1123
1209
|
if (completedEarly && active.size) {
|
|
1124
|
-
const
|
|
1125
|
-
void Promise.allSettled(
|
|
1210
|
+
const pending2 = [...active.values()];
|
|
1211
|
+
void Promise.allSettled(pending2).then((rows) => {
|
|
1126
1212
|
for (const settled of rows) if (settled.status === "fulfilled") settled.value.row.results.forEach((candidate, rank) => collected.push({ provider: settled.value.row.id, rank, candidate }));
|
|
1127
1213
|
this.cache.set(key, { createdAt: this.now(), results: select(fuseCandidates(collected)) });
|
|
1128
1214
|
this.trimCache();
|
|
@@ -1589,42 +1675,42 @@ ${addition}
|
|
|
1589
1675
|
const source = validSkillSource(sourceValue);
|
|
1590
1676
|
await pruneSkillInspections();
|
|
1591
1677
|
if (selection.inspectionToken) {
|
|
1592
|
-
const
|
|
1593
|
-
if (!
|
|
1594
|
-
if (
|
|
1678
|
+
const pending22 = pendingSkillInspections.get(selection.inspectionToken);
|
|
1679
|
+
if (!pending22 || pending22.expiresAt <= Date.now()) throw Error("The Skill selection expired. Inspect the source again.");
|
|
1680
|
+
if (pending22.source !== source || pending22.workspace !== workspace) throw Error("The Skill selection does not match this source and workspace.");
|
|
1595
1681
|
const requested = [...new Set((selection.skills || []).map((value) => String(value || "").trim()).filter(Boolean))];
|
|
1596
1682
|
if (!requested.length) throw Error("Choose at least one Skill from the inspected source.");
|
|
1597
|
-
const selectedNames = requested.length === 1 && requested[0] === "*" ?
|
|
1598
|
-
const unknown = selectedNames.filter((name) => !
|
|
1683
|
+
const selectedNames = requested.length === 1 && requested[0] === "*" ? pending22.candidates.map((candidate) => candidate.name) : requested.map(validName);
|
|
1684
|
+
const unknown = selectedNames.filter((name) => !pending22.candidates.some((candidate) => candidate.name === name));
|
|
1599
1685
|
if (unknown.length) throw Error(`The inspected source does not contain: ${unknown.join(", ")}.`);
|
|
1600
|
-
const installed = await this.#installInspected(
|
|
1686
|
+
const installed = await this.#installInspected(pending22, selectedNames, settings);
|
|
1601
1687
|
pendingSkillInspections.delete(selection.inspectionToken);
|
|
1602
|
-
if (
|
|
1688
|
+
if (pending22.cleanupPath) await rm(pending22.cleanupPath, { recursive: true, force: true });
|
|
1603
1689
|
return { status: "installed", installed };
|
|
1604
1690
|
}
|
|
1605
1691
|
if (selection.skills?.length) throw Error("Inspect the Skill source before selecting members to install.");
|
|
1606
|
-
const
|
|
1607
|
-
if (
|
|
1692
|
+
const pending2 = await this.#inspectSource(source, workspace);
|
|
1693
|
+
if (pending2.candidates.length === 1) {
|
|
1608
1694
|
try {
|
|
1609
|
-
return { status: "installed", installed: await this.#installInspected(
|
|
1695
|
+
return { status: "installed", installed: await this.#installInspected(pending2, [pending2.candidates[0].name], settings) };
|
|
1610
1696
|
} finally {
|
|
1611
|
-
if (
|
|
1697
|
+
if (pending2.cleanupPath) await rm(pending2.cleanupPath, { recursive: true, force: true });
|
|
1612
1698
|
}
|
|
1613
1699
|
}
|
|
1614
1700
|
const inspectionToken = randomUUID();
|
|
1615
|
-
pendingSkillInspections.set(inspectionToken,
|
|
1701
|
+
pendingSkillInspections.set(inspectionToken, pending2);
|
|
1616
1702
|
return {
|
|
1617
1703
|
status: "selection_required",
|
|
1618
1704
|
inspectionToken,
|
|
1619
|
-
candidates:
|
|
1705
|
+
candidates: pending2.candidates.map(({ name, description }) => ({ name, description }))
|
|
1620
1706
|
};
|
|
1621
1707
|
}
|
|
1622
1708
|
async installSource(sourceValue, settings, workspace = "") {
|
|
1623
1709
|
const outcome = await this.requestInstall(sourceValue, settings, workspace);
|
|
1624
1710
|
if (outcome.status === "installed") return outcome.installed;
|
|
1625
|
-
const
|
|
1711
|
+
const pending2 = pendingSkillInspections.get(outcome.inspectionToken);
|
|
1626
1712
|
pendingSkillInspections.delete(outcome.inspectionToken);
|
|
1627
|
-
if (
|
|
1713
|
+
if (pending2?.cleanupPath) await rm(pending2.cleanupPath, { recursive: true, force: true });
|
|
1628
1714
|
const choices = outcome.candidates.map((candidate, index) => `${index + 1}. ${candidate.name} — ${candidate.description}`).join("\n");
|
|
1629
1715
|
throw Error(`This source contains ${outcome.candidates.length} Skills. Install it from a task and choose which Skills to install:
|
|
1630
1716
|
${choices}`);
|
|
@@ -1667,26 +1753,26 @@ ${choices}`);
|
|
|
1667
1753
|
});
|
|
1668
1754
|
return { source, workspace, expiresAt: Date.now() + SKILL_INSPECTION_TTL_MS, kind: "package", candidates };
|
|
1669
1755
|
}
|
|
1670
|
-
async #installInspected(
|
|
1756
|
+
async #installInspected(pending2, selectedNames, settings) {
|
|
1671
1757
|
const selected = new Set(selectedNames);
|
|
1672
1758
|
let installed;
|
|
1673
|
-
if (
|
|
1674
|
-
if (!
|
|
1675
|
-
installed = await this.importPath(
|
|
1759
|
+
if (pending2.kind === "github") {
|
|
1760
|
+
if (!pending2.target) throw Error("The inspected Skill source is no longer available.");
|
|
1761
|
+
installed = await this.importPath(pending2.target, settings, selectedNames);
|
|
1676
1762
|
} else {
|
|
1677
|
-
const refs =
|
|
1678
|
-
installed = await this.installPackage(
|
|
1763
|
+
const refs = pending2.candidates.filter((candidate) => selected.has(candidate.name)).map((candidate) => candidate.installRef);
|
|
1764
|
+
installed = await this.installPackage(pending2.source, settings, pending2.workspace, refs);
|
|
1679
1765
|
const installedNames = new Set(installed.map((skill) => skill.name));
|
|
1680
1766
|
const missing = selectedNames.filter((name) => !installedNames.has(name));
|
|
1681
1767
|
if (missing.length) {
|
|
1682
|
-
await this.removePackage(
|
|
1768
|
+
await this.removePackage(pending2.source, pending2.workspace).catch(() => false);
|
|
1683
1769
|
throw Error(`Selected Skills were not installed from this source: ${missing.join(", ")}.`);
|
|
1684
1770
|
}
|
|
1685
1771
|
installed = installed.filter((skill) => selected.has(skill.name));
|
|
1686
1772
|
}
|
|
1687
1773
|
return Promise.all(installed.map(async (skill) => {
|
|
1688
1774
|
try {
|
|
1689
|
-
await this.prepareRuntime(skill.id, settings,
|
|
1775
|
+
await this.prepareRuntime(skill.id, settings, pending2.workspace);
|
|
1690
1776
|
return skill;
|
|
1691
1777
|
} catch (error) {
|
|
1692
1778
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1808,10 +1894,10 @@ function inspectedCandidates(skills, installRef) {
|
|
|
1808
1894
|
}
|
|
1809
1895
|
async function pruneSkillInspections() {
|
|
1810
1896
|
const now = Date.now();
|
|
1811
|
-
const expired = [...pendingSkillInspections.entries()].filter(([,
|
|
1812
|
-
for (const [token,
|
|
1897
|
+
const expired = [...pendingSkillInspections.entries()].filter(([, pending2]) => pending2.expiresAt <= now);
|
|
1898
|
+
for (const [token, pending2] of expired) {
|
|
1813
1899
|
pendingSkillInspections.delete(token);
|
|
1814
|
-
if (
|
|
1900
|
+
if (pending2.cleanupPath) await rm(pending2.cleanupPath, { recursive: true, force: true });
|
|
1815
1901
|
}
|
|
1816
1902
|
}
|
|
1817
1903
|
function validSkillSource(value) {
|
|
@@ -2000,10 +2086,10 @@ async function systemPython() {
|
|
|
2000
2086
|
throw Error("Python 3 is required to run this Skill, but no Python interpreter was found.");
|
|
2001
2087
|
}
|
|
2002
2088
|
function pythonImportModules(content) {
|
|
2003
|
-
const
|
|
2004
|
-
for (const match of content.matchAll(/^\s*(?:from|import)\s+([A-Za-z_][A-Za-z0-9_]*)/gm))
|
|
2005
|
-
|
|
2006
|
-
return [...
|
|
2089
|
+
const modules2 = /* @__PURE__ */ new Set();
|
|
2090
|
+
for (const match of content.matchAll(/^\s*(?:from|import)\s+([A-Za-z_][A-Za-z0-9_]*)/gm)) modules2.add(match[1]);
|
|
2091
|
+
modules2.delete("__future__");
|
|
2092
|
+
return [...modules2].sort();
|
|
2007
2093
|
}
|
|
2008
2094
|
const pythonDistributionAliases = {
|
|
2009
2095
|
PIL: "Pillow",
|
|
@@ -2290,10 +2376,10 @@ async function runAgentSession(req, signal, emitRaw, options) {
|
|
|
2290
2376
|
options.outcomePolicy?.observe(event);
|
|
2291
2377
|
const interruption = options.outcomePolicy?.interrupt?.();
|
|
2292
2378
|
if (interruption) void session.steer(interruption).catch((error) => console.warn("[outcome-policy]", error));
|
|
2293
|
-
const
|
|
2294
|
-
if (
|
|
2295
|
-
pendingForwards.add(
|
|
2296
|
-
void
|
|
2379
|
+
const pending2 = forwardSessionEvent(req, session, event, toolInputs, emit, cwd, contextState, options.materializeToolResultImages);
|
|
2380
|
+
if (pending2) {
|
|
2381
|
+
pendingForwards.add(pending2);
|
|
2382
|
+
void pending2.finally(() => pendingForwards.delete(pending2));
|
|
2297
2383
|
}
|
|
2298
2384
|
});
|
|
2299
2385
|
const abort = () => {
|
|
@@ -3370,7 +3456,7 @@ function encodeCanvas(canvas, quality) {
|
|
|
3370
3456
|
}
|
|
3371
3457
|
async function rasterImage(bytes, mimeType, options) {
|
|
3372
3458
|
try {
|
|
3373
|
-
const { createCanvas, loadImage } = await
|
|
3459
|
+
const { createCanvas, loadImage } = await loadCapabilityModule("@napi-rs/canvas");
|
|
3374
3460
|
const source = await loadImage(bytes), scale = Math.min(1, options.maxDimension / Math.max(source.width, source.height)), canvas = createCanvas(Math.max(1, Math.round(source.width * scale)), Math.max(1, Math.round(source.height * scale)));
|
|
3375
3461
|
canvas.getContext("2d").drawImage(source, 0, 0, canvas.width, canvas.height);
|
|
3376
3462
|
return options.budget ? encodeWithinBudget(canvas, options.budget, createCanvas, mimeType) : encodeCanvas(canvas, options.quality ?? 92);
|
|
@@ -3382,7 +3468,7 @@ async function rasterImage(bytes, mimeType, options) {
|
|
|
3382
3468
|
async function normalizeImageForModel(bytes, mimeType) {
|
|
3383
3469
|
if (bytes.length <= MAX_MODEL_OVERVIEW_BYTES && ["image/png", "image/jpeg", "image/gif", "image/webp"].includes(mimeType)) {
|
|
3384
3470
|
try {
|
|
3385
|
-
const { loadImage } = await
|
|
3471
|
+
const { loadImage } = await loadCapabilityModule("@napi-rs/canvas"), source = await loadImage(bytes);
|
|
3386
3472
|
if (Math.max(source.width, source.height) <= MAX_MODEL_RASTER_DIMENSION) {
|
|
3387
3473
|
return { bytes, mimeType, width: source.width, height: source.height };
|
|
3388
3474
|
}
|
|
@@ -3393,7 +3479,7 @@ async function normalizeImageForModel(bytes, mimeType) {
|
|
|
3393
3479
|
return { bytes: Buffer.from(image.data, "base64"), mimeType: image.mimeType, width: image.width, height: image.height };
|
|
3394
3480
|
}
|
|
3395
3481
|
async function pdfPage(bytes, pageValue, maxDimension) {
|
|
3396
|
-
const pdfjs = await
|
|
3482
|
+
const pdfjs = await loadCapabilityModule("pdfjs-dist/legacy/build/pdf.mjs"), { createCanvas } = await loadCapabilityModule("@napi-rs/canvas");
|
|
3397
3483
|
const loading = pdfjs.getDocument({ data: new Uint8Array(bytes), useWorkerFetch: false, useSystemFonts: true }), document2 = await loading.promise;
|
|
3398
3484
|
try {
|
|
3399
3485
|
const pageNumber = Math.max(1, Math.min(document2.numPages, Math.floor(pageValue))), page = await document2.getPage(pageNumber), base = page.getViewport({ scale: 1 });
|
|
@@ -6062,21 +6148,21 @@ async function ensurePluginRuntimeExecutable(executable, fetchExecutable, onProg
|
|
|
6062
6148
|
} finally {
|
|
6063
6149
|
}
|
|
6064
6150
|
}
|
|
6065
|
-
const
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
for (const listener of
|
|
6151
|
+
const install = { promise: void 0, listeners: /* @__PURE__ */ new Set() };
|
|
6152
|
+
install.promise = installPluginRuntimeExecutable(executable, fetchExecutable, (progress) => {
|
|
6153
|
+
install.latest = progress;
|
|
6154
|
+
for (const listener of install.listeners) {
|
|
6069
6155
|
try {
|
|
6070
6156
|
listener(progress);
|
|
6071
6157
|
} catch {
|
|
6072
6158
|
}
|
|
6073
6159
|
}
|
|
6074
6160
|
});
|
|
6075
|
-
executableInstalls.set(executable.cachePath,
|
|
6161
|
+
executableInstalls.set(executable.cachePath, install);
|
|
6076
6162
|
try {
|
|
6077
|
-
return await
|
|
6163
|
+
return await install.promise;
|
|
6078
6164
|
} finally {
|
|
6079
|
-
if (executableInstalls.get(executable.cachePath) ===
|
|
6165
|
+
if (executableInstalls.get(executable.cachePath) === install) executableInstalls.delete(executable.cachePath);
|
|
6080
6166
|
}
|
|
6081
6167
|
}
|
|
6082
6168
|
async function installPluginRuntimeExecutable(executable, fetchExecutable, onProgress) {
|
|
@@ -6307,18 +6393,23 @@ class HostBrowserPreview {
|
|
|
6307
6393
|
this.root = root;
|
|
6308
6394
|
}
|
|
6309
6395
|
async launch() {
|
|
6396
|
+
const [{ default: puppeteer }, { PUPPETEER_REVISIONS }, { Browser: BrowserKind, computeExecutablePath, install }] = await Promise.all([
|
|
6397
|
+
loadCapabilityModule("puppeteer-core"),
|
|
6398
|
+
loadCapabilityModule("puppeteer-core/internal/revisions.js"),
|
|
6399
|
+
loadCapabilityModule("@puppeteer/browsers")
|
|
6400
|
+
]);
|
|
6310
6401
|
const cacheDir = join(this.root, "browsers"), buildId = PUPPETEER_REVISIONS.chrome;
|
|
6311
|
-
const executablePath = computeExecutablePath({ browser:
|
|
6402
|
+
const executablePath = computeExecutablePath({ browser: BrowserKind.CHROME, buildId, cacheDir });
|
|
6312
6403
|
await access(executablePath).catch(async () => {
|
|
6313
|
-
await install({ browser:
|
|
6404
|
+
await install({ browser: BrowserKind.CHROME, buildId, cacheDir });
|
|
6314
6405
|
});
|
|
6315
6406
|
await mkdir(join(this.root, "preview-profile"), { recursive: true, mode: 448 });
|
|
6316
6407
|
return puppeteer.launch({ executablePath, headless: true, userDataDir: join(this.root, "preview-profile"), defaultViewport: { width: 1280, height: 800 } });
|
|
6317
6408
|
}
|
|
6318
6409
|
page(taskId) {
|
|
6319
|
-
let
|
|
6320
|
-
if (!
|
|
6321
|
-
|
|
6410
|
+
let pending2 = this.pages.get(taskId);
|
|
6411
|
+
if (!pending2) {
|
|
6412
|
+
pending2 = (async () => {
|
|
6322
6413
|
const browser = await (this.browser ||= this.launch().catch((error) => {
|
|
6323
6414
|
this.browser = void 0;
|
|
6324
6415
|
throw error;
|
|
@@ -6338,9 +6429,9 @@ class HostBrowserPreview {
|
|
|
6338
6429
|
this.pages.delete(taskId);
|
|
6339
6430
|
throw error;
|
|
6340
6431
|
});
|
|
6341
|
-
this.pages.set(taskId,
|
|
6432
|
+
this.pages.set(taskId, pending2);
|
|
6342
6433
|
}
|
|
6343
|
-
return
|
|
6434
|
+
return pending2;
|
|
6344
6435
|
}
|
|
6345
6436
|
async inspect(taskId, options = {}) {
|
|
6346
6437
|
const preview = await this.page(taskId), { page } = preview;
|
|
@@ -7619,32 +7710,11 @@ async function gitStatus(workspace) {
|
|
|
7619
7710
|
return "";
|
|
7620
7711
|
}
|
|
7621
7712
|
}
|
|
7622
|
-
const slashCommands = [
|
|
7623
|
-
["help", "Show available commands"],
|
|
7624
|
-
["connect", "Connect a model provider"],
|
|
7625
|
-
["providers", "Manage model providers"],
|
|
7626
|
-
["model", "Choose a model"],
|
|
7627
|
-
["resume", "Resume a conversation"],
|
|
7628
|
-
["session", "Show this conversation"],
|
|
7629
|
-
["name", "Rename this conversation"],
|
|
7630
|
-
["tasks", "Browse conversations"],
|
|
7631
|
-
["new", "Start a new conversation"],
|
|
7632
|
-
["clear", "Start fresh; keep previous conversations"],
|
|
7633
|
-
["trust", "Manage project trust"],
|
|
7634
|
-
["paste", "Attach an image from the clipboard"],
|
|
7635
|
-
["attach", "Attach an image file"],
|
|
7636
|
-
["images", "Preview or remove attached images"],
|
|
7637
|
-
["processes", "Manage background processes"],
|
|
7638
|
-
["skills", "Manage Agent Skills"],
|
|
7639
|
-
["desktop", "Open this conversation in Shun"],
|
|
7640
|
-
["stop", "Stop the current task"],
|
|
7641
|
-
["quit", "Exit the terminal"]
|
|
7642
|
-
].map(([name, description]) => ({ name, description }));
|
|
7643
7713
|
const clean$1 = (text2) => stripTerminalSequences(text2).replace(/[\x00-\x1f\x7f]/g, "");
|
|
7644
7714
|
const accent = (text2) => `\x1B[38;5;205m${text2}\x1B[0m`;
|
|
7645
7715
|
const muted = (text2) => `\x1B[2m${text2}\x1B[0m`;
|
|
7646
7716
|
const bold = (text2) => `\x1B[1m${text2}\x1B[0m`;
|
|
7647
|
-
const version$1 = "0.1.
|
|
7717
|
+
const version$1 = "0.1.146";
|
|
7648
7718
|
class WelcomeHeader {
|
|
7649
7719
|
state = { title: "", model: "", workspace: "", running: false, compact: false, ready: false };
|
|
7650
7720
|
update(state) {
|
|
@@ -7958,10 +8028,10 @@ class TranscriptViewport extends Container {
|
|
|
7958
8028
|
async function runTui(call, options = {}) {
|
|
7959
8029
|
if (!process.stdin.isTTY || !process.stdout.isTTY) throw Error('Interactive Shun needs a terminal. Use shun run "message" for scripts.');
|
|
7960
8030
|
const tui = new TuiMainScreen(new ProcessTerminal(), true);
|
|
7961
|
-
const header = new WelcomeHeader(), feed = new TranscriptViewport(),
|
|
8031
|
+
const header = new WelcomeHeader(), feed = new TranscriptViewport(), pending2 = new Container(), panel = new Container(), status = new Text("", 1, 0);
|
|
7962
8032
|
const editor = new Composer(tui, { borderColor: cyan, selectList: theme }, { paddingX: 1 });
|
|
7963
|
-
for (const child of [header, feed,
|
|
7964
|
-
feed.limit = () => Math.max(1, (process.stdout.rows || 24) - [header,
|
|
8033
|
+
for (const child of [header, feed, pending2, panel, editor, status]) tui.addChild(child);
|
|
8034
|
+
feed.limit = () => Math.max(1, (process.stdout.rows || 24) - [header, pending2, panel, editor, status].reduce((total, item) => total + item.render(process.stdout.columns || 80).length, 0));
|
|
7965
8035
|
let snapshot, attachments = [], activeRun;
|
|
7966
8036
|
let animatedPhases = [];
|
|
7967
8037
|
let visibleTurnLimit = 24;
|
|
@@ -8065,8 +8135,8 @@ async function runTui(call, options = {}) {
|
|
|
8065
8135
|
tui.requestRender();
|
|
8066
8136
|
};
|
|
8067
8137
|
const showAttachments = () => {
|
|
8068
|
-
|
|
8069
|
-
for (const item of attachments)
|
|
8138
|
+
pending2.clear();
|
|
8139
|
+
for (const item of attachments) pending2.addChild(new Text(`[${plain(attachmentLabel(item))}]`, 1, 0));
|
|
8070
8140
|
tui.requestRender();
|
|
8071
8141
|
};
|
|
8072
8142
|
const ask = (label, initial = "", secret = false) => new Promise((resolve2, reject) => {
|
|
@@ -8264,7 +8334,9 @@ async function runTui(call, options = {}) {
|
|
|
8264
8334
|
return;
|
|
8265
8335
|
}
|
|
8266
8336
|
if (name === "/help") {
|
|
8267
|
-
|
|
8337
|
+
const selected = await choose("Commands · choose to insert", slashCommands.map((item) => ({ value: item.name, label: `/${item.name}`, description: item.description })));
|
|
8338
|
+
editor.setText(`/${selected} `);
|
|
8339
|
+
tui.requestRender();
|
|
8268
8340
|
return;
|
|
8269
8341
|
}
|
|
8270
8342
|
if (name === "/providers") {
|
|
@@ -8336,7 +8408,7 @@ async function runTui(call, options = {}) {
|
|
|
8336
8408
|
} else {
|
|
8337
8409
|
const preview = await call("attachment.preview", { taskId: snapshot.task.id, id });
|
|
8338
8410
|
if (preview.mode !== "image") throw Error("Image preview is unavailable.");
|
|
8339
|
-
|
|
8411
|
+
pending2.addChild(new Image(preview.data, preview.mimeType, { fallbackColor: dim }, { maxWidthCells: 60, maxHeightCells: 16 }));
|
|
8340
8412
|
tui.requestRender();
|
|
8341
8413
|
}
|
|
8342
8414
|
return;
|
|
@@ -8622,7 +8694,7 @@ ${activeRun ? "Task continues running in Shun.\n" : ""}Resume this conversation:
|
|
|
8622
8694
|
process.off("SIGTERM", onSignal);
|
|
8623
8695
|
process.off("SIGINT", onSignal);
|
|
8624
8696
|
}
|
|
8625
|
-
const version = "0.1.
|
|
8697
|
+
const version = "0.1.146";
|
|
8626
8698
|
const args = process.argv.slice(2);
|
|
8627
8699
|
async function main() {
|
|
8628
8700
|
if (args.includes("--version") || args.includes("-v")) {
|
|
@@ -8648,7 +8720,8 @@ shun service stop Stop the service when tasks are idle
|
|
|
8648
8720
|
shun desktop Open the desktop interface
|
|
8649
8721
|
shun desktop --install Download and verify the desktop installer
|
|
8650
8722
|
|
|
8651
|
-
In the terminal:
|
|
8723
|
+
In the terminal:
|
|
8724
|
+
${slashCommands.map((item) => `/${item.name.padEnd(14)} ${item.description}`).join("\n")}
|
|
8652
8725
|
/paste attaches a clipboard image locally; /attach imports an image file.
|
|
8653
8726
|
Ctrl+D detaches; active tasks keep running. Ctrl+C stops generation or returns home; press twice at home to exit. /stop stops the current run.
|
|
8654
8727
|
|
package/package.json
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"@earendil-works/pi-ai": "0.84.2",
|
|
24
24
|
"@earendil-works/pi-coding-agent": "0.84.2",
|
|
25
25
|
"@earendil-works/pi-tui": "0.84.2",
|
|
26
|
-
"@napi-rs/canvas": "1.0.6",
|
|
27
26
|
"diff": "^9.0.0",
|
|
28
27
|
"fflate": "0.8.2",
|
|
29
28
|
"typebox": "1.3.7",
|
|
@@ -31,10 +30,7 @@
|
|
|
31
30
|
"https-proxy-agent": "7.0.6",
|
|
32
31
|
"socks-proxy-agent": "8.0.5",
|
|
33
32
|
"defuddle": "0.19.2",
|
|
34
|
-
"linkedom": "0.18.13"
|
|
35
|
-
"pdfjs-dist": "^6.2.108",
|
|
36
|
-
"puppeteer-core": "^25.16.0",
|
|
37
|
-
"@puppeteer/browsers": "^3.2.6"
|
|
33
|
+
"linkedom": "0.18.13"
|
|
38
34
|
},
|
|
39
35
|
"optionalDependencies": {
|
|
40
36
|
"@mariozechner/clipboard-darwin-arm64": "0.3.9",
|
|
@@ -51,5 +47,18 @@
|
|
|
51
47
|
"bugs": {
|
|
52
48
|
"url": "https://github.com/kyleslight/shun/issues"
|
|
53
49
|
},
|
|
54
|
-
"
|
|
50
|
+
"keywords": [
|
|
51
|
+
"shun",
|
|
52
|
+
"ai",
|
|
53
|
+
"agent",
|
|
54
|
+
"coding-agent",
|
|
55
|
+
"cli",
|
|
56
|
+
"tui",
|
|
57
|
+
"terminal",
|
|
58
|
+
"local-first",
|
|
59
|
+
"local-llm",
|
|
60
|
+
"mcp",
|
|
61
|
+
"developer-tools"
|
|
62
|
+
],
|
|
63
|
+
"version": "0.1.146"
|
|
55
64
|
}
|