@codeworksh/cli 0.5.0 → 0.6.0-canary.100.1.g71d09a02
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 +27 -2
- package/{acp-JnyJmRCD.mjs → acp-DLewRhY0.mjs} +92 -42
- package/acp-DLewRhY0.mjs.map +1 -0
- package/{add-Dzsv-fKd.mjs → add-DtqnGWjN.mjs} +5 -5
- package/add-DtqnGWjN.mjs.map +1 -0
- package/add-cjwCaNUh.mjs +87 -0
- package/add-cjwCaNUh.mjs.map +1 -0
- package/{catalog-C1G3pzHZ.mjs → catalog-XfqtqMDz.mjs} +2 -2
- package/{catalog-C1G3pzHZ.mjs.map → catalog-XfqtqMDz.mjs.map} +1 -1
- package/{check-DhojkK_E.mjs → check-DnIEQ4vp.mjs} +4 -4
- package/{check-DhojkK_E.mjs.map → check-DnIEQ4vp.mjs.map} +1 -1
- package/control-kIq8zb3O.mjs +31 -0
- package/control-kIq8zb3O.mjs.map +1 -0
- package/disconnect-BzjVSYdQ.mjs +2 -0
- package/{entries-KpYvZdpi.mjs → entries-hMxcOaPm.mjs} +3 -3
- package/{entries-KpYvZdpi.mjs.map → entries-hMxcOaPm.mjs.map} +1 -1
- package/{error-BMI81XvR.mjs → error-BVSfzBzb.mjs} +240 -91
- package/error-BVSfzBzb.mjs.map +1 -0
- package/fork-DQWc28Mp.mjs +32 -0
- package/fork-DQWc28Mp.mjs.map +1 -0
- package/{identity-BA1-EGoN.mjs → identity-b5SuHVok.mjs} +2 -2
- package/{identity-BA1-EGoN.mjs.map → identity-b5SuHVok.mjs.map} +1 -1
- package/index.mjs +40 -25
- package/index.mjs.map +1 -1
- package/{install-BLRDBzp1.mjs → install-Cl2JX_Ds.mjs} +4 -4
- package/{install-BLRDBzp1.mjs.map → install-Cl2JX_Ds.mjs.map} +1 -1
- package/jsonc-BwztMdEB.mjs +58 -0
- package/jsonc-BwztMdEB.mjs.map +1 -0
- package/{link--UnM2qnT.mjs → link-CVW9LiJQ.mjs} +3 -3
- package/{link--UnM2qnT.mjs.map → link-CVW9LiJQ.mjs.map} +1 -1
- package/list-C4029JEd.mjs +36 -0
- package/list-C4029JEd.mjs.map +1 -0
- package/list-CKxJokDj.mjs +71 -0
- package/list-CKxJokDj.mjs.map +1 -0
- package/{list-BE4xSEe3.mjs → list-CQcI-iX0.mjs} +4 -4
- package/{list-BE4xSEe3.mjs.map → list-CQcI-iX0.mjs.map} +1 -1
- package/{list-9fVqelid.mjs → list-CtFUvztt.mjs} +4 -4
- package/{list-9fVqelid.mjs.map → list-CtFUvztt.mjs.map} +1 -1
- package/{login-CRwxi5WD.mjs → login-DT1s4zCM.mjs} +4 -4
- package/{login-CRwxi5WD.mjs.map → login-DT1s4zCM.mjs.map} +1 -1
- package/login-qqBsseni.mjs +59 -0
- package/login-qqBsseni.mjs.map +1 -0
- package/logout-D1-vVgEh.mjs +17 -0
- package/logout-D1-vVgEh.mjs.map +1 -0
- package/{logout-C89X0B9M.mjs → logout-OnEsebcY.mjs} +4 -4
- package/{logout-C89X0B9M.mjs.map → logout-OnEsebcY.mjs.map} +1 -1
- package/package-DdxpVK0O.mjs +6 -0
- package/package-DdxpVK0O.mjs.map +1 -0
- package/package.json +3 -4
- package/{providers-BrXJvY2P.mjs → providers-DnhkGLsd.mjs} +4 -4
- package/{providers-BrXJvY2P.mjs.map → providers-DnhkGLsd.mjs.map} +1 -1
- package/reconnect-B0WnyTXS.mjs +2 -0
- package/{refresh--j0Pj4Cw.mjs → refresh-BUW0WVh_.mjs} +4 -4
- package/{refresh--j0Pj4Cw.mjs.map → refresh-BUW0WVh_.mjs.map} +1 -1
- package/{refresh-D0wBP2Go.mjs → refresh-PdkrwU5g.mjs} +4 -4
- package/{refresh-D0wBP2Go.mjs.map → refresh-PdkrwU5g.mjs.map} +1 -1
- package/relink-CAPQjc2V.mjs +23 -0
- package/relink-CAPQjc2V.mjs.map +1 -0
- package/{reload-DgPawyzr.mjs → reload-DVPHF5gJ.mjs} +3 -3
- package/{reload-DgPawyzr.mjs.map → reload-DVPHF5gJ.mjs.map} +1 -1
- package/remove-DY5b7L8Y.mjs +26 -0
- package/remove-DY5b7L8Y.mjs.map +1 -0
- package/{remove-DfFme5w2.mjs → remove-iGViyrLi.mjs} +4 -4
- package/{remove-DfFme5w2.mjs.map → remove-iGViyrLi.mjs.map} +1 -1
- package/{restart-DDrkmn2h.mjs → restart-BtqqBQLt.mjs} +4 -4
- package/{restart-DDrkmn2h.mjs.map → restart-BtqqBQLt.mjs.map} +1 -1
- package/{run-CVRkm_Iz.mjs → run-B0PLTBoU.mjs} +34 -18
- package/run-B0PLTBoU.mjs.map +1 -0
- package/{runtime-B43doHjV.mjs → runtime-CK2CunDw.mjs} +175 -20
- package/runtime-CK2CunDw.mjs.map +1 -0
- package/{serve-DDw1dCvW.mjs → serve-DbmAg7QU.mjs} +122 -75
- package/serve-DbmAg7QU.mjs.map +1 -0
- package/{service-DJR6nPam.mjs → service-Ddcq73-8.mjs} +8 -32
- package/service-Ddcq73-8.mjs.map +1 -0
- package/{settings-BfmoL27m.mjs → settings-Ct8kxLeD.mjs} +8 -36
- package/settings-Ct8kxLeD.mjs.map +1 -0
- package/{shared-CnuCjvcG.mjs → shared-B6BI-4BA.mjs} +3 -3
- package/{shared-CnuCjvcG.mjs.map → shared-B6BI-4BA.mjs.map} +1 -1
- package/shared-QBlwaQPR.mjs +88 -0
- package/shared-QBlwaQPR.mjs.map +1 -0
- package/{start-DwhV9ucd.mjs → start-KGLC_hu2.mjs} +4 -4
- package/{start-DwhV9ucd.mjs.map → start-KGLC_hu2.mjs.map} +1 -1
- package/{status-DVzFDoek.mjs → status-B1zDTFpF.mjs} +4 -4
- package/{status-DVzFDoek.mjs.map → status-B1zDTFpF.mjs.map} +1 -1
- package/{status-Bklxb3u6.mjs → status-l1g4IrPc.mjs} +4 -4
- package/{status-Bklxb3u6.mjs.map → status-l1g4IrPc.mjs.map} +1 -1
- package/{stop-DI91UvG_.mjs → stop-ttgPPf0H.mjs} +4 -4
- package/{stop-DI91UvG_.mjs.map → stop-ttgPPf0H.mjs.map} +1 -1
- package/thread-skUkybyv.mjs +15 -0
- package/thread-skUkybyv.mjs.map +1 -0
- package/{update-D0XPVfJu.mjs → update-Y2GmQPZW.mjs} +4 -4
- package/{update-D0XPVfJu.mjs.map → update-Y2GmQPZW.mjs.map} +1 -1
- package/acp-JnyJmRCD.mjs.map +0 -1
- package/add-Dzsv-fKd.mjs.map +0 -1
- package/error-BMI81XvR.mjs.map +0 -1
- package/package-Bi5FfVSP.mjs +0 -6
- package/package-Bi5FfVSP.mjs.map +0 -1
- package/run-CVRkm_Iz.mjs.map +0 -1
- package/runtime-B43doHjV.mjs.map +0 -1
- package/serve-DDw1dCvW.mjs.map +0 -1
- package/service-DJR6nPam.mjs.map +0 -1
- package/settings-BfmoL27m.mjs.map +0 -1
- package/tui-Cdim7SjU.mjs +0 -76
- package/tui-Cdim7SjU.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-
|
|
1
|
+
{"version":3,"file":"remove-iGViyrLi.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/plugin/remove.ts"],"sourcesContent":["import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, FileSystem, Option, Path } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tidentify,\n\tmatching,\n\treadPlugins,\n\tresolveTarget,\n\tspellings,\n\twithPluginsLock,\n\twritePlugins,\n} from \"./settings.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.plugin.commands.remove,\n\tEffect.fn(\"CLI.plugin.remove\")(function* ({ package: reference, global: userWide }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst shared = yield* Cmd.spec;\n\t\t\tconst path = yield* Path.Path;\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\t\t\tconst target = yield* resolveTarget(shared, userWide, undefined, false);\n\t\t\t// Removing from a directory that is not a project is a read-only no-op. In particular, it\n\t\t\t// must not create the marker that would make this directory shadow a real project later.\n\t\t\tif (!(yield* fs.exists(path.dirname(target.path)))) {\n\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst spelled = yield* spellings(reference, path.resolve(\".\"));\n\t\t\tyield* withPluginsLock(\n\t\t\t\ttarget.path,\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { source, plugins } = yield* readPlugins(target.path);\n\t\t\t\t\t// Both the module entry and any configuration written against it: the package it was\n\t\t\t\t\t// added as, the path or version it was written with, and the ID it declares all name\n\t\t\t\t\t// the one plugin being removed.\n\t\t\t\t\tconst entries = yield* identify(plugins, target.path, paths.cache);\n\t\t\t\t\tconst selected = matching(entries, spelled);\n\t\t\t\t\tconst kept = entries.filter((entry) => !selected.has(entry)).map((entry) => entry.value);\n\t\t\t\t\tif (kept.length === plugins.length) {\n\t\t\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tyield* writePlugins(target.path, source, kept);\n\t\t\t\t\tconst dropped = plugins.length - kept.length;\n\t\t\t\t\tyield* writeOut(\n\t\t\t\t\t\t`Removed ${dropped} ${dropped === 1 ? \"entry\" : \"entries\"} for \"${reference}\" from ${target.path}\\n`,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,iBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,QAC7B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE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6 +1,6 @@
|
|
|
1
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
+
import { f as writeOut, i as reportFailure } from "./error-BVSfzBzb.mjs";
|
|
3
|
+
import { a as stop, i as ensure, n as options } from "./service-Ddcq73-8.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
//#region src/cli/cmd/handlers/service/restart.ts
|
|
6
6
|
var restart_default = handler(Cmd.commands.service.commands.restart, Effect.fn("CLI.service.restart")(function* ({ host, port }) {
|
|
@@ -18,4 +18,4 @@ var restart_default = handler(Cmd.commands.service.commands.restart, Effect.fn("
|
|
|
18
18
|
//#endregion
|
|
19
19
|
export { restart_default as default };
|
|
20
20
|
|
|
21
|
-
//# sourceMappingURL=restart-
|
|
21
|
+
//# sourceMappingURL=restart-BtqqBQLt.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restart-
|
|
1
|
+
{"version":3,"file":"restart-BtqqBQLt.mjs","names":["Runtime.handler","options","Service.options","Discovery.stop","Discovery.ensure"],"sources":["../../src/cli/cmd/handlers/service/restart.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { Discovery } from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Service } from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.restart,\n\tEffect.fn(\"CLI.service.restart\")(function* ({ host, port }) {\n\t\tconst options = yield* Service.options(yield* Cmd.spec, { host, port });\n\t\tyield* Discovery.stop(options.home);\n\t\tconst server = yield* Discovery.ensure({ ...options, replace: true });\n\t\tyield* writeOut(`${server.url}\\n`);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;AAQA,IAAA,kBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,SAC9B,OAAO,GAAG,qBAAqB,CAAC,CAAC,WAAW,EAAE,MAAM,QAAQ;CAC3D,MAAMC,YAAU,OAAOC,QAAgB,OAAO,IAAI,MAAM;EAAE;EAAM;CAAK,CAAC;CACtE,OAAOC,KAAeF,UAAQ,IAAI;CAClC,MAAM,SAAS,OAAOG,OAAiB;EAAE,GAAGH;EAAS,SAAS;CAAK,CAAC;CACpE,OAAO,SAAS,GAAG,OAAO,IAAI,GAAG;AAClC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { i as Cmd, t as handler } from "./runtime-
|
|
2
|
-
import { a as addUsage, c as terminalColumns,
|
|
1
|
+
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
+
import { a as addUsage, c as terminalColumns, f as writeOut, h as run, l as usage, m as make, o as emptyUsage, p as layer, r as renderError, s as header, t as InvalidInputError, u as writeError } from "./error-BVSfzBzb.mjs";
|
|
3
3
|
import { t as harnessOptions } from "./harness-6d8TlAVk.mjs";
|
|
4
|
+
import { t as threadFlag } from "./thread-skUkybyv.mjs";
|
|
4
5
|
import { Effect, Exit, Fiber, Logger, Option, Queue, Ref, Schema, Stream } from "effect";
|
|
5
6
|
import { EventList, Harness, Sandbox, Session } from "@codeworksh/harness/effect";
|
|
6
7
|
//#region src/cli/cmd/handlers/run.ts
|
|
@@ -25,7 +26,8 @@ const render = (state, ended) => Effect.fn("CLI.render")(function* (event) {
|
|
|
25
26
|
if (isLLMEnded(event)) {
|
|
26
27
|
yield* Ref.update(state, (current) => ({
|
|
27
28
|
...current,
|
|
28
|
-
usage: addUsage(current.usage, event.data.message)
|
|
29
|
+
usage: addUsage(current.usage, event.data.message),
|
|
30
|
+
reason: event.data.reason
|
|
29
31
|
}));
|
|
30
32
|
return;
|
|
31
33
|
}
|
|
@@ -35,6 +37,12 @@ const finish = Effect.fn("CLI.finish")(function* (state, columns) {
|
|
|
35
37
|
const rendered = yield* Ref.get(state);
|
|
36
38
|
if (rendered.textSeen && !rendered.textEndsWithNewline) yield* writeOut("\n");
|
|
37
39
|
yield* writeError(usage(rendered.usage, columns));
|
|
40
|
+
if (rendered.reason === "length") {
|
|
41
|
+
yield* writeError("Response was truncated: the model reached its output token limit.\n");
|
|
42
|
+
yield* Effect.sync(() => {
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
38
46
|
});
|
|
39
47
|
const awaitMessage = Effect.fn("CLI.awaitMessage")(function* (ended, messageId) {
|
|
40
48
|
while ((yield* Queue.take(ended)) !== messageId);
|
|
@@ -47,9 +55,11 @@ const selectSandbox = Effect.fn("CLI.selectSandbox", { level: "Info" })(function
|
|
|
47
55
|
}
|
|
48
56
|
return selection.info;
|
|
49
57
|
});
|
|
50
|
-
var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info" })(function* ({ prompt, session, cwd, sandboxDriver, sandboxProviderId, sandboxId, provider, model, thinking, server }) {
|
|
58
|
+
var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info" })(function* ({ prompt, session, thread, cwd, sandboxDriver, sandboxProviderId, sandboxId, provider, model, thinking, server }) {
|
|
51
59
|
const shared = yield* Cmd.spec;
|
|
52
60
|
if (Option.isSome(session) && (Option.isSome(cwd) || Option.isSome(sandboxDriver) || Option.isSome(sandboxProviderId) || Option.isSome(sandboxId))) return yield* new InvalidInputError({ message: "--cwd, --sandbox-driver, --sandbox-id, and --sandbox-provider-id can only be used when creating a new session" });
|
|
61
|
+
if (Option.isSome(thread) && Option.isNone(session)) return yield* new InvalidInputError({ message: "--thread continues a thread of --session" });
|
|
62
|
+
const threadId = yield* threadFlag(thread);
|
|
53
63
|
if (Option.isSome(provider) !== Option.isSome(model)) return yield* new InvalidInputError({ message: "--provider and --model must be provided together" });
|
|
54
64
|
if (Option.isSome(sandboxProviderId) && Option.isNone(sandboxDriver)) return yield* new InvalidInputError({ message: "--sandbox-provider-id requires a remote --sandbox-driver" });
|
|
55
65
|
if (Option.isSome(server) && [
|
|
@@ -72,8 +82,9 @@ var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info"
|
|
|
72
82
|
};
|
|
73
83
|
const remote = Effect.gen(function* () {
|
|
74
84
|
const rpc = yield* make;
|
|
75
|
-
const info = Option.isSome(session) ? yield* rpc["
|
|
85
|
+
const info = Option.isSome(session) ? yield* rpc["thread.configure"]({
|
|
76
86
|
sessionId: Session.SessionSchema.ID.make(session.value),
|
|
87
|
+
...threadId === void 0 ? {} : { threadId },
|
|
77
88
|
runtime
|
|
78
89
|
}) : yield* rpc["session.create"]({
|
|
79
90
|
runtime,
|
|
@@ -84,32 +95,37 @@ var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info"
|
|
|
84
95
|
const state = yield* Ref.make(initialRenderState);
|
|
85
96
|
const columns = terminalColumns();
|
|
86
97
|
yield* writeError(header({
|
|
87
|
-
sessionId: info.id,
|
|
88
|
-
sandbox: info.sandbox?.driver ?? "local",
|
|
89
|
-
directory: info.directory,
|
|
98
|
+
sessionId: info.session.id,
|
|
99
|
+
sandbox: info.session.sandbox?.driver ?? "local",
|
|
100
|
+
directory: info.placement?.directory ?? info.session.directory,
|
|
90
101
|
columns
|
|
91
102
|
}));
|
|
92
|
-
if (info.sandbox !== void 0) yield* writeError(`sandbox-id: ${info.sandbox.id}\n`);
|
|
103
|
+
if (info.session.sandbox !== void 0) yield* writeError(`sandbox-id: ${info.session.sandbox.id}\n`);
|
|
93
104
|
yield* run(rpc, {
|
|
94
|
-
sessionId: info.id,
|
|
105
|
+
sessionId: info.session.id,
|
|
106
|
+
threadId: info.id,
|
|
95
107
|
text: prompt
|
|
96
|
-
}, render(state)).pipe(Effect.onInterrupt(() => rpc["
|
|
108
|
+
}, render(state)).pipe(Effect.onInterrupt(() => rpc["thread.interrupt"]({
|
|
109
|
+
sessionId: info.session.id,
|
|
110
|
+
threadId: info.id
|
|
111
|
+
}).pipe(Effect.timeout("5 seconds"), Effect.ignore)));
|
|
97
112
|
yield* finish(state, columns);
|
|
98
113
|
});
|
|
99
114
|
const program = Effect.gen(function* () {
|
|
100
115
|
let handle;
|
|
101
116
|
if (Option.isSome(session)) handle = yield* Session.attach({
|
|
102
117
|
sessionId: Session.SessionSchema.ID.make(session.value),
|
|
118
|
+
...threadId === void 0 ? {} : { threadId },
|
|
103
119
|
...runtime
|
|
104
120
|
});
|
|
105
121
|
else {
|
|
106
122
|
const selected = yield* selectSandbox(selection);
|
|
107
|
-
handle = yield* Session.create({
|
|
123
|
+
handle = (yield* Session.create({
|
|
108
124
|
...runtime,
|
|
109
125
|
...selected === void 0 ? {} : { sandbox: selected },
|
|
110
126
|
...Option.isNone(cwd) ? {} : { directory: cwd.value },
|
|
111
127
|
hostDir
|
|
112
|
-
});
|
|
128
|
+
})).main;
|
|
113
129
|
}
|
|
114
130
|
const ended = yield* Queue.unbounded();
|
|
115
131
|
const renderState = yield* Ref.make(initialRenderState);
|
|
@@ -117,9 +133,9 @@ var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info"
|
|
|
117
133
|
const info = yield* handle.info;
|
|
118
134
|
const columns = terminalColumns();
|
|
119
135
|
yield* writeError(header({
|
|
120
|
-
sessionId: handle.
|
|
121
|
-
sandbox: info.sandbox?.driver ?? "local",
|
|
122
|
-
directory: info.directory,
|
|
136
|
+
sessionId: handle.sessionId,
|
|
137
|
+
sandbox: info.session.sandbox?.driver ?? "local",
|
|
138
|
+
directory: info.placement?.directory ?? info.session.directory,
|
|
123
139
|
columns
|
|
124
140
|
}));
|
|
125
141
|
const execution = yield* handle.prompt({
|
|
@@ -128,7 +144,7 @@ var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info"
|
|
|
128
144
|
}).pipe(Effect.andThen(handle.resume()), Effect.onInterrupt(() => handle.interrupt().pipe(Effect.timeout("5 seconds"), Effect.ignore)), Effect.exit);
|
|
129
145
|
yield* handle.wait();
|
|
130
146
|
if (Exit.isFailure(execution)) return yield* Effect.failCause(execution.cause);
|
|
131
|
-
const leaf = (yield* handle.
|
|
147
|
+
const leaf = (yield* handle.history()).at(-1);
|
|
132
148
|
if (leaf !== void 0) yield* awaitMessage(ended, leaf.entry.id);
|
|
133
149
|
yield* Fiber.interrupt(printer);
|
|
134
150
|
yield* finish(renderState, columns);
|
|
@@ -143,4 +159,4 @@ var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info"
|
|
|
143
159
|
//#endregion
|
|
144
160
|
export { run_default as default };
|
|
145
161
|
|
|
146
|
-
//# sourceMappingURL=run-
|
|
162
|
+
//# sourceMappingURL=run-B0PLTBoU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-B0PLTBoU.mjs","names":["Runtime.handler","Client.make","Client.run","Client.layer"],"sources":["../../src/cli/cmd/handlers/run.ts"],"sourcesContent":["import { EventList, type EventSchema, Harness, Sandbox, Session } from \"@codeworksh/harness/effect\";\nimport { Effect, Exit, Fiber, Logger, Option, Queue, Ref, Schema, Stream } from \"effect\";\nimport { Runtime } from \"../../../framework/runtime.ts\";\nimport { Client } from \"../../../server/client.ts\";\nimport { InvalidInputError, renderError } from \"../../error.ts\";\nimport { harnessOptions } from \"../../harness.ts\";\nimport {\n\taddUsage,\n\temptyUsage,\n\theader,\n\tterminalColumns,\n\tusage,\n\ttype UsageSummary,\n\twriteError,\n\twriteOut,\n} from \"../../output.ts\";\nimport { threadFlag } from \"../../thread.ts\";\nimport { Cmd } from \"../cmd.ts\";\n\ninterface RenderState {\n\treadonly usage: UsageSummary;\n\treadonly textSeen: boolean;\n\treadonly textEndsWithNewline: boolean;\n\treadonly reason?: EventList.LLMEnded[\"data\"][\"reason\"];\n}\n\nconst initialRenderState: RenderState = {\n\tusage: emptyUsage,\n\ttextSeen: false,\n\ttextEndsWithNewline: false,\n};\n\nconst isTextDelta = Schema.is(EventList.LLMTextDelta);\nconst isLLMEnded = Schema.is(EventList.LLMEnded);\nconst isTurnEnded = Schema.is(EventList.TurnEnded);\n\nconst render = (state: Ref.Ref<RenderState>, ended?: Queue.Queue<string>) =>\n\tEffect.fn(\"CLI.render\")(function* (event: EventSchema.Payload) {\n\t\tif (isTextDelta(event)) {\n\t\t\tyield* writeOut(event.data.delta);\n\t\t\tif (event.data.delta.length > 0) {\n\t\t\t\tyield* Ref.update(state, (current) => ({\n\t\t\t\t\t...current,\n\t\t\t\t\ttextSeen: true,\n\t\t\t\t\ttextEndsWithNewline: event.data.delta.endsWith(\"\\n\"),\n\t\t\t\t}));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (isLLMEnded(event)) {\n\t\t\tyield* Ref.update(state, (current) => ({\n\t\t\t\t...current,\n\t\t\t\tusage: addUsage(current.usage, event.data.message),\n\t\t\t\treason: event.data.reason,\n\t\t\t}));\n\t\t\treturn;\n\t\t}\n\t\tif (ended !== undefined && isTurnEnded(event)) {\n\t\t\tyield* Queue.offer(ended, event.data.messageId);\n\t\t}\n\t});\n\nconst finish = Effect.fn(\"CLI.finish\")(function* (state: Ref.Ref<RenderState>, columns: number) {\n\tconst rendered = yield* Ref.get(state);\n\tif (rendered.textSeen && !rendered.textEndsWithNewline) yield* writeOut(\"\\n\");\n\tyield* writeError(usage(rendered.usage, columns));\n\tif (rendered.reason === \"length\") {\n\t\tyield* writeError(\"Response was truncated: the model reached its output token limit.\\n\");\n\t\tyield* Effect.sync(() => {\n\t\t\tprocess.exitCode = 1;\n\t\t});\n\t}\n});\n\nconst awaitMessage = Effect.fn(\"CLI.awaitMessage\")(function* (ended: Queue.Queue<string>, messageId: string) {\n\twhile ((yield* Queue.take(ended)) !== messageId) {\n\t\t// Earlier turns in the same drain are expected when a tool call continues.\n\t}\n});\n\nconst selectSandbox = Effect.fn(\"CLI.selectSandbox\", { level: \"Info\" })(function* (input: Sandbox.Selection) {\n\tconst selection = yield* Sandbox.resolve(input);\n\tif (selection.created && selection.info !== undefined) {\n\t\tconst id = selection.info.id;\n\t\tyield* Effect.addFinalizer(() => Effect.ignore(Sandbox.stop(id)));\n\t}\n\treturn selection.info;\n});\n\nexport default Runtime.handler(\n\tCmd.commands.run,\n\tEffect.fn(\"CLI.run\", { level: \"Info\" })(function* ({\n\t\tprompt,\n\t\tsession,\n\t\tthread,\n\t\tcwd,\n\t\tsandboxDriver,\n\t\tsandboxProviderId,\n\t\tsandboxId,\n\t\tprovider,\n\t\tmodel,\n\t\tthinking,\n\t\tserver,\n\t}) {\n\t\tconst shared = yield* Cmd.spec;\n\t\tif (\n\t\t\tOption.isSome(session) &&\n\t\t\t(Option.isSome(cwd) ||\n\t\t\t\tOption.isSome(sandboxDriver) ||\n\t\t\t\tOption.isSome(sandboxProviderId) ||\n\t\t\t\tOption.isSome(sandboxId))\n\t\t) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage:\n\t\t\t\t\t\"--cwd, --sandbox-driver, --sandbox-id, and --sandbox-provider-id can only be used when creating a new session\",\n\t\t\t});\n\t\t}\n\t\tif (Option.isSome(thread) && Option.isNone(session)) {\n\t\t\treturn yield* new InvalidInputError({ message: \"--thread continues a thread of --session\" });\n\t\t}\n\t\tconst threadId = yield* threadFlag(thread);\n\t\tif (Option.isSome(provider) !== Option.isSome(model)) {\n\t\t\treturn yield* new InvalidInputError({ message: \"--provider and --model must be provided together\" });\n\t\t}\n\t\tif (Option.isSome(sandboxProviderId) && Option.isNone(sandboxDriver)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--sandbox-provider-id requires a remote --sandbox-driver\",\n\t\t\t});\n\t\t}\n\t\tif (Option.isSome(server) && [shared.home, shared.database, shared.userConfigDir].some(Option.isSome)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--home, --database, and --user-config-dir belong on codework serve when using --server\",\n\t\t\t});\n\t\t}\n\n\t\tif (Option.isSome(sandboxId) && (Option.isSome(sandboxDriver) || Option.isSome(sandboxProviderId))) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--sandbox-id cannot be combined with --sandbox-driver or --sandbox-provider-id\",\n\t\t\t});\n\t\t}\n\t\tconst selection: Sandbox.Selection = Option.isSome(sandboxId)\n\t\t\t? { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) }\n\t\t\t: {\n\t\t\t\t\tdriver: Option.getOrElse(sandboxDriver, () => \"local\"),\n\t\t\t\t\t...(Option.isNone(sandboxProviderId) ? {} : { providerResourceId: sandboxProviderId.value }),\n\t\t\t\t};\n\n\t\t// The session's host directory, with no flag to set it: a person running a command is always\n\t\t// somewhere, and that somewhere is what they mean by \"this project\". `--cwd` is a different\n\t\t// thing entirely -- where the work runs inside the session's space, which may be a sandbox\n\t\t// on another machine.\n\t\tconst hostDir = Session.AbsolutePath.make(process.cwd());\n\n\t\tconst runtime = {\n\t\t\t...(Option.isNone(provider) || Option.isNone(model)\n\t\t\t\t? {}\n\t\t\t\t: { model: { provider: provider.value, id: model.value } }),\n\t\t\t...(Option.isNone(thinking) ? {} : { thinkingLevel: thinking.value }),\n\t\t};\n\t\tconst remote = Effect.gen(function* () {\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst info = Option.isSome(session)\n\t\t\t\t? yield* rpc[\"thread.configure\"]({\n\t\t\t\t\t\tsessionId: Session.SessionSchema.ID.make(session.value),\n\t\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t\truntime,\n\t\t\t\t\t})\n\t\t\t\t: yield* rpc[\"session.create\"]({\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\t...(Option.isNone(cwd) ? {} : { directory: cwd.value }),\n\t\t\t\t\t\thostDir,\n\t\t\t\t\t\tsandbox: selection,\n\t\t\t\t\t});\n\t\t\tconst state = yield* Ref.make(initialRenderState);\n\t\t\tconst columns = terminalColumns();\n\t\t\tyield* writeError(\n\t\t\t\theader({\n\t\t\t\t\tsessionId: info.session.id,\n\t\t\t\t\tsandbox: info.session.sandbox?.driver ?? \"local\",\n\t\t\t\t\tdirectory: info.placement?.directory ?? info.session.directory,\n\t\t\t\t\tcolumns,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (info.session.sandbox !== undefined) yield* writeError(`sandbox-id: ${info.session.sandbox.id}\\n`);\n\t\t\tyield* Client.run(rpc, { sessionId: info.session.id, threadId: info.id, text: prompt }, render(state)).pipe(\n\t\t\t\tEffect.onInterrupt(() =>\n\t\t\t\t\trpc[\"thread.interrupt\"]({ sessionId: info.session.id, threadId: info.id }).pipe(\n\t\t\t\t\t\tEffect.timeout(\"5 seconds\"),\n\t\t\t\t\t\tEffect.ignore,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t\tyield* finish(state, columns);\n\t\t});\n\t\tconst program = Effect.gen(function* () {\n\t\t\tlet handle: Session.ThreadHandle;\n\t\t\tif (Option.isSome(session)) {\n\t\t\t\thandle = yield* Session.attach({\n\t\t\t\t\tsessionId: Session.SessionSchema.ID.make(session.value),\n\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t...runtime,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst selected = yield* selectSandbox(selection);\n\t\t\t\tconst created = yield* Session.create({\n\t\t\t\t\t...runtime,\n\t\t\t\t\t...(selected === undefined ? {} : { sandbox: selected }),\n\t\t\t\t\t...(Option.isNone(cwd) ? {} : { directory: cwd.value }),\n\t\t\t\t\thostDir,\n\t\t\t\t});\n\t\t\t\thandle = created.main;\n\t\t\t}\n\t\t\tconst ended = yield* Queue.unbounded<string>();\n\t\t\tconst renderState = yield* Ref.make(initialRenderState);\n\t\t\tconst printer = yield* handle\n\t\t\t\t.events()\n\t\t\t\t.pipe(Stream.runForEach(render(renderState, ended)), Effect.forkScoped({ startImmediately: true }));\n\n\t\t\tconst info = yield* handle.info;\n\t\t\tconst columns = terminalColumns();\n\t\t\tyield* writeError(\n\t\t\t\theader({\n\t\t\t\t\tsessionId: handle.sessionId,\n\t\t\t\t\tsandbox: info.session.sandbox?.driver ?? \"local\",\n\t\t\t\t\tdirectory: info.placement?.directory ?? info.session.directory,\n\t\t\t\t\tcolumns,\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// The local command joins execution to retain typed error details. Ctrl+C is the user stopping\n\t\t\t// the run, as on the remote path: named so, the next server start does not resume it.\n\t\t\tconst execution = yield* handle.prompt({ text: prompt, delivery: \"followUp\" }).pipe(\n\t\t\t\tEffect.andThen(handle.resume()),\n\t\t\t\tEffect.onInterrupt(() => handle.interrupt().pipe(Effect.timeout(\"5 seconds\"), Effect.ignore)),\n\t\t\t\tEffect.exit,\n\t\t\t);\n\t\t\tyield* handle.wait();\n\t\t\tif (Exit.isFailure(execution)) return yield* Effect.failCause(execution.cause);\n\t\t\tconst leaf = (yield* handle.history()).at(-1);\n\t\t\tif (leaf !== undefined) yield* awaitMessage(ended, leaf.entry.id);\n\t\t\tyield* Fiber.interrupt(printer);\n\t\t\tyield* finish(renderState, columns);\n\t\t});\n\n\t\t// Scope inside the provided layer, so the run's finalizers (stopping a created sandbox) close\n\t\t// while the harness and its database are still open.\n\t\tconst execute = Effect.gen(function* () {\n\t\t\tif (Option.isSome(server))\n\t\t\t\treturn yield* remote.pipe(Effect.scoped, Effect.provide(Client.layer(server.value)));\n\t\t\t// Stdout carries only the response; harness logs go with the rest of the diagnostics.\n\t\t\treturn yield* program.pipe(\n\t\t\t\tEffect.scoped,\n\t\t\t\tEffect.provide(Harness.layer(harnessOptions(shared))),\n\t\t\t\tEffect.provideService(Logger.LogToStderr, true),\n\t\t\t);\n\t\t});\n\t\treturn yield* execute.pipe(\n\t\t\tEffect.catch((error) =>\n\t\t\t\twriteError(renderError(error)).pipe(\n\t\t\t\t\tEffect.andThen(\n\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n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@ const AuthParams = {
|
|
|
32
32
|
server: Flag.String("server").pipe(Flag.withDescription("RPC server URL (ws://host:port/rpc/v1)"), Flag.optional),
|
|
33
33
|
authFile: Flag.String("auth-file").pipe(Flag.withDescription("Credential file (defaults to <home>/aikit/auth.json)"), Flag.optional)
|
|
34
34
|
};
|
|
35
|
-
/** Where the background server binds when `
|
|
35
|
+
/** Where the background server binds when `service` has to start one. */
|
|
36
36
|
const ServerAddress = {
|
|
37
37
|
host: Flag.String("host").pipe(Flag.withDescription("Host interface the background server binds"), Flag.withDefault("127.0.0.1")),
|
|
38
38
|
port: Flag.Int("port").pipe(Flag.withSchema(Schema.Int.check(Schema.isBetween({
|
|
@@ -40,6 +40,15 @@ const ServerAddress = {
|
|
|
40
40
|
maximum: 65535
|
|
41
41
|
}))), Flag.withDescription("Port the background server listens on"), Flag.withDefault(7433))
|
|
42
42
|
};
|
|
43
|
+
/** For commands that only talk to a server that is already running. */
|
|
44
|
+
const RunningServer = Flag.String("server").pipe(Flag.withDescription("RPC server URL (ws://host:port/rpc/v1)"), Flag.withDefault("ws://127.0.0.1:7433/rpc/v1"));
|
|
45
|
+
/** A thread's MCP server in a running server: every thread sharing its instance is affected. */
|
|
46
|
+
const McpControlParams = {
|
|
47
|
+
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
|
|
48
|
+
session: Flag.String("session").pipe(Flag.withAlias("s"), Flag.withDescription("The session")),
|
|
49
|
+
thread: Flag.String("thread").pipe(Flag.withDescription("Thread of --session whose server it is: a thread ID, or main (default)"), Flag.optional),
|
|
50
|
+
server: RunningServer
|
|
51
|
+
};
|
|
43
52
|
const JsonFlag = Flag.Boolean("json").pipe(Flag.withDescription("Print machine-readable output"), Flag.withDefault(false));
|
|
44
53
|
const Cmd = make("codework", {
|
|
45
54
|
description: "CodeWork Command Line Interface",
|
|
@@ -113,12 +122,120 @@ const Cmd = make("codework", {
|
|
|
113
122
|
})
|
|
114
123
|
]
|
|
115
124
|
}),
|
|
125
|
+
make("mcp", {
|
|
126
|
+
description: "Manage MCP servers",
|
|
127
|
+
commands: [
|
|
128
|
+
make("add", {
|
|
129
|
+
description: "Add or replace a server in mcp.json",
|
|
130
|
+
params: {
|
|
131
|
+
name: Argument.String("name").pipe(Argument.withDescription("Server name")),
|
|
132
|
+
command: Argument.String("command").pipe(Argument.withDescription("Command and arguments of a stdio server, after --"), Argument.variadic({ min: 0 })),
|
|
133
|
+
url: Flag.String("url").pipe(Flag.withDescription("Streamable HTTP server URL (instead of a command)"), Flag.optional),
|
|
134
|
+
env: Flag.KeyValuePair("env").pipe(Flag.withDescription("Environment variable of a stdio server, as KEY=VALUE"), Flag.optional),
|
|
135
|
+
cwd: Flag.String("cwd").pipe(Flag.withDescription("Working directory of a stdio server"), Flag.optional),
|
|
136
|
+
header: Flag.KeyValuePair("header").pipe(Flag.withDescription("HTTP header, as KEY=VALUE"), Flag.optional),
|
|
137
|
+
bearerTokenEnvVar: Flag.String("bearer-token-env-var").pipe(Flag.withDescription("Send \"Authorization: Bearer ${NAME}\""), Flag.optional),
|
|
138
|
+
oauthClientId: Flag.String("oauth-client-id").pipe(Flag.withDescription("Pre-registered OAuth client id"), Flag.optional),
|
|
139
|
+
oauthClientSecret: Flag.String("oauth-client-secret").pipe(Flag.withDescription("OAuth client secret (may be ${NAME} or !command)"), Flag.optional),
|
|
140
|
+
oauthCallbackPort: Flag.Int("oauth-callback-port").pipe(Flag.withSchema(Schema.Int.check(Schema.isBetween({
|
|
141
|
+
minimum: 1,
|
|
142
|
+
maximum: 65535
|
|
143
|
+
}))), Flag.withDescription("Fixed OAuth callback port"), Flag.optional),
|
|
144
|
+
oauthClientName: Flag.String("oauth-client-name").pipe(Flag.withDescription("Client name sent when registering with the OAuth server"), Flag.optional),
|
|
145
|
+
exposure: Flag.Literals("exposure", [
|
|
146
|
+
"direct",
|
|
147
|
+
"hidden",
|
|
148
|
+
"codemode",
|
|
149
|
+
"deferred"
|
|
150
|
+
]).pipe(Flag.withDescription("How the model reaches the server's tools (default: direct)"), Flag.optional),
|
|
151
|
+
description: Flag.String("description").pipe(Flag.withDescription("What the server offers"), Flag.optional),
|
|
152
|
+
local: Flag.Boolean("local").pipe(Flag.withAlias("l"), Flag.withDescription("Write the project's .codework/mcp.json instead of the user one"), Flag.withDefault(false))
|
|
153
|
+
},
|
|
154
|
+
examples: [
|
|
155
|
+
{
|
|
156
|
+
command: "codework mcp add fs -- npx -y @modelcontextprotocol/server-filesystem .",
|
|
157
|
+
description: "Add a stdio server"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
command: "codework mcp add linear --url https://mcp.linear.app/mcp",
|
|
161
|
+
description: "Add an HTTP server; sign in with codework mcp login linear"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
command: "codework mcp add tools -l --url http://127.0.0.1:8080/mcp",
|
|
165
|
+
description: "Add a server to this project only"
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}),
|
|
169
|
+
make("remove", {
|
|
170
|
+
description: "Remove a server from mcp.json",
|
|
171
|
+
params: {
|
|
172
|
+
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
|
|
173
|
+
local: Flag.Boolean("local").pipe(Flag.withAlias("l"), Flag.withDescription("Remove it from the project's .codework/mcp.json instead of the user one"), Flag.withDefault(false))
|
|
174
|
+
},
|
|
175
|
+
examples: [{
|
|
176
|
+
command: "codework mcp remove linear",
|
|
177
|
+
description: "Remove the linear server"
|
|
178
|
+
}]
|
|
179
|
+
}),
|
|
180
|
+
make("list", {
|
|
181
|
+
description: "Connect to every enabled server and show its state, tools and errors",
|
|
182
|
+
params: { json: JsonFlag },
|
|
183
|
+
examples: [{
|
|
184
|
+
command: "codework mcp list",
|
|
185
|
+
description: "Check every configured server; exits 1 on a failure"
|
|
186
|
+
}]
|
|
187
|
+
}),
|
|
188
|
+
make("login", {
|
|
189
|
+
description: "Sign in to an MCP server with OAuth",
|
|
190
|
+
params: {
|
|
191
|
+
name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")),
|
|
192
|
+
browser: Flag.Boolean("browser").pipe(Flag.withDescription("Open the authorization URL in the default browser"), Flag.withDefault(true)),
|
|
193
|
+
timeout: Flag.Int("timeout").pipe(Flag.withSchema(Schema.Int.check(Schema.isGreaterThan(0))), Flag.withDescription("Seconds the whole sign-in may take"), Flag.withDefault(300))
|
|
194
|
+
},
|
|
195
|
+
examples: [{
|
|
196
|
+
command: "codework mcp login linear",
|
|
197
|
+
description: "Sign in to the linear server"
|
|
198
|
+
}, {
|
|
199
|
+
command: "codework mcp login linear --browser=false",
|
|
200
|
+
description: "Print the URL; paste the redirected URL back if the browser is elsewhere"
|
|
201
|
+
}]
|
|
202
|
+
}),
|
|
203
|
+
make("logout", {
|
|
204
|
+
description: "Remove the stored OAuth credentials of an MCP server",
|
|
205
|
+
params: { name: Argument.String("name").pipe(Argument.withDescription("Server name in mcp.json")) },
|
|
206
|
+
examples: [{
|
|
207
|
+
command: "codework mcp logout linear",
|
|
208
|
+
description: "Sign out of the linear server"
|
|
209
|
+
}]
|
|
210
|
+
}),
|
|
211
|
+
make("reconnect", {
|
|
212
|
+
description: "Connect a thread's MCP server afresh in a running server",
|
|
213
|
+
params: McpControlParams,
|
|
214
|
+
examples: [{
|
|
215
|
+
command: "codework mcp reconnect linear --session ses_01h9",
|
|
216
|
+
description: "Restart the linear server the main thread uses; its tools return from the next turn"
|
|
217
|
+
}, {
|
|
218
|
+
command: "codework mcp reconnect linear --session ses_01h9 --thread thr_01ja",
|
|
219
|
+
description: "Restart the one a thread of the session uses"
|
|
220
|
+
}]
|
|
221
|
+
}),
|
|
222
|
+
make("disconnect", {
|
|
223
|
+
description: "Close a thread's MCP server in a running server until it is reconnected",
|
|
224
|
+
params: McpControlParams,
|
|
225
|
+
examples: [{
|
|
226
|
+
command: "codework mcp disconnect linear --session ses_01h9",
|
|
227
|
+
description: "Close the linear server the main thread uses"
|
|
228
|
+
}]
|
|
229
|
+
})
|
|
230
|
+
]
|
|
231
|
+
}),
|
|
116
232
|
make("run", {
|
|
117
233
|
description: "Start or continue an agent session",
|
|
118
234
|
params: {
|
|
119
235
|
server: Flag.String("server").pipe(Flag.withDescription("RPC server URL (ws://host:port/rpc/v1)"), Flag.optional),
|
|
120
236
|
prompt: Argument.String("prompt").pipe(Argument.withDescription("Prompt for the agent")),
|
|
121
237
|
session: Flag.String("session").pipe(Flag.withAlias("s"), Flag.withDescription("Continue an existing session"), Flag.optional),
|
|
238
|
+
thread: Flag.String("thread").pipe(Flag.withDescription("Thread of --session to continue: a thread ID, or main (default)"), Flag.optional),
|
|
122
239
|
cwd: Flag.String("cwd").pipe(Flag.withAlias("C"), Flag.withDescription("Working directory for a new session"), Flag.optional),
|
|
123
240
|
sandboxDriver: Flag.String("sandbox-driver").pipe(Flag.withDescription("Sandbox driver for a new session (default: local)"), Flag.optional),
|
|
124
241
|
sandboxId: Flag.String("sandbox-id").pipe(Flag.withDescription("Reuse an existing sandbox instance"), Flag.optional),
|
|
@@ -147,24 +264,13 @@ const Cmd = make("codework", {
|
|
|
147
264
|
{
|
|
148
265
|
command: "codework run --session <id> --provider openai --model gpt-5.6-luna \"Now fix them\"",
|
|
149
266
|
description: "Continue a session with explicit model bindings"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
command: "codework run --session <id> --thread <thread-id> \"Try OAuth instead\"",
|
|
270
|
+
description: "Continue one of the session's threads"
|
|
150
271
|
}
|
|
151
272
|
]
|
|
152
273
|
}),
|
|
153
|
-
make("tui", {
|
|
154
|
-
description: "Launch the CodeWork terminal UI against the background server",
|
|
155
|
-
params: {
|
|
156
|
-
server: Flag.String("server").pipe(Flag.withDescription("RPC server URL to use instead of the background server (ws://host:port/rpc/v1)"), Flag.optional),
|
|
157
|
-
...ServerAddress,
|
|
158
|
-
args: Argument.variadic(Argument.String("args").pipe(Argument.withDescription("Arguments forwarded to the terminal UI")))
|
|
159
|
-
},
|
|
160
|
-
examples: [{
|
|
161
|
-
command: "codework tui",
|
|
162
|
-
description: "Start or reuse the local server and open the terminal UI"
|
|
163
|
-
}, {
|
|
164
|
-
command: "codework tui --server ws://127.0.0.1:7433/rpc/v1",
|
|
165
|
-
description: "Attach the terminal UI to a server you started yourself"
|
|
166
|
-
}]
|
|
167
|
-
}),
|
|
168
274
|
make("serve", {
|
|
169
275
|
description: "Start the CodeWork RPC server",
|
|
170
276
|
params: {
|
|
@@ -173,7 +279,7 @@ const Cmd = make("codework", {
|
|
|
173
279
|
minimum: 0,
|
|
174
280
|
maximum: 65535
|
|
175
281
|
}))), Flag.withDescription("Port to listen on (0 for an ephemeral port)"), Flag.withDefault(7433)),
|
|
176
|
-
service: Flag.Boolean("service").pipe(Flag.withDescription("Run as the background server `codework
|
|
282
|
+
service: Flag.Boolean("service").pipe(Flag.withDescription("Run as the background server `codework service` manages, logging to <home>/log/server.log"), Flag.withDefault(false))
|
|
177
283
|
},
|
|
178
284
|
examples: [{
|
|
179
285
|
command: "codework serve",
|
|
@@ -206,7 +312,7 @@ const Cmd = make("codework", {
|
|
|
206
312
|
session: Argument.String("session-id").pipe(Argument.withDescription("The session to link")),
|
|
207
313
|
path: Argument.String("path").pipe(Argument.withDescription("Host directory to anchor to — typically the directory holding your .codework configuration; defaults to the shell's"), Argument.optional),
|
|
208
314
|
unlink: Flag.Boolean("unlink").pipe(Flag.withDescription("Clear the anchor, leaving the session with no host directory"), Flag.withDefault(false)),
|
|
209
|
-
server:
|
|
315
|
+
server: RunningServer
|
|
210
316
|
},
|
|
211
317
|
examples: [
|
|
212
318
|
{
|
|
@@ -222,6 +328,55 @@ const Cmd = make("codework", {
|
|
|
222
328
|
description: "Clear the anchor"
|
|
223
329
|
}
|
|
224
330
|
]
|
|
331
|
+
}), make("relink", {
|
|
332
|
+
description: "Move where a session's work, or one thread's, happens",
|
|
333
|
+
params: {
|
|
334
|
+
session: Argument.String("session-id").pipe(Argument.withDescription("The session to move")),
|
|
335
|
+
thread: Flag.String("thread").pipe(Flag.withDescription("Move only this thread: a thread ID, or main; omitted moves the session's default"), Flag.optional),
|
|
336
|
+
directory: Flag.String("directory").pipe(Flag.withAlias("C"), Flag.withDescription("Checkout to move into; the work keeps its position under it when that path exists there"), Flag.optional),
|
|
337
|
+
sandboxId: Flag.String("sandbox-id").pipe(Flag.withDescription("Sandbox instance to move to (default: local)"), Flag.optional),
|
|
338
|
+
json: JsonFlag,
|
|
339
|
+
server: RunningServer
|
|
340
|
+
},
|
|
341
|
+
examples: [{
|
|
342
|
+
command: "codework session relink ses_01h9 -C ~/work/api",
|
|
343
|
+
description: "Move the session to a local checkout"
|
|
344
|
+
}, {
|
|
345
|
+
command: "codework session relink ses_01h9 --thread thr_01ja --sandbox-id sbx_01k2",
|
|
346
|
+
description: "Run one thread in a sandbox, leaving the others where they are"
|
|
347
|
+
}]
|
|
348
|
+
})]
|
|
349
|
+
}),
|
|
350
|
+
make("thread", {
|
|
351
|
+
description: "Manage a session's threads",
|
|
352
|
+
commands: [make("list", {
|
|
353
|
+
description: "List a session's threads, newest first",
|
|
354
|
+
params: {
|
|
355
|
+
session: Argument.String("session-id").pipe(Argument.withDescription("The session")),
|
|
356
|
+
json: JsonFlag,
|
|
357
|
+
server: RunningServer
|
|
358
|
+
},
|
|
359
|
+
examples: [{
|
|
360
|
+
command: "codework thread list ses_01h9",
|
|
361
|
+
description: "List the session's threads"
|
|
362
|
+
}]
|
|
363
|
+
}), make("fork", {
|
|
364
|
+
description: "Start a new thread from a committed entry of a thread's history",
|
|
365
|
+
params: {
|
|
366
|
+
session: Argument.String("session-id").pipe(Argument.withDescription("The session")),
|
|
367
|
+
thread: Flag.String("thread").pipe(Flag.withDescription("Thread to fork: a thread ID, or main (default)"), Flag.optional),
|
|
368
|
+
at: Flag.String("at").pipe(Flag.withDescription("Keep history through this entry"), Flag.optional),
|
|
369
|
+
before: Flag.String("before").pipe(Flag.withDescription("Keep history up to this user entry, and print its text to edit"), Flag.optional),
|
|
370
|
+
json: JsonFlag,
|
|
371
|
+
server: RunningServer
|
|
372
|
+
},
|
|
373
|
+
examples: [{
|
|
374
|
+
command: "codework thread fork ses_01h9 --at 01jb",
|
|
375
|
+
description: "Continue the main thread's history through an entry in a new thread"
|
|
376
|
+
}, {
|
|
377
|
+
command: "codework thread fork ses_01h9 --thread thr_01ja --before 01jc",
|
|
378
|
+
description: "Branch just before a prompt, to send it again differently"
|
|
379
|
+
}]
|
|
225
380
|
})]
|
|
226
381
|
}),
|
|
227
382
|
make("plugin", {
|
|
@@ -299,7 +454,7 @@ const Cmd = make("codework", {
|
|
|
299
454
|
}),
|
|
300
455
|
make("reload", {
|
|
301
456
|
description: "Re-import configured plugins in a running server",
|
|
302
|
-
params: { server:
|
|
457
|
+
params: { server: RunningServer },
|
|
303
458
|
examples: [{
|
|
304
459
|
command: "codework plugin reload",
|
|
305
460
|
description: "Pick up edits to a local plugin without restarting"
|
|
@@ -457,4 +612,4 @@ function provide(node, handlers, context) {
|
|
|
457
612
|
//#endregion
|
|
458
613
|
export { Cmd as i, handlers as n, run as r, handler as t };
|
|
459
614
|
|
|
460
|
-
//# sourceMappingURL=runtime-
|
|
615
|
+
//# sourceMappingURL=runtime-CK2CunDw.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-CK2CunDw.mjs","names":["Spec.make","Otel.layer"],"sources":["../../src/framework/spec.ts","../../src/cli/cmd/cmd.ts","../../src/framework/otel.ts","../../src/framework/runtime.ts"],"sourcesContent":["import { Command } from \"effect/cli\";\n\n/**\n * A declarative command tree. Specs carry only the shape of a command -- its\n * name, parameters, description, and children -- so the whole CLI surface can\n * be read in one file. Handlers are attached separately by {@link Runtime}, which\n * keeps their imports (and the harness they pull in) off the startup path.\n */\n\nexport interface Example {\n\treadonly command: string;\n\treadonly description: string;\n}\n\ninterface Options<\n\tConfig extends Command.Command.Config,\n\tShared extends Command.Command.FlagConfig,\n\tCommands extends ReadonlyArray<Any>,\n> {\n\treadonly description?: string;\n\treadonly params?: Config;\n\t/** Flags declared here are also parsed by every descendant command. */\n\treadonly shared?: Shared;\n\treadonly examples?: ReadonlyArray<Example>;\n\treadonly commands?: Commands;\n}\n\nexport interface Node<\n\tName extends string,\n\t// The tree is heterogeneous, so a node has to accept any command shape here.\n\t// Concrete types are recovered per-command through `Runtime.Input`.\n\t// biome-ignore lint/suspicious/noExplicitAny: heterogeneous command tree\n\tSpec extends Command.Command<Name, any, any, any, any>,\n\tCommands extends Children,\n> {\n\treadonly name: Name;\n\treadonly spec: Spec;\n\treadonly commands: Commands;\n}\n\n// The command name is invariant on `Command`, so the erased node type has to\n// admit any name for concrete nodes to be assignable to it.\n// biome-ignore lint/suspicious/noExplicitAny: heterogeneous command tree\nexport type Any = Node<string, Command.Command<any, any, any, any, any>, Children>;\nexport type Children = Readonly<Record<string, Any>>;\n\ntype ChildrenOf<Commands extends ReadonlyArray<Any>> = {\n\treadonly [Node in Commands[number] as Node[\"name\"]]: Node;\n};\n\nexport function make<\n\tconst Name extends string,\n\tconst Config extends Command.Command.Config = {},\n\tconst Shared extends Command.Command.FlagConfig = {},\n\tconst Commands extends ReadonlyArray<Any> = [],\n>(name: Name, options: Options<Config, Shared, Commands> = {}) {\n\tlet spec = Command.make(name, options.params ?? ({} as Config)).pipe(\n\t\tCommand.withSharedFlags(options.shared ?? ({} as Shared)),\n\t);\n\tif (options.description !== undefined) spec = spec.pipe(Command.withDescription(options.description));\n\tif (options.examples !== undefined) spec = spec.pipe(Command.withExamples(options.examples));\n\treturn {\n\t\tname,\n\t\tspec,\n\t\tcommands: Object.fromEntries(\n\t\t\t(options.commands ?? []).map((command) => [command.name, command]),\n\t\t) as ChildrenOf<Commands>,\n\t};\n}\n\nexport * as Spec from \"./spec.ts\";\n","import { Model } from \"@codeworksh/aikit\";\nimport { Schema } from \"effect\";\nimport { Argument, Flag } from \"effect/cli\";\nimport { Spec } from \"../../framework/spec.ts\";\n\n/**\n * The full command surface of the `codework` CLI. Declarations only -- each\n * command's behaviour lives in `./handlers`, wired up in `src/index.ts`.\n */\n\nexport const thinkingLevels = Object.values(Model.ThinkingLevelEnum);\n\n/**\n * Every `auth` subcommand answers the same three questions: which provider,\n * whose credentials, and where they live. Only `login` needs anything more.\n */\nconst AuthParams = {\n\topenaiCodex: Flag.Boolean(\"openai-codex\").pipe(\n\t\tFlag.withDescription(\"Use OpenAI Codex OAuth\"),\n\t\tFlag.withDefault(false),\n\t),\n\tgithubCopilot: Flag.Boolean(\"github-copilot\").pipe(\n\t\tFlag.withDescription(\"Use GitHub Copilot OAuth (device flow)\"),\n\t\tFlag.withDefault(false),\n\t),\n\tserver: Flag.String(\"server\").pipe(Flag.withDescription(\"RPC server URL (ws://host:port/rpc/v1)\"), Flag.optional),\n\tauthFile: Flag.String(\"auth-file\").pipe(\n\t\tFlag.withDescription(\"Credential file (defaults to <home>/aikit/auth.json)\"),\n\t\tFlag.optional,\n\t),\n};\n\n/** Where the background server binds when `service` has to start one. */\nconst ServerAddress = {\n\thost: Flag.String(\"host\").pipe(\n\t\tFlag.withDescription(\"Host interface the background server binds\"),\n\t\tFlag.withDefault(\"127.0.0.1\"),\n\t),\n\tport: Flag.Int(\"port\").pipe(\n\t\tFlag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 65535 }))),\n\t\tFlag.withDescription(\"Port the background server listens on\"),\n\t\tFlag.withDefault(7433),\n\t),\n};\n\n/** For commands that only talk to a server that is already running. */\nconst RunningServer = Flag.String(\"server\").pipe(\n\tFlag.withDescription(\"RPC server URL (ws://host:port/rpc/v1)\"),\n\tFlag.withDefault(\"ws://127.0.0.1:7433/rpc/v1\"),\n);\n\n/** A thread's MCP server in a running server: every thread sharing its instance is affected. */\nconst McpControlParams = {\n\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\tsession: Flag.String(\"session\").pipe(Flag.withAlias(\"s\"), Flag.withDescription(\"The session\")),\n\tthread: Flag.String(\"thread\").pipe(\n\t\tFlag.withDescription(\"Thread of --session whose server it is: a thread ID, or main (default)\"),\n\t\tFlag.optional,\n\t),\n\tserver: RunningServer,\n};\n\nconst JsonFlag = Flag.Boolean(\"json\").pipe(\n\tFlag.withDescription(\"Print machine-readable output\"),\n\tFlag.withDefault(false),\n);\n\nexport const Cmd = Spec.make(\"codework\", {\n\tdescription: \"CodeWork Command Line Interface\",\n\tshared: {\n\t\tuserConfigDir: Flag.String(\"user-config-dir\").pipe(\n\t\t\tFlag.withDescription(\"Directory whose settings.jsonc replaces the user settings in --home\"),\n\t\t\tFlag.optional,\n\t\t),\n\t\thome: Flag.String(\"home\").pipe(\n\t\t\tFlag.withDescription(\"CodeWork home: user settings, credentials, cache and data (default: ~/.codework)\"),\n\t\t\tFlag.optional,\n\t\t),\n\t\tdatabase: Flag.String(\"database\").pipe(Flag.withDescription(\"SQLite database path or :memory:\"), Flag.optional),\n\t},\n\tcommands: [\n\t\tSpec.make(\"auth\", {\n\t\t\tdescription: \"Manage OAuth credentials\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"login\", {\n\t\t\t\t\tdescription: \"Sign in to a provider\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\t...AuthParams,\n\t\t\t\t\t\tbrowser: Flag.Boolean(\"browser\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Open the authorization URL in the default browser\"),\n\t\t\t\t\t\t\tFlag.withDefault(true),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdevice: Flag.Boolean(\"device\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Use the device-code flow instead of a localhost browser callback\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tenterprise: Flag.String(\"enterprise\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"GitHub Enterprise domain for GitHub Copilot login\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tenableModels: Flag.Boolean(\"enable-models\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Enable unconfigured Copilot catalog models after login\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework auth login --openai-codex\", description: \"Sign in with ChatGPT\" },\n\t\t\t\t\t\t{ command: \"codework auth login --github-copilot\", description: \"Sign in with GitHub Copilot\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework auth login --openai-codex --device\",\n\t\t\t\t\t\t\tdescription: \"Sign in with a device code, no local port\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework auth login --openai-codex --server ws://127.0.0.1:7433/rpc/v1\",\n\t\t\t\t\t\t\tdescription: \"Sign in the running server\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"status\", {\n\t\t\t\t\tdescription: \"Show a stored login without refreshing it\",\n\t\t\t\t\tparams: { ...AuthParams, json: JsonFlag },\n\t\t\t\t\texamples: [{ command: \"codework auth status --openai-codex\", description: \"Show the stored login\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"refresh\", {\n\t\t\t\t\tdescription: \"Refresh a stored login if it has expired\",\n\t\t\t\t\tparams: { ...AuthParams, json: JsonFlag },\n\t\t\t\t\texamples: [{ command: \"codework auth refresh --openai-codex\", description: \"Renew an expired login\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"logout\", {\n\t\t\t\t\tdescription: \"Clear a stored login\",\n\t\t\t\t\tparams: AuthParams,\n\t\t\t\t\texamples: [{ command: \"codework auth logout --github-copilot\", description: \"Clear the stored login\" }],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"mcp\", {\n\t\t\tdescription: \"Manage MCP servers\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"add\", {\n\t\t\t\t\tdescription: \"Add or replace a server in mcp.json\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name\")),\n\t\t\t\t\t\tcommand: Argument.String(\"command\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Command and arguments of a stdio server, after --\"),\n\t\t\t\t\t\t\tArgument.variadic({ min: 0 }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\turl: Flag.String(\"url\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Streamable HTTP server URL (instead of a command)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tenv: Flag.KeyValuePair(\"env\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Environment variable of a stdio server, as KEY=VALUE\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcwd: Flag.String(\"cwd\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Working directory of a stdio server\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\theader: Flag.KeyValuePair(\"header\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"HTTP header, as KEY=VALUE\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tbearerTokenEnvVar: Flag.String(\"bearer-token-env-var\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription('Send \"Authorization: Bearer ${NAME}\"'),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthClientId: Flag.String(\"oauth-client-id\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Pre-registered OAuth client id\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthClientSecret: Flag.String(\"oauth-client-secret\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"OAuth client secret (may be ${NAME} or !command)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthCallbackPort: Flag.Int(\"oauth-callback-port\").pipe(\n\t\t\t\t\t\t\tFlag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 }))),\n\t\t\t\t\t\t\tFlag.withDescription(\"Fixed OAuth callback port\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\toauthClientName: Flag.String(\"oauth-client-name\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Client name sent when registering with the OAuth server\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\texposure: Flag.Literals(\"exposure\", [\"direct\", \"hidden\", \"codemode\", \"deferred\"]).pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"How the model reaches the server's tools (default: direct)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdescription: Flag.String(\"description\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"What the server offers\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tlocal: Flag.Boolean(\"local\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"l\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Write the project's .codework/mcp.json instead of the user one\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp add fs -- npx -y @modelcontextprotocol/server-filesystem .\",\n\t\t\t\t\t\t\tdescription: \"Add a stdio server\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp add linear --url https://mcp.linear.app/mcp\",\n\t\t\t\t\t\t\tdescription: \"Add an HTTP server; sign in with codework mcp login linear\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp add tools -l --url http://127.0.0.1:8080/mcp\",\n\t\t\t\t\t\t\tdescription: \"Add a server to this project only\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"remove\", {\n\t\t\t\t\tdescription: \"Remove a server from mcp.json\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\t\t\t\t\t\tlocal: Flag.Boolean(\"local\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"l\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Remove it from the project's .codework/mcp.json instead of the user one\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework mcp remove linear\", description: \"Remove the linear server\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"list\", {\n\t\t\t\t\tdescription: \"Connect to every enabled server and show its state, tools and errors\",\n\t\t\t\t\tparams: { json: JsonFlag },\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework mcp list\", description: \"Check every configured server; exits 1 on a failure\" },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"login\", {\n\t\t\t\t\tdescription: \"Sign in to an MCP server with OAuth\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\t\t\t\t\t\tbrowser: Flag.Boolean(\"browser\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Open the authorization URL in the default browser\"),\n\t\t\t\t\t\t\tFlag.withDefault(true),\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttimeout: Flag.Int(\"timeout\").pipe(\n\t\t\t\t\t\t\tFlag.withSchema(Schema.Int.check(Schema.isGreaterThan(0))),\n\t\t\t\t\t\t\tFlag.withDescription(\"Seconds the whole sign-in may take\"),\n\t\t\t\t\t\t\tFlag.withDefault(300),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework mcp login linear\", description: \"Sign in to the linear server\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp login linear --browser=false\",\n\t\t\t\t\t\t\tdescription: \"Print the URL; paste the redirected URL back if the browser is elsewhere\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"logout\", {\n\t\t\t\t\tdescription: \"Remove the stored OAuth credentials of an MCP server\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tname: Argument.String(\"name\").pipe(Argument.withDescription(\"Server name in mcp.json\")),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework mcp logout linear\", description: \"Sign out of the linear server\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"reconnect\", {\n\t\t\t\t\tdescription: \"Connect a thread's MCP server afresh in a running server\",\n\t\t\t\t\tparams: McpControlParams,\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp reconnect linear --session ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Restart the linear server the main thread uses; its tools return from the next turn\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp reconnect linear --session ses_01h9 --thread thr_01ja\",\n\t\t\t\t\t\t\tdescription: \"Restart the one a thread of the session uses\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"disconnect\", {\n\t\t\t\t\tdescription: \"Close a thread's MCP server in a running server until it is reconnected\",\n\t\t\t\t\tparams: McpControlParams,\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework mcp disconnect linear --session ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Close the linear server the main thread uses\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"run\", {\n\t\t\tdescription: \"Start or continue an agent session\",\n\t\t\tparams: {\n\t\t\t\tserver: Flag.String(\"server\").pipe(\n\t\t\t\t\tFlag.withDescription(\"RPC server URL (ws://host:port/rpc/v1)\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tprompt: Argument.String(\"prompt\").pipe(Argument.withDescription(\"Prompt for the agent\")),\n\t\t\t\tsession: Flag.String(\"session\").pipe(\n\t\t\t\t\tFlag.withAlias(\"s\"),\n\t\t\t\t\tFlag.withDescription(\"Continue an existing session\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tthread: Flag.String(\"thread\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Thread of --session to continue: a thread ID, or main (default)\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tcwd: Flag.String(\"cwd\").pipe(\n\t\t\t\t\tFlag.withAlias(\"C\"),\n\t\t\t\t\tFlag.withDescription(\"Working directory for a new session\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tsandboxDriver: Flag.String(\"sandbox-driver\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Sandbox driver for a new session (default: local)\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tsandboxId: Flag.String(\"sandbox-id\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Reuse an existing sandbox instance\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tsandboxProviderId: Flag.String(\"sandbox-provider-id\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Provider ID of an existing remote sandbox\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t\tprovider: Flag.String(\"provider\").pipe(Flag.withDescription(\"Model catalog provider ID\"), Flag.optional),\n\t\t\t\tmodel: Flag.String(\"model\").pipe(Flag.withDescription(\"Model ID\"), Flag.optional),\n\t\t\t\tthinking: Flag.Literals(\"thinking\", thinkingLevels).pipe(\n\t\t\t\t\tFlag.withDescription(\"Reasoning effort the model uses before answering\"),\n\t\t\t\t\tFlag.optional,\n\t\t\t\t),\n\t\t\t},\n\t\t\texamples: [\n\t\t\t\t{ command: 'codework run \"Inspect the failing tests\"', description: \"Create a session\" },\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --provider openai --model gpt-5.5 --thinking high \"Inspect the failing tests\"',\n\t\t\t\t\tdescription: \"Create a session with an explicit model\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --sandbox-driver daytona \"Inspect the repository\"',\n\t\t\t\t\tdescription: \"Create a Daytona sandbox and session\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --sandbox-driver daytona --sandbox-provider-id <id> \"Inspect the repository\"',\n\t\t\t\t\tdescription: \"Use an existing remote sandbox\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --session <id> --provider openai --model gpt-5.6-luna \"Now fix them\"',\n\t\t\t\t\tdescription: \"Continue a session with explicit model bindings\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcommand: 'codework run --session <id> --thread <thread-id> \"Try OAuth instead\"',\n\t\t\t\t\tdescription: \"Continue one of the session's threads\",\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"serve\", {\n\t\t\tdescription: \"Start the CodeWork RPC server\",\n\t\t\tparams: {\n\t\t\t\thost: Flag.String(\"host\").pipe(\n\t\t\t\t\tFlag.withDescription(\"Host interface to bind\"),\n\t\t\t\t\tFlag.withDefault(\"127.0.0.1\"),\n\t\t\t\t),\n\t\t\t\tport: Flag.Int(\"port\").pipe(\n\t\t\t\t\tFlag.withSchema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 65535 }))),\n\t\t\t\t\tFlag.withDescription(\"Port to listen on (0 for an ephemeral port)\"),\n\t\t\t\t\tFlag.withDefault(7433),\n\t\t\t\t),\n\t\t\t\tservice: Flag.Boolean(\"service\").pipe(\n\t\t\t\t\tFlag.withDescription(\n\t\t\t\t\t\t\"Run as the background server `codework service` manages, logging to <home>/log/server.log\",\n\t\t\t\t\t),\n\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t),\n\t\t\t},\n\t\t\texamples: [\n\t\t\t\t{ command: \"codework serve\", description: \"Start the RPC server on 127.0.0.1:7433\" },\n\t\t\t\t{ command: \"codework serve --port 0\", description: \"Choose an available local port\" },\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"service\", {\n\t\t\tdescription: \"Manage the background server\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"start\", { description: \"Start the background server\", params: ServerAddress }),\n\t\t\t\tSpec.make(\"restart\", { description: \"Restart the background server\", params: ServerAddress }),\n\t\t\t\tSpec.make(\"status\", { description: \"Show background server status\" }),\n\t\t\t\tSpec.make(\"stop\", { description: \"Stop the background server\" }),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"session\", {\n\t\t\tdescription: \"Manage sessions\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"link\", {\n\t\t\t\t\tdescription: \"Anchor a session to a host directory\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session to link\")),\n\t\t\t\t\t\tpath: Argument.String(\"path\").pipe(\n\t\t\t\t\t\t\t// The anchor is not a configuration mechanism, but `.codework` is the landmark\n\t\t\t\t\t\t\t// a person recognises, so the help names it to make the directory concrete.\n\t\t\t\t\t\t\tArgument.withDescription(\n\t\t\t\t\t\t\t\t\"Host directory to anchor to — typically the directory holding your .codework configuration; defaults to the shell's\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tArgument.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tunlink: Flag.Boolean(\"unlink\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Clear the anchor, leaving the session with no host directory\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session link ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Link it to the directory you are standing in\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session link ses_01h9 ~/work/api\",\n\t\t\t\t\t\t\tdescription: \"Link it to a project elsewhere on this machine\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session link ses_01h9 --unlink\",\n\t\t\t\t\t\t\tdescription: \"Clear the anchor\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"relink\", {\n\t\t\t\t\tdescription: \"Move where a session's work, or one thread's, happens\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session to move\")),\n\t\t\t\t\t\tthread: Flag.String(\"thread\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\n\t\t\t\t\t\t\t\t\"Move only this thread: a thread ID, or main; omitted moves the session's default\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tdirectory: Flag.String(\"directory\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"C\"),\n\t\t\t\t\t\t\tFlag.withDescription(\n\t\t\t\t\t\t\t\t\"Checkout to move into; the work keeps its position under it when that path exists there\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tsandboxId: Flag.String(\"sandbox-id\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Sandbox instance to move to (default: local)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session relink ses_01h9 -C ~/work/api\",\n\t\t\t\t\t\t\tdescription: \"Move the session to a local checkout\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework session relink ses_01h9 --thread thr_01ja --sandbox-id sbx_01k2\",\n\t\t\t\t\t\t\tdescription: \"Run one thread in a sandbox, leaving the others where they are\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"thread\", {\n\t\t\tdescription: \"Manage a session's threads\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"list\", {\n\t\t\t\t\tdescription: \"List a session's threads, newest first\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session\")),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework thread list ses_01h9\", description: \"List the session's threads\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"fork\", {\n\t\t\t\t\tdescription: \"Start a new thread from a committed entry of a thread's history\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tsession: Argument.String(\"session-id\").pipe(Argument.withDescription(\"The session\")),\n\t\t\t\t\t\tthread: Flag.String(\"thread\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Thread to fork: a thread ID, or main (default)\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tat: Flag.String(\"at\").pipe(Flag.withDescription(\"Keep history through this entry\"), Flag.optional),\n\t\t\t\t\t\tbefore: Flag.String(\"before\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Keep history up to this user entry, and print its text to edit\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tjson: JsonFlag,\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework thread fork ses_01h9 --at 01jb\",\n\t\t\t\t\t\t\tdescription: \"Continue the main thread's history through an entry in a new thread\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework thread fork ses_01h9 --thread thr_01ja --before 01jc\",\n\t\t\t\t\t\t\tdescription: \"Branch just before a prompt, to send it again differently\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"plugin\", {\n\t\t\tdescription: \"Manage plugins\",\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"add\", {\n\t\t\t\t\tdescription: \"Install a plugin and add it to a settings file\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tpackage: Argument.String(\"package\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Package spec, path, or file: URL\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tglobal: Flag.Boolean(\"global\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"g\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Write the user-wide settings file instead of this project's\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tsession: Flag.String(\"session\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Write the project a session is linked to, rather than this directory's\"),\n\t\t\t\t\t\t\tFlag.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin add @acme/codework-tool-proc@1.2.0\",\n\t\t\t\t\t\t\tdescription: \"Install a published plugin into this project's settings\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin add @acme/codework-tool-proc --session ses_01h9\",\n\t\t\t\t\t\t\tdescription: \"Write the project that session is linked to, from anywhere\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin add @acme/codework-tool-proc -g\",\n\t\t\t\t\t\t\tdescription: \"Install it for every project this user runs\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"install\", {\n\t\t\t\t\tdescription: \"Install every plugin the settings files name\",\n\t\t\t\t\tparams: {},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin install\",\n\t\t\t\t\t\t\tdescription: \"Materialise what a fresh checkout already declares\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"list\", {\n\t\t\t\t\tdescription: \"List configured plugins and what each one resolved to\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tverbose: Flag.Boolean(\"verbose\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Show the message behind a failure, not only its reason\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [{ command: \"codework plugin list\", description: \"Show every configured plugin\" }],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"check\", {\n\t\t\t\t\tdescription: \"Report which configured plugins have a newer revision available\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tspec: Argument.String(\"spec\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Only this configured plugin: a package name or spec, git spec, or path\"),\n\t\t\t\t\t\t\tArgument.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// An answer is reused for an hour, which is right for a command someone may\n\t\t\t\t\t\t// run repeatedly and wrong for the minute after they pushed a plugin. Without\n\t\t\t\t\t\t// this there is no way to say \"ask again\", and `check` reports a moving branch\n\t\t\t\t\t\t// as current while `update` — which always refreshes — moves it.\n\t\t\t\t\t\trefresh: Flag.Boolean(\"refresh\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Ask the remote again instead of reusing a recent answer\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework plugin check\", description: \"Ask the registry what has moved\" },\n\t\t\t\t\t\t{ command: \"codework plugin check @acme/codework-tool-proc\", description: \"Ask about one plugin\" },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin check --refresh\",\n\t\t\t\t\t\t\tdescription: \"Ignore the cached answer, after pushing a plugin\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"update\", {\n\t\t\t\t\tdescription: \"Fetch a newer revision of every plugin that has one\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tspec: Argument.String(\"spec\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Only this configured plugin: a package name or spec, git spec, or path\"),\n\t\t\t\t\t\t\tArgument.optional,\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework plugin update\", description: \"Take whatever `check` found\" },\n\t\t\t\t\t\t{ command: \"codework plugin update @acme/codework-tool-proc\", description: \"Update one plugin\" },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"reload\", {\n\t\t\t\t\tdescription: \"Re-import configured plugins in a running server\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tserver: RunningServer,\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin reload\",\n\t\t\t\t\t\t\tdescription: \"Pick up edits to a local plugin without restarting\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"remove\", {\n\t\t\t\t\tdescription: \"Remove a plugin from a settings file\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tpackage: Argument.String(\"package\").pipe(\n\t\t\t\t\t\t\tArgument.withDescription(\"Configured package spec, path, or plugin ID\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tglobal: Flag.Boolean(\"global\").pipe(\n\t\t\t\t\t\t\tFlag.withAlias(\"g\"),\n\t\t\t\t\t\t\tFlag.withDescription(\"Edit the user-wide settings file instead of this project's\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcommand: \"codework plugin remove @acme/codework-tool-proc\",\n\t\t\t\t\t\t\tdescription: \"Drop a plugin and any configuration written against it\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"models\", {\n\t\t\tdescription: \"List or refresh the model catalog\",\n\t\t\tparams: {\n\t\t\t\tprovider: Flag.String(\"provider\").pipe(Flag.withDescription(\"Model catalog provider ID\"), Flag.optional),\n\t\t\t},\n\t\t\texamples: [\n\t\t\t\t{ command: \"codework models\", description: \"List all models from all providers\" },\n\t\t\t\t{\n\t\t\t\t\tcommand: \"codework models --provider openai\",\n\t\t\t\t\tdescription: \"List models for a specific provider\",\n\t\t\t\t},\n\t\t\t\t{ command: \"codework models providers\", description: \"List all available provider IDs\" },\n\t\t\t],\n\t\t\tcommands: [\n\t\t\t\tSpec.make(\"providers\", {\n\t\t\t\t\tdescription: \"List available model providers in the catalog\",\n\t\t\t\t}),\n\t\t\t\tSpec.make(\"refresh\", {\n\t\t\t\t\tdescription: \"Download the model catalog into the home if it is stale\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\tforce: Flag.Boolean(\"force\").pipe(\n\t\t\t\t\t\t\tFlag.withDescription(\"Download it even if it is still fresh\"),\n\t\t\t\t\t\t\tFlag.withDefault(false),\n\t\t\t\t\t\t),\n\t\t\t\t\t},\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{ command: \"codework models refresh\", description: \"Refresh a catalog older than 15 minutes\" },\n\t\t\t\t\t\t{ command: \"codework models refresh --force\", description: \"Download the catalog now\" },\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t\tSpec.make(\"acp\", {\n\t\t\tdescription: \"Start the CodeWork Agent Client Protocol (ACP) server over stdio\",\n\t\t\texamples: [{ command: \"codework acp\", description: \"Start the ACP server on stdio\" }],\n\t\t}),\n\t],\n});\n","import { Config, ConfigProvider, Effect, Layer, Metric, Option, References, Schema } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { OtlpMetrics, OtlpSerialization, OtlpTracer } from \"effect/observability\";\nimport { uuidv7 } from \"uuidv7\";\n\n// Configured by the standard `OTEL_*` variables alone. A configuration that fails\n// to build runs the command without export rather than failing it.\n\n// The OTel spec defaults `OTEL_{TRACES,METRICS}_EXPORTER` to `otlp`; Effect reads an\n// unset list as none, so an endpoint alone would export nothing.\nconst exporterDefaults = ConfigProvider.layerAdd(\n\tConfigProvider.fromUnknown({ OTEL_TRACES_EXPORTER: [\"otlp\"], OTEL_METRICS_EXPORTER: [\"otlp\"] }),\n);\n\n// Effect's fiber metrics hook every fiber start and end, so they follow metrics export.\nconst metricsEnabled = Config.all({\n\tdisabled: Config.Boolean(\"OTEL_SDK_DISABLED\").pipe(Config.withDefault(false)),\n\tendpoint: Config.String(\"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT\").pipe(\n\t\tConfig.orElse(() => Config.String(\"OTEL_EXPORTER_OTLP_ENDPOINT\")),\n\t\tConfig.option,\n\t),\n\texporters: Config.Array(Schema.String, \"OTEL_METRICS_EXPORTER\"),\n}).pipe(\n\tConfig.map(\n\t\t({ disabled, endpoint, exporters }) =>\n\t\t\t!disabled && Option.isSome(endpoint) && exporters.some((exporter) => exporter.trim().toLowerCase() === \"otlp\"),\n\t),\n);\n\nconst fiberMetrics = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\treturn (yield* metricsEnabled) ? Metric.enableRuntimeMetricsLayer : Layer.empty;\n\t}),\n);\n\n// Only spans marked `level: \"Info\"` are exported; the rest, Effect's own `sql.*`\n// among them, default to `Debug`. Effect drops a span's children with it, so every\n// span on the path from a command to a model or tool call must be `Info`.\nconst levels = { all: \"All\", trace: \"Trace\", debug: \"Debug\", info: \"Info\", warn: \"Warn\", error: \"Error\" } as const;\n\nconst traceLevels = Layer.unwrap(\n\tEffect.gen(function* () {\n\t\tconst name = yield* Config.String(\"CODEWORK_TRACE_LEVEL\").pipe(Config.withDefault(\"info\"));\n\t\tconst minimum = levels[name.trim().toLowerCase() as keyof typeof levels] ?? \"Info\";\n\t\treturn Layer.mergeAll(\n\t\t\tLayer.succeed(References.CurrentTraceLevel, \"Debug\"),\n\t\t\tLayer.succeed(References.MinimumTraceLevel, minimum),\n\t\t);\n\t}),\n);\n\ninterface OtlpResource {\n\treadonly serviceName: string;\n\treadonly serviceVersion: string;\n\treadonly attributes: Record<string, string>;\n}\n\n// Effect has no gRPC exporter: `grpc` exports nothing rather than sending HTTP to a gRPC port.\nconst exporters = (resource: OtlpResource) =>\n\tLayer.unwrap(\n\t\tEffect.gen(function* () {\n\t\t\tconst protocol = yield* Config.String(\"OTEL_EXPORTER_OTLP_PROTOCOL\").pipe(Config.withDefault(\"http/protobuf\"));\n\t\t\tconst format = {\n\t\t\t\t\"http/json\": OtlpSerialization.layerJson,\n\t\t\t\t\"http/protobuf\": OtlpSerialization.layerProtobuf,\n\t\t\t}[protocol.trim().toLowerCase()];\n\t\t\tif (format === undefined) return Layer.empty;\n\t\t\treturn Layer.mergeAll(\n\t\t\t\tOtlpTracer.layerFromConfig({ resource }),\n\t\t\t\tOtlpMetrics.layerFromConfig({ resource }),\n\t\t\t).pipe(Layer.provide(format));\n\t\t}),\n\t);\n\nconst channel = (version: string) =>\n\tversion.includes(\"-canary.\") ? \"canary\" : version.includes(\"-dev.\") ? \"dev\" : \"latest\";\n\nconst instanceId = uuidv7();\n\nexport const layer = (options: { readonly version: string; readonly command: string }) => {\n\tconst resource: OtlpResource = {\n\t\tserviceName: \"codework\",\n\t\tserviceVersion: options.version,\n\t\tattributes: {\n\t\t\t\"service.instance.id\": instanceId,\n\t\t\t\"deployment.environment.name\": channel(options.version),\n\t\t\t\"codework.command\": options.command,\n\t\t},\n\t};\n\treturn Layer.mergeAll(exporters(resource), fiberMetrics, traceLevels).pipe(\n\t\tLayer.provide(FetchHttpClient.layer),\n\t\tLayer.provide(exporterDefaults),\n\t\tLayer.catchCause(() => Layer.empty),\n\t);\n};\n\nexport * as Otel from \"./otel.ts\";\n","import { Effect } from \"effect\";\nimport { Command } from \"effect/cli\";\nimport type { CommandError } from \"../cli/error.ts\";\nimport { Otel } from \"./otel.ts\";\nimport { Spec } from \"./spec.ts\";\n\n/**\n * Binds handlers to a {@link Spec} tree. Handlers are loaded through dynamic\n * imports so that starting the process -- or printing `--help` -- never pulls in\n * the harness, its sandbox drivers, or the model catalog.\n */\n\n/** Recovers the parsed input type of a spec node, for typing its handler. */\nexport type Input<Value> =\n\tValue extends Spec.Node<infer _Name, infer Spec, infer _Commands>\n\t\t? Input<Spec>\n\t\t: Value extends Command.Command<infer _Name, infer Parsed, infer _Context, infer _Error, infer _Requirements>\n\t\t\t? Parsed\n\t\t\t: never;\n\n/**\n * A handler may yield an ancestor's spec to read its shared flags, which shows up\n * as a `CommandContext` requirement; `withSubcommands` discharges it when the tree\n * is assembled.\n */\ntype Requirements = Command.Environment | Command.CommandContext<string>;\ntype Run<Parsed> = (input: Parsed) => Effect.Effect<void, CommandError, Requirements>;\ntype Loader<Node extends Spec.Any> = () => Promise<{ readonly default: Run<Input<Node>> }>;\n\n/**\n * The handler registry for a spec tree: a loader per leaf, mirroring the shape of\n * the tree. A parent with children takes its own handler under `$`.\n */\nexport type Handlers<Node extends Spec.Any> = keyof Node[\"commands\"] extends never\n\t? Loader<Node>\n\t: { readonly $?: Loader<Node> } & { readonly [Key in keyof Node[\"commands\"]]: Handlers<Node[\"commands\"][Key]> };\n\ninterface LazyHandler {\n\treadonly spec: Command.Command.Any;\n\t// biome-ignore lint/suspicious/noExplicitAny: input is recovered per-command by `Input`\n\treadonly load: () => Promise<{ readonly default: Run<any> }>;\n}\n\ntype LazyHandlers = LazyHandler[\"load\"] | { readonly [key: string]: LazyHandlers | undefined };\n\ntype ProvidedCommand = Command.Command<string, unknown, unknown, CommandError, Command.Environment>;\n\n/** Type-checks a handler against the spec node it implements. */\nexport function handler<const Node extends Spec.Any>(_node: Node, run: Run<Input<Node>>) {\n\treturn run;\n}\n\nexport function handlers<const Root extends Spec.Any>(\n\troot: Root,\n\thandlers: Handlers<Root>,\n): ReadonlyArray<LazyHandler> {\n\tconst result: LazyHandler[] = [];\n\n\tfunction add(node: Spec.Any, value: LazyHandlers) {\n\t\tif (typeof value === \"function\") {\n\t\t\tresult.push({ spec: node.spec, load: value });\n\t\t\treturn;\n\t\t}\n\t\tif (value.$ !== undefined) result.push({ spec: node.spec, load: value.$ as LazyHandler[\"load\"] });\n\t\tfor (const [name, child] of Object.entries(node.commands)) {\n\t\t\tconst nested = value[name];\n\t\t\tif (nested !== undefined) add(child, nested);\n\t\t}\n\t}\n\n\tadd(root, handlers as LazyHandlers);\n\treturn result;\n}\n\nexport function run(root: Spec.Any, handlers: ReadonlyArray<LazyHandler>, options: { readonly version: string }) {\n\treturn Command.run(provide(root, handlers, { version: options.version, path: [] }), options);\n}\n\nfunction provide(\n\tnode: Spec.Any,\n\thandlers: ReadonlyArray<LazyHandler>,\n\tcontext: { readonly version: string; readonly path: ReadonlyArray<string> },\n): ProvidedCommand {\n\tconst found = handlers.find((entry) => entry.spec === node.spec);\n\tconst command = context.path.length === 0 ? node.name : context.path.join(\" \");\n\tconst spec = found\n\t\t? node.spec.pipe(\n\t\t\t\tCommand.withHandler((input) =>\n\t\t\t\t\tEffect.promise(found.load).pipe(\n\t\t\t\t\t\tEffect.flatMap((module) => module.default(input)),\n\t\t\t\t\t\tEffect.provide(Otel.layer({ version: context.version, command })),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t: node.spec;\n\tconst children = Object.values(node.commands);\n\tif (children.length === 0) return spec as ProvidedCommand;\n\treturn spec.pipe(\n\t\tCommand.withSubcommands(\n\t\t\tchildren.map((child) => provide(child, handlers, { ...context, path: [...context.path, child.name] })),\n\t\t),\n\t) as ProvidedCommand;\n}\n\nexport * as Runtime from \"./runtime.ts\";\n"],"mappings":";;;;;;;AAkDA,SAAgB,KAKd,MAAY,UAA6C,CAAC,GAAG;CAC9D,IAAI,OAAO,QAAQ,KAAK,MAAM,QAAQ,UAAW,CAAC,CAAY,CAAC,CAAC,KAC/D,QAAQ,gBAAgB,QAAQ,UAAW,CAAC,CAAY,CACzD;CACA,IAAI,QAAQ,gBAAgB,KAAA,GAAW,OAAO,KAAK,KAAK,QAAQ,gBAAgB,QAAQ,WAAW,CAAC;CACpG,IAAI,QAAQ,aAAa,KAAA,GAAW,OAAO,KAAK,KAAK,QAAQ,aAAa,QAAQ,QAAQ,CAAC;CAC3F,OAAO;EACN;EACA;EACA,UAAU,OAAO,aACf,QAAQ,YAAY,CAAC,EAAA,CAAG,KAAK,YAAY,CAAC,QAAQ,MAAM,OAAO,CAAC,CAClE;CACD;AACD;;;;;;;AC1DA,MAAa,iBAAiB,OAAO,OAAO,MAAM,iBAAiB;;;;;AAMnE,MAAM,aAAa;CAClB,aAAa,KAAK,QAAQ,cAAc,CAAC,CAAC,KACzC,KAAK,gBAAgB,wBAAwB,GAC7C,KAAK,YAAY,KAAK,CACvB;CACA,eAAe,KAAK,QAAQ,g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