@krapht/ork 0.3.0 → 1.0.0-alpha.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.
Files changed (39) hide show
  1. package/README.md +16 -12
  2. package/dist/__build_info__-DdTVd2p5.mjs +615 -0
  3. package/dist/bin.mjs +1572 -909
  4. package/dist/clean-NnboOuz6.mjs +88 -0
  5. package/dist/completion-snnYGjgK.mjs +405 -0
  6. package/dist/{context-BFGC_C02.mjs → context-DO3sBy9v.mjs} +30 -191
  7. package/dist/decide-B81wCZQg.mjs +113 -0
  8. package/dist/{find-BcvhT6UN.mjs → find-BKW-uGey.mjs} +1 -1
  9. package/dist/{format-DqpObyMl.mjs → format-CmTlTOjT.mjs} +72 -198
  10. package/dist/help-groups-BwYoAWsh.mjs +354 -0
  11. package/dist/{in-a-run-BbLhZOFW.mjs → in-a-run-BPXX09Bs.mjs} +1 -1
  12. package/dist/{limits-BKYAmqCR.mjs → limits-JCve2QpI.mjs} +1 -1
  13. package/dist/list-C7UEgmtd.mjs +110 -0
  14. package/dist/{mcp-BWsdQyri.mjs → mcp-CKPyNaKD.mjs} +7 -7
  15. package/dist/{output-Q2EdeVUt.mjs → output-B1V6ZJSx.mjs} +130 -36
  16. package/dist/{pause-DKACDfV1.mjs → pause-B_SL_yDz.mjs} +4 -4
  17. package/dist/{relay-CbK-Wme9.mjs → relay-o-Luee1c.mjs} +2 -2
  18. package/dist/remove-DAZ7ZCzt.mjs +194 -0
  19. package/dist/{send-C6yr04Fe.mjs → send-3B64fBNB.mjs} +3 -3
  20. package/dist/{src-D5ruZFgD.mjs → src-BJTegEzY.mjs} +1212 -57
  21. package/dist/{src-DtN1k-B3.mjs → src-C38BPzit.mjs} +251 -18
  22. package/dist/{src-Cz1yOUTg.mjs → src-DHvWU4tX.mjs} +2742 -1659
  23. package/dist/{src-CZOVF2yU.mjs → src-Dyz_Gy1q.mjs} +35 -8
  24. package/dist/ui/THIRD_PARTY_LICENSES.txt +2 -2
  25. package/dist/ui/assets/app-C8nJ6NpT.js +67 -0
  26. package/dist/ui/assets/app-CH7YC3in.css +1 -0
  27. package/dist/ui/assets/{index-BiO54L90.css → index-BPIbqRRb.css} +1 -1
  28. package/dist/ui/assets/{index-BoG6O-Lp.js → index-D83F2OKZ.js} +2 -2
  29. package/dist/ui/index.html +2 -3
  30. package/dist/ui-CY4xxJUu.mjs +472 -0
  31. package/dist/{usage-BIjf9Xdt.mjs → usage-CJnytoe4.mjs} +6 -5
  32. package/dist/{watch-B8o4Szd_.mjs → watch-BJB82ZJ7.mjs} +7 -7
  33. package/dist/workflows-CiM7S3l0.mjs +88 -0
  34. package/dist/worktrees-86ySXxR6.mjs +212 -0
  35. package/package.json +6 -6
  36. package/dist/__build_info__-CXXMLvjt.mjs +0 -104
  37. package/dist/ui/assets/app-BlDdP396.js +0 -61
  38. package/dist/ui/assets/app-C722xNZ3.css +0 -1
  39. package/dist/ui-CZS1XKla.mjs +0 -160
