@ngockhoale/ckit 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +12 -33
- package/README.md +15 -57
- package/dist/src/cli/ckit.js +6 -94
- package/dist/src/cli/lifecycle.d.ts +19 -0
- package/dist/src/cli/lifecycle.js +90 -0
- package/dist/src/cli/setup.js +1 -1
- package/dist/src/gui/server.js +60 -6
- package/dist/src/team/cli-args.d.ts +10 -0
- package/dist/src/team/cli-args.js +58 -0
- package/dist/src/team/config.js +208 -9
- package/dist/src/team/engine.d.ts +19 -1
- package/dist/src/team/engine.js +503 -109
- package/dist/src/team/runners.d.ts +6 -0
- package/dist/src/team/runners.js +47 -13
- package/dist/src/team/types.d.ts +92 -10
- package/dist/src/team/types.js +17 -1
- package/dist/src/tui/team/app.js +12 -12
- package/dist/src/tui/team/model.d.ts +23 -12
- package/dist/src/tui/team/model.js +25 -9
- package/gui/app.css +21 -1
- package/gui/app.js +310 -63
- package/gui/index.html +2 -2
- package/gui/network.js +38 -13
- package/package.json +2 -3
package/.env.example
CHANGED
|
@@ -1,42 +1,21 @@
|
|
|
1
|
-
# CKit
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
#
|
|
1
|
+
# CKit KHÔNG cần file .env để chạy: agent dùng đăng nhập của chính codex / claude / omp,
|
|
2
|
+
# còn CLI + model của từng agent chỉnh trong giao diện (nút Config), lưu ở .ckit/team.json.
|
|
3
|
+
#
|
|
4
|
+
# File này chỉ để tùy chỉnh giao diện web "ckit gui". Cần thì sao chép thành .env trong thư mục
|
|
5
|
+
# bạn chạy "ckit gui" (không commit .env), bỏ dấu # ở dòng muốn dùng rồi điền giá trị.
|
|
6
|
+
# Thứ tự ưu tiên: cờ (--host / --port / --lan) > biến môi trường shell > file .env > .ckit/gui.json > mặc định.
|
|
6
7
|
# Đổi xong phải dừng (Ctrl+C) và chạy lại "ckit gui"; mở đúng link mà lệnh in ra.
|
|
7
8
|
|
|
8
|
-
# Địa chỉ lắng nghe. Mặc định 127.0.0.1 = chỉ máy này
|
|
9
|
-
# (HTTP thường, không mã hóa; ai có link đều điều khiển được agent).
|
|
9
|
+
# Địa chỉ lắng nghe. Mặc định 127.0.0.1 = chỉ máy này mở được.
|
|
10
|
+
# 0.0.0.0 = máy khác trong mạng LAN mở được (HTTP thường, không mã hóa; ai có link đều điều khiển được agent).
|
|
10
11
|
# CKIT_GUI_HOST=
|
|
11
12
|
|
|
12
|
-
# Cổng cố định (1..65535). Mặc định 4317.
|
|
13
|
+
# Cổng cố định (1..65535). Mặc định 4317; nếu cổng bận và không đặt cố định, CKit tự chọn cổng khác.
|
|
13
14
|
# CKIT_GUI_PORT=
|
|
14
15
|
|
|
15
|
-
# Token cố định để link không đổi mỗi lần chạy: 16..128 ký
|
|
16
|
-
# Bỏ trống = token ngẫu nhiên mỗi lần. Coi như mật khẩu, không commit.
|
|
16
|
+
# Token cố định để link không đổi sau mỗi lần chạy: 16..128 ký tự, chỉ gồm A-Z a-z 0-9 _ -
|
|
17
|
+
# Bỏ trống hoặc sai định dạng = token ngẫu nhiên mỗi lần chạy. Coi token như mật khẩu, không commit.
|
|
17
18
|
# CKIT_GUI_TOKEN=
|
|
18
19
|
|
|
19
20
|
# Từ máy khác mở: http://<IP-của-máy-này>:<cổng>/?t=<token>
|
|
20
|
-
|
|
21
|
-
# ---- Advisor API cho "ckit run" (chỉ cần khi dùng ckit run) ----
|
|
22
|
-
# URL gốc endpoint OpenAI-compatible, PHẢI gồm phần phiên bản, ví dụ: https://<host>/v1
|
|
23
|
-
CKIT_OPENAI_BASE_URL=
|
|
24
|
-
|
|
25
|
-
# API key. Chỉ gửi tới endpoint ở trên; không bao giờ gửi cho executor, log hay giao diện.
|
|
26
|
-
# Endpoint không cần key: để trống và đặt CKIT_OPENAI_AUTH=none
|
|
27
|
-
CKIT_OPENAI_API_KEY=
|
|
28
|
-
CKIT_OPENAI_AUTH=
|
|
29
|
-
|
|
30
|
-
# Model của advisor.
|
|
31
|
-
CKIT_OPENAI_MODEL=
|
|
32
|
-
|
|
33
|
-
# Executor chạy việc trong dự án: claude-code (mặc định) hoặc omp; và model của nó (tùy chọn).
|
|
34
|
-
CKIT_EXECUTOR=
|
|
35
|
-
CKIT_EXECUTOR_MODEL=
|
|
36
|
-
|
|
37
|
-
# Cho worker claude-code được ghi file: acceptEdits hoặc dontAsk. Mặc định tắt (không ghi được file).
|
|
38
|
-
# CKIT_EXECUTOR_PERMISSION_MODE=
|
|
39
|
-
|
|
40
|
-
# Nâng cao, hiếm khi cần (xem README): CKIT_ADVISOR_PROVIDER, CKIT_PRIMARY_MODEL, CKIT_REVIEWER_MODEL, CKIT_REVIEWERS,
|
|
41
|
-
# CKIT_OPENAI_TIMEOUT_MS, CKIT_OPENAI_MAX_TOKENS, CKIT_EXECUTOR_PATH, CKIT_EXECUTOR_TIMEOUT_MS, CKIT_VERIFY_ALLOW,
|
|
42
|
-
# CKIT_VERIFY_TIMEOUT_MS, CKIT_MAX_TASKS
|
|
21
|
+
# (nếu không vào được, kiểm tra Firewall của macOS có chặn "node" không).
|
package/README.md
CHANGED
|
@@ -6,16 +6,18 @@ nothing here is a released product, and no live provider/agent integration is cl
|
|
|
6
6
|
## Use it like a normal app
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
|
-
npm install -g @ngockhoale/ckit
|
|
10
|
-
|
|
11
|
-
ckit
|
|
12
|
-
|
|
13
|
-
ckit
|
|
9
|
+
npm install -g @ngockhoale/ckit # once per machine
|
|
10
|
+
cd your-project
|
|
11
|
+
ckit install # once per project: writes .ckit/team.json (an existing one is kept)
|
|
12
|
+
ckit # opens the GUI in this folder; agents read and write files here
|
|
13
|
+
ckit update # later: upgrade to the newest version from npm (ckit update --check only looks)
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
No env file and no API key are needed: every agent uses the login of its own CLI (`codex`, `claude`, `omp`). Pick the CLI and model per agent in the GUI (Config).
|
|
17
|
+
|
|
16
18
|
## Agent Company (team mode)
|
|
17
19
|
|
|
18
|
-
A Director plus Team BA (2 agents discuss, then write one handoff) → Team Implement → Team QC (2 reviewers; FAIL returns to Implement, up to `limits.qcLoops`) →
|
|
20
|
+
A Director plus Team BA (2 agents discuss, then write one handoff) → Team Implement → Team QC (2 reviewers; FAIL returns to Implement, up to `limits.qcLoops`) → (optional) Director review against your original request → Director delivery report. Inside a team the agents discuss in bounded rounds (`limits.baRounds`, early stop on AGREED), the lead writes one `### HANDOFF` (DONE / DECISIONS / OPEN / FOR YOU) and the next team gets it in full. Before any team starts the Director triages the request (PROCEED / NEED INFO, up to 3 rounds, no turns are spent while it waits for you / CANNOT DO, shown as `declined`); runs live only in the CKit process that started them, so a run waiting for your answer is not resumed after a restart and shows in Runs as interrupted. You always talk to the Director; it can continue, redirect or stop the run.
|
|
19
21
|
|
|
20
22
|
```bash
|
|
21
23
|
ckit # no command, in a terminal: opens the GUI. First time in a project it lands on Config so setup is done there
|
|
@@ -26,47 +28,11 @@ ckit team --demo # same pipeline in the terminal, fully SIMULATED (no mo
|
|
|
26
28
|
ckit team "<goal>" # real run with the agents in <project>/.ckit/team.json (codex / claude-code / omp / api)
|
|
27
29
|
ckit team --init # write the default .ckit/team.json (--force overwrites)
|
|
28
30
|
```
|
|
31
|
+
- Teams are configurable in Config: only the Director is mandatory; BA, Implement and QC can each be removed or re-added, and `+ Add team` creates your own team (`extraTeams` in `.ckit/team.json`: name, mission, agents). All teams follow one numbered flow, `order` (e.g. `["ba","implement","test","qc"]`, reorder with the arrows in Config; absent = ba, implement, qc with custom teams placed by the old `runAfter`): work goes Director -> team 1 -> team 2 ..., each team gets the Director's brief and the previous team's output. A team can end its message with `ASK PREVIOUS: <question>` (the team before it, or the Director, answers) or `RETURN TO PREVIOUS: <reason>` (QC's FAIL means the same); both are limited to `limits.qcLoops` per team boundary ("Max send-backs per team"). Each agent (Director too) also has an optional `cliArgs` text box ("Extra CLI arguments"), e.g. `--settings ./other-settings.json`: it is split like a shell would (quotes group, no `~` or `$VAR` expansion), appended to that agent's start command after CKit's own flags and before the prompt, and empty means not used.
|
|
29
32
|
|
|
30
33
|
Every run is journaled to `.ckit/team/runs/<runId>/` (`events.jsonl`, `handoff-ba.md`, `qc-report-N.md`, `transcript.md`, `report.md`). Real agents use their own CLI login; codex runs `read-only` unless the agent has `access: "write"` (then `workspace-write`), claude uses `acceptEdits` only for write access, never bypass.
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## Quick start (API advisor)
|
|
35
|
-
|
|
36
|
-
No browser login is needed. The advisor is any OpenAI-compatible HTTP endpoint; the executor is your own `claude` (Claude Code) or `omp` CLI.
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
cp .env.example .env # then fill the variables below; never commit .env
|
|
40
|
-
# CKIT_OPENAI_BASE_URL=https://<host>/v1 (must include the version segment; CKit appends only /chat/completions)
|
|
41
|
-
# CKIT_OPENAI_API_KEY=<key> (or CKIT_OPENAI_AUTH=none for a keyless endpoint)
|
|
42
|
-
# CKIT_OPENAI_MODEL=<model>
|
|
43
|
-
# CKIT_EXECUTOR=claude-code (or omp)
|
|
44
|
-
npx ckit doctor # offline config check, no network
|
|
45
|
-
npx ckit doctor --check-connection # optional: exactly one GET <base>/models
|
|
46
|
-
npx ckit run "<goal>" # planned run: Primary plans tasks + acceptance checks -> executor runs each task -> CKit verifies -> reviewers -> Primary verdict
|
|
47
|
-
npx ckit run --single "<goal>" # one instruction, one executor run, no acceptance checks (previous flow)
|
|
48
|
-
npx ckit run --single "<goal>" --project=/path/to/scratch --config-root=/path/with/.env # settings from one folder, worker edits only the other
|
|
49
|
-
npx ckit status # latest session with outcome / advisor delivery / worker execution / acceptance (read-only)
|
|
50
|
-
npx ckit tui # Mission Control, live: in a terminal it re-reads the journal every 0.7 s, so a `ckit run` in another terminal shows up as it happens (read-only, no requests; `q` quits)
|
|
51
|
-
npx ckit sessions # list recorded sessions (read-only)
|
|
52
|
-
npx ckit open <sessionId> # one session's outcome and events (read-only, no requests)
|
|
53
|
-
npx ckit replay <sessionId> # replay the journal (inert: never resends)
|
|
54
|
-
npx ckit backup <dest-dir> # copy .ckit journal + artifacts (regular files only)
|
|
55
|
-
npx ckit restore <backup-dir> # hash-checked restore with rollback; refused while a run holds the lock; a backup from another project needs --allow-other-project
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Pause/resume of a running session is not available yet; Ctrl-C stops the worker (a second Ctrl-C kills its process group).
|
|
59
|
-
|
|
60
|
-
- The config file is `<project root>/.env`, where the project root is the nearest directory with `.ckit/project.json` (then `.git`); `--project=<path>` overrides. Flags `--executor`, `--model`, `--reviewers` override the matching variables.
|
|
61
|
-
- Planned run: the Primary replies with a JSON plan (at most `CKIT_MAX_TASKS`, default 6); each task needs at least one required automatic check (`command` or `file-exists`). CKit runs the checks itself, without a shell, in the project root. A task is `verified` only when every required check passes; a Primary or reviewer ACCEPT never overrides a failed check, and the run exits 0 only when every task is verified and the verdict is ACCEPT.
|
|
62
|
-
- Acceptance commands must start with an entry of `CKIT_VERIFY_ALLOW` (whole-token match; default `npm test`, `npm run build`, `npm run lint`, `npm run typecheck`, `npx tsc --noEmit`, `node --test`, `pytest`, `go test`, `cargo test`, `make test`) and contain no shell metacharacters. `CKIT_VERIFY_TIMEOUT_MS` bounds each check. An invalid plan stops the run with no task executed and no re-request.
|
|
63
|
-
- Supported dialect: Chat Completions, non-streaming only (`stream:false`). No Responses API, no streaming, no tools. `usage` is optional.
|
|
64
|
-
- The executor uses its own login, config and permissions. CKit never passes any `CKIT_*` variable to it and never changes its config. Any other inherited variable whose value equals or contains the advisor key is withheld, except the worker's own credential variable for the selected executor (claude-code: `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_API_KEY`; omp: none) when you set it yourself with exactly that value (ADR-017, 2026-11-08). `ckit doctor` and `ckit run` print the withheld names and `worker auth: present|missing` (never values, validity not checked) before any advisor request.
|
|
65
|
-
- Headless `claude -p` cannot ask anyone to approve a file edit, so by default the worker cannot write files. To let it edit inside the workspace, set `CKIT_EXECUTOR_PERMISSION_MODE=acceptEdits` (or `dontAsk`) in your own `.env`. It is off by default; `bypassPermissions` and `--dangerously-skip-permissions` are refused. omp ignores this field and says so.
|
|
66
|
-
- What is sent to the endpoint: only the goal, the Primary instruction, the executor result text and reviewer opinions, each passed through secret redaction first.
|
|
67
|
-
- One request per step, no automatic resend or retry, and no fallback to another endpoint. A failed or uncertain step stops the run and is journaled.
|
|
68
|
-
- Mock/local test results are OFFLINE evidence only; a live endpoint check needs your own `.env`.
|
|
69
|
-
- Browser advisors are deferred and not part of this flow.
|
|
35
|
+
`ckit gui` network settings (all optional): flags > shell env > the folder's env file > `.ckit/gui.json` > default `127.0.0.1:4317`; see `.env.example`. The earlier `ckit run` command (API advisor + single executor) was removed on 2026-11-14; use the GUI or `ckit team`.
|
|
70
36
|
|
|
71
37
|
## Quick start (contributor)
|
|
72
38
|
|
|
@@ -76,24 +42,13 @@ npm run build # strict tsc build -> dist/
|
|
|
76
42
|
npm test # node:test suite over dist/
|
|
77
43
|
npm run demo # minimal task flow through the SIMULATED advisor (offline, no external send)
|
|
78
44
|
npm run demo:fault # same flow with an injected ack-lost fault -> unknown outcome, no resend
|
|
79
|
-
npm run try # walk through the real `ckit run` flow offline: local mock advisor + fake worker in a temp project,
|
|
80
|
-
# then `doctor`, `status`, `sessions`; prints the command to open Mission Control on that run
|
|
81
45
|
```
|
|
82
46
|
|
|
83
47
|
Requirements: Node.js >= 22 (observed on v22.22.1, macOS arm64).
|
|
84
48
|
|
|
85
|
-
##
|
|
49
|
+
## Requirements
|
|
86
50
|
|
|
87
|
-
Published on npm as `@ngockhoale/ckit` (owner decision 2026-11-14
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
npm install -g @ngockhoale/ckit # update later with the same command
|
|
91
|
-
cd your-project && ckit # opens the GUI; first time it lands on Config
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Each machine needs its own logged-in agent CLIs (`codex`, `claude`, `omp`); CKit ships no credentials.
|
|
95
|
-
|
|
96
|
-
Requirements: Node.js >= 22 (uses `node:sqlite`, which prints an ExperimentalWarning on 22.x). Runtime deps: `ink`, `react` (MIT; lockfile licenses allowlisted by `test/security-supply-chain.test.ts`). Verified clean install on macOS arm64 / Node 22.22.1 only; other platforms are unverified. Live provider/native-agent integration is **not** included (T00-03/T00-04/T10-02 gates), so this package is a local preview, not a finished product.
|
|
51
|
+
Requirements: Node.js >= 22 (uses `node:sqlite`, which prints an ExperimentalWarning on 22.x). Runtime deps: `ink`, `react` (MIT; lockfile licenses allowlisted by `test/security-supply-chain.test.ts`). Used on macOS arm64 / Node 22.22.1 only so far; other platforms are unverified. Published on npm as `@ngockhoale/ckit` (owner decision 2026-11-14).
|
|
97
52
|
|
|
98
53
|
## What exists now
|
|
99
54
|
|
|
@@ -115,3 +70,6 @@ the exact shape the UI will consume. ADR-016 records the hand-written state mach
|
|
|
115
70
|
- Published as `@ngockhoale/ckit`; publish only on the owner's request, after `npm test` passes.
|
|
116
71
|
- Simulated adapter output must stay labeled `simulated`; live evidence requires a `live` provenance ref.
|
|
117
72
|
- Unknown external outcomes stop the flow (`needsReconciliation`); the core never blind-resends.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Optional project-wide `systemPrompt` (Config, "System prompt (optional)") is sent to every agent; empty means prompts are unchanged. Each prompt box has an Enhance button that shows a proposal next to your text and applies it only when you press "Use this". Optional `lanes` (`[{id, name, when, order}]`) let the Director pick which teams a request needs (it answers `LANE: <id>`; the owner can fix a lane in the composer); without lanes the single `order` flow runs as before.
|
package/dist/src/cli/ckit.js
CHANGED
|
@@ -28,9 +28,8 @@ import { buildDiagnosticBundle, describeConnection, formatDoctorReport, projectK
|
|
|
28
28
|
import { hasAnyAdvisorConfig, loadCkitConfig, maskedConfigSummary, resolveProjectRoot } from '../settings/env-config.js';
|
|
29
29
|
import { checkConnection } from '../adapters/openai/openai-advisor.js';
|
|
30
30
|
import { describeWorkerEnv, describeWorkerPermission, executorEnvironmentReport, resolveExecutable, selectExecutor } from '../adapters/launch/executor.js';
|
|
31
|
-
import { runApiTask } from '../run/api-run.js';
|
|
32
|
-
import { runPlannedTask } from '../run/plan-run.js';
|
|
33
31
|
import { runSetup } from './setup.js';
|
|
32
|
+
import { runInstallCommand, runUpdateCommand } from './lifecycle.js';
|
|
34
33
|
import { runGuiCommand } from '../gui/server.js';
|
|
35
34
|
import { loadTeamConfig, writeDefaultTeamConfig } from '../team/config.js';
|
|
36
35
|
import { startTeamRun } from '../team/engine.js';
|
|
@@ -177,7 +176,7 @@ function advisorDoctorState(root) {
|
|
|
177
176
|
const loaded = loadCkitConfig({ projectRoot: root });
|
|
178
177
|
return loaded.ok ? { state: 'ok', summary: maskedConfigSummary(loaded.config), versionHint: !/\/v\d+(\/|$)/i.test(new URL(loaded.config.baseUrl).pathname) } : { state: 'invalid', variables: [...new Set(loaded.issues.map(issue => issue.variable))], problems: loaded.issues.map(issue => ({ variable: issue.variable, problem: issue.problem })) };
|
|
179
178
|
}
|
|
180
|
-
/** Executor as
|
|
179
|
+
/** Executor as the team/advisor config resolves it (same selectExecutor/resolveExecutable); undefined when the advisor config is absent or invalid. */
|
|
181
180
|
function executorDoctorState(root) {
|
|
182
181
|
if (!hasAnyAdvisorConfig(root))
|
|
183
182
|
return undefined;
|
|
@@ -238,94 +237,6 @@ async function showDoctor(flags) {
|
|
|
238
237
|
}
|
|
239
238
|
return report.overall === 'fail' || connectionFailed ? 1 : 0;
|
|
240
239
|
}
|
|
241
|
-
const RUN_USAGE = 'usage: ckit run "<goal>" [--single] [--project=<path>] [--config-root=<dir>] [--executor=claude-code|omp] [--model=<m>] [--reviewers=<n>]';
|
|
242
|
-
async function showRun(args) {
|
|
243
|
-
const overrides = {};
|
|
244
|
-
let project, goal, configRootArg, single = false;
|
|
245
|
-
for (const arg of args) {
|
|
246
|
-
const eq = arg.indexOf('=');
|
|
247
|
-
const [name, value] = arg.startsWith('--') && eq > 2 ? [arg.slice(0, eq), arg.slice(eq + 1)] : [arg, ''];
|
|
248
|
-
if (arg === '--single')
|
|
249
|
-
single = true;
|
|
250
|
-
else if (name === '--project' && value)
|
|
251
|
-
project = value;
|
|
252
|
-
else if (name === '--config-root' && value)
|
|
253
|
-
configRootArg = value;
|
|
254
|
-
else if (name === '--executor' && value)
|
|
255
|
-
overrides['CKIT_EXECUTOR'] = value;
|
|
256
|
-
else if (name === '--model' && value)
|
|
257
|
-
overrides['CKIT_OPENAI_MODEL'] = value;
|
|
258
|
-
else if (name === '--reviewers' && value)
|
|
259
|
-
overrides['CKIT_REVIEWERS'] = value;
|
|
260
|
-
else if (!arg.startsWith('--') && goal === undefined)
|
|
261
|
-
goal = arg;
|
|
262
|
-
else
|
|
263
|
-
throw new TypeError(RUN_USAGE);
|
|
264
|
-
}
|
|
265
|
-
if (goal === undefined)
|
|
266
|
-
throw new TypeError(RUN_USAGE);
|
|
267
|
-
const root = resolveProjectRoot(process.cwd(), project);
|
|
268
|
-
let configRoot = root;
|
|
269
|
-
if (configRootArg !== undefined) {
|
|
270
|
-
try {
|
|
271
|
-
configRoot = realpathSync(resolve(configRootArg));
|
|
272
|
-
if (!statSync(configRoot).isDirectory())
|
|
273
|
-
throw new Error('not a directory');
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
console.error('ckit: --config-root must be an existing directory. Fix: pass --config-root=<dir> where <dir> contains the settings file, or omit the flag to use the project root.');
|
|
277
|
-
return 2;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const loaded = loadCkitConfig({ projectRoot: configRoot, overrides });
|
|
281
|
-
if (!loaded.ok) {
|
|
282
|
-
console.error('ckit: advisor configuration is not valid:');
|
|
283
|
-
for (const issue of loaded.issues)
|
|
284
|
-
console.error(` ${issue.variable}: ${issue.problem}. ${issue.fix}`);
|
|
285
|
-
return 2;
|
|
286
|
-
}
|
|
287
|
-
const spec = selectExecutor(loaded.config);
|
|
288
|
-
let executorPath;
|
|
289
|
-
try {
|
|
290
|
-
executorPath = resolveExecutable(spec, loaded.config);
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
console.error(`ckit: ${error instanceof Error ? error.message : 'executor not available'}`);
|
|
294
|
-
return 2;
|
|
295
|
-
}
|
|
296
|
-
safeText(goal);
|
|
297
|
-
const { binding, stateDir } = await canonicalProject(root);
|
|
298
|
-
const journal = { projectId: binding.projectId, stateDir, read: () => readEvents(join(stateDir, EVENTS_FILE)), write: events => writeEvents(stateDir, events), lock: operation => withJournalLock(stateDir, operation) };
|
|
299
|
-
console.log(`ckit run: ${maskedConfigSummary(loaded.config)}`);
|
|
300
|
-
console.log(`config: ${loaded.configFile ?? 'none (process env only)'}`);
|
|
301
|
-
console.log(`workspace: ${binding.canonicalCwd}`);
|
|
302
|
-
const base = { projectRoot: binding.canonicalCwd, goal, config: loaded.config, journal, executorSpec: spec, executorPath };
|
|
303
|
-
// The worker runs in its own process group (detached), so a terminal Ctrl-C no longer reaches it.
|
|
304
|
-
// Forward SIGINT/SIGTERM into the run's AbortSignal: the executor's cancelled path group-kills the worker,
|
|
305
|
-
// the outcome is journaled cancelled/unknown (never success), and nothing is resent.
|
|
306
|
-
// Exit code for an interrupted run: 130 (SIGINT) or 143 (SIGTERM), the shell convention 128+signal. A repeat signal escalates to SIGKILL.
|
|
307
|
-
const controller = new AbortController(), hard = new AbortController();
|
|
308
|
-
let interruptedBy;
|
|
309
|
-
// process.on (not once): a repeat signal during the kill grace must not reach Node's default action, which would exit
|
|
310
|
-
// ckit and leave a SIGTERM-ignoring worker orphaned. The first signal aborts; a repeat escalates to SIGKILL on the group.
|
|
311
|
-
const onSignal = (sig) => { if (interruptedBy === undefined) {
|
|
312
|
-
interruptedBy = sig;
|
|
313
|
-
controller.abort();
|
|
314
|
-
}
|
|
315
|
-
else
|
|
316
|
-
hard.abort(); };
|
|
317
|
-
const onSigint = () => onSignal('SIGINT'), onSigterm = () => onSignal('SIGTERM');
|
|
318
|
-
process.on('SIGINT', onSigint);
|
|
319
|
-
process.on('SIGTERM', onSigterm);
|
|
320
|
-
try {
|
|
321
|
-
const result = await (single ? runApiTask({ ...base, signal: controller.signal, hardKill: hard.signal }) : runPlannedTask({ ...base, signal: controller.signal, hardKill: hard.signal }));
|
|
322
|
-
return interruptedBy === undefined ? result.exitCode : interruptedBy === 'SIGINT' ? 130 : 143;
|
|
323
|
-
}
|
|
324
|
-
finally {
|
|
325
|
-
process.removeListener('SIGINT', onSigint);
|
|
326
|
-
process.removeListener('SIGTERM', onSigterm);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
240
|
/** Mission options for `ckit tui`: one read-only Plan snapshot, REPLAY mode (no side effects); the Actions panel is bound to nothing, so every control is disabled with a reason. */
|
|
330
241
|
export async function buildTuiMissionOptions(cwd, width = Math.max(20, (process.stdout.columns ?? 80) - 4)) {
|
|
331
242
|
const plan = await readMissionPlan(cwd);
|
|
@@ -352,7 +263,7 @@ async function showTui() {
|
|
|
352
263
|
const mission = await buildTuiMissionOptions(cwd);
|
|
353
264
|
try {
|
|
354
265
|
// Ctrl-C quits through Ink's default exitOnCtrlC; `q` unmounts via onQuit.
|
|
355
|
-
// TTY: live follow — re-reads the journal (read-only) so a
|
|
266
|
+
// TTY: live follow — re-reads the journal (read-only) so a run in another terminal shows up as it happens.
|
|
356
267
|
if (process.stdin.isTTY) {
|
|
357
268
|
const load = async () => (await getProjectEvents()).events;
|
|
358
269
|
const instance = render(React.createElement(LiveApp, { initial: events, load, ...(setup ? { setupModel: setup.model } : {}), viewOptions: { viewKeys: true, mission, onQuit: () => instance.unmount() } }));
|
|
@@ -432,10 +343,11 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
432
343
|
await showTui();
|
|
433
344
|
return 0;
|
|
434
345
|
case 'setup': return await runSetup(rest);
|
|
346
|
+
case 'install': return await runInstallCommand(rest);
|
|
347
|
+
case 'update': return await runUpdateCommand(rest);
|
|
435
348
|
case 'gui': return await runGuiCommand(rest);
|
|
436
349
|
case 'team': return await showTeam(rest);
|
|
437
350
|
case 'doctor': return await showDoctor(rest);
|
|
438
|
-
case 'run': return await showRun(rest);
|
|
439
351
|
case 'sessions': return await showSessions(rest);
|
|
440
352
|
case 'open': return await showOpen(rest);
|
|
441
353
|
case 'replay': return await showReplay(rest);
|
|
@@ -451,7 +363,7 @@ export async function main(args = process.argv.slice(2)) {
|
|
|
451
363
|
case undefined: if (process.stdin.isTTY === true && process.stdout.isTTY === true)
|
|
452
364
|
return await runGuiCommand([]);
|
|
453
365
|
// falls through
|
|
454
|
-
default: throw new TypeError('usage: ckit (no command: opens the GUI) | ckit <new <goal>|status|demo|tui|gui [--port=<n>] [--no-open]|team "<goal>"|team --demo|team --init|setup [--path]|
|
|
366
|
+
default: throw new TypeError('usage: ckit (no command: opens the GUI) | ckit <install|update [--check]|new <goal>|status|demo|tui|gui [--port=<n>] [--no-open]|team "<goal>"|team --demo|team --init|setup [--path]|sessions|open <sessionId>|replay <sessionId>|backup <dest-dir>|restore <backup-dir> (each takes [--project=<path>])|doctor [--bundle] [--agent=<path>] [--check-connection]|--version>');
|
|
455
367
|
}
|
|
456
368
|
}
|
|
457
369
|
catch (error) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME = "@ngockhoale/ckit";
|
|
2
|
+
export declare function installedVersion(): string;
|
|
3
|
+
export interface InstallResult {
|
|
4
|
+
readonly root: string;
|
|
5
|
+
readonly configFile: string;
|
|
6
|
+
readonly created: boolean;
|
|
7
|
+
readonly gitignoreUpdated: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Prepares `cwd` (exactly that folder, never a parent) for CKit: writes the default .ckit/team.json when missing; keeps an existing one untouched. */
|
|
10
|
+
export declare function installProject(cwd: string): InstallResult;
|
|
11
|
+
export declare function runInstallCommand(args: readonly string[]): Promise<number>;
|
|
12
|
+
/** Runs npm; returns exit status and captured stdout (stdout is '' when inherited). */
|
|
13
|
+
export type NpmRunner = (args: readonly string[], inherit: boolean) => {
|
|
14
|
+
status: number;
|
|
15
|
+
stdout: string;
|
|
16
|
+
};
|
|
17
|
+
/** true when version a is newer than b (numeric major.minor.patch; with equal numbers a release beats a pre-release). */
|
|
18
|
+
export declare function isNewer(a: string, b: string): boolean;
|
|
19
|
+
export declare function runUpdateCommand(args: readonly string[], npm?: NpmRunner, current?: string, log?: (line: string) => void): Promise<number>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// `ckit install` (prepare the current folder) and `ckit update` (upgrade the globally installed package from npm).
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { appendFileSync, existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { teamConfigPath, writeDefaultTeamConfig } from '../team/config.js';
|
|
7
|
+
export const PACKAGE_NAME = '@ngockhoale/ckit';
|
|
8
|
+
const IGNORE_LINE = '.ckit/team/';
|
|
9
|
+
export function installedVersion() {
|
|
10
|
+
// dist/src/cli/lifecycle.js -> package root is three levels up.
|
|
11
|
+
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'package.json'), 'utf8'));
|
|
12
|
+
return typeof pkg.version === 'string' ? pkg.version : 'unknown';
|
|
13
|
+
}
|
|
14
|
+
/** Prepares `cwd` (exactly that folder, never a parent) for CKit: writes the default .ckit/team.json when missing; keeps an existing one untouched. */
|
|
15
|
+
export function installProject(cwd) {
|
|
16
|
+
let root;
|
|
17
|
+
try {
|
|
18
|
+
root = realpathSync(resolve(cwd));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
root = resolve(cwd);
|
|
22
|
+
}
|
|
23
|
+
const configFile = teamConfigPath(root), created = !existsSync(configFile);
|
|
24
|
+
if (created)
|
|
25
|
+
writeDefaultTeamConfig(root);
|
|
26
|
+
// Run journals and uploads are local working data: keep them out of git when the folder already has a .gitignore.
|
|
27
|
+
let gitignoreUpdated = false;
|
|
28
|
+
const gi = join(root, '.gitignore');
|
|
29
|
+
if (existsSync(gi)) {
|
|
30
|
+
const text = readFileSync(gi, 'utf8');
|
|
31
|
+
if (!text.split(/\r?\n/).some(l => l.trim() === IGNORE_LINE || l.trim() === '.ckit/' || l.trim() === '.ckit')) {
|
|
32
|
+
appendFileSync(gi, `${text === '' || text.endsWith('\n') ? '' : '\n'}${IGNORE_LINE}\n`);
|
|
33
|
+
gitignoreUpdated = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { root, configFile, created, gitignoreUpdated };
|
|
37
|
+
}
|
|
38
|
+
export async function runInstallCommand(args) {
|
|
39
|
+
if (args.length !== 0)
|
|
40
|
+
throw new TypeError('usage: ckit install');
|
|
41
|
+
const r = installProject(process.cwd());
|
|
42
|
+
console.log(`CKit ${installedVersion()} is ready in ${r.root}`);
|
|
43
|
+
console.log(r.created ? `created ${r.configFile} (default team; change CLI and model per agent in the GUI: Config)` : `kept your existing ${r.configFile}`);
|
|
44
|
+
if (r.gitignoreUpdated)
|
|
45
|
+
console.log(`added ${IGNORE_LINE} to .gitignore (run journals and uploads stay local)`);
|
|
46
|
+
console.log('next: run "ckit" in this folder to open the GUI.');
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
const realNpm = (args, inherit) => {
|
|
50
|
+
const r = spawnSync('npm', [...args], { encoding: 'utf8', stdio: inherit ? 'inherit' : ['ignore', 'pipe', 'pipe'], shell: process.platform === 'win32' });
|
|
51
|
+
return { status: r.error ? 1 : r.status ?? 1, stdout: typeof r.stdout === 'string' ? r.stdout : '' };
|
|
52
|
+
};
|
|
53
|
+
/** true when version a is newer than b (numeric major.minor.patch; with equal numbers a release beats a pre-release). */
|
|
54
|
+
export function isNewer(a, b) {
|
|
55
|
+
const parse = (v) => { const [core = '', ...rest] = v.split('-'); return { n: core.split('.').map(x => Number(x) || 0), pre: rest.length > 0 }; };
|
|
56
|
+
const x = parse(a), y = parse(b);
|
|
57
|
+
for (let i = 0; i < 3; i++) {
|
|
58
|
+
const d = (x.n[i] ?? 0) - (y.n[i] ?? 0);
|
|
59
|
+
if (d !== 0)
|
|
60
|
+
return d > 0;
|
|
61
|
+
}
|
|
62
|
+
return !x.pre && y.pre;
|
|
63
|
+
}
|
|
64
|
+
export async function runUpdateCommand(args, npm = realNpm, current = installedVersion(), log = console.log) {
|
|
65
|
+
const checkOnly = args.length === 1 && args[0] === '--check';
|
|
66
|
+
if (args.length !== 0 && !checkOnly)
|
|
67
|
+
throw new TypeError('usage: ckit update [--check]');
|
|
68
|
+
const view = npm(['view', `${PACKAGE_NAME}@latest`, 'version'], false), latest = view.stdout.trim();
|
|
69
|
+
if (view.status !== 0 || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?$/.test(latest)) {
|
|
70
|
+
log(`could not read the latest version of ${PACKAGE_NAME} from npm (check the network and "npm whoami"/registry settings). Installed: ${current}`);
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
if (!isNewer(latest, current)) {
|
|
74
|
+
log(latest === current ? `CKit is up to date (${current}).` : `CKit ${current} is newer than the published ${latest}; nothing to update.`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
if (checkOnly) {
|
|
78
|
+
log(`update available: ${current} -> ${latest}. Run "ckit update" to install it.`);
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
log(`updating CKit ${current} -> ${latest} (npm install -g ${PACKAGE_NAME}@${latest})`);
|
|
82
|
+
const r = npm(['install', '-g', `${PACKAGE_NAME}@${latest}`], true);
|
|
83
|
+
if (r.status !== 0) {
|
|
84
|
+
log(`npm could not install the update (exit ${r.status}). Run it yourself to see why: npm install -g ${PACKAGE_NAME}@latest`);
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
log(`CKit ${latest} installed. Restart any running "ckit gui" to use it; your projects' .ckit/team.json files are unchanged.`);
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=lifecycle.js.map
|
package/dist/src/cli/setup.js
CHANGED
|
@@ -102,7 +102,7 @@ export async function setupWith(args, io) {
|
|
|
102
102
|
renameSync(temp, file);
|
|
103
103
|
say(`Saved ${file}`);
|
|
104
104
|
say(maskedConfigSummary(check.config));
|
|
105
|
-
say('Next: ckit doctor --check-connection, then ckit
|
|
105
|
+
say('Next: ckit doctor --check-connection, then run ckit (GUI) or ckit team "<goal>" inside your project folder');
|
|
106
106
|
return 0;
|
|
107
107
|
}
|
|
108
108
|
finally {
|
package/dist/src/gui/server.js
CHANGED
|
@@ -16,6 +16,7 @@ import { replayTeamRun, startTeamRun } from '../team/engine.js';
|
|
|
16
16
|
import { detectClis } from '../team/cli-models.js';
|
|
17
17
|
import { dispatchRunner } from '../team/runners.js';
|
|
18
18
|
import { listTeamRuns, readTeamJournal } from '../team/journal.js';
|
|
19
|
+
import { DEFAULT_MISSIONS, allAgentsOf, effectiveOrder } from '../team/types.js';
|
|
19
20
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
20
21
|
import { dirname } from 'node:path';
|
|
21
22
|
const GUI_DIR = resolve(fileURLToPath(new URL('../../../gui/', import.meta.url)));
|
|
@@ -27,7 +28,7 @@ const MAX_UPLOAD_BYTES = 2 * 1024 ** 3, MAX_PENDING_UPLOADS = 100, MAX_ATTACHMEN
|
|
|
27
28
|
const UPLOAD_ID_RE = /^[0-9a-f]{24}$/, ATTACHMENT_NAME_RE = /^[^\\/\0]{1,160}$/;
|
|
28
29
|
/** Shown inline (thumbnails / new tab); every other attachment is sent as a download so the browser never runs it. */
|
|
29
30
|
const INLINE_IMAGE = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.webp': 'image/webp' };
|
|
30
|
-
const allAgents =
|
|
31
|
+
const allAgents = allAgentsOf;
|
|
31
32
|
function json(res, status, body) {
|
|
32
33
|
const s = JSON.stringify(body);
|
|
33
34
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store', 'content-length': Buffer.byteLength(s) });
|
|
@@ -83,7 +84,7 @@ export async function startGuiServer(opts) {
|
|
|
83
84
|
const loadConfig = () => { const r = loadTeamConfig(root); return r.ok ? r.config : defaultTeamConfig(); };
|
|
84
85
|
const publicConfig = (c) => {
|
|
85
86
|
const dec = (a) => ({ ...a, hasKey: a.apiKeyRef ? hasSecret(a.apiKeyRef) : false });
|
|
86
|
-
return { version: 1, director: dec(c.director), teams: { ba: c.teams.ba.map(dec), implement: c.teams.implement.map(dec), qc: c.teams.qc.map(dec) }, limits: c.limits };
|
|
87
|
+
return { version: 1, director: dec(c.director), teams: { ba: c.teams.ba.map(dec), implement: c.teams.implement.map(dec), qc: c.teams.qc.map(dec) }, ...(c.extraTeams?.length ? { extraTeams: c.extraTeams.map(t => ({ ...t, agents: t.agents.map(dec) })) } : {}), ...(c.order ? { order: c.order } : {}), ...(c.lanes?.length ? { lanes: c.lanes } : {}), ...(c.directorReview === false ? { directorReview: false } : {}), ...(c.systemPrompt ? { systemPrompt: c.systemPrompt } : {}), ...(c.missions ? { missions: c.missions } : {}), limits: c.limits };
|
|
87
88
|
};
|
|
88
89
|
const runDirOf = (id) => {
|
|
89
90
|
if (id === 'current')
|
|
@@ -118,7 +119,7 @@ export async function startGuiServer(opts) {
|
|
|
118
119
|
uploads.delete(i);
|
|
119
120
|
}
|
|
120
121
|
} };
|
|
121
|
-
let checks = 0;
|
|
122
|
+
let checks = 0, enhancing = false;
|
|
122
123
|
async function api(req, res, url) {
|
|
123
124
|
const m = req.method ?? 'GET', p = url.pathname;
|
|
124
125
|
if (m === 'GET' && p === '/api/events') {
|
|
@@ -200,7 +201,8 @@ export async function startGuiServer(opts) {
|
|
|
200
201
|
const goal = first?.type === 'run.started' ? first.goal : '';
|
|
201
202
|
const outcome = last?.type === 'run.completed' ? last.outcome : 'incomplete';
|
|
202
203
|
const durationMs = first && last ? Math.max(0, Date.parse(last.at) - Date.parse(first.at)) : 0;
|
|
203
|
-
|
|
204
|
+
const lane = ev.find(e => e.type === 'lane.chosen');
|
|
205
|
+
return { runId: r.runId, goal, outcome, lane: lane && lane.type === 'lane.chosen' ? lane.name : null, waiting: last?.type === 'run.waiting', startedAt: first?.at ?? null, durationMs, simulated: first?.type === 'run.started' ? first.simulated : false };
|
|
204
206
|
});
|
|
205
207
|
return json(res, 200, { runs });
|
|
206
208
|
}
|
|
@@ -243,7 +245,10 @@ export async function startGuiServer(opts) {
|
|
|
243
245
|
if (!goal)
|
|
244
246
|
return json(res, 400, { error: 'goal required' });
|
|
245
247
|
const simulated = b['simulated'] === true;
|
|
246
|
-
const
|
|
248
|
+
const cfgNow = loadConfig(), laneId = typeof b['lane'] === 'string' ? b['lane'] : '';
|
|
249
|
+
if (laneId && !(cfgNow.lanes ?? []).some(l => l.id === laneId))
|
|
250
|
+
return json(res, 400, { error: `unknown lane "${laneId.slice(0, 40)}"` });
|
|
251
|
+
const handle = startTeamRun({ projectRoot: root, goal, config: cfgNow, simulated, attachments: files, ...(laneId ? { lane: laneId } : {}) });
|
|
247
252
|
release(b['attachments']);
|
|
248
253
|
attach(handle, goal, simulated);
|
|
249
254
|
return json(res, 200, { runId: handle.runId });
|
|
@@ -326,6 +331,55 @@ export async function startGuiServer(opts) {
|
|
|
326
331
|
release(b['attachments']);
|
|
327
332
|
return json(res, 200, { ok: true });
|
|
328
333
|
}
|
|
334
|
+
if (m === 'POST' && p === '/api/runs/current/proceed') {
|
|
335
|
+
if (!isRunning() || !current)
|
|
336
|
+
return json(res, 409, { error: 'no active run' });
|
|
337
|
+
if (!current.handle.proceedWithAssumptions)
|
|
338
|
+
return json(res, 409, { error: 'this run cannot proceed with assumptions' });
|
|
339
|
+
current.handle.proceedWithAssumptions();
|
|
340
|
+
return json(res, 200, { ok: true });
|
|
341
|
+
}
|
|
342
|
+
if (m === 'POST' && p === '/api/enhance-prompt') {
|
|
343
|
+
// One read-only turn of the Director's CLI that rewrites a draft. Own process, so it also works while a run is active. Never applied automatically.
|
|
344
|
+
const b = obj(await readBody(req)), kind = b['kind'], text = typeof b['text'] === 'string' ? b['text'] : '';
|
|
345
|
+
if (kind !== 'system' && kind !== 'mission' && kind !== 'persona' && kind !== 'lane')
|
|
346
|
+
return json(res, 400, { error: 'kind must be system, mission, persona or lane' });
|
|
347
|
+
if (!text.trim())
|
|
348
|
+
return json(res, 400, { error: 'text required' });
|
|
349
|
+
if (text.length > (kind === 'system' ? 8000 : 4000))
|
|
350
|
+
return json(res, 400, { error: 'text is too long' });
|
|
351
|
+
if (text.includes('\0'))
|
|
352
|
+
return json(res, 400, { error: 'text must not contain NUL characters' });
|
|
353
|
+
if (enhancing)
|
|
354
|
+
return json(res, 429, { error: 'another enhance is running; wait for it to finish' });
|
|
355
|
+
const cfg = loadConfig(), ids = obj(b['ids']), teamName = (id) => { const x = typeof id === 'string' ? id : ''; return x === 'ba' ? 'BA' : x === 'implement' ? 'Implement' : x === 'qc' ? 'QC' : (cfg.extraTeams ?? []).find(t => t.id === x)?.name ?? x; };
|
|
356
|
+
const missionOf = (id) => (cfg.extraTeams ?? []).find(t => t.id === id)?.mission ?? cfg.missions?.[id] ?? DEFAULT_MISSIONS[id] ?? '';
|
|
357
|
+
const allIds = ['ba', 'implement', 'qc', ...(cfg.extraTeams ?? []).map(t => t.id)];
|
|
358
|
+
const teamId = typeof ids['team'] === 'string' ? ids['team'] : '';
|
|
359
|
+
const others = allIds.filter(i => i !== teamId).map(i => `- ${teamName(i)}: ${missionOf(i)}`).join('\n');
|
|
360
|
+
const ctx = kind === 'mission' ? `This is the mission of team "${teamName(teamId)}" (position ${Math.max(0, effectiveOrder(cfg).indexOf(teamId)) + 1} of ${effectiveOrder(cfg).length}). Other teams:\n${others}`
|
|
361
|
+
: kind === 'persona' ? `This is the persona of the agent "${typeof ids['agent'] === 'string' ? ids['agent'].slice(0, 60) : 'agent'}" in team "${teamName(teamId)}". The team mission: ${missionOf(teamId)}`
|
|
362
|
+
: kind === 'lane' ? `This is the "when to use" text of a lane (it tells the Director which requests belong in the lane). Other lanes:\n${(cfg.lanes ?? []).filter(l => l.id !== ids['lane']).map(l => `- ${l.name}: ${l.when}`).join('\n') || '(none)'}`
|
|
363
|
+
: `These are project-wide instructions sent to every agent. The teams:\n${allIds.map(i => `- ${teamName(i)}`).join('\n')}`;
|
|
364
|
+
const words = kind === 'system' ? 400 : 200;
|
|
365
|
+
const d = cfg.director;
|
|
366
|
+
if (d.cli === 'auto' || d.cli === 'simulated') { // offline / demo: deterministic rewrite
|
|
367
|
+
const t = text.trim().replace(/\s+/g, ' ');
|
|
368
|
+
return json(res, 200, { ok: true, proposal: (`${t.charAt(0).toUpperCase()}${t.slice(1)}`.replace(/[.!?]*$/, '') + '. Be specific, keep to this scope and report anything unclear.').slice(0, 8000) });
|
|
369
|
+
}
|
|
370
|
+
const prompt = `Rewrite the DRAFT below into clear, specific, non-contradictory instructions. Rules: write in the same language as the draft; keep every intent of the draft; add nothing new; at most about ${words} words; output ONLY the rewritten text, with no preface, no quotes and no commentary. Do not use any tools.\nCONTEXT: ${ctx}\nDRAFT:\n${text}`;
|
|
371
|
+
enhancing = true;
|
|
372
|
+
try {
|
|
373
|
+
const r = await dispatchRunner({ ...d, access: 'read' }, prompt, { cwd: root, timeoutMs: Math.min(cfg.limits.agentTimeoutMs, 120_000) });
|
|
374
|
+
if (!r.ok)
|
|
375
|
+
return json(res, 200, { ok: false, reason: r.reason });
|
|
376
|
+
const out = r.text.trim().slice(0, kind === 'system' ? 8000 : 4000);
|
|
377
|
+
return json(res, 200, out ? { ok: true, proposal: out } : { ok: false, reason: 'the agent returned no text' });
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
enhancing = false;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
329
383
|
if (m === 'POST' && p === '/api/runs/current/stop') {
|
|
330
384
|
if (!isRunning() || !current)
|
|
331
385
|
return json(res, 409, { error: 'no active run' });
|
|
@@ -489,7 +543,7 @@ export async function runGuiCommand(args) {
|
|
|
489
543
|
throw error;
|
|
490
544
|
srv = await startGuiServer({ projectRoot: root, port: 0, open, host, ...extra });
|
|
491
545
|
}
|
|
492
|
-
process.stdout.write(`CKit Agent Company GUI: ${srv.url}\nProject folder (agents run here): ${root}\n${host === '127.0.0.1' ? '' : `LAN access is ON (host ${host}): from another machine open one of:\n${[hostname(), ...Object.values(networkInterfaces()).flat().filter(i => i && i.family === 'IPv4' && !i.internal).map(i => i.address)].map(h => ` ${srv.url.replace('127.0.0.1', h)}`).join('\n')}\nAnyone on the network holding this link can drive the agents; the link is plain HTTP.\n`}Ctrl+C to stop.\n`);
|
|
546
|
+
process.stdout.write(`CKit Agent Company GUI: ${srv.url}\nProject folder (agents run here): ${root}\nKeeps running after the browser tab is closed (runs continue; reopen the link any time). Stop it with Ctrl+C in this terminal.\n${host === '127.0.0.1' ? '' : `LAN access is ON (host ${host}): from another machine open one of:\n${[hostname(), ...Object.values(networkInterfaces()).flat().filter(i => i && i.family === 'IPv4' && !i.internal).map(i => i.address)].map(h => ` ${srv.url.replace('127.0.0.1', h)}`).join('\n')}\nAnyone on the network holding this link can drive the agents; the link is plain HTTP.\n`}Ctrl+C to stop.\n`);
|
|
493
547
|
await new Promise(r => { process.once('SIGINT', () => r()); process.once('SIGTERM', () => r()); });
|
|
494
548
|
await srv.close();
|
|
495
549
|
return 0;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Splits `text` on whitespace; single and double quotes group; a backslash escapes the next character outside quotes and inside double quotes. No ~ or $VAR expansion. */
|
|
2
|
+
export declare function splitCliArgs(text: string): {
|
|
3
|
+
ok: true;
|
|
4
|
+
args: string[];
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
/** Tokens for an agent; a value that does not split (cannot happen after parseTeamConfig) yields none. */
|
|
10
|
+
export declare const cliArgTokens: (cliArgs: string | undefined) => string[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Per-agent "extra CLI arguments": a shell-like splitter (no shell is ever involved; tokens go straight into the spawn argv array).
|
|
2
|
+
/** Splits `text` on whitespace; single and double quotes group; a backslash escapes the next character outside quotes and inside double quotes. No ~ or $VAR expansion. */
|
|
3
|
+
export function splitCliArgs(text) {
|
|
4
|
+
const args = [];
|
|
5
|
+
let cur = '', has = false, quote = null;
|
|
6
|
+
for (let i = 0; i < text.length; i++) {
|
|
7
|
+
const c = text[i];
|
|
8
|
+
if (quote === "'") {
|
|
9
|
+
if (c === "'")
|
|
10
|
+
quote = null;
|
|
11
|
+
else
|
|
12
|
+
cur += c;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (c === '\\') {
|
|
16
|
+
if (i + 1 >= text.length)
|
|
17
|
+
return { ok: false, error: 'ends with a lone backslash' };
|
|
18
|
+
cur += text[++i];
|
|
19
|
+
has = true;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (quote === '"') {
|
|
23
|
+
if (c === '"')
|
|
24
|
+
quote = null;
|
|
25
|
+
else
|
|
26
|
+
cur += c;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (c === '"' || c === "'") {
|
|
30
|
+
quote = c;
|
|
31
|
+
has = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (/\s/.test(c)) {
|
|
35
|
+
if (has) {
|
|
36
|
+
args.push(cur);
|
|
37
|
+
cur = '';
|
|
38
|
+
has = false;
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
cur += c;
|
|
43
|
+
has = true;
|
|
44
|
+
}
|
|
45
|
+
if (quote)
|
|
46
|
+
return { ok: false, error: `has an unterminated ${quote === '"' ? 'double' : 'single'} quote` };
|
|
47
|
+
if (has)
|
|
48
|
+
args.push(cur);
|
|
49
|
+
return { ok: true, args };
|
|
50
|
+
}
|
|
51
|
+
/** Tokens for an agent; a value that does not split (cannot happen after parseTeamConfig) yields none. */
|
|
52
|
+
export const cliArgTokens = (cliArgs) => {
|
|
53
|
+
if (!cliArgs || !cliArgs.trim())
|
|
54
|
+
return [];
|
|
55
|
+
const r = splitCliArgs(cliArgs);
|
|
56
|
+
return r.ok ? r.args : [];
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=cli-args.js.map
|