@netnodeag/kraftwerk 0.36.0 → 0.37.1
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 +39 -1
- package/dist/cli/doctor.js +18 -1
- package/dist/cli/init.js +16 -9
- package/dist/cli/kraftwerk.js +3 -0
- package/dist/cli/projects.d.ts +14 -0
- package/dist/cli/projects.js +3 -2
- package/dist/cli/repos.d.ts +2 -0
- package/dist/cli/repos.js +115 -0
- package/dist/cli/routines.d.ts +10 -0
- package/dist/cli/routines.js +1 -1
- package/dist/cli/ui.js +2 -2
- package/dist/config.d.ts +35 -0
- package/dist/config.js +68 -1
- package/dist/inspector/chat/sessions.js +29 -2
- package/dist/inspector/git.d.ts +14 -0
- package/dist/inspector/git.js +11 -9
- package/dist/inspector/instances.js +7 -7
- package/dist/inspector/repos.d.ts +118 -0
- package/dist/inspector/repos.js +249 -0
- package/dist/inspector/server.js +43 -1
- package/dist/inspector/settings.d.ts +7 -1
- package/dist/inspector/settings.js +32 -1
- package/inspector/dist/assets/{editor-7ImnDC3D.js → editor-vM6JSj5h.js} +3 -3
- package/inspector/dist/assets/{index-DbmSSHvr.js → index-BAAjszPI.js} +1 -1
- package/inspector/dist/assets/{index-DjRBLY9N.js → index-BKcOp35r.js} +1 -1
- package/inspector/dist/assets/index-Ba8VU6Wz.js +217 -0
- package/inspector/dist/assets/{index-C3Ob1O7W.js → index-Bb08wK-l.js} +1 -1
- package/inspector/dist/assets/{index-Ct_jZSyD.js → index-BrCwDkJZ.js} +1 -1
- package/inspector/dist/assets/{index-DKrBjjGQ.js → index-Bs1U0rWW.js} +1 -1
- package/inspector/dist/assets/{index-BC7aIJ-h.js → index-C1UXlW32.js} +1 -1
- package/inspector/dist/assets/{index-CIjv7yxE.js → index-CQ2XKqmD.js} +1 -1
- package/inspector/dist/assets/{index-BuRajvjQ.js → index-CReepirH.js} +1 -1
- package/inspector/dist/assets/{index-YZtBJhWD.js → index-CUGfxoYt.js} +1 -1
- package/inspector/dist/assets/{index-B_CIhKa4.js → index-CaKmxcD6.js} +1 -1
- package/inspector/dist/assets/{index-BZeYO5wT.js → index-CtMGH62C.js} +1 -1
- package/inspector/dist/assets/{index-BA7nx4V5.css → index-D4_mLTSH.css} +1 -1
- package/inspector/dist/assets/{index-DPBAv_kj.js → index-D_11IZBV.js} +1 -1
- package/inspector/dist/assets/{index-CRAwmMfk.js → index-DfZT0IoM.js} +1 -1
- package/inspector/dist/assets/{index-DL_bJiOj.js → index-DykDNrYm.js} +1 -1
- package/inspector/dist/assets/{index-BIXYBiw7.js → index-MWv5H1oP.js} +1 -1
- package/inspector/dist/assets/{index-fWUFhIGR.js → index-oIQqfbwm.js} +1 -1
- package/inspector/dist/assets/{index--2I7vpcS.js → index-yGZsomcy.js} +1 -1
- package/inspector/dist/index.html +2 -2
- package/package.json +1 -1
- package/schema/kraftwerk.schema.json +15 -0
- package/inspector/dist/assets/index-B2ThRS2S.js +0 -217
package/README.md
CHANGED
|
@@ -180,7 +180,7 @@ Optional, at the project root, and also the root marker for the walk-up. All
|
|
|
180
180
|
fields are optional. `workflows:` sets the workflows root, `output:` the
|
|
181
181
|
run-artifact directory (default `output/`), `knowledge:` the OKF bundle root
|
|
182
182
|
(default `knowledge/`), and `agents:` the agent-definition root (default
|
|
183
|
-
`agents/`).
|
|
183
|
+
`agents/`). `repos:` turns on the [repositories](#repositories) folder.
|
|
184
184
|
|
|
185
185
|
`switcher:` links other kraftwerk workspaces from the inspector header. The
|
|
186
186
|
workspace name becomes a dropdown listing them:
|
|
@@ -296,6 +296,44 @@ the model via ACP session options and the thinking budget via
|
|
|
296
296
|
are created and edited in the UI, or by editing the files, since the
|
|
297
297
|
definition is read fresh for each new session.
|
|
298
298
|
|
|
299
|
+
### Repositories
|
|
300
|
+
|
|
301
|
+
Turn on `repos:` in `kraftwerk.yml` (or the checkbox in settings) and the
|
|
302
|
+
workspace gets one folder for the git repositories its agents work on:
|
|
303
|
+
|
|
304
|
+
```yaml
|
|
305
|
+
repos:
|
|
306
|
+
root: kraftwerk-data/repos # default: repos/ — git-ignored, never synced
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
The folder is the registry. Whatever has a `.git` directly under the root is
|
|
310
|
+
a repository, whether the "repositories" screen cloned it, `kraftwerk repos
|
|
311
|
+
add <url>` did, or an agent ran `git clone` there. Every entry is read live
|
|
312
|
+
from git: origin, branch, head, uncommitted changes, ahead/behind. The
|
|
313
|
+
screen clones by url, fetches and fast-forwards clean clones, and removes
|
|
314
|
+
them (refusing while they hold unpushed or uncommitted work). Cloning uses
|
|
315
|
+
your own git credentials and never prompts, so a private remote has to work
|
|
316
|
+
from a terminal first.
|
|
317
|
+
|
|
318
|
+
Every agent, and the inspector assistant, gets the list as context: where
|
|
319
|
+
the root is, what is cloned, and how to add more with the CLI. So "look at
|
|
320
|
+
the widgets repo" works as soon as it is cloned, and "clone
|
|
321
|
+
github:org/widgets and look at it" works before.
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
kraftwerk repos # name, branch, head, state
|
|
325
|
+
kraftwerk repos add github:org/widgets # or any https / ssh url
|
|
326
|
+
kraftwerk repos add <url> --name tools --branch dev
|
|
327
|
+
kraftwerk repos add <url> --depth 1 # shallow clone of a large repository
|
|
328
|
+
kraftwerk repos update widgets # fetch, fast-forward when clean
|
|
329
|
+
kraftwerk repos remove widgets [--force]
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
`GET /api/repos` returns the same list for automation. The root must be a
|
|
333
|
+
folder inside the project (never the project itself): it is excluded from the
|
|
334
|
+
workspace git sync, the first clone adds it to `.gitignore`, and `kraftwerk
|
|
335
|
+
doctor` warns when git does not ignore it.
|
|
336
|
+
|
|
299
337
|
### Skills in chat
|
|
300
338
|
|
|
301
339
|
Chats, both general ones and agent sessions, can use skills. These are
|
package/dist/cli/doctor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import chalk from "chalk";
|
|
5
|
-
import { isDir, resolveProject } from "../config.js";
|
|
5
|
+
import { ignoreEntryFor, isDir, reposRootFor, resolveProject } from "../config.js";
|
|
6
6
|
import { discoverWorkflows } from "../discover.js";
|
|
7
7
|
import { missingEnv } from "../yaml.js";
|
|
8
8
|
const ICONS = {
|
|
@@ -106,6 +106,23 @@ export async function runDoctor(cwd) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
// Repositories: the clones root must stay out of the workspace git. git
|
|
110
|
+
// itself decides — that covers worktrees (.git is a file), a workspace
|
|
111
|
+
// nested in a larger repo, a .gitignore at the toplevel, global excludes.
|
|
112
|
+
const reposRoot = reposRootFor(project);
|
|
113
|
+
if (reposRoot) {
|
|
114
|
+
const entry = ignoreEntryFor(project.root, reposRoot) ?? path.relative(project.root, reposRoot);
|
|
115
|
+
const label = `repos: ${path.relative(cwd, reposRoot) || "."}`;
|
|
116
|
+
const check = spawnSync("git", ["check-ignore", "-q", "--", reposRoot], { cwd: project.root, encoding: "utf8" });
|
|
117
|
+
if (check.error)
|
|
118
|
+
report("info", label, "git not found — cannot check .gitignore");
|
|
119
|
+
else if (check.status === 0)
|
|
120
|
+
report("ok", label, "git-ignored");
|
|
121
|
+
else if (check.status === 1)
|
|
122
|
+
report("warn", label, `${entry}/ is not git-ignored — clones would show up as untracked gitlinks; add it to .gitignore`);
|
|
123
|
+
else
|
|
124
|
+
report("ok", label, "not inside a git repository");
|
|
125
|
+
}
|
|
109
126
|
const found = project.workflowsRoot ? await discoverWorkflows(cwd) : [];
|
|
110
127
|
if (!project.workflowsRoot) {
|
|
111
128
|
report("warn", "no workflows root", "expected src/workflows/ or workflows/ — `kraftwerk init` scaffolds one");
|
package/dist/cli/init.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
-
import { CONFIG_SCHEMA_URL, SCHEMA_URL } from "../config.js";
|
|
4
|
+
import { CONFIG_SCHEMA_URL, gitignoreHas, SCHEMA_URL } from "../config.js";
|
|
5
5
|
import { initBundle, writeConcept } from "../okf.js";
|
|
6
6
|
/**
|
|
7
7
|
* `kraftwerk init` — make any repository a kraftwerk consumer in one
|
|
@@ -22,6 +22,8 @@ output: ${DATA_DIR}/output # where run artifacts land (git-ignored)
|
|
|
22
22
|
knowledge: ${DATA_DIR}/knowledge # OKF knowledge bundles
|
|
23
23
|
agents: ${DATA_DIR}/agents # agent definitions
|
|
24
24
|
skills: ${DATA_DIR}/skills # workspace skills (shared instruction packages)
|
|
25
|
+
# repos: # git repositories the agents work on (uncomment both lines to enable)
|
|
26
|
+
# root: ${DATA_DIR}/repos # clones land here (git-ignored); a bare \`repos:\` uses repos/ instead
|
|
25
27
|
`;
|
|
26
28
|
const WORKFLOW_TEMPLATE = `# yaml-language-server: $schema=${SCHEMA_URL}
|
|
27
29
|
name: hello
|
|
@@ -124,20 +126,25 @@ export async function runInit(cwd) {
|
|
|
124
126
|
await writeConcept(knowledgeRoot, DEMO_BUNDLE, "playbooks/refunds", DEMO_CONCEPT, "kraftwerk-init");
|
|
125
127
|
created.push(bundleRel);
|
|
126
128
|
}
|
|
127
|
-
// .gitignore:
|
|
128
|
-
|
|
129
|
+
// .gitignore: the output dir and the repos root (clones must never become
|
|
130
|
+
// gitlinks of the workspace repo). A missing file gets both in one write;
|
|
131
|
+
// an existing one only the entries it lacks.
|
|
129
132
|
const gitignorePath = path.join(cwd, ".gitignore");
|
|
130
133
|
const gitignore = (await readFile(gitignorePath, "utf8").catch(() => null)) ?? null;
|
|
134
|
+
const entries = [`${DATA_DIR}/output`, `${DATA_DIR}/repos`];
|
|
131
135
|
if (gitignore === null) {
|
|
132
|
-
await writeFile(gitignorePath, `${
|
|
136
|
+
await writeFile(gitignorePath, entries.map((e) => `${e}/\n`).join(""));
|
|
133
137
|
created.push(".gitignore");
|
|
134
138
|
}
|
|
135
|
-
else if (!gitignore.split("\n").some((l) => l.trim().replace(/\/$/, "") === outputEntry)) {
|
|
136
|
-
await appendFile(gitignorePath, `${gitignore.endsWith("\n") ? "" : "\n"}${outputEntry}/\n`);
|
|
137
|
-
created.push(`.gitignore (${outputEntry}/ added)`);
|
|
138
|
-
}
|
|
139
139
|
else {
|
|
140
|
-
|
|
140
|
+
const missing = entries.filter((e) => !gitignoreHas(gitignore, e));
|
|
141
|
+
if (missing.length === 0) {
|
|
142
|
+
skipped.push(".gitignore");
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
await appendFile(gitignorePath, `${gitignore.endsWith("\n") ? "" : "\n"}${missing.map((e) => `${e}/\n`).join("")}`);
|
|
146
|
+
created.push(`.gitignore (${missing.map((e) => `${e}/`).join(", ")} added)`);
|
|
147
|
+
}
|
|
141
148
|
}
|
|
142
149
|
for (const f of created)
|
|
143
150
|
console.log(`${chalk.green("✔")} ${f}`);
|
package/dist/cli/kraftwerk.js
CHANGED
|
@@ -13,6 +13,7 @@ import { runDoctor } from "./doctor.js";
|
|
|
13
13
|
import { runInit } from "./init.js";
|
|
14
14
|
import { registerKnowledgeCommands } from "./knowledge.js";
|
|
15
15
|
import { registerProjectCommands } from "./projects.js";
|
|
16
|
+
import { registerRepoCommands } from "./repos.js";
|
|
16
17
|
import { registerRoutineCommands } from "./routines.js";
|
|
17
18
|
import { listRuns, showRun } from "./runs.js";
|
|
18
19
|
import { runUi } from "./ui.js";
|
|
@@ -27,6 +28,7 @@ import { runUi } from "./ui.js";
|
|
|
27
28
|
* kraftwerk routines ... per-agent scheduled prompts (list/add/remove/enable/run)
|
|
28
29
|
* kraftwerk ui start the inspector web UI (localhost:1981)
|
|
29
30
|
* kraftwerk projects ... known projects on this machine (list/start/forget)
|
|
31
|
+
* kraftwerk repos ... repositories the agents work on (list/add/update/remove)
|
|
30
32
|
* kraftwerk doctor preflight: harness CLIs, docker, workflows, env
|
|
31
33
|
* kraftwerk validate [paths...] validate without executing
|
|
32
34
|
*
|
|
@@ -259,6 +261,7 @@ runs
|
|
|
259
261
|
registerKnowledgeCommands(program);
|
|
260
262
|
registerRoutineCommands(program);
|
|
261
263
|
registerProjectCommands(program);
|
|
264
|
+
registerRepoCommands(program);
|
|
262
265
|
program
|
|
263
266
|
.command("ui")
|
|
264
267
|
.description("Start the inspector web UI for this project's runs and workflows")
|
package/dist/cli/projects.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* `kraftwerk projects` — every project that ever ran the inspector on this
|
|
4
|
+
* machine (~/.kraftwerk/projects), joined with what is running right now.
|
|
5
|
+
* The answer to "where did I start that UI, and how do I get it back":
|
|
6
|
+
*
|
|
7
|
+
* kraftwerk projects list: name, root, running/stopped
|
|
8
|
+
* kraftwerk projects start <ref> relaunch `kraftwerk ui` in that root, detached
|
|
9
|
+
* kraftwerk projects stop <ref> SIGTERM a running UI (also ones started in a terminal)
|
|
10
|
+
* kraftwerk projects forget <ref> drop the record (the folder stays)
|
|
11
|
+
*
|
|
12
|
+
* <ref> is a project name, the root's folder name, the root path, or a
|
|
13
|
+
* port / localhost:port for running instances that recorded no root.
|
|
14
|
+
*/
|
|
15
|
+
export declare const fmtAgo: (iso?: string) => string;
|
|
2
16
|
export declare function registerProjectCommands(program: Command): void;
|
package/dist/cli/projects.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
+
import { absolutePath } from "../config.js";
|
|
3
4
|
import Table from "cli-table3";
|
|
4
5
|
import { discoverWorkspaces, forgetProject, startProject, stopProject, tildify, } from "../inspector/instances.js";
|
|
5
6
|
/**
|
|
@@ -15,7 +16,7 @@ import { discoverWorkspaces, forgetProject, startProject, stopProject, tildify,
|
|
|
15
16
|
* <ref> is a project name, the root's folder name, the root path, or a
|
|
16
17
|
* port / localhost:port for running instances that recorded no root.
|
|
17
18
|
*/
|
|
18
|
-
const fmtAgo = (iso) => {
|
|
19
|
+
export const fmtAgo = (iso) => {
|
|
19
20
|
if (!iso)
|
|
20
21
|
return "—";
|
|
21
22
|
const s = Math.max(0, (Date.now() - Date.parse(iso)) / 1000);
|
|
@@ -43,7 +44,7 @@ const status = (e) => {
|
|
|
43
44
|
/** Match a ref against known workspaces; `needRoot` excludes rootless live instances (start/forget need a root). */
|
|
44
45
|
async function resolveRef(ref, needRoot = true) {
|
|
45
46
|
const all = (await discoverWorkspaces()).filter((e) => e.root || !needRoot);
|
|
46
|
-
const abs =
|
|
47
|
+
const abs = absolutePath(ref);
|
|
47
48
|
const port = /^\d+$/.test(ref) ? `http://localhost:${ref}` : `http://${ref.replace(/^https?:\/\//, "")}`;
|
|
48
49
|
const hits = all.filter((e) => e.root === abs ||
|
|
49
50
|
e.root === ref ||
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import Table from "cli-table3";
|
|
3
|
+
import { addRepo, listRepos, removeRepo, updateRepo } from "../inspector/repos.js";
|
|
4
|
+
import { fmtAgo } from "./projects.js";
|
|
5
|
+
import { initContext as prepare } from "./routines.js";
|
|
6
|
+
/**
|
|
7
|
+
* `kraftwerk repos` — the git repositories the agents work on, kept under
|
|
8
|
+
* the project's repos root (`repos.root` in kraftwerk.yml). The same module
|
|
9
|
+
* the inspector uses, so a clone made here shows up on the repositories
|
|
10
|
+
* screen and in every agent's context at once:
|
|
11
|
+
*
|
|
12
|
+
* kraftwerk repos list: name, branch, head, state
|
|
13
|
+
* kraftwerk repos add <url> [--name x] [--branch b] [--depth n]
|
|
14
|
+
* kraftwerk repos update <name> fetch, fast-forward when clean
|
|
15
|
+
* kraftwerk repos remove <name> [--force]
|
|
16
|
+
*/
|
|
17
|
+
const die = (msg) => {
|
|
18
|
+
console.error(chalk.red(msg));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
};
|
|
21
|
+
export function registerRepoCommands(program) {
|
|
22
|
+
const repos = program
|
|
23
|
+
.command("repos")
|
|
24
|
+
.description("Repositories the agents work on: list, clone one into the repos root, update, remove");
|
|
25
|
+
repos
|
|
26
|
+
.command("list", { isDefault: true })
|
|
27
|
+
.description("List the clones under the repos root with branch, head and state")
|
|
28
|
+
.option("--json", "Machine-readable output")
|
|
29
|
+
.action(async (opts) => {
|
|
30
|
+
await prepare();
|
|
31
|
+
const view = await listRepos();
|
|
32
|
+
if (opts.json) {
|
|
33
|
+
console.log(JSON.stringify(view, null, 2));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!view.enabled)
|
|
37
|
+
die(view.error ?? "repositories are off");
|
|
38
|
+
if (view.repos.length === 0) {
|
|
39
|
+
console.log(chalk.dim(`No repositories under ${view.root} yet — \`kraftwerk repos add <url>\` clones one.`));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const table = new Table({
|
|
43
|
+
head: ["name", "branch", "head", "state", "url"].map((h) => chalk.bold(h)),
|
|
44
|
+
wordWrap: true,
|
|
45
|
+
colWidths: [22, 16, 30, 18, 40],
|
|
46
|
+
});
|
|
47
|
+
for (const r of view.repos) {
|
|
48
|
+
const state = r.error
|
|
49
|
+
? chalk.red(r.error)
|
|
50
|
+
: [
|
|
51
|
+
r.dirty ? chalk.yellow(`${r.dirty} changed`) : "",
|
|
52
|
+
r.ahead ? chalk.green(`${r.ahead}↑`) : "",
|
|
53
|
+
r.behind ? chalk.cyan(`${r.behind}↓`) : "",
|
|
54
|
+
]
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.join(" ") || chalk.dim("clean");
|
|
57
|
+
table.push([
|
|
58
|
+
chalk.cyan(r.slug),
|
|
59
|
+
r.branch ?? "—",
|
|
60
|
+
r.head ? `${r.head} ${chalk.dim(r.subject ?? "")}\n${chalk.dim(fmtAgo(r.committedAt))}` : "—",
|
|
61
|
+
state,
|
|
62
|
+
r.url ?? chalk.dim("(no origin)"),
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
console.log(table.toString());
|
|
66
|
+
console.log(chalk.dim(view.root ?? ""));
|
|
67
|
+
});
|
|
68
|
+
repos
|
|
69
|
+
.command("add")
|
|
70
|
+
.description("Clone a repository into the repos root")
|
|
71
|
+
.argument("<url>", "git url, or github:org/repo")
|
|
72
|
+
.option("--name <name>", "Folder name under the root (default: last url segment)")
|
|
73
|
+
.option("--branch <branch>", "Branch to check out")
|
|
74
|
+
.option("--depth <n>", "Shallow clone with n commits of history (large repositories)")
|
|
75
|
+
.option("--json", "Print the new entry as JSON")
|
|
76
|
+
.action(async (url, opts) => {
|
|
77
|
+
await prepare();
|
|
78
|
+
try {
|
|
79
|
+
const depth = opts.depth === undefined ? undefined : Number(opts.depth);
|
|
80
|
+
const repo = await addRepo({ url, name: opts.name, branch: opts.branch, depth });
|
|
81
|
+
if (opts.json)
|
|
82
|
+
console.log(JSON.stringify(repo, null, 2));
|
|
83
|
+
else
|
|
84
|
+
console.log(`${chalk.green("✔")} ${chalk.cyan(repo.slug)} → ${repo.path}${repo.branch ? chalk.dim(` (${repo.branch})`) : ""}`);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
die(err.message);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
repos
|
|
91
|
+
.command("update")
|
|
92
|
+
.description("Fetch a repository and fast-forward it when it is clean")
|
|
93
|
+
.argument("<name>", "Folder name under the root")
|
|
94
|
+
.action(async (name) => {
|
|
95
|
+
await prepare();
|
|
96
|
+
const r = await updateRepo(name).catch((err) => ({ ok: false, error: err.message, repo: undefined }));
|
|
97
|
+
if (!r.ok)
|
|
98
|
+
die(r.error ?? "update failed");
|
|
99
|
+
const repo = r.repo;
|
|
100
|
+
const tail = r.error ? chalk.yellow(` — ${r.error}`) : "";
|
|
101
|
+
console.log(`${chalk.green("✔")} ${chalk.cyan(name)} at ${repo.head} ${chalk.dim(repo.subject ?? "")}${tail}`);
|
|
102
|
+
});
|
|
103
|
+
repos
|
|
104
|
+
.command("remove")
|
|
105
|
+
.description("Delete a clone from the repos root (refused while it holds unpushed or uncommitted work)")
|
|
106
|
+
.argument("<name>", "Folder name under the root")
|
|
107
|
+
.option("--force", "Delete even with local changes")
|
|
108
|
+
.action(async (name, opts) => {
|
|
109
|
+
await prepare();
|
|
110
|
+
const r = await removeRepo(name, !!opts.force).catch((err) => ({ ok: false, error: err.message }));
|
|
111
|
+
if (!r.ok)
|
|
112
|
+
die(r.error ?? "remove failed");
|
|
113
|
+
console.log(`${chalk.green("✔")} removed ${chalk.cyan(name)}`);
|
|
114
|
+
});
|
|
115
|
+
}
|
package/dist/cli/routines.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* `kraftwerk routines` — CLI surface over per-agent scheduled prompts
|
|
4
|
+
* (agents/<slug>/routines.yml). Definition CRUD works directly on the
|
|
5
|
+
* files; `run` fires through the running inspector server, because the
|
|
6
|
+
* session (chat) and the scheduler live there.
|
|
7
|
+
*/
|
|
8
|
+
/** Point the inspector context at this project so agent/routine paths resolve. */
|
|
9
|
+
export declare function initContext(): Promise<{
|
|
10
|
+
port: number;
|
|
11
|
+
}>;
|
|
2
12
|
export declare function registerRoutineCommands(program: Command): void;
|
package/dist/cli/routines.js
CHANGED
|
@@ -12,7 +12,7 @@ import { getAgent, listAgents } from "../inspector/agents.js";
|
|
|
12
12
|
* session (chat) and the scheduler live there.
|
|
13
13
|
*/
|
|
14
14
|
/** Point the inspector context at this project so agent/routine paths resolve. */
|
|
15
|
-
async function initContext() {
|
|
15
|
+
export async function initContext() {
|
|
16
16
|
const project = await resolveProject(process.cwd());
|
|
17
17
|
setProjectRoot(project.root);
|
|
18
18
|
setOutputDir(project.outputDir);
|
package/dist/cli/ui.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { spawn, spawnSync } from "node:child_process";
|
|
6
6
|
import chalk from "chalk";
|
|
7
|
-
import { resolveProject } from "../config.js";
|
|
7
|
+
import { absolutePath, resolveProject } from "../config.js";
|
|
8
8
|
import { selfCommand } from "../inspector/self-command.js";
|
|
9
9
|
import { RESTART_EXIT_CODE, startInspector } from "../inspector/server.js";
|
|
10
10
|
/**
|
|
@@ -52,7 +52,7 @@ export async function runUi(cwd, opts) {
|
|
|
52
52
|
return superviseUi(opts);
|
|
53
53
|
const staticDir = ensureBuilt();
|
|
54
54
|
const project = await resolveProject(cwd);
|
|
55
|
-
const outputDir = opts.output ?
|
|
55
|
+
const outputDir = opts.output ? absolutePath(opts.output, cwd) : project.outputDir;
|
|
56
56
|
// Port precedence: --port flag > kraftwerk.yml `port` > 1981.
|
|
57
57
|
const port = opts.port ? Number(opts.port) : (project.config.port ?? 1981);
|
|
58
58
|
await startInspector({ outputDir, staticDir, port, projectRoot: project.root });
|
package/dist/config.d.ts
CHANGED
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
* remote: origin
|
|
26
26
|
* interval: 300 # seconds between background fetches
|
|
27
27
|
* autosync: pull # off | pull
|
|
28
|
+
* repos: # git repositories the agents work on (absent = off, bare key = on)
|
|
29
|
+
* root: kraftwerk-data/repos # where clones land, relative to the file. Default: repos
|
|
28
30
|
*/
|
|
29
31
|
/** Stable, versionless URL of the workflow JSON schema (editor validation). */
|
|
30
32
|
export declare const SCHEMA_URL = "https://raw.githubusercontent.com/NETNODEAG/kraftwerk/main/kraftwerk/schema/workflow.schema.json";
|
|
@@ -49,6 +51,29 @@ export interface GitConfig {
|
|
|
49
51
|
/** off = fetch only. pull = also fast-forward when behind and clean. Default: pull. */
|
|
50
52
|
autosync?: "off" | "pull";
|
|
51
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Repositories: git clones the agents work on, kept under one root inside
|
|
56
|
+
* the project so every agent finds them at a known path. The root is never
|
|
57
|
+
* synced by the workspace git and should be git-ignored.
|
|
58
|
+
*/
|
|
59
|
+
export interface ReposConfig {
|
|
60
|
+
/** false keeps the block but turns the feature off. Default: true. */
|
|
61
|
+
enabled?: boolean;
|
|
62
|
+
/** Where clones land, relative to the project root. Default: repos */
|
|
63
|
+
root?: string;
|
|
64
|
+
}
|
|
65
|
+
/** Where clones land when `repos.root` is not set. */
|
|
66
|
+
export declare const REPOS_DEFAULT_ROOT = "repos";
|
|
67
|
+
/**
|
|
68
|
+
* Absolute repos root when the feature is on, undefined otherwise. The one
|
|
69
|
+
* place that reads the block, so the sync exclude, the doctor check, the
|
|
70
|
+
* settings save and the module itself cannot disagree.
|
|
71
|
+
*/
|
|
72
|
+
export declare function reposRootFor(project: Project): string | undefined;
|
|
73
|
+
/** A directory as a .gitignore entry: relative, forward slashes, no trailing slash; undefined outside the root. */
|
|
74
|
+
export declare function ignoreEntryFor(projectRoot: string, dir: string): string | undefined;
|
|
75
|
+
/** True when .gitignore text already covers the entry (with or without a leading or trailing slash). */
|
|
76
|
+
export declare function gitignoreHas(text: string, entry: string): boolean;
|
|
52
77
|
/** One entry of the workspace switcher: another kraftwerk instance to link to. */
|
|
53
78
|
export interface SwitcherEntry {
|
|
54
79
|
/** Display name of the other workspace. */
|
|
@@ -79,6 +104,8 @@ export interface ProjectConfig {
|
|
|
79
104
|
switcher?: SwitcherEntry[];
|
|
80
105
|
/** Workspace git sync. Absent = off. */
|
|
81
106
|
git?: GitConfig;
|
|
107
|
+
/** Repositories the agents work on. Absent = off. */
|
|
108
|
+
repos?: ReposConfig;
|
|
82
109
|
}
|
|
83
110
|
export interface Project {
|
|
84
111
|
/** Absolute project root the CLI operates on. */
|
|
@@ -93,6 +120,14 @@ export interface Project {
|
|
|
93
120
|
outputDir: string;
|
|
94
121
|
}
|
|
95
122
|
/** True when the path exists and is a directory. */
|
|
123
|
+
/**
|
|
124
|
+
* A user-supplied path as an absolute one: a leading `~` is the home
|
|
125
|
+
* directory (shells expand it, JSON bodies and quoted args do not), then
|
|
126
|
+
* path.resolve. Every path that gets stored or compared — registry roots,
|
|
127
|
+
* `--output`, project refs — goes through here so nothing ever persists
|
|
128
|
+
* `~/…` or `<cwd>/~/…`.
|
|
129
|
+
*/
|
|
130
|
+
export declare function absolutePath(p: string, from?: string): string;
|
|
96
131
|
export declare const isDir: (p: string) => Promise<boolean>;
|
|
97
132
|
/**
|
|
98
133
|
* Resolve the project for a cwd: walk up until a kraftwerk.yml or a
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile, stat } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { parse } from "yaml";
|
|
4
5
|
/**
|
|
@@ -28,6 +29,8 @@ import { parse } from "yaml";
|
|
|
28
29
|
* remote: origin
|
|
29
30
|
* interval: 300 # seconds between background fetches
|
|
30
31
|
* autosync: pull # off | pull
|
|
32
|
+
* repos: # git repositories the agents work on (absent = off, bare key = on)
|
|
33
|
+
* root: kraftwerk-data/repos # where clones land, relative to the file. Default: repos
|
|
31
34
|
*/
|
|
32
35
|
/** Stable, versionless URL of the workflow JSON schema (editor validation). */
|
|
33
36
|
export const SCHEMA_URL = "https://raw.githubusercontent.com/NETNODEAG/kraftwerk/main/kraftwerk/schema/workflow.schema.json";
|
|
@@ -35,8 +38,44 @@ export const SCHEMA_URL = "https://raw.githubusercontent.com/NETNODEAG/kraftwerk
|
|
|
35
38
|
export const CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/NETNODEAG/kraftwerk/main/kraftwerk/schema/kraftwerk.schema.json";
|
|
36
39
|
export const CONFIG_FILENAMES = ["kraftwerk.yml", "kraftwerk.yaml"];
|
|
37
40
|
const WORKFLOW_ROOT_CANDIDATES = ["src/workflows", "workflows"];
|
|
41
|
+
/** Where clones land when `repos.root` is not set. */
|
|
42
|
+
export const REPOS_DEFAULT_ROOT = "repos";
|
|
43
|
+
/**
|
|
44
|
+
* Absolute repos root when the feature is on, undefined otherwise. The one
|
|
45
|
+
* place that reads the block, so the sync exclude, the doctor check, the
|
|
46
|
+
* settings save and the module itself cannot disagree.
|
|
47
|
+
*/
|
|
48
|
+
export function reposRootFor(project) {
|
|
49
|
+
const r = project.config.repos;
|
|
50
|
+
if (!r || r.enabled === false)
|
|
51
|
+
return undefined;
|
|
52
|
+
return path.resolve(project.root, r.root ?? REPOS_DEFAULT_ROOT);
|
|
53
|
+
}
|
|
54
|
+
/** A directory as a .gitignore entry: relative, forward slashes, no trailing slash; undefined outside the root. */
|
|
55
|
+
export function ignoreEntryFor(projectRoot, dir) {
|
|
56
|
+
const rel = path.relative(projectRoot, path.resolve(projectRoot, dir)).split(path.sep).join("/");
|
|
57
|
+
if (!rel || rel === "." || rel.startsWith(".."))
|
|
58
|
+
return undefined;
|
|
59
|
+
return rel;
|
|
60
|
+
}
|
|
61
|
+
/** True when .gitignore text already covers the entry (with or without a leading or trailing slash). */
|
|
62
|
+
export function gitignoreHas(text, entry) {
|
|
63
|
+
return text.split("\n").some((l) => l.trim().replace(/^\//, "").replace(/\/$/, "") === entry);
|
|
64
|
+
}
|
|
38
65
|
const exists = async (p) => !!(await stat(p).catch(() => null));
|
|
39
66
|
/** True when the path exists and is a directory. */
|
|
67
|
+
/**
|
|
68
|
+
* A user-supplied path as an absolute one: a leading `~` is the home
|
|
69
|
+
* directory (shells expand it, JSON bodies and quoted args do not), then
|
|
70
|
+
* path.resolve. Every path that gets stored or compared — registry roots,
|
|
71
|
+
* `--output`, project refs — goes through here so nothing ever persists
|
|
72
|
+
* `~/…` or `<cwd>/~/…`.
|
|
73
|
+
*/
|
|
74
|
+
export function absolutePath(p, from = process.cwd()) {
|
|
75
|
+
if (p === "~" || p.startsWith("~/") || p.startsWith("~\\"))
|
|
76
|
+
p = path.join(os.homedir(), p.slice(1));
|
|
77
|
+
return path.resolve(from, p);
|
|
78
|
+
}
|
|
40
79
|
export const isDir = async (p) => (await stat(p).catch(() => null))?.isDirectory() ?? false;
|
|
41
80
|
async function findConfigFile(dir) {
|
|
42
81
|
for (const name of CONFIG_FILENAMES) {
|
|
@@ -87,7 +126,7 @@ export async function resolveProject(cwd) {
|
|
|
87
126
|
const root = gitFallback ?? start;
|
|
88
127
|
return { root, config: {}, outputDir: path.join(root, "output") };
|
|
89
128
|
}
|
|
90
|
-
const KNOWN_KEYS = ["name", "icon", "port", "workflows", "output", "knowledge", "agents", "skills", "switcher", "git"];
|
|
129
|
+
const KNOWN_KEYS = ["name", "icon", "port", "workflows", "output", "knowledge", "agents", "skills", "switcher", "git", "repos"];
|
|
91
130
|
async function loadConfig(configPath) {
|
|
92
131
|
let raw;
|
|
93
132
|
try {
|
|
@@ -123,6 +162,11 @@ async function loadConfig(configPath) {
|
|
|
123
162
|
config[key] = {};
|
|
124
163
|
validateGit(configPath, config[key]);
|
|
125
164
|
}
|
|
165
|
+
else if (key === "repos") {
|
|
166
|
+
if (config[key] === null)
|
|
167
|
+
config[key] = {};
|
|
168
|
+
validateRepos(configPath, config[key]);
|
|
169
|
+
}
|
|
126
170
|
else if (typeof config[key] !== "string") {
|
|
127
171
|
throw new Error(`${path.basename(configPath)}: ${key} must be a string`);
|
|
128
172
|
}
|
|
@@ -182,3 +226,26 @@ function validateGit(configPath, value) {
|
|
|
182
226
|
throw new Error(`${file}: git.autosync must be "off" or "pull"`);
|
|
183
227
|
}
|
|
184
228
|
}
|
|
229
|
+
function validateRepos(configPath, value) {
|
|
230
|
+
const file = path.basename(configPath);
|
|
231
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
232
|
+
throw new Error(`${file}: repos must be a mapping (enabled, root)`);
|
|
233
|
+
}
|
|
234
|
+
const r = value;
|
|
235
|
+
for (const key of Object.keys(r)) {
|
|
236
|
+
if (!["enabled", "root"].includes(key)) {
|
|
237
|
+
throw new Error(`${file}: repos.${key} is unknown (allowed: enabled, root)`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (r.enabled !== undefined && typeof r.enabled !== "boolean") {
|
|
241
|
+
throw new Error(`${file}: repos.enabled must be true or false`);
|
|
242
|
+
}
|
|
243
|
+
if (r.root !== undefined && (typeof r.root !== "string" || !r.root.trim())) {
|
|
244
|
+
throw new Error(`${file}: repos.root must be a non-empty string`);
|
|
245
|
+
}
|
|
246
|
+
// The root is what `repos remove --force` deletes under, so it must never
|
|
247
|
+
// be the project itself or anything outside it.
|
|
248
|
+
if (typeof r.root === "string" && !ignoreEntryFor(path.dirname(configPath), r.root.trim())) {
|
|
249
|
+
throw new Error(`${file}: repos.root must be a directory inside the project (not ".", ".." or an absolute path outside it)`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -6,6 +6,7 @@ import { getRun, listRuns, safeRunDir } from "../runs.js";
|
|
|
6
6
|
import { listSkills, readSkill } from "../skills.js";
|
|
7
7
|
import { listWorkflows } from "../workflows.js";
|
|
8
8
|
import { getAgent, listAgents } from "../agents.js";
|
|
9
|
+
import { listRepos } from "../repos.js";
|
|
9
10
|
import { startAcpBackend } from "./acp.js";
|
|
10
11
|
import { startPiBackend } from "./pi.js";
|
|
11
12
|
import { appendEvent, listChatMetas, newChatId, readEvents, readMeta, safeChatDir, writeMeta, } from "./store.js";
|
|
@@ -144,6 +145,29 @@ async function agentKnowledgeContext(def) {
|
|
|
144
145
|
`Never hand-edit index.md or log.md, and never add \`verified\` yourself — verification is the human's ` +
|
|
145
146
|
`click in the UI.\n\n`);
|
|
146
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* "## Repositories" block: the clones under the repos root, when the
|
|
150
|
+
* feature is on. Empty when it is off, so agents in a workspace without
|
|
151
|
+
* it never hear about it.
|
|
152
|
+
*/
|
|
153
|
+
async function reposContext() {
|
|
154
|
+
const view = await listRepos().catch(() => null);
|
|
155
|
+
if (!view?.enabled || !view.root)
|
|
156
|
+
return "";
|
|
157
|
+
const lines = view.repos
|
|
158
|
+
.map((r) => {
|
|
159
|
+
const state = r.error ? `unreadable: ${r.error}` : [r.dirty ? `${r.dirty} uncommitted` : "clean", r.ahead ? `${r.ahead} ahead` : "", r.behind ? `${r.behind} behind` : ""].filter(Boolean).join(", ");
|
|
160
|
+
return `- ${r.slug} — ${r.path}${r.url ? ` (${r.url})` : ""}${r.branch ? `, branch ${r.branch}` : ""}${r.head ? ` @ ${r.head}` : ""}, ${state}`;
|
|
161
|
+
})
|
|
162
|
+
.join("\n");
|
|
163
|
+
return (`## Repositories\nGit repositories this workspace works on live under ${view.root} (one clone per folder). ` +
|
|
164
|
+
`When the user names one of them, work inside its folder: read its README and structure first, keep commits on a ` +
|
|
165
|
+
`branch unless told otherwise, and never push or force-push without asking.\n${lines || "(none cloned yet)"}\n\n` +
|
|
166
|
+
`Clone a new one with \`npx kraftwerk repos add <url> [--name <folder>] [--branch <b>] [--depth <n>]\` so it lands in ` +
|
|
167
|
+
`that root (\`--depth 1\` for a large repository; a plain \`git clone\` into that folder works too); ` +
|
|
168
|
+
`\`npx kraftwerk repos\` lists them, \`update <name>\` fetches and fast-forwards a clean clone, \`remove <name>\` ` +
|
|
169
|
+
`deletes one. A repository the user mentions that is not listed is not cloned yet — offer to add it.`);
|
|
170
|
+
}
|
|
147
171
|
/** Base context per scope; scopeContext() appends the shared skills block. */
|
|
148
172
|
async function baseScopeContext(scope, agent) {
|
|
149
173
|
if (scope.kind === "agent") {
|
|
@@ -278,11 +302,14 @@ const RENDERING_BLOCK = `## Chat rendering\n` +
|
|
|
278
302
|
`Prefer these relative /api/... URLs over file paths when showing results: they render directly ` +
|
|
279
303
|
`in this chat and keep working wherever the inspector is reachable.`;
|
|
280
304
|
async function scopeContext(scope, agent) {
|
|
281
|
-
|
|
305
|
+
// The repositories block reads every clone from git, so it runs alongside
|
|
306
|
+
// the rest instead of adding its spawns to the first prompt's latency.
|
|
307
|
+
const [base, repos, skills] = await Promise.all([
|
|
282
308
|
baseScopeContext(scope, agent),
|
|
309
|
+
scope.kind === "agent" || scope.kind === "kraftwerk" ? reposContext() : Promise.resolve(""),
|
|
283
310
|
availableSkills(scope),
|
|
284
311
|
]);
|
|
285
|
-
return [base, RENDERING_BLOCK, skillsBlock(skills)].filter(Boolean).join("\n\n");
|
|
312
|
+
return [base, repos, RENDERING_BLOCK, skillsBlock(skills)].filter(Boolean).join("\n\n");
|
|
286
313
|
}
|
|
287
314
|
/* ---------- backend lifecycle ---------- */
|
|
288
315
|
/** Agent sessions carry the agent's model/effort; resolved live so edits apply to new backends. */
|
package/dist/inspector/git.d.ts
CHANGED
|
@@ -40,6 +40,20 @@ export interface GitDiff {
|
|
|
40
40
|
/** The diff was cut at MAX_DIFF; the rest is available in a terminal. */
|
|
41
41
|
truncated?: boolean;
|
|
42
42
|
}
|
|
43
|
+
export interface GitResult {
|
|
44
|
+
ok: boolean;
|
|
45
|
+
/** Exit status, or null when git never ran (spawn error) or was killed. */
|
|
46
|
+
code: number | null;
|
|
47
|
+
stdout: string;
|
|
48
|
+
stderr: string;
|
|
49
|
+
}
|
|
50
|
+
export declare const NET_TIMEOUT = 60000;
|
|
51
|
+
export declare function git(args: string[], cwd: string, timeoutMs?: number, env?: NodeJS.ProcessEnv): Promise<GitResult>;
|
|
52
|
+
export declare function sshCommandFor(repoRoot: string): Promise<string>;
|
|
53
|
+
/** A git call that may touch the network: longer timeout, non-interactive ssh. */
|
|
54
|
+
export declare function gitNet(args: string[], repoRoot: string): Promise<GitResult>;
|
|
55
|
+
/** Repo root for a directory, or null when it is not inside a git repo. */
|
|
56
|
+
export declare function repoRootFor(dir: string): Promise<string | null>;
|
|
43
57
|
/**
|
|
44
58
|
* Everything the git screen renders. Each call shells out to git a handful
|
|
45
59
|
* of times, and the nav badge polls it from every open tab, so results are
|