@@ -1,160 +0,0 @@
1
- import { n as ORK_VERSION } from "./__build_info__-CXXMLvjt.mjs";
2
- import { a as write, i as style, o as writeErr } from "./output-Q2EdeVUt.mjs";
3
- import { i as uiFilePath, n as startServer, r as runningServer, t as DEFAULT_PORT } from "./src-D5ruZFgD.mjs";
4
- import { a as mayShowSignIn } from "./in-a-run-BbLhZOFW.mjs";
5
- import { defineCommand } from "citty";
6
- import path from "node:path";
7
- import { spawn } from "node:child_process";
8
- import { fileURLToPath } from "node:url";
9
- // src/browser/folder.ts
10
- /**
11
- * @file Where `ork ui` finds the built UI: `dist/ui` beside the published
12
- * bundle, or, run from source, `packages/ui/dist` once it is built (`pnpm
13
- * --filter @krapht/ork-ui build`). The CLI takes the UI's built files, never
14
- * its source; without them the server shows its placeholder page.
15
- */
16
- /** The UI package's built folder in the workspace, or null outside it. */
17
- const workspaceUi = () => {
18
- try {
19
- const manifest = fileURLToPath(import.meta.resolve("@krapht/ork-ui/package.json"));
20
- return path.join(path.dirname(manifest), "dist");
21
- } catch {
22
- return null;
23
- }
24
- };
25
- /** The folders that may hold the built UI, in the order they are tried. */
26
- const uiFolders = () => {
27
- const workspace = workspaceUi();
28
- return [path.join(import.meta.dirname, "ui"), ...workspace === null ? [] : [workspace]];
29
- };
30
- // src/browser/open.ts
31
- /**
32
- * @file Opening a link in the user's browser, for `ork ui`. Each way is an
33
- * opener in a registry, tried in order when it applies to this platform:
34
- * `open` on macOS, `wslview` then `xdg-open` under WSL, `xdg-open` on Linux.
35
- * Adding a platform is one more entry. When none starts, the caller prints
36
- * the link instead.
37
- */
38
- const wsl = (env) => env["WSL_DISTRO_NAME"] !== void 0;
39
- const OPENERS = [
40
- {
41
- id: "macos",
42
- applies: (platform) => platform === "darwin",
43
- program: "open"
44
- },
45
- {
46
- id: "wslview",
47
- applies: (platform, env) => platform === "linux" && wsl(env),
48
- program: "wslview"
49
- },
50
- {
51
- id: "xdg-open",
52
- applies: (platform) => platform === "linux" || platform === "freebsd",
53
- program: "xdg-open"
54
- }
55
- ];
56
- /** Starts one program with the link; false when it cannot be started. */
57
- const start = (program, url) => new Promise((resolve) => {
58
- const child = spawn(program, [url], {
59
- detached: true,
60
- stdio: "ignore"
61
- });
62
- child.once("error", () => {
63
- resolve(false);
64
- });
65
- child.once("spawn", () => {
66
- child.unref();
67
- resolve(true);
68
- });
69
- });
70
- /** Opens `url` with the first opener that starts; false when none did. */
71
- const openInBrowser = async (url, options = {}) => {
72
- const platform = options.platform ?? process.platform;
73
- const env = options.env ?? process.env;
74
- for (const opener of options.openers ?? OPENERS) {
75
- if (!opener.applies(platform, env)) continue;
76
- if (await start(opener.program, url)) return true;
77
- }
78
- return false;
79
- };
80
- // src/commands/ui.ts
81
- /**
82
- * @file `ork ui`: starts the local server (ADR-039) on loopback and opens it in
83
- * the browser, signed in with the server's token; or, when one is already
84
- * running (`~/.ork/ui.json`), opens that one. The server runs nothing: runs
85
- * it starts keep running when it stops, and the CLI works without it.
86
- */
87
- /** The link that signs the browser in; the server swaps it for a cookie. */
88
- const signInLink = (port, token) => `http://127.0.0.1:${String(port)}/?token=${token}`;
89
- /** `--port`: 0 to 65535 (0 picks a free port); `null` when invalid. */
90
- const portArg = (value) => {
91
- if (value === void 0) return DEFAULT_PORT;
92
- const port = Number(value);
93
- return Number.isInteger(port) && port >= 0 && port <= 65535 ? port : null;
94
- };
95
- /** Opens the link, or prints it when there is no browser to open. */
96
- const show = async (link, open) => {
97
- if (!mayShowSignIn()) {
98
- writeErr("A program or an agent in a run does not get the sign-in link, which acts as you. Run `ork ui` in your own terminal.");
99
- return;
100
- }
101
- if (!(open && process.stdout.isTTY && await openInBrowser(link))) write(`Open it with this link, which signs you in: ${link}`);
102
- };
103
- const stopped = () => new Promise((resolve) => {
104
- process.once("SIGINT", () => {
105
- resolve();
106
- });
107
- process.once("SIGTERM", () => {
108
- resolve();
109
- });
110
- });
111
- const ui = defineCommand({
112
- meta: {
113
- name: "ui",
114
- description: "Start Ork's local UI and open it, or open the running one"
115
- },
116
- args: {
117
- port: {
118
- type: "string",
119
- description: `The port to serve on (default ${String(DEFAULT_PORT)})`
120
- },
121
- open: {
122
- type: "boolean",
123
- description: "Open the browser (--no-open only prints the address)",
124
- default: true
125
- }
126
- },
127
- run: async ({ args }) => {
128
- const port = portArg(args.port);
129
- if (port === null) {
130
- writeErr(`--port must be a number from 0 to 65535, not \`${args.port ?? ""}\`.`);
131
- process.exitCode = 1;
132
- return;
133
- }
134
- const running = runningServer(uiFilePath());
135
- if (running !== null) {
136
- write(`Ork's UI is already running at http://127.0.0.1:${String(running.port)} (process ${String(running.pid)}).`);
137
- await show(signInLink(running.port, running.token), args.open);
138
- return;
139
- }
140
- let server;
141
- try {
142
- server = await startServer({
143
- version: ORK_VERSION,
144
- port,
145
- ui: uiFolders()
146
- });
147
- } catch (error) {
148
- writeErr(error instanceof Error ? error.message : String(error));
149
- process.exitCode = 1;
150
- return;
151
- }
152
- write(`Ork's UI is at ${server.url}`);
153
- write(style("dim", "Runs keep running when it stops, and every ork command works without it. Ctrl-C stops it."));
154
- await show(signInLink(server.port, server.token), args.open);
155
- await stopped();
156
- await server.close();
157
- write(style("dim", "Ork's UI stopped."));
158
- }
159
- });
160
- export { ui };