diacode 0.2.3 → 0.3.0-rc.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/CHANGELOG.md +55 -0
- package/README.md +7 -7
- package/bin/{dcursed.js → diacode.js} +335 -145
- package/editor/app/compact/index.html +3 -3
- package/editor/app/index.html +3 -3
- package/editor/assets/{app-BukOKzI8.css → app-CjcAXrq_.css} +1 -1
- package/editor/assets/{app-DkKBnx6M.js → app-DVSOOhHv.js} +14 -14
- package/editor/assets/{compact-BwaR1-sL.js → compact-C0l0YQyL.js} +14 -14
- package/editor/assets/{compact-DPQA5WVu.css → compact-CI7siydb.css} +1 -1
- package/editor/assets/fonts-B3jhzXCH.js +156 -0
- package/opencode-plugin.js +19 -19
- package/package.json +2 -2
- package/editor/assets/fonts-D2FlQA0D.js +0 -156
|
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
|
5
5
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
// packages/server/bin/
|
|
8
|
+
// packages/server/bin/diacode.js
|
|
9
9
|
import { existsSync as existsSync2, readFileSync as readFileSync3, statSync } from "node:fs";
|
|
10
10
|
import { resolve as resolve6, relative as relative4 } from "node:path";
|
|
11
11
|
|
|
@@ -126,9 +126,9 @@ var EDGE_KINDS = (
|
|
|
126
126
|
["needs", "after", "approve", "ask", "input"]
|
|
127
127
|
);
|
|
128
128
|
var CHECKPOINTS = /* @__PURE__ */ new Set(["approve", "ask", "input"]);
|
|
129
|
-
var SCHEMA = "
|
|
130
|
-
var OLDER = ["dcursed.plan/0"];
|
|
131
|
-
var SOURCES = ["dcursed", "cursor-plan", "claude-code-plan", "mermaid", "markdown"];
|
|
129
|
+
var SCHEMA = "diacode.plan/1";
|
|
130
|
+
var OLDER = ["diacode.plan/0", "dcursed.plan/1", "dcursed.plan/0"];
|
|
131
|
+
var SOURCES = ["diacode", "dcursed", "cursor-plan", "claude-code-plan", "mermaid", "markdown"];
|
|
132
132
|
var STATUS_FROM = ["reported", "observed", "you"];
|
|
133
133
|
var isString = (v, min = 0, max = Infinity) => typeof v === "string" && v.length >= min && v.length <= max;
|
|
134
134
|
var FILES_MAX = 64;
|
|
@@ -140,7 +140,9 @@ var isOptionList = (v) => Array.isArray(v) && v.length >= 1 && v.length <= OPTIO
|
|
|
140
140
|
var OPTIONS_PROBLEM = `options is 1-${OPTIONS_MAX} answers, each 1-${OPTION_MAX} characters with no space at either end`;
|
|
141
141
|
var NOTE_MAX = 2e3;
|
|
142
142
|
function upgradePlan(plan) {
|
|
143
|
-
|
|
143
|
+
if (!isObject(plan) || !OLDER.includes(plan.schema)) return plan;
|
|
144
|
+
const source = isObject(plan.source) && plan.source.kind === "dcursed" ? { source: { ...plan.source, kind: "diacode" } } : {};
|
|
145
|
+
return { ...plan, ...source, schema: SCHEMA };
|
|
144
146
|
}
|
|
145
147
|
var isFileList = (v) => Array.isArray(v) && v.length <= FILES_MAX && v.every((s) => isString(s, 1, FILE_MAX));
|
|
146
148
|
var FILES_PROBLEM = `files is a list of paths or globs (at most ${FILES_MAX}, each 1-${FILE_MAX} characters)`;
|
|
@@ -1278,7 +1280,7 @@ var STEP = { along: 230, across: 72 };
|
|
|
1278
1280
|
var FIRST = { along: 90, across: 50 };
|
|
1279
1281
|
var MARGIN = { x: 70, y: 55 };
|
|
1280
1282
|
var MIN_CANVAS = { width: 640, height: 240 };
|
|
1281
|
-
var newLayout = (planId, direction = "LR") => ({ schema: "
|
|
1283
|
+
var newLayout = (planId, direction = "LR") => ({ schema: "diacode.layout/0", plan: planId, direction, canvas: { ...MIN_CANVAS }, nodes: {} });
|
|
1282
1284
|
function placeUnplaced(plan, layout, { paths, loops = false } = {}) {
|
|
1283
1285
|
const td = layout.direction === "TD";
|
|
1284
1286
|
const get = (p) => td ? { along: p.y, across: p.x } : { along: p.x, across: p.y };
|
|
@@ -1678,7 +1680,7 @@ function describeBrief({ plan, review }) {
|
|
|
1678
1680
|
`DiaCode plan "${plan.title}" (${plan.id}) \xB7 rev ${plan.rev} \xB7 ${plan.phase} \xB7 ${finished}/${work.length} done.`,
|
|
1679
1681
|
...plan.phase === "paused" ? [PAUSED] : [],
|
|
1680
1682
|
...parts.length ? [parts.join(" ")] : [],
|
|
1681
|
-
"The person edits this plan while you work. Follow it with the
|
|
1683
|
+
"The person edits this plan while you work. Follow it with the diacode tools (plan_read, step_start, step_done), report as you go, and read what changed since you last looked."
|
|
1682
1684
|
].join("\n");
|
|
1683
1685
|
}
|
|
1684
1686
|
|
|
@@ -2072,6 +2074,7 @@ __export(arch_exports, {
|
|
|
2072
2074
|
standIn: () => standIn,
|
|
2073
2075
|
stepArrow: () => stepArrow,
|
|
2074
2076
|
toFlowchart: () => toFlowchart,
|
|
2077
|
+
upgradeArch: () => upgradeArch,
|
|
2075
2078
|
usedBy: () => usedBy,
|
|
2076
2079
|
usersOf: () => usersOf,
|
|
2077
2080
|
validateArch: () => validateArch,
|
|
@@ -2127,7 +2130,8 @@ function standIn(arch2, id, folded) {
|
|
|
2127
2130
|
}
|
|
2128
2131
|
|
|
2129
2132
|
// packages/core/src/arch/validate.js
|
|
2130
|
-
var SCHEMA2 = "
|
|
2133
|
+
var SCHEMA2 = "diacode.arch/0";
|
|
2134
|
+
var OLDER2 = ["dcursed.arch/0"];
|
|
2131
2135
|
var KINDS2 = (
|
|
2132
2136
|
/** @type {const} */
|
|
2133
2137
|
["person", "service", "component", "store", "queue", "group"]
|
|
@@ -2136,7 +2140,12 @@ var PHASES2 = (
|
|
|
2136
2140
|
/** @type {const} */
|
|
2137
2141
|
["draft", "accepted"]
|
|
2138
2142
|
);
|
|
2139
|
-
var SOURCES2 = ["dcursed", "mermaid", "c4", "markdown", "cursor-plan"];
|
|
2143
|
+
var SOURCES2 = ["diacode", "dcursed", "mermaid", "c4", "markdown", "cursor-plan"];
|
|
2144
|
+
function upgradeArch(a) {
|
|
2145
|
+
if (!isObject2(a) || !OLDER2.includes(a.schema)) return a;
|
|
2146
|
+
const source = isObject2(a.source) && a.source.kind === "dcursed" ? { source: { ...a.source, kind: "diacode" } } : {};
|
|
2147
|
+
return { ...a, ...source, schema: SCHEMA2 };
|
|
2148
|
+
}
|
|
2140
2149
|
var TECH_MAX = 120;
|
|
2141
2150
|
var FLOWS_MAX = 40;
|
|
2142
2151
|
var FLOW_STEPS_MAX = 60;
|
|
@@ -2653,15 +2662,17 @@ function addArrow(a, op) {
|
|
|
2653
2662
|
|
|
2654
2663
|
// packages/core/src/arch/log.js
|
|
2655
2664
|
function newArch({ title, goal, phase = "accepted", source }) {
|
|
2656
|
-
return { schema: SCHEMA2, title, ...goal ? { goal } : {}, rev: 0, phase, source: source ?? { kind: "
|
|
2665
|
+
return { schema: SCHEMA2, title, ...goal ? { goal } : {}, rev: 0, phase, source: source ?? { kind: "diacode" }, nodes: {}, edges: [], flows: [] };
|
|
2657
2666
|
}
|
|
2658
2667
|
function replay2(start, lines) {
|
|
2659
2668
|
let arch2 = start;
|
|
2660
2669
|
for (const line of lines) {
|
|
2661
2670
|
if (line.snapshot) {
|
|
2662
|
-
arch2 =
|
|
2663
|
-
|
|
2664
|
-
|
|
2671
|
+
arch2 = upgradeArch(
|
|
2672
|
+
/** @type {Arch} */
|
|
2673
|
+
/** @type {unknown} */
|
|
2674
|
+
structuredClone(line.snapshot)
|
|
2675
|
+
);
|
|
2665
2676
|
if (arch2.rev !== line.rev) throw new Error(`log rev ${line.rev}: the snapshot is rev ${arch2.rev}`);
|
|
2666
2677
|
continue;
|
|
2667
2678
|
}
|
|
@@ -3302,7 +3313,7 @@ function newPlan({ id, title, goal, source }) {
|
|
|
3302
3313
|
...goal ? { goal } : {},
|
|
3303
3314
|
rev: 0,
|
|
3304
3315
|
phase: "planning",
|
|
3305
|
-
source: source ?? { kind: "
|
|
3316
|
+
source: source ?? { kind: "diacode" },
|
|
3306
3317
|
nodes: {},
|
|
3307
3318
|
edges: []
|
|
3308
3319
|
};
|
|
@@ -3318,12 +3329,12 @@ import { watch, mkdirSync } from "node:fs";
|
|
|
3318
3329
|
// packages/server/src/files.js
|
|
3319
3330
|
import { mkdir, readFile, writeFile, rename, appendFile, readdir } from "node:fs/promises";
|
|
3320
3331
|
import { join, dirname } from "node:path";
|
|
3321
|
-
var plansDir = (root2) => join(root2, ".
|
|
3322
|
-
var
|
|
3332
|
+
var plansDir = (root2) => join(root2, ".diacode", "plans");
|
|
3333
|
+
var diacodeDir = (root2) => join(root2, ".diacode");
|
|
3323
3334
|
var archPathsOf = (root2) => ({
|
|
3324
|
-
arch: join(
|
|
3325
|
-
layout: join(
|
|
3326
|
-
log: join(
|
|
3335
|
+
arch: join(diacodeDir(root2), "architecture.json"),
|
|
3336
|
+
layout: join(diacodeDir(root2), "architecture.layout.json"),
|
|
3337
|
+
log: join(diacodeDir(root2), "architecture.log.jsonl")
|
|
3327
3338
|
});
|
|
3328
3339
|
var pathsOf = (root2, id) => ({
|
|
3329
3340
|
plan: join(plansDir(root2), `${id}.plan.json`),
|
|
@@ -3389,12 +3400,12 @@ var HttpError = class extends Error {
|
|
|
3389
3400
|
this.status = status;
|
|
3390
3401
|
}
|
|
3391
3402
|
};
|
|
3392
|
-
var DRIFT_IGNORED = /(^|\/)(\.
|
|
3403
|
+
var DRIFT_IGNORED = /(^|\/)(\.diacode|\.opencode|\.git|node_modules|dist|build|coverage)\/|(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml)$/;
|
|
3393
3404
|
var same3 = (a, b) => JSON.stringify(canonicalPlan(a)) === JSON.stringify(canonicalPlan(b));
|
|
3394
3405
|
var LIVE = /* @__PURE__ */ new Set(["planning", "approved", "executing", "paused"]);
|
|
3395
3406
|
var PlanStore = class extends EventEmitter {
|
|
3396
3407
|
/**
|
|
3397
|
-
* @param {string} root the repository; plans live in <root>/.
|
|
3408
|
+
* @param {string} root the repository; plans live in <root>/.diacode/plans/
|
|
3398
3409
|
* @param {{ now?: () => string }} [options]
|
|
3399
3410
|
*/
|
|
3400
3411
|
constructor(root2, { now = () => (/* @__PURE__ */ new Date()).toISOString() } = {}) {
|
|
@@ -3819,8 +3830,8 @@ function parsePlan(text2, id) {
|
|
|
3819
3830
|
function parseLayout(text2, id) {
|
|
3820
3831
|
try {
|
|
3821
3832
|
const l = JSON.parse(text2);
|
|
3822
|
-
if (
|
|
3823
|
-
return { ...l, direction: l.direction === "TD" ? "TD" : "LR" };
|
|
3833
|
+
if (!["diacode.layout/0", "dcursed.layout/0"].includes(l?.schema) || l.plan !== id || typeof l.nodes !== "object" || l.nodes === null) return null;
|
|
3834
|
+
return { ...l, schema: "diacode.layout/0", direction: l.direction === "TD" ? "TD" : "LR" };
|
|
3824
3835
|
} catch {
|
|
3825
3836
|
return null;
|
|
3826
3837
|
}
|
|
@@ -3837,7 +3848,7 @@ var same4 = (a, b) => JSON.stringify(arch.canonicalArch(a)) === JSON.stringify(a
|
|
|
3837
3848
|
var newLayout2 = () => newLayout(arch.LAYOUT_OF);
|
|
3838
3849
|
var ArchStore = class extends EventEmitter2 {
|
|
3839
3850
|
/**
|
|
3840
|
-
* @param {string} root the repository; the architecture lives in <root>/.
|
|
3851
|
+
* @param {string} root the repository; the architecture lives in <root>/.diacode/architecture.json
|
|
3841
3852
|
* @param {{ now?: () => string }} [options]
|
|
3842
3853
|
*/
|
|
3843
3854
|
constructor(root2, { now = () => (/* @__PURE__ */ new Date()).toISOString() } = {}) {
|
|
@@ -4032,7 +4043,7 @@ var ArchStore = class extends EventEmitter2 {
|
|
|
4032
4043
|
return this.proposeFootprint(planId, arch.dropPlannedOps, `plan ${planId} is abandoned: drop what it planned, and keep what it was going to retire`);
|
|
4033
4044
|
}
|
|
4034
4045
|
/**
|
|
4035
|
-
* @param {string} planId @param {(a: Arch, planId: string) => import('@
|
|
4046
|
+
* @param {string} planId @param {(a: Arch, planId: string) => import('@diacode/core/src/arch/types.js').Op[]} makeOps @param {string} reason
|
|
4036
4047
|
*/
|
|
4037
4048
|
proposeFootprint(planId, makeOps, reason) {
|
|
4038
4049
|
return this.enqueue(async () => {
|
|
@@ -4059,8 +4070,8 @@ var ArchStore = class extends EventEmitter2 {
|
|
|
4059
4070
|
// ── hand edits ───────────────────────────────────────────────────────────
|
|
4060
4071
|
/** Watch the folder; a file someone else wrote is a hand edit. */
|
|
4061
4072
|
watch() {
|
|
4062
|
-
mkdirSync2(
|
|
4063
|
-
this.watcher = watch2(
|
|
4073
|
+
mkdirSync2(diacodeDir(this.root), { recursive: true });
|
|
4074
|
+
this.watcher = watch2(diacodeDir(this.root), (_event, filename) => {
|
|
4064
4075
|
const m = filename && /^architecture(\.layout)?\.json$/.exec(String(filename));
|
|
4065
4076
|
if (!m) return;
|
|
4066
4077
|
clearTimeout(this.timers.get(m[0]));
|
|
@@ -4159,14 +4170,16 @@ function parseArch(text2) {
|
|
|
4159
4170
|
return `architecture.json is not JSON: ${/** @type {Error} */
|
|
4160
4171
|
e.message}`;
|
|
4161
4172
|
}
|
|
4173
|
+
parsed = arch.upgradeArch(parsed);
|
|
4162
4174
|
const problems = arch.validateArch(parsed);
|
|
4163
4175
|
return problems.length ? `architecture.json: ${problems.join("; ")}` : parsed;
|
|
4164
4176
|
}
|
|
4177
|
+
var LAYOUT_IDS = ["diacode.layout/0", "dcursed.layout/0"];
|
|
4165
4178
|
function parseLayout2(text2) {
|
|
4166
4179
|
try {
|
|
4167
4180
|
const l = JSON.parse(text2);
|
|
4168
|
-
if (l?.schema
|
|
4169
|
-
return { ...l, direction: l.direction === "TD" ? "TD" : "LR" };
|
|
4181
|
+
if (!LAYOUT_IDS.includes(l?.schema) || typeof l.nodes !== "object" || l.nodes === null) return null;
|
|
4182
|
+
return { ...l, schema: "diacode.layout/0", direction: l.direction === "TD" ? "TD" : "LR" };
|
|
4170
4183
|
} catch {
|
|
4171
4184
|
return null;
|
|
4172
4185
|
}
|
|
@@ -4177,7 +4190,7 @@ import { randomUUID } from "node:crypto";
|
|
|
4177
4190
|
|
|
4178
4191
|
// packages/server/src/guide.js
|
|
4179
4192
|
var FLOW_HINT = "How it goes: tell your agent the task. It draws the architecture in the editor; you change what is wrong and press Approve architecture. It draws the plan; you change it and press Approve plan. It checks the architecture against the plan and asks you about any change; then you press Start. After that, a change you make on one side is told to the agent, which proposes the matching change on the other.";
|
|
4180
|
-
var GUIDE = `DiaCode keeps this repository's architecture and plans as files in .
|
|
4193
|
+
var GUIDE = `DiaCode keeps this repository's architecture and plans as files in .diacode/, and the person edits them in a diagram while you work, so they change under you.
|
|
4181
4194
|
|
|
4182
4195
|
THE ORDER. The person approves each stage in the editor before the next; do the stage you are in, then STOP and say it is ready.
|
|
4183
4196
|
1. THE TASK. When the person gives you something to build or change, your first and only job is the ARCHITECTURE: call arch_draft with the system AS IT WILL BE (who uses it, the services, the parts inside them, the stores and queues, and how they use each other). Mark every part that does not exist yet planned: true. An empty repository is no excuse: draw what you are about to build. Then stop and say in a sentence that it is ready to review. Do not call plan_create, do not write code, and do not ask the person questions in your own window: assume what you need, say so in the architecture (the goal, a box's detail), and they correct the drawing.
|
|
@@ -4199,7 +4212,7 @@ How to work with a plan
|
|
|
4199
4212
|
- Once the person has approved a plan, changes to its structure (steps, arrows, labels) become proposals the person accepts; statuses and claims land at once. Finished steps are history: you cannot rewrite them.
|
|
4200
4213
|
- The person can PAUSE a plan: finish the step you are on, then start nothing new and end your turn; you are told when it resumes, with what they changed meanwhile. They can also STOP it: then stop at once, without finishing your step, and end your turn (every tool you call is refused until you do). A stopped plan waits for them to press Start again.
|
|
4201
4214
|
- When every step is done, say so in a sentence and stop: the person closes the plan in the editor, and is then asked whether to make the boxes it planned real.
|
|
4202
|
-
- Do not edit the files in .
|
|
4215
|
+
- Do not edit the files in .diacode/plans/ by hand. The tools check the rules and keep the log.
|
|
4203
4216
|
|
|
4204
4217
|
Showing the person something
|
|
4205
4218
|
- A step that shows the person something (a page, a running app, a file to open) leaves it RUNNING when the step ends: do not stop the server or close the window until the person has approved. Put the full address in that step's note (step_done), such as "Running at http://localhost:3000", and say there what to try. A checkpoint that asks the person to look at something (an approve checkpoint, or the label you give it) says what to look at and where, never "try npm start". The editor turns an address in a note into a link and puts an Open button on the checkpoint.
|
|
@@ -4208,11 +4221,11 @@ Working while the person watches
|
|
|
4208
4221
|
- Write and change files with your file tools, not with shell redirects or heredocs, and keep each shell command plain: one command, no loops, no variables. The person's tool asks them to approve every command it cannot check, and each such prompt holds the run until they come to its window.
|
|
4209
4222
|
|
|
4210
4223
|
The architecture
|
|
4211
|
-
- The repository has one ARCHITECTURE, in .
|
|
4224
|
+
- The repository has one ARCHITECTURE, in .diacode/architecture.json: the system as the person has approved it, which every plan is a change to. Its boxes are person, service, component, store, queue or group (external: someone else runs it); an arrow from A to B means A USES B (not "A first"); a box sits only in a service or a group, and a box with boxes inside it is a frame that takes no arrows. Flows are the ordered steps of what a user does, over those arrows.
|
|
4212
4225
|
- Draw what runs and who uses it, and keep it small: a few boxes per service. Tests, build scripts, docs and configuration are not boxes (list them in the files of the box they belong to): a test box that uses everything draws an arrow to everything. Keep arrow labels to a few words ("Fetch poems"); say the protocol in tech, not in the label.
|
|
4213
4226
|
- arch_read shows it; read it before you plan work that changes the system. arch_draft makes the first one (only when there is none; a repository that already has code is drawn from the code and the task together). A plan is refused until the person has approved an architecture.
|
|
4214
4227
|
- When a plan adds or removes a part of the system, say so in the architecture: arch_edit a box with planned: true (or retiring: "<plan id>"), and give the plan's steps the boxes they change with touches. When the plan is closed the person is asked to make it real.
|
|
4215
|
-
- Do not edit .
|
|
4228
|
+
- Do not edit .diacode/architecture.json by hand either.`;
|
|
4216
4229
|
|
|
4217
4230
|
// packages/server/src/calls.js
|
|
4218
4231
|
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
@@ -4278,7 +4291,7 @@ var Calls = class extends EventEmitter3 {
|
|
|
4278
4291
|
}
|
|
4279
4292
|
/**
|
|
4280
4293
|
* A batch landed. Only yours can make a call: an agent does not wake an agent.
|
|
4281
|
-
* @param {string} id @param {import('@
|
|
4294
|
+
* @param {string} id @param {import('@diacode/core/src/log.js').LogLine} line
|
|
4282
4295
|
*/
|
|
4283
4296
|
noticed(id, line) {
|
|
4284
4297
|
if (line.actor !== "you" || line.proposed) return;
|
|
@@ -4337,7 +4350,7 @@ var Calls = class extends EventEmitter3 {
|
|
|
4337
4350
|
* A batch landed on the architecture. Only yours can make a call. Accepting the draft an agent drew tells it that its
|
|
4338
4351
|
* changes are proposals from now on; accepting or rejecting a proposal tells the agent that made it what you decided
|
|
4339
4352
|
* (the server's own, for a finished plan's boxes, has no agent to tell). Several in a row are one call to each agent.
|
|
4340
|
-
* @param {{ rev: number, line: import('@
|
|
4353
|
+
* @param {{ rev: number, line: import('@diacode/core/src/log.js').LogLine, phaseWas?: string, quiet?: boolean }} e
|
|
4341
4354
|
*/
|
|
4342
4355
|
archNoticed({ rev, line, phaseWas, quiet }) {
|
|
4343
4356
|
const arch2 = this.arch?.arch;
|
|
@@ -4503,7 +4516,7 @@ var Calls = class extends EventEmitter3 {
|
|
|
4503
4516
|
/**
|
|
4504
4517
|
* You stopped a plan: an order for every agent at work on it (the ones that held the steps the stop put back, and
|
|
4505
4518
|
* any agent seen working on it or asking you in its window), and a `stopped` call to each that a plugin listens for.
|
|
4506
|
-
* @param {string} id @param {import('@
|
|
4519
|
+
* @param {string} id @param {import('@diacode/core/src/log.js').LogLine} line
|
|
4507
4520
|
*/
|
|
4508
4521
|
stopAll(id, line) {
|
|
4509
4522
|
const plan = this.store.get(id).plan;
|
|
@@ -4937,7 +4950,7 @@ function bareBoxesWords(bare) {
|
|
|
4937
4950
|
}
|
|
4938
4951
|
function startedText(plan, id, { archToo = false, again = false } = {}) {
|
|
4939
4952
|
return [
|
|
4940
|
-
`[DiaCode] The person pressed Start${again ? " again" : ""} on the plan "${plan.title}" (${id}) in the editor${archToo ? ", and approved the architecture you drew with it (your changes to the architecture are proposals from now on)" : ""}. Carry it out now with the
|
|
4953
|
+
`[DiaCode] The person pressed Start${again ? " again" : ""} on the plan "${plan.title}" (${id}) in the editor${archToo ? ", and approved the architecture you drew with it (your changes to the architecture are proposals from now on)" : ""}. Carry it out now with the diacode tools, one step at a time:`,
|
|
4941
4954
|
"step_start, do the work, then step_done saying what is true now. Read it with plan_read first, because the person may have changed it while reviewing.",
|
|
4942
4955
|
"If a step is unclear, stop on it with step_wait and say what you need. If doing the work makes the plan and the architecture disagree, propose the matching change on the other side (plan_edit or arch_edit, with a reason) instead of letting them drift."
|
|
4943
4956
|
].join(" ");
|
|
@@ -5736,7 +5749,7 @@ ${changes.map((c) => `- ${clip(c)}`).join("\n")}`;
|
|
|
5736
5749
|
...ok2({
|
|
5737
5750
|
protocolVersion: VERSIONS.includes(asked) ? asked : VERSIONS[0],
|
|
5738
5751
|
capabilities: { tools: { listChanged: false } },
|
|
5739
|
-
serverInfo: { name: "
|
|
5752
|
+
serverInfo: { name: "diacode", title: "DiaCode plan server", version },
|
|
5740
5753
|
instructions: GUIDE
|
|
5741
5754
|
})
|
|
5742
5755
|
};
|
|
@@ -5812,7 +5825,7 @@ var OPS_HELP = [
|
|
|
5812
5825
|
'edge.add {"op":"edge.add","from":"a","to":"b"} (b depends on a)',
|
|
5813
5826
|
'edge.remove {"op":"edge.remove","from":"a","to":"b"}'
|
|
5814
5827
|
].map((l) => ` ${l}`).join("\n");
|
|
5815
|
-
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".
|
|
5828
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".diacode", ".opencode", "dist", "build", "coverage", ".next", ".venv", "__pycache__"]);
|
|
5816
5829
|
var LIMITS = { entries: 120, depth: 4, file: 3500, total: 14e3 };
|
|
5817
5830
|
var LOCKFILE = /(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|.*\.min\.js|.*\.map|.*\.svg|.*\.png|.*\.jpe?g|.*\.ico)$/;
|
|
5818
5831
|
var PRIVATE = /(^|\/)(\.[^/]+|id_(rsa|dsa|ecdsa|ed25519)(\.pub)?|[^/]*\.(pem|key|p12|pfx|jks|keystore|tfstate)|credentials[^/]*\.json)(\/|$)/i;
|
|
@@ -6004,7 +6017,7 @@ function parseFindings(text2) {
|
|
|
6004
6017
|
}
|
|
6005
6018
|
throw new Error("the reply was not the JSON that was asked for");
|
|
6006
6019
|
}
|
|
6007
|
-
var READ_ONLY = { mcp: {
|
|
6020
|
+
var READ_ONLY = { mcp: { diacode: { enabled: false } }, permission: { edit: "deny", bash: "ask", webfetch: "deny", external_directory: "deny" } };
|
|
6008
6021
|
var ANSI = /\u001b\[[0-9;]*m/g;
|
|
6009
6022
|
function openCodeRunner(options) {
|
|
6010
6023
|
return async (prompt) => {
|
|
@@ -6480,7 +6493,7 @@ var Presence = class extends EventEmitter5 {
|
|
|
6480
6493
|
* The steps in progress whose owner has stopped. An owner we know nothing about is not flagged:
|
|
6481
6494
|
* with no plugin there is nothing to be silent. Nor is one asking the person: it has not stopped, it is
|
|
6482
6495
|
* waiting on them, and the editor says that instead.
|
|
6483
|
-
* @param {import('@
|
|
6496
|
+
* @param {import('@diacode/core/src/types.js').Plan | null | undefined} plan
|
|
6484
6497
|
* @returns {Record<string, Stalled>}
|
|
6485
6498
|
*/
|
|
6486
6499
|
stalled(plan) {
|
|
@@ -6504,7 +6517,7 @@ var Presence = class extends EventEmitter5 {
|
|
|
6504
6517
|
* What a plan's viewers should see now, and a key that changes only when it is news: `seen`
|
|
6505
6518
|
* moves with every heartbeat, so only a state, a plan or a stall changes the key. Each listener
|
|
6506
6519
|
* keeps the last key it was sent; two editors on one plan must both hear every change.
|
|
6507
|
-
* @param {string | undefined} planId @param {import('@
|
|
6520
|
+
* @param {string | undefined} planId @param {import('@diacode/core/src/types.js').Plan | null | undefined} plan
|
|
6508
6521
|
* @param {any[]} [drift] files edited that no step lists (the store's; shown with who is working because it is just as live)
|
|
6509
6522
|
* @returns {{ view: { presence: Agent[], stalled: Record<string, Stalled>, drift: any[], reads: Read[] }, key: string }}
|
|
6510
6523
|
*/
|
|
@@ -6552,7 +6565,7 @@ var TYPES = (
|
|
|
6552
6565
|
);
|
|
6553
6566
|
function findEditor() {
|
|
6554
6567
|
const candidates = [
|
|
6555
|
-
process.env.
|
|
6568
|
+
process.env.DIACODE_EDITOR,
|
|
6556
6569
|
fileURLToPath(new URL("../editor", import.meta.url)),
|
|
6557
6570
|
fileURLToPath(new URL("../../../dist", import.meta.url))
|
|
6558
6571
|
];
|
|
@@ -6577,7 +6590,7 @@ async function serveEditor(root2, pathname) {
|
|
|
6577
6590
|
|
|
6578
6591
|
// packages/server/src/agents.js
|
|
6579
6592
|
var SILENT_MS = 15 * 6e4;
|
|
6580
|
-
var OURS = /(^|[^a-z])(plan_list|plan_read|plan_create|plan_edit|step_start|step_done|step_failed|step_wait|step_ask)$|^
|
|
6593
|
+
var OURS = /(^|[^a-z])(plan_list|plan_read|plan_create|plan_edit|step_start|step_done|step_failed|step_wait|step_ask)$|^diacode_/;
|
|
6581
6594
|
var Agents = class {
|
|
6582
6595
|
/**
|
|
6583
6596
|
* @param {{ store: import('./store.js').PlanStore, presence: import('./presence.js').Presence, now?: () => number, stage?: () => string }} options
|
|
@@ -6877,7 +6890,7 @@ var MESSAGE_MAX = 300;
|
|
|
6877
6890
|
var EventRing = class {
|
|
6878
6891
|
/**
|
|
6879
6892
|
* @param {number} [max] how many are kept
|
|
6880
|
-
* @param {{ now?: () => string, log?: (line: string) => void }} [options] `log` gets each one as it happens (
|
|
6893
|
+
* @param {{ now?: () => string, log?: (line: string) => void }} [options] `log` gets each one as it happens (DIACODE_DEBUG)
|
|
6881
6894
|
*/
|
|
6882
6895
|
constructor(max = 100, { now = () => (/* @__PURE__ */ new Date()).toISOString(), log } = {}) {
|
|
6883
6896
|
this.max = max;
|
|
@@ -6890,7 +6903,7 @@ var EventRing = class {
|
|
|
6890
6903
|
const event = { at: this.now(), kind, message: message.replace(/\s+/g, " ").trim().slice(0, MESSAGE_MAX) };
|
|
6891
6904
|
this.events.push(event);
|
|
6892
6905
|
if (this.events.length > this.max) this.events.shift();
|
|
6893
|
-
this.log?.(`[
|
|
6906
|
+
this.log?.(`[diacode] ${kind}: ${event.message}`);
|
|
6894
6907
|
}
|
|
6895
6908
|
/** Oldest first. @returns {ServerEvent[]} */
|
|
6896
6909
|
list() {
|
|
@@ -6939,6 +6952,12 @@ function alwaysFrom(suggestions) {
|
|
|
6939
6952
|
}
|
|
6940
6953
|
return void 0;
|
|
6941
6954
|
}
|
|
6955
|
+
var FULL_MAX = 2e4;
|
|
6956
|
+
function wholeCommand(tool, input2) {
|
|
6957
|
+
const c = typeof input2.command === "string" ? input2.command : "";
|
|
6958
|
+
if (!c || c.length <= 300 && !/\n/.test(c)) return {};
|
|
6959
|
+
return c.length > FULL_MAX ? { full: c.slice(0, FULL_MAX), partial: true } : { full: c };
|
|
6960
|
+
}
|
|
6942
6961
|
function describeRequest(tool, input2) {
|
|
6943
6962
|
const clip2 = (s) => {
|
|
6944
6963
|
const t = String(s ?? "").replace(/\s+/g, " ").trim();
|
|
@@ -6973,7 +6992,7 @@ var Permissions = class extends EventEmitter6 {
|
|
|
6973
6992
|
});
|
|
6974
6993
|
let timer;
|
|
6975
6994
|
const always = alwaysFrom(suggestions);
|
|
6976
|
-
const permission = { id, actor, ...session ? { session } : {}, tool, what: describeRequest(tool, input2), at: new Date(this.now()).toISOString(), ...always ? { always: { label: always.label } } : {} };
|
|
6995
|
+
const permission = { id, actor, ...session ? { session } : {}, tool, what: describeRequest(tool, input2), ...wholeCommand(tool, input2), at: new Date(this.now()).toISOString(), ...always ? { always: { label: always.label } } : {} };
|
|
6977
6996
|
const settle = (d) => {
|
|
6978
6997
|
clearTimeout(timer);
|
|
6979
6998
|
if (!this.pending.delete(id)) return;
|
|
@@ -6993,11 +7012,13 @@ var Permissions = class extends EventEmitter6 {
|
|
|
6993
7012
|
/**
|
|
6994
7013
|
* Your answer. @param {string} id @param {'allow' | 'deny'} decision @param {string} [reason] for a deny: the agent is told it
|
|
6995
7014
|
* @param {boolean} [always] for an allow: and do not ask again for what Claude Code offered (this session only)
|
|
6996
|
-
* @returns {boolean | 'no-always'} whether it was still waiting; `no-always`: it was, but offered no such choice
|
|
7015
|
+
* @returns {boolean | 'no-always' | 'too-long'} whether it was still waiting; `no-always`: it was, but offered no such choice; `too-long`: an Allow
|
|
7016
|
+
* for a command too long to have been shown whole (nothing was answered in either case)
|
|
6997
7017
|
*/
|
|
6998
7018
|
decide(id, decision, reason, always = false) {
|
|
6999
7019
|
const p = this.pending.get(id);
|
|
7000
7020
|
if (!p) return false;
|
|
7021
|
+
if (decision === "allow" && p.partial) return "too-long";
|
|
7001
7022
|
if (always && (decision !== "allow" || !p.offer)) return "no-always";
|
|
7002
7023
|
p.settle(decision === "allow" ? { behavior: "allow", ...always && p.offer ? { updatedPermissions: [p.offer.update] } : {} } : { behavior: "deny", message: reason?.trim() ? `The person denied this in the DiaCode editor: ${reason.trim().slice(0, 500)}` : "The person denied this in the DiaCode editor." });
|
|
7003
7024
|
return true;
|
|
@@ -7030,7 +7051,7 @@ var CLOSE_GRACE_MS = 1e3;
|
|
|
7030
7051
|
var AGENT_EVENTS = /* @__PURE__ */ new Set(["session-start", "prompt", "tool-after", "turn-end", "asking", "error", "session-end"]);
|
|
7031
7052
|
var HOLD = { plugin: { default: 5e4, max: 12e4 }, hook: { default: 6e5, max: 864e5 } };
|
|
7032
7053
|
var REPORT_MS = 3e4;
|
|
7033
|
-
function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", allowedOrigins = [], now, reconciler: rc = {}, presence: presenceOptions, editor = findEditor(), debug = Boolean(process.env.
|
|
7054
|
+
function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", allowedOrigins = [], now, reconciler: rc = {}, presence: presenceOptions, editor = findEditor(), debug = Boolean(process.env.DIACODE_DEBUG), calls: callOptions = {} }) {
|
|
7034
7055
|
const startedAt = Date.now();
|
|
7035
7056
|
const ring = new EventRing(100, { log: debug ? (line) => console.error(line) : void 0 });
|
|
7036
7057
|
const store = new PlanStore(root2, { now });
|
|
@@ -7068,7 +7089,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7068
7089
|
return agents2.map((a) => {
|
|
7069
7090
|
const b = a.state === "gone" && on.has(a.actor) ? { ...a, state: "idle" } : a;
|
|
7070
7091
|
const p = permissions.list(a.actor)[0];
|
|
7071
|
-
return p ? { ...b, state: "asking", detail: `wants to ${p.what}`, permission: { id: p.id, what: p.what, tool: p.tool, ...p.always ? { always: p.always } : {} } } : b;
|
|
7092
|
+
return p ? { ...b, state: "asking", detail: `wants to ${p.what}`, permission: { id: p.id, what: p.what, tool: p.tool, ...p.full ? { full: p.full } : {}, ...p.partial ? { partial: true } : {}, ...p.always ? { always: p.always } : {} } } : b;
|
|
7072
7093
|
});
|
|
7073
7094
|
};
|
|
7074
7095
|
const mcp = createMcp({ store, arch: archStore, presence, stopped: (actor) => calls.stoppedFor(actor), version: VERSION });
|
|
@@ -7157,7 +7178,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7157
7178
|
}
|
|
7158
7179
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
7159
7180
|
const parts = url.pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
7160
|
-
if (req.method === "GET" && url.pathname === "/api/health") return send2(res, 200, { ok: true, root: root2, version: VERSION, api: API_VERSION, schemas: [SCHEMA, "
|
|
7181
|
+
if (req.method === "GET" && url.pathname === "/api/health") return send2(res, 200, { ok: true, root: root2, version: VERSION, api: API_VERSION, schemas: [SCHEMA, "diacode.plan/0", arch_exports.SCHEMA], replanner: opencodeReplans ? "opencode" : "agent" });
|
|
7161
7182
|
if (req.method === "GET" && url.pathname === "/api/flow") {
|
|
7162
7183
|
const f = flowNow({ store, arch: archStore, presence });
|
|
7163
7184
|
const p2 = (
|
|
@@ -7219,7 +7240,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7219
7240
|
}
|
|
7220
7241
|
if (parts[0] === "api" && parts[1] === "agent" && parts[2] === "events" && parts.length === 3 && req.method === "POST") {
|
|
7221
7242
|
const who = whoOf(req);
|
|
7222
|
-
if (who.actor === "you") throw new HttpError(400, "agent events are for a harness: send x-
|
|
7243
|
+
if (who.actor === "you") throw new HttpError(400, "agent events are for a harness: send x-diacode-agent: <harness>:<agent>");
|
|
7223
7244
|
const ev = (
|
|
7224
7245
|
/** @type {any} */
|
|
7225
7246
|
await body(req)
|
|
@@ -7229,7 +7250,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7229
7250
|
}
|
|
7230
7251
|
if (parts[0] === "api" && parts[1] === "agent" && parts[2] === "wait" && parts.length === 3 && req.method === "POST") {
|
|
7231
7252
|
const who = whoOf(req);
|
|
7232
|
-
if (who.actor === "you") throw new HttpError(400, "waiting for calls is for a harness plugin: send x-
|
|
7253
|
+
if (who.actor === "you") throw new HttpError(400, "waiting for calls is for a harness plugin: send x-diacode-agent: <harness>:<agent>");
|
|
7233
7254
|
const { plans } = (
|
|
7234
7255
|
/** @type {{ plans?: unknown }} */
|
|
7235
7256
|
await body(req)
|
|
@@ -7253,6 +7274,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7253
7274
|
);
|
|
7254
7275
|
if (decision !== "allow" && decision !== "deny") throw new HttpError(400, "decision is allow or deny");
|
|
7255
7276
|
const ok2 = permissions.decide(parts[2], decision, typeof reason === "string" ? reason : void 0, always === true);
|
|
7277
|
+
if (ok2 === "too-long") return send2(res, 409, { error: "that command is too long to show whole here, so it cannot be allowed from here: read it in the agent's window, and answer it there" });
|
|
7256
7278
|
if (ok2 === "no-always") return send2(res, 409, { error: `Claude Code offered no "don't ask again" for this one: allow it once, or deny it` });
|
|
7257
7279
|
return send2(res, ok2 ? 200 : 404, ok2 ? { ok: true } : { error: "that prompt is no longer waiting: it was answered in the agent's window, or it went away" });
|
|
7258
7280
|
}
|
|
@@ -7272,7 +7294,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7272
7294
|
if (req.method === "GET") return send2(res, 200, { agents: heard(presence.list()) });
|
|
7273
7295
|
if (req.method === "POST") {
|
|
7274
7296
|
const who = whoOf(req);
|
|
7275
|
-
if (who.actor === "you") throw new HttpError(400, "presence is for a harness plugin: send x-
|
|
7297
|
+
if (who.actor === "you") throw new HttpError(400, "presence is for a harness plugin: send x-diacode-agent: <harness>:<agent>");
|
|
7276
7298
|
const { state, plan: planId, detail, pid } = (
|
|
7277
7299
|
/** @type {{ state?: any, plan?: unknown, detail?: unknown, pid?: unknown }} */
|
|
7278
7300
|
await body(req)
|
|
@@ -7288,10 +7310,10 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7288
7310
|
}
|
|
7289
7311
|
}
|
|
7290
7312
|
if (req.method === "GET" && parts[0] === "api" && parts[1] === "brief" && parts.length === 2) {
|
|
7291
|
-
const asked = req.headers["x-
|
|
7313
|
+
const asked = req.headers["x-diacode-agent"] === void 0 ? void 0 : whoOf(req).actor;
|
|
7292
7314
|
const { text: planText, plan: plan2, rev } = store.brief(url.searchParams.get("plan") ?? void 0, asked);
|
|
7293
7315
|
const text2 = [agents.stage(), planText].filter(Boolean).join("\n\n");
|
|
7294
|
-
return sendText(res, 200, text2, plan2 === void 0 ? {} : { "x-
|
|
7316
|
+
return sendText(res, 200, text2, plan2 === void 0 ? {} : { "x-diacode-plan": plan2, "x-diacode-rev": String(rev) });
|
|
7295
7317
|
}
|
|
7296
7318
|
if (req.method === "GET" && parts[0] === "api" && parts[1] === "events" && parts.length === 2) return listEvents(req, res);
|
|
7297
7319
|
if (parts[0] === "api" && parts[1] === "architecture") {
|
|
@@ -7383,7 +7405,7 @@ function createServer({ root: root2, port: port2 = 7300, host = "127.0.0.1", all
|
|
|
7383
7405
|
}
|
|
7384
7406
|
if (parts.length === 4 && parts[3] === "observe" && req.method === "POST") {
|
|
7385
7407
|
const who = whoOf(req);
|
|
7386
|
-
if (who.actor === "you") throw new HttpError(400, "observe is for a harness plugin: send x-
|
|
7408
|
+
if (who.actor === "you") throw new HttpError(400, "observe is for a harness plugin: send x-diacode-agent: <harness>:<agent>");
|
|
7387
7409
|
const { file } = (
|
|
7388
7410
|
/** @type {{ file?: unknown }} */
|
|
7389
7411
|
await body(req)
|
|
@@ -7635,10 +7657,10 @@ function holdOf(url, bounds) {
|
|
|
7635
7657
|
return Number.isFinite(asked) && asked > 0 ? Math.min(Math.max(asked, 1e3), bounds.max) : bounds.default;
|
|
7636
7658
|
}
|
|
7637
7659
|
function whoOf(req) {
|
|
7638
|
-
const agent = req.headers["x-
|
|
7660
|
+
const agent = req.headers["x-diacode-agent"];
|
|
7639
7661
|
if (agent === void 0) return { actor: "you", via: "editor" };
|
|
7640
7662
|
if (typeof agent !== "string" || agent === "you" || !isActor(agent)) {
|
|
7641
|
-
throw new HttpError(400, "x-
|
|
7663
|
+
throw new HttpError(400, "x-diacode-agent names an agent as <harness>:<agent>, such as opencode:build");
|
|
7642
7664
|
}
|
|
7643
7665
|
return { actor: agent, via: "plugin" };
|
|
7644
7666
|
}
|
|
@@ -7685,12 +7707,12 @@ import { spawnSync } from "node:child_process";
|
|
|
7685
7707
|
|
|
7686
7708
|
// packages/server/src/invoke.js
|
|
7687
7709
|
function invocation(env = process.env) {
|
|
7688
|
-
if (env.npm_command === "exec" || env.
|
|
7689
|
-
if (env.npm_lifecycle_event === "
|
|
7710
|
+
if (env.npm_command === "exec" || env.DIACODE_EDITOR === "1") return "npx diacode";
|
|
7711
|
+
if (env.npm_lifecycle_event === "diacode") return "npm run diacode --";
|
|
7690
7712
|
return "diacode";
|
|
7691
7713
|
}
|
|
7692
7714
|
function serveHint(port2, env = process.env) {
|
|
7693
|
-
return env.
|
|
7715
|
+
return env.DIACODE_EDITOR === "1" ? `The DiaCode extension runs the plan server for this folder, on port ${port2}.` : `Start the plan server with: ${invocation(env)} serve --root . --port ${port2}`;
|
|
7694
7716
|
}
|
|
7695
7717
|
function nodeWarning(version = process.versions.node) {
|
|
7696
7718
|
const major = Number(version.split(".")[0]);
|
|
@@ -7698,8 +7720,8 @@ function nodeWarning(version = process.versions.node) {
|
|
|
7698
7720
|
}
|
|
7699
7721
|
|
|
7700
7722
|
// packages/server/src/init.js
|
|
7701
|
-
var BEGIN = "<!--
|
|
7702
|
-
var END = "<!--
|
|
7723
|
+
var BEGIN = "<!-- diacode:begin (written by `diacode init`; edit outside these markers) -->";
|
|
7724
|
+
var END = "<!-- diacode:end -->";
|
|
7703
7725
|
async function read(path) {
|
|
7704
7726
|
try {
|
|
7705
7727
|
return await readFile4(path, "utf8");
|
|
@@ -7721,7 +7743,7 @@ async function put(path, text2, what) {
|
|
|
7721
7743
|
async function pluginSource() {
|
|
7722
7744
|
const published = new URL("../opencode-plugin.js", import.meta.url);
|
|
7723
7745
|
const found = await read(fileURLToPath2(published));
|
|
7724
|
-
return found ?? readFile4(new URL(import.meta.resolve("@
|
|
7746
|
+
return found ?? readFile4(new URL(import.meta.resolve("@diacode/opencode-plugin")), "utf8");
|
|
7725
7747
|
}
|
|
7726
7748
|
async function initOpenCode({ root: root2, port: port2 = 7300, agent = "build" }) {
|
|
7727
7749
|
const server = `http://127.0.0.1:${port2}`;
|
|
@@ -7740,21 +7762,21 @@ async function initOpenCode({ root: root2, port: port2 = 7300, agent = "build" }
|
|
|
7740
7762
|
}
|
|
7741
7763
|
}
|
|
7742
7764
|
if (mergeable) {
|
|
7743
|
-
config.mcp = { ...config.mcp ?? {},
|
|
7765
|
+
config.mcp = { ...config.mcp ?? {}, diacode: entry };
|
|
7744
7766
|
said.push(await put(configPath, `${JSON.stringify(config, null, 2)}
|
|
7745
|
-
`, "opencode.json (the
|
|
7767
|
+
`, "opencode.json (the diacode MCP server)"));
|
|
7746
7768
|
} else {
|
|
7747
7769
|
said.push(`NOT DONE opencode.json: it has comments or is not plain JSON, so add this yourself under "mcp":
|
|
7748
|
-
"
|
|
7770
|
+
"diacode": ${JSON.stringify(entry)}`);
|
|
7749
7771
|
}
|
|
7750
|
-
said.push(await put(join4(root2, ".
|
|
7751
|
-
said.push(await put(join4(root2, ".opencode", "plugins", "
|
|
7772
|
+
said.push(await put(join4(root2, ".diacode", "opencode-plugin.js"), await pluginSource(), ".diacode/opencode-plugin.js (the plugin)"));
|
|
7773
|
+
said.push(await put(join4(root2, ".opencode", "plugins", "diacode.js"), [
|
|
7752
7774
|
"// Written by `diacode init opencode`: gives the DiaCode plugin its options.",
|
|
7753
|
-
"import { DiaCode } from '../../.
|
|
7775
|
+
"import { DiaCode } from '../../.diacode/opencode-plugin.js';",
|
|
7754
7776
|
"",
|
|
7755
7777
|
`export const DiaCodePlugin = (/** @type {any} */ ctx) => DiaCode(ctx, ${JSON.stringify({ server, agent })});`,
|
|
7756
7778
|
""
|
|
7757
|
-
].join("\n"), ".opencode/plugins/
|
|
7779
|
+
].join("\n"), ".opencode/plugins/diacode.js (loads it)"));
|
|
7758
7780
|
const rulesPath = join4(root2, "AGENTS.md");
|
|
7759
7781
|
const rules = await read(rulesPath);
|
|
7760
7782
|
const block = `${BEGIN}
|
|
@@ -7792,14 +7814,14 @@ async function mergeJson(root2, rel, change, what, snippet) {
|
|
|
7792
7814
|
}
|
|
7793
7815
|
var curlHook = (port2, harness, hook, agent, fallback = "{}") => `curl -s --max-time 2 -X POST -H 'content-type: application/json' --data-binary @- 'http://127.0.0.1:${port2}/hooks/${harness}/${hook}?agent=${agent}' || echo '${fallback}'`;
|
|
7794
7816
|
var askHook = (port2, harness, hook, agent) => `curl -s --max-time 2 -X POST -H 'content-type: application/json' --data-binary @- 'http://127.0.0.1:${port2}/hooks/${harness}/${hook}?agent=${agent}&pid='"$PPID" || echo '{}'`;
|
|
7795
|
-
var ALLOW_TOOLS = "
|
|
7817
|
+
var ALLOW_TOOLS = "mcp__diacode";
|
|
7796
7818
|
var WAKE_SECONDS = 86400;
|
|
7797
7819
|
var wakeHook = (port2, harness, agent) => `out=$(curl -sf --max-time ${WAKE_SECONDS - 30} -X POST -H 'content-type: application/json' --data-binary @- 'http://127.0.0.1:${port2}/hooks/${harness}/wake?agent=${agent}&hold=${(WAKE_SECONDS - 40) * 1e3}') && [ -n "$out" ] && { printf '%s' "$out" >&2; exit 2; }; exit 0`;
|
|
7798
7820
|
var ACCEPT_EDITS_WORDS = [
|
|
7799
7821
|
"Accept edits is on for this folder (you asked for it with --accept-edits): Claude Code now edits and writes files in it, and runs",
|
|
7800
7822
|
"mkdir, touch, rm, rmdir, mv, cp and sed on files in it, without asking. Everything else (npm, node, git, curl\u2026) still asks, and so",
|
|
7801
7823
|
"does anything outside this folder. It is in .claude/settings.local.json, which is not committed. `init claude-code --remove` takes it out again.",
|
|
7802
|
-
"Claude Code's folder-trust dialog lists the allow rule (
|
|
7824
|
+
"Claude Code's folder-trust dialog lists the allow rule (mcp__diacode) but does not mention this mode, so this message, `doctor` and that file are where it is written down."
|
|
7803
7825
|
];
|
|
7804
7826
|
async function setAcceptEdits(root2) {
|
|
7805
7827
|
const rel = ".claude/settings.local.json";
|
|
@@ -7858,8 +7880,8 @@ async function initClaudeCode({ root: root2, port: port2 = 7300, agent = "main",
|
|
|
7858
7880
|
const url = `http://127.0.0.1:${p}/mcp/claude-code?agent=${encodeURIComponent(agent)}`;
|
|
7859
7881
|
const entry = { type: "http", url, alwaysLoad: true };
|
|
7860
7882
|
said.push(await mergeJson(root2, ".mcp.json", (d) => {
|
|
7861
|
-
d.mcpServers = { ...d.mcpServers ?? {},
|
|
7862
|
-
}, "the
|
|
7883
|
+
d.mcpServers = { ...d.mcpServers ?? {}, diacode: entry };
|
|
7884
|
+
}, "the diacode MCP server", `"mcpServers": { "diacode": ${JSON.stringify(entry)} }`));
|
|
7863
7885
|
const http2 = (hook, timeout = 3) => ({ type: "http", url: `http://127.0.0.1:${p}/hooks/claude-code/${hook}?agent=${encodeURIComponent(agent)}`, timeout });
|
|
7864
7886
|
const ours = (
|
|
7865
7887
|
/** @type {Record<string, any>} */
|
|
@@ -7900,8 +7922,8 @@ async function initClaudeCode({ root: root2, port: port2 = 7300, agent = "main",
|
|
|
7900
7922
|
if (kept) said.push(kept);
|
|
7901
7923
|
}
|
|
7902
7924
|
}
|
|
7903
|
-
said.push(await ownRules(root2, ".claude/rules/
|
|
7904
|
-
said.push("", FLOW_HINT, "", serveHint(port2), "Then start a new Claude Code session in this folder (approve the
|
|
7925
|
+
said.push(await ownRules(root2, ".claude/rules/diacode.md", `${RULES_BODY}`, "how to work with the plan"));
|
|
7926
|
+
said.push("", FLOW_HINT, "", serveHint(port2), "Then start a new Claude Code session in this folder (approve the diacode MCP server when asked).");
|
|
7905
7927
|
return said;
|
|
7906
7928
|
}
|
|
7907
7929
|
async function initCursor({ root: root2, port: port2 = 7300, agent = "agent" }) {
|
|
@@ -7910,8 +7932,8 @@ async function initCursor({ root: root2, port: port2 = 7300, agent = "agent" })
|
|
|
7910
7932
|
const said = [];
|
|
7911
7933
|
const entry = { url: `http://127.0.0.1:${p}/mcp/cursor?agent=${a}` };
|
|
7912
7934
|
said.push(await mergeJson(root2, ".cursor/mcp.json", (d) => {
|
|
7913
|
-
d.mcpServers = { ...d.mcpServers ?? {},
|
|
7914
|
-
}, "the
|
|
7935
|
+
d.mcpServers = { ...d.mcpServers ?? {}, diacode: entry };
|
|
7936
|
+
}, "the diacode MCP server", `"mcpServers": { "diacode": ${JSON.stringify(entry)} }`));
|
|
7915
7937
|
const hook = (name2, fallback = "{}") => ({ command: curlHook(p, "cursor", name2, a, fallback), timeout: 3 });
|
|
7916
7938
|
const ours = (
|
|
7917
7939
|
/** @type {Record<string, any[]>} */
|
|
@@ -7930,13 +7952,13 @@ async function initCursor({ root: root2, port: port2 = 7300, agent = "agent" })
|
|
|
7930
7952
|
d.hooks = d.hooks ?? {};
|
|
7931
7953
|
for (const [event, list] of Object.entries(ours)) d.hooks[event] = [...(d.hooks[event] ?? []).filter((h) => !mine(h)), ...list];
|
|
7932
7954
|
}, "the hooks that tell the plan server what the agent does, and tell the agent what changed", `"hooks": ${JSON.stringify(ours)}`));
|
|
7933
|
-
said.push(await ownRules(root2, ".cursor/rules/
|
|
7955
|
+
said.push(await ownRules(root2, ".cursor/rules/diacode.mdc", `---
|
|
7934
7956
|
description: How to work with this repository's DiaCode plans
|
|
7935
7957
|
alwaysApply: true
|
|
7936
7958
|
---
|
|
7937
7959
|
|
|
7938
7960
|
${RULES_BODY}`, "how to work with the plan"));
|
|
7939
|
-
said.push("", FLOW_HINT, "", serveHint(port2), "Then enable the
|
|
7961
|
+
said.push("", FLOW_HINT, "", serveHint(port2), "Then enable the diacode server in Cursor Settings \u2192 MCP, and start a new chat.");
|
|
7940
7962
|
return said;
|
|
7941
7963
|
}
|
|
7942
7964
|
async function initAntigravity({ root: root2, port: port2 = 7300, agent = "agent" }) {
|
|
@@ -7945,8 +7967,8 @@ async function initAntigravity({ root: root2, port: port2 = 7300, agent = "agent
|
|
|
7945
7967
|
const said = [];
|
|
7946
7968
|
const entry = { serverUrl: `http://127.0.0.1:${p}/mcp/antigravity?agent=${a}` };
|
|
7947
7969
|
said.push(await mergeJson(root2, ".agents/mcp_config.json", (d) => {
|
|
7948
|
-
d.mcpServers = { ...d.mcpServers ?? {},
|
|
7949
|
-
}, "the
|
|
7970
|
+
d.mcpServers = { ...d.mcpServers ?? {}, diacode: entry };
|
|
7971
|
+
}, "the diacode MCP server", `"mcpServers": { "diacode": ${JSON.stringify(entry)} }`));
|
|
7950
7972
|
const command = (name2) => ({ type: "command", command: curlHook(p, "antigravity", name2, a), timeout: 4 });
|
|
7951
7973
|
const ours = {
|
|
7952
7974
|
enabled: true,
|
|
@@ -7957,9 +7979,9 @@ async function initAntigravity({ root: root2, port: port2 = 7300, agent = "agent
|
|
|
7957
7979
|
Stop: [command("Stop")]
|
|
7958
7980
|
};
|
|
7959
7981
|
said.push(await mergeJson(root2, ".agents/hooks.json", (d) => {
|
|
7960
|
-
d.
|
|
7961
|
-
}, "the hooks that tell the plan server what the agent does, and tell the agent what changed", `"
|
|
7962
|
-
said.push(await ownRules(root2, ".agents/rules/
|
|
7982
|
+
d.diacode = ours;
|
|
7983
|
+
}, "the hooks that tell the plan server what the agent does, and tell the agent what changed", `"diacode": ${JSON.stringify(ours)}`));
|
|
7984
|
+
said.push(await ownRules(root2, ".agents/rules/diacode.md", `---
|
|
7963
7985
|
trigger: always_on
|
|
7964
7986
|
description: How to work with this repository's DiaCode plans
|
|
7965
7987
|
---
|
|
@@ -8012,14 +8034,14 @@ async function removeOpenCode({ root: root2 }) {
|
|
|
8012
8034
|
const said = [];
|
|
8013
8035
|
said.push(await unmergeJson(root2, "opencode.json", (d) => {
|
|
8014
8036
|
if (d.mcp) {
|
|
8015
|
-
delete d.mcp.
|
|
8037
|
+
delete d.mcp.diacode;
|
|
8016
8038
|
pruneEmpty(d, "mcp");
|
|
8017
8039
|
}
|
|
8018
|
-
}, (d) => onlyOurs(d, ["$schema"]), /
|
|
8040
|
+
}, (d) => onlyOurs(d, ["$schema"]), /diacode/, 'the "diacode" entry under "mcp"'));
|
|
8019
8041
|
const jsonc = await read(join4(root2, "opencode.jsonc"));
|
|
8020
|
-
if (jsonc !== null && /
|
|
8021
|
-
said.push(await drop(root2, ".opencode/plugins/
|
|
8022
|
-
said.push(await drop(root2, ".
|
|
8042
|
+
if (jsonc !== null && /diacode/.test(jsonc)) said.push('NOT DONE opencode.jsonc: it has comments, so remove the "diacode" entry under "mcp" yourself');
|
|
8043
|
+
said.push(await drop(root2, ".opencode/plugins/diacode.js", "the plugin's loader"));
|
|
8044
|
+
said.push(await drop(root2, ".diacode/opencode-plugin.js", "the plugin"));
|
|
8023
8045
|
const agents = await read(join4(root2, "AGENTS.md"));
|
|
8024
8046
|
if (agents === null || !agents.includes(BEGIN)) {
|
|
8025
8047
|
said.push(`absent AGENTS.md (no DiaCode block)`);
|
|
@@ -8038,10 +8060,10 @@ async function removeClaudeCode({ root: root2 }) {
|
|
|
8038
8060
|
const said = [];
|
|
8039
8061
|
said.push(await unmergeJson(root2, ".mcp.json", (d) => {
|
|
8040
8062
|
if (d.mcpServers) {
|
|
8041
|
-
delete d.mcpServers.
|
|
8063
|
+
delete d.mcpServers.diacode;
|
|
8042
8064
|
pruneEmpty(d, "mcpServers");
|
|
8043
8065
|
}
|
|
8044
|
-
}, (d) => onlyOurs(d), /
|
|
8066
|
+
}, (d) => onlyOurs(d), /diacode/, 'the "diacode" entry under "mcpServers"'));
|
|
8045
8067
|
for (const rel of [".claude/settings.local.json", ".claude/settings.json"]) {
|
|
8046
8068
|
said.push(await unmergeJson(root2, rel, (d) => {
|
|
8047
8069
|
const ours = isOurs("/hooks/claude-code/");
|
|
@@ -8073,9 +8095,9 @@ async function removeClaudeCode({ root: root2 }) {
|
|
|
8073
8095
|
delete d.permissions.defaultMode;
|
|
8074
8096
|
pruneEmpty(d, "permissions");
|
|
8075
8097
|
}
|
|
8076
|
-
}, (d) => onlyOurs(d), /\/hooks\/claude-code\/|
|
|
8098
|
+
}, (d) => onlyOurs(d), /\/hooks\/claude-code\/|mcp__diacode|"defaultMode":\s*"acceptEdits"/, 'the hooks whose address contains /hooks/claude-code/, the "mcp__diacode" allow rule, and "defaultMode": "acceptEdits" in settings.local.json'));
|
|
8077
8099
|
}
|
|
8078
|
-
said.push(await drop(root2, ".claude/rules/
|
|
8100
|
+
said.push(await drop(root2, ".claude/rules/diacode.md", "the rules"));
|
|
8079
8101
|
const unhidden = await letGitSeeAgain(root2, ".claude/settings.local.json");
|
|
8080
8102
|
if (unhidden) said.push(unhidden);
|
|
8081
8103
|
return said;
|
|
@@ -8084,10 +8106,10 @@ async function removeCursor({ root: root2 }) {
|
|
|
8084
8106
|
const said = [];
|
|
8085
8107
|
said.push(await unmergeJson(root2, ".cursor/mcp.json", (d) => {
|
|
8086
8108
|
if (d.mcpServers) {
|
|
8087
|
-
delete d.mcpServers.
|
|
8109
|
+
delete d.mcpServers.diacode;
|
|
8088
8110
|
pruneEmpty(d, "mcpServers");
|
|
8089
8111
|
}
|
|
8090
|
-
}, (d) => onlyOurs(d), /
|
|
8112
|
+
}, (d) => onlyOurs(d), /diacode/, 'the "diacode" entry under "mcpServers"'));
|
|
8091
8113
|
said.push(await unmergeJson(root2, ".cursor/hooks.json", (d) => {
|
|
8092
8114
|
for (const [event, list] of Object.entries(d.hooks ?? {})) {
|
|
8093
8115
|
d.hooks[event] = /** @type {any[]} */
|
|
@@ -8096,21 +8118,21 @@ async function removeCursor({ root: root2 }) {
|
|
|
8096
8118
|
}
|
|
8097
8119
|
pruneEmpty(d, "hooks");
|
|
8098
8120
|
}, (d) => onlyOurs(d, ["version"]), /\/hooks\/cursor\//, "the hooks whose command contains /hooks/cursor/"));
|
|
8099
|
-
said.push(await drop(root2, ".cursor/rules/
|
|
8121
|
+
said.push(await drop(root2, ".cursor/rules/diacode.mdc", "the rules"));
|
|
8100
8122
|
return said;
|
|
8101
8123
|
}
|
|
8102
8124
|
async function removeAntigravity({ root: root2 }) {
|
|
8103
8125
|
const said = [];
|
|
8104
8126
|
said.push(await unmergeJson(root2, ".agents/mcp_config.json", (d) => {
|
|
8105
8127
|
if (d.mcpServers) {
|
|
8106
|
-
delete d.mcpServers.
|
|
8128
|
+
delete d.mcpServers.diacode;
|
|
8107
8129
|
pruneEmpty(d, "mcpServers");
|
|
8108
8130
|
}
|
|
8109
|
-
}, (d) => onlyOurs(d), /
|
|
8131
|
+
}, (d) => onlyOurs(d), /diacode/, 'the "diacode" entry under "mcpServers"'));
|
|
8110
8132
|
said.push(await unmergeJson(root2, ".agents/hooks.json", (d) => {
|
|
8111
|
-
delete d.
|
|
8112
|
-
}, (d) => onlyOurs(d), /
|
|
8113
|
-
said.push(await drop(root2, ".agents/rules/
|
|
8133
|
+
delete d.diacode;
|
|
8134
|
+
}, (d) => onlyOurs(d), /diacode|\/hooks\/antigravity\//, 'the "diacode" key'));
|
|
8135
|
+
said.push(await drop(root2, ".agents/rules/diacode.md", "the rules"));
|
|
8114
8136
|
return said;
|
|
8115
8137
|
}
|
|
8116
8138
|
var HARNESS_REMOVE = (
|
|
@@ -8123,17 +8145,161 @@ var HARNESS_REMOVE = (
|
|
|
8123
8145
|
}
|
|
8124
8146
|
);
|
|
8125
8147
|
|
|
8148
|
+
// packages/server/src/migrate.js
|
|
8149
|
+
import { readdir as readdir3, rename as rename2, rm as rm2, rmdir as rmdir2, writeFile as writeFile3, readFile as readFile5, mkdir as mkdir3, stat as stat3 } from "node:fs/promises";
|
|
8150
|
+
import { join as join5 } from "node:path";
|
|
8151
|
+
var OLD_DIR = ".dcursed";
|
|
8152
|
+
var NEW_DIR = ".diacode";
|
|
8153
|
+
var OLD_SERVER = "dcursed";
|
|
8154
|
+
var OLD_RULE = "mcp__dcursed";
|
|
8155
|
+
var OLD_BEGIN = /<!-- dcursed:begin[^>]*-->/;
|
|
8156
|
+
var OLD_END = "<!-- dcursed:end -->";
|
|
8157
|
+
var MCP_FILES = (
|
|
8158
|
+
/** @type {const} */
|
|
8159
|
+
[[".mcp.json", "mcpServers"], [".cursor/mcp.json", "mcpServers"], [".agents/mcp_config.json", "mcpServers"], ["opencode.json", "mcp"]]
|
|
8160
|
+
);
|
|
8161
|
+
var OLD_FILES = [".claude/rules/dcursed.md", ".cursor/rules/dcursed.mdc", ".agents/rules/dcursed.md", ".opencode/plugins/dcursed.js"];
|
|
8162
|
+
var SETTINGS = [".claude/settings.local.json", ".claude/settings.json"];
|
|
8163
|
+
var exists = async (path) => {
|
|
8164
|
+
try {
|
|
8165
|
+
await stat3(path);
|
|
8166
|
+
return true;
|
|
8167
|
+
} catch {
|
|
8168
|
+
return false;
|
|
8169
|
+
}
|
|
8170
|
+
};
|
|
8171
|
+
async function legacyFound(root2) {
|
|
8172
|
+
const found = [];
|
|
8173
|
+
if (await exists(join5(root2, OLD_DIR))) found.push(`the ${OLD_DIR}/ folder`);
|
|
8174
|
+
for (const [rel, key2] of MCP_FILES) {
|
|
8175
|
+
const { data } = await readJson(join5(root2, rel));
|
|
8176
|
+
if (data?.[key2]?.[OLD_SERVER] !== void 0) found.push(`the "${OLD_SERVER}" entry in ${rel}`);
|
|
8177
|
+
}
|
|
8178
|
+
const hooks = await readJson(join5(root2, ".agents/hooks.json"));
|
|
8179
|
+
if (hooks.data?.[OLD_SERVER] !== void 0) found.push(`the "${OLD_SERVER}" key in .agents/hooks.json`);
|
|
8180
|
+
for (const rel of SETTINGS) {
|
|
8181
|
+
const { data } = await readJson(join5(root2, rel));
|
|
8182
|
+
if (Array.isArray(data?.permissions?.allow) && data.permissions.allow.includes(OLD_RULE)) found.push(`the ${OLD_RULE} allow rule in ${rel}`);
|
|
8183
|
+
}
|
|
8184
|
+
for (const rel of OLD_FILES) if (await exists(join5(root2, rel))) found.push(rel);
|
|
8185
|
+
const agents = await read(join5(root2, "AGENTS.md"));
|
|
8186
|
+
if (agents && OLD_BEGIN.test(agents)) found.push("the old block in AGENTS.md");
|
|
8187
|
+
return found;
|
|
8188
|
+
}
|
|
8189
|
+
async function moveInto(from, to, label, said) {
|
|
8190
|
+
let complete = true;
|
|
8191
|
+
const info = await stat3(from);
|
|
8192
|
+
if (info.isDirectory()) {
|
|
8193
|
+
await mkdir3(to, { recursive: true });
|
|
8194
|
+
for (const name2 of await readdir3(from)) complete = await moveInto(join5(from, name2), join5(to, name2), `${label}/${name2}`, said) && complete;
|
|
8195
|
+
if (complete) await rmdir2(from);
|
|
8196
|
+
return complete;
|
|
8197
|
+
}
|
|
8198
|
+
if (await exists(to)) {
|
|
8199
|
+
said.push(`NOT DONE ${label}: it is in both folders, so the old one was left; keep the one you want and delete the other`);
|
|
8200
|
+
return false;
|
|
8201
|
+
}
|
|
8202
|
+
await mkdir3(join5(to, ".."), { recursive: true });
|
|
8203
|
+
await rename2(from, to);
|
|
8204
|
+
return true;
|
|
8205
|
+
}
|
|
8206
|
+
var renameFormats = (text2) => text2.replace(/("schema"\s*:\s*")dcursed\.(plan|arch|layout)\//g, "$1diacode.$2/").replace(/("kind"\s*:\s*)"dcursed"/g, '$1"diacode"');
|
|
8207
|
+
async function migrate(root2) {
|
|
8208
|
+
const said = [];
|
|
8209
|
+
const oldDir = join5(root2, OLD_DIR);
|
|
8210
|
+
if (await exists(oldDir)) {
|
|
8211
|
+
const newDir = join5(root2, NEW_DIR);
|
|
8212
|
+
await rm2(join5(oldDir, "opencode-plugin.js"), { force: true });
|
|
8213
|
+
const moved = await moveInto(oldDir, newDir, OLD_DIR, said);
|
|
8214
|
+
const files = [];
|
|
8215
|
+
for (const sub of ["", "plans"]) {
|
|
8216
|
+
try {
|
|
8217
|
+
for (const f of await readdir3(join5(newDir, sub))) if (/\.(plan|arch|layout)\.json$|^architecture(\.layout)?\.json$/.test(f)) files.push(join5(newDir, sub, f));
|
|
8218
|
+
} catch {
|
|
8219
|
+
}
|
|
8220
|
+
}
|
|
8221
|
+
let renamed = 0;
|
|
8222
|
+
for (const file of files) {
|
|
8223
|
+
const text2 = await readFile5(file, "utf8");
|
|
8224
|
+
const next = renameFormats(text2);
|
|
8225
|
+
if (next !== text2) {
|
|
8226
|
+
await writeFile3(file, next);
|
|
8227
|
+
renamed += 1;
|
|
8228
|
+
}
|
|
8229
|
+
}
|
|
8230
|
+
said.push(moved ? `moved ${OLD_DIR}/ to ${NEW_DIR}/ (${renamed} file${renamed === 1 ? "" : "s"} now say diacode.*; the plan logs are as they were)` : `partly moved ${OLD_DIR}/ to ${NEW_DIR}/ (see above)`);
|
|
8231
|
+
}
|
|
8232
|
+
for (const [rel, key2] of MCP_FILES) {
|
|
8233
|
+
const path = join5(root2, rel);
|
|
8234
|
+
const { data, text: text2, ok: ok2 } = await readJson(path);
|
|
8235
|
+
if (text2 === null) continue;
|
|
8236
|
+
if (!ok2) {
|
|
8237
|
+
if (text2.includes(`"${OLD_SERVER}"`)) said.push(`NOT DONE ${rel}: it has comments or is not plain JSON, so remove the "${OLD_SERVER}" entry under "${key2}" yourself`);
|
|
8238
|
+
continue;
|
|
8239
|
+
}
|
|
8240
|
+
if (data?.[key2]?.[OLD_SERVER] === void 0) continue;
|
|
8241
|
+
delete data[key2][OLD_SERVER];
|
|
8242
|
+
pruneEmpty(data, key2);
|
|
8243
|
+
if (Object.keys(data).every((k) => k === "$schema")) said.push(await drop(root2, rel, "it held only the old DcurseD entry"));
|
|
8244
|
+
else {
|
|
8245
|
+
await writeFile3(path, `${JSON.stringify(data, null, 2)}
|
|
8246
|
+
`);
|
|
8247
|
+
said.push(`updated ${rel} (the "${OLD_SERVER}" entry removed)`);
|
|
8248
|
+
}
|
|
8249
|
+
}
|
|
8250
|
+
{
|
|
8251
|
+
const path = join5(root2, ".agents/hooks.json");
|
|
8252
|
+
const { data, ok: ok2 } = await readJson(path);
|
|
8253
|
+
if (ok2 && data?.[OLD_SERVER] !== void 0) {
|
|
8254
|
+
delete data[OLD_SERVER];
|
|
8255
|
+
if (Object.keys(data).length === 0) said.push(await drop(root2, ".agents/hooks.json", "it held only the old DcurseD hooks"));
|
|
8256
|
+
else {
|
|
8257
|
+
await writeFile3(path, `${JSON.stringify(data, null, 2)}
|
|
8258
|
+
`);
|
|
8259
|
+
said.push(`updated .agents/hooks.json (the "${OLD_SERVER}" key removed)`);
|
|
8260
|
+
}
|
|
8261
|
+
}
|
|
8262
|
+
}
|
|
8263
|
+
for (const rel of SETTINGS) {
|
|
8264
|
+
const path = join5(root2, rel);
|
|
8265
|
+
const { data, ok: ok2 } = await readJson(path);
|
|
8266
|
+
if (!ok2 || !Array.isArray(data?.permissions?.allow) || !data.permissions.allow.includes(OLD_RULE)) continue;
|
|
8267
|
+
data.permissions.allow = data.permissions.allow.filter((r) => r !== OLD_RULE);
|
|
8268
|
+
pruneEmpty(data.permissions, "allow");
|
|
8269
|
+
pruneEmpty(data, "permissions");
|
|
8270
|
+
await writeFile3(path, `${JSON.stringify(data, null, 2)}
|
|
8271
|
+
`);
|
|
8272
|
+
said.push(`updated ${rel} (the ${OLD_RULE} allow rule removed; init adds mcp__diacode)`);
|
|
8273
|
+
}
|
|
8274
|
+
for (const rel of OLD_FILES) if (await exists(join5(root2, rel))) said.push(await drop(root2, rel, "written by the old init"));
|
|
8275
|
+
const agentsPath = join5(root2, "AGENTS.md");
|
|
8276
|
+
const agents = await read(agentsPath);
|
|
8277
|
+
if (agents !== null && OLD_BEGIN.test(agents) && agents.includes(OLD_END)) {
|
|
8278
|
+
const rest = agents.replace(new RegExp(`\\n*${OLD_BEGIN.source}[\\s\\S]*?${escape(OLD_END)}\\n*`), "\n\n").replace(/^\n+/, "").replace(/\n{3,}/g, "\n\n");
|
|
8279
|
+
if (!rest.trim()) said.push(await drop(root2, "AGENTS.md", "it held only the old DcurseD block"));
|
|
8280
|
+
else {
|
|
8281
|
+
await writeFile3(agentsPath, rest.replace(/\n*$/, "\n"));
|
|
8282
|
+
said.push("updated AGENTS.md (the old DcurseD block removed)");
|
|
8283
|
+
}
|
|
8284
|
+
}
|
|
8285
|
+
try {
|
|
8286
|
+
await rmdir2(oldDir);
|
|
8287
|
+
} catch {
|
|
8288
|
+
}
|
|
8289
|
+
return said;
|
|
8290
|
+
}
|
|
8291
|
+
|
|
8126
8292
|
// packages/server/src/doctor.js
|
|
8127
|
-
import { readFile as
|
|
8293
|
+
import { readFile as readFile6, readdir as readdir4 } from "node:fs/promises";
|
|
8128
8294
|
import { accessSync, constants } from "node:fs";
|
|
8129
|
-
import { join as
|
|
8295
|
+
import { join as join6, resolve as resolve4, delimiter } from "node:path";
|
|
8130
8296
|
import { homedir } from "node:os";
|
|
8131
8297
|
var ok = (text2) => ({ level: "ok", text: text2 });
|
|
8132
8298
|
var problem = (text2, fix) => ({ level: "problem", text: text2, ...fix ? { fix } : {} });
|
|
8133
8299
|
var note = (text2) => ({ level: "note", text: text2 });
|
|
8134
8300
|
async function text(root2, rel) {
|
|
8135
8301
|
try {
|
|
8136
|
-
return await
|
|
8302
|
+
return await readFile6(join6(root2, rel), "utf8");
|
|
8137
8303
|
} catch {
|
|
8138
8304
|
return null;
|
|
8139
8305
|
}
|
|
@@ -8153,7 +8319,7 @@ function portsIn(s, after = "") {
|
|
|
8153
8319
|
function onPath(cmd2) {
|
|
8154
8320
|
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
8155
8321
|
try {
|
|
8156
|
-
accessSync(
|
|
8322
|
+
accessSync(join6(dir, cmd2), constants.X_OK);
|
|
8157
8323
|
return true;
|
|
8158
8324
|
} catch {
|
|
8159
8325
|
}
|
|
@@ -8165,11 +8331,11 @@ async function mcpEntry(root2, rel, harness, pick3) {
|
|
|
8165
8331
|
if (t === null) return { finding: problem(`${rel} is missing, so the agent has no plan tools`, "{init}"), ports: [] };
|
|
8166
8332
|
const data = json(t);
|
|
8167
8333
|
if (data === null) {
|
|
8168
|
-
return t.includes(`/mcp/${harness}`) ? { finding: ok(`${rel} names the
|
|
8334
|
+
return t.includes(`/mcp/${harness}`) ? { finding: ok(`${rel} names the diacode MCP server (it has comments, so read as text)`), ports: portsIn(t, `/mcp/${harness}`) } : { finding: problem(`${rel} has comments and no diacode MCP entry`, `add the entry \`${invocation()} init\` printed, by hand`), ports: [] };
|
|
8169
8335
|
}
|
|
8170
8336
|
const url = pick3(data);
|
|
8171
|
-
if (!url) return { finding: problem(`${rel} has no
|
|
8172
|
-
return { finding: ok(`${rel}: the
|
|
8337
|
+
if (!url) return { finding: problem(`${rel} has no diacode entry`, "{init}"), ports: [] };
|
|
8338
|
+
return { finding: ok(`${rel}: the diacode MCP server at ${url}`), ports: portsIn(url) };
|
|
8173
8339
|
}
|
|
8174
8340
|
async function hooksEntry(root2, files, harness, events, hooksOf) {
|
|
8175
8341
|
const marker = `/hooks/${harness}/`;
|
|
@@ -8201,36 +8367,36 @@ async function rulesFile(root2, rel, what) {
|
|
|
8201
8367
|
async function openCode(root2) {
|
|
8202
8368
|
const configFile = await text(root2, "opencode.json") !== null ? "opencode.json" : await text(root2, "opencode.jsonc") !== null ? "opencode.jsonc" : "opencode.json";
|
|
8203
8369
|
const config = await text(root2, configFile);
|
|
8204
|
-
const loader = await text(root2, ".opencode/plugins/
|
|
8370
|
+
const loader = await text(root2, ".opencode/plugins/diacode.js");
|
|
8205
8371
|
if (config === null && loader === null) return null;
|
|
8206
8372
|
const findings = [];
|
|
8207
8373
|
const ports = [];
|
|
8208
|
-
const mcp = await mcpEntry(root2, configFile, "opencode", (d) => d?.mcp?.
|
|
8374
|
+
const mcp = await mcpEntry(root2, configFile, "opencode", (d) => d?.mcp?.diacode?.url);
|
|
8209
8375
|
findings.push(mcp.finding);
|
|
8210
8376
|
ports.push(...mcp.ports);
|
|
8211
|
-
if (loader === null) findings.push(problem(".opencode/plugins/
|
|
8377
|
+
if (loader === null) findings.push(problem(".opencode/plugins/diacode.js is missing, so OpenCode does not load the plugin", "{init}"));
|
|
8212
8378
|
else {
|
|
8213
|
-
findings.push(ok(".opencode/plugins/
|
|
8379
|
+
findings.push(ok(".opencode/plugins/diacode.js (loads the plugin)"));
|
|
8214
8380
|
ports.push(...portsIn(loader));
|
|
8215
8381
|
}
|
|
8216
|
-
const installed = await text(root2, ".
|
|
8217
|
-
if (installed === null) findings.push(problem(".
|
|
8218
|
-
else if (installed !== await pluginSource()) findings.push(problem(".
|
|
8219
|
-
else findings.push(ok(".
|
|
8382
|
+
const installed = await text(root2, ".diacode/opencode-plugin.js");
|
|
8383
|
+
if (installed === null) findings.push(problem(".diacode/opencode-plugin.js is missing: the plugin itself", "{init}"));
|
|
8384
|
+
else if (installed !== await pluginSource()) findings.push(problem(".diacode/opencode-plugin.js is not the plugin that ships with this diacode (an older one, or edited)", "{init}"));
|
|
8385
|
+
else findings.push(ok(".diacode/opencode-plugin.js is this version's plugin"));
|
|
8220
8386
|
const agents = await text(root2, "AGENTS.md");
|
|
8221
8387
|
findings.push(!agents?.includes(BEGIN) ? problem("AGENTS.md has no DiaCode block: the agent is not told how to work with the plan", "{init}") : agents.includes("THE ORDER") ? ok("AGENTS.md (how to work with the plan)") : problem("AGENTS.md has the DiaCode block of an older version: it does not tell the agent the order (architecture, then plan, then Start)", "{init}"));
|
|
8222
8388
|
return { harness: "opencode", label: "OpenCode", ports, findings };
|
|
8223
8389
|
}
|
|
8224
8390
|
async function claudeCode(root2) {
|
|
8225
|
-
const files = [".mcp.json", ".claude/settings.local.json", ".claude/settings.json", ".claude/rules/
|
|
8391
|
+
const files = [".mcp.json", ".claude/settings.local.json", ".claude/settings.json", ".claude/rules/diacode.md"];
|
|
8226
8392
|
const present = await Promise.all(files.map((f) => text(root2, f)));
|
|
8227
8393
|
const mcpText = present[0];
|
|
8228
8394
|
const hasOurs = (mcpText ?? "").includes("/mcp/claude-code") || present.slice(1, 3).some((t) => (t ?? "").includes("/hooks/claude-code/")) || present[3] !== null;
|
|
8229
8395
|
if (!hasOurs) return null;
|
|
8230
8396
|
const findings = [];
|
|
8231
|
-
const mcp = await mcpEntry(root2, ".mcp.json", "claude-code", (d) => d?.mcpServers?.
|
|
8397
|
+
const mcp = await mcpEntry(root2, ".mcp.json", "claude-code", (d) => d?.mcpServers?.diacode?.url);
|
|
8232
8398
|
const hooks = await hooksEntry(root2, [".claude/settings.local.json", ".claude/settings.json"], "claude-code", ["SessionStart", "UserPromptSubmit", "PostToolUse", "Stop", "SessionEnd"], (d) => d?.hooks);
|
|
8233
|
-
findings.push(mcp.finding, hooks.finding, await rulesFile(root2, ".claude/rules/
|
|
8399
|
+
findings.push(mcp.finding, hooks.finding, await rulesFile(root2, ".claude/rules/diacode.md", "the agent is not told how to work with the plan"));
|
|
8234
8400
|
const hookText = present.slice(1, 3).map((t) => t ?? "").join("\n");
|
|
8235
8401
|
if (hookText.includes("/hooks/claude-code/Stop") && !hookText.includes("/hooks/claude-code/wake")) {
|
|
8236
8402
|
findings.push(problem("no wake hook: approving the plan in the editor, or answering a question, cannot start this agent (it is told at its next step)", "{init}"));
|
|
@@ -8244,7 +8410,7 @@ async function claudeCode(root2) {
|
|
|
8244
8410
|
findings.push(problem("no PermissionRequest hook: when the agent asks your permission, the editor says so but cannot answer it (only its own window can)", "{init}"));
|
|
8245
8411
|
}
|
|
8246
8412
|
if (hookText.includes("/hooks/claude-code/Stop") && !hookText.includes("/hooks/claude-code/PreToolUse")) {
|
|
8247
|
-
findings.push(problem("no PreToolUse hook: Stop in the editor cannot halt the agent mid-turn (it hears it at its next
|
|
8413
|
+
findings.push(problem("no PreToolUse hook: Stop in the editor cannot halt the agent mid-turn (it hears it at its next diacode tool)", "{init}"));
|
|
8248
8414
|
}
|
|
8249
8415
|
if (hookText.includes("/hooks/claude-code/Stop") && !hookText.includes(ALLOW_TOOLS)) {
|
|
8250
8416
|
findings.push(note(`Claude Code asks permission before each plan call; init adds one rule, "${ALLOW_TOOLS}", that covers only the plan tools (run init again to add it, or skip it if you want the prompts)`));
|
|
@@ -8254,9 +8420,9 @@ async function claudeCode(root2) {
|
|
|
8254
8420
|
return { harness: "claude-code", label: "Claude Code", ports: [...mcp.ports, ...hooks.ports], findings };
|
|
8255
8421
|
}
|
|
8256
8422
|
async function cursor(root2) {
|
|
8257
|
-
const t = [await text(root2, ".cursor/mcp.json"), await text(root2, ".cursor/hooks.json"), await text(root2, ".cursor/rules/
|
|
8423
|
+
const t = [await text(root2, ".cursor/mcp.json"), await text(root2, ".cursor/hooks.json"), await text(root2, ".cursor/rules/diacode.mdc")];
|
|
8258
8424
|
if (!((t[0] ?? "").includes("/mcp/cursor") || (t[1] ?? "").includes("/hooks/cursor/") || t[2] !== null)) return null;
|
|
8259
|
-
const mcp = await mcpEntry(root2, ".cursor/mcp.json", "cursor", (d) => d?.mcpServers?.
|
|
8425
|
+
const mcp = await mcpEntry(root2, ".cursor/mcp.json", "cursor", (d) => d?.mcpServers?.diacode?.url);
|
|
8260
8426
|
const hooks = await hooksEntry(root2, [".cursor/hooks.json"], "cursor", ["sessionStart", "beforeSubmitPrompt", "afterFileEdit", "postToolUse", "stop", "sessionEnd"], (d) => d?.hooks);
|
|
8261
8427
|
return {
|
|
8262
8428
|
harness: "cursor",
|
|
@@ -8265,17 +8431,17 @@ async function cursor(root2) {
|
|
|
8265
8431
|
findings: [
|
|
8266
8432
|
mcp.finding,
|
|
8267
8433
|
hooks.finding,
|
|
8268
|
-
await rulesFile(root2, ".cursor/rules/
|
|
8269
|
-
note("Cursor asks you to enable the
|
|
8434
|
+
await rulesFile(root2, ".cursor/rules/diacode.mdc", "the agent is not told how to work with the plan"),
|
|
8435
|
+
note("Cursor asks you to enable the diacode server in Settings \u2192 MCP; that switch is inside Cursor, so this cannot see it.")
|
|
8270
8436
|
]
|
|
8271
8437
|
};
|
|
8272
8438
|
}
|
|
8273
8439
|
async function antigravity(root2) {
|
|
8274
|
-
const t = [await text(root2, ".agents/mcp_config.json"), await text(root2, ".agents/hooks.json"), await text(root2, ".agents/rules/
|
|
8440
|
+
const t = [await text(root2, ".agents/mcp_config.json"), await text(root2, ".agents/hooks.json"), await text(root2, ".agents/rules/diacode.md")];
|
|
8275
8441
|
if (!((t[0] ?? "").includes("/mcp/antigravity") || (t[1] ?? "").includes("/hooks/antigravity/") || t[2] !== null)) return null;
|
|
8276
|
-
const mcp = await mcpEntry(root2, ".agents/mcp_config.json", "antigravity", (d) => d?.mcpServers?.
|
|
8277
|
-
const hooks = await hooksEntry(root2, [".agents/hooks.json"], "antigravity", ["SessionStart", "PreInvocation", "PostToolUse", "Stop"], (d) => d?.
|
|
8278
|
-
const enabled = json(t[1])?.
|
|
8442
|
+
const mcp = await mcpEntry(root2, ".agents/mcp_config.json", "antigravity", (d) => d?.mcpServers?.diacode?.serverUrl);
|
|
8443
|
+
const hooks = await hooksEntry(root2, [".agents/hooks.json"], "antigravity", ["SessionStart", "PreInvocation", "PostToolUse", "Stop"], (d) => d?.diacode);
|
|
8444
|
+
const enabled = json(t[1])?.diacode?.enabled;
|
|
8279
8445
|
return {
|
|
8280
8446
|
harness: "antigravity",
|
|
8281
8447
|
label: "Antigravity",
|
|
@@ -8284,7 +8450,7 @@ async function antigravity(root2) {
|
|
|
8284
8450
|
mcp.finding,
|
|
8285
8451
|
hooks.finding,
|
|
8286
8452
|
...enabled === false ? [problem("the DiaCode hooks are switched off (`enabled: false` in .agents/hooks.json)", "{init}")] : [],
|
|
8287
|
-
await rulesFile(root2, ".agents/rules/
|
|
8453
|
+
await rulesFile(root2, ".agents/rules/diacode.md", "the agent is not told how to work with the plan"),
|
|
8288
8454
|
note("Workspace hooks load only for a trusted folder; trusting it is inside Antigravity, so this cannot see it.")
|
|
8289
8455
|
]
|
|
8290
8456
|
};
|
|
@@ -8311,7 +8477,7 @@ async function liveChecks(port2, root2, connections) {
|
|
|
8311
8477
|
}
|
|
8312
8478
|
out.push(ok(`the plan server for this folder is running on port ${port2}`));
|
|
8313
8479
|
if (typeof health.version === "string" && health.version !== VERSION) {
|
|
8314
|
-
out.push(note(`the running server is
|
|
8480
|
+
out.push(note(`the running server is diacode ${health.version} and this is ${VERSION}: stop the server and start it again to match, and run \`init\` again if an agent misbehaves`));
|
|
8315
8481
|
}
|
|
8316
8482
|
try {
|
|
8317
8483
|
const res = await fetch(`${base}/app/`, { signal: AbortSignal.timeout(1500) });
|
|
@@ -8335,7 +8501,7 @@ async function liveChecks(port2, root2, connections) {
|
|
|
8335
8501
|
if (session) await fetch(door, { method: "DELETE", headers: { "mcp-session-id": session }, signal: AbortSignal.timeout(1e3) }).catch(() => {
|
|
8336
8502
|
});
|
|
8337
8503
|
const n = tools.body?.result?.tools?.length ?? 0;
|
|
8338
|
-
out.push(init.body?.result?.serverInfo?.name === "
|
|
8504
|
+
out.push(init.body?.result?.serverInfo?.name === "diacode" && n > 0 ? ok(`${c.label}: the MCP door /mcp/${c.harness} opens and offers ${n} tools`) : problem(`${c.label}: the MCP door /mcp/${c.harness} did not answer like a DiaCode server`));
|
|
8339
8505
|
} catch (e) {
|
|
8340
8506
|
out.push(problem(`${c.label}: the MCP door /mcp/${c.harness} failed (${e instanceof Error ? e.message : e})`));
|
|
8341
8507
|
}
|
|
@@ -8368,10 +8534,12 @@ async function diagnose({ root: root2, port: port2 }) {
|
|
|
8368
8534
|
const basics = [major >= 22 ? ok(`Node ${process.versions.node}`) : problem(`Node ${process.versions.node}: DiaCode needs Node 22 or newer`, "install a current Node from nodejs.org")];
|
|
8369
8535
|
let plans = 0;
|
|
8370
8536
|
try {
|
|
8371
|
-
plans = (await
|
|
8537
|
+
plans = (await readdir4(join6(root2, ".diacode", "plans"))).filter((f) => f.endsWith(".plan.json")).length;
|
|
8372
8538
|
} catch {
|
|
8373
8539
|
}
|
|
8374
|
-
basics.push(plans ? ok(`${plans} plan${plans === 1 ? "" : "s"} in .
|
|
8540
|
+
basics.push(plans ? ok(`${plans} plan${plans === 1 ? "" : "s"} in .diacode/plans`) : note("no plans yet: ask an agent to draft one, or use New plan or Import\u2026 in the editor"));
|
|
8541
|
+
const legacy = await legacyFound(root2);
|
|
8542
|
+
if (legacy.length) basics.push(problem(`this repository still has what DiaCode 0.2 (then called DcurseD) wrote: ${legacy.join("; ")}`, `${invocation()} migrate, then ${invocation()} init <agent> again`));
|
|
8375
8543
|
sections.push({ title: root2, findings: basics });
|
|
8376
8544
|
const connections = (
|
|
8377
8545
|
/** @type {Connection[]} */
|
|
@@ -8431,7 +8599,7 @@ async function issueReport({ root: root2, port: port2 }) {
|
|
|
8431
8599
|
"",
|
|
8432
8600
|
"What the server has noticed",
|
|
8433
8601
|
...seen ? [
|
|
8434
|
-
`
|
|
8602
|
+
` diacode ${seen.version}, API ${seen.api}, up ${seen.uptimeSeconds} s, ${seen.plans} plan${seen.plans === 1 ? "" : "s"}`,
|
|
8435
8603
|
...seen.events?.length ? seen.events.map((e) => ` ${e.at} ${e.kind}: ${e.message}`) : [" nothing since it started"]
|
|
8436
8604
|
] : [" (no server answered on this port, or it is too old to say)"]
|
|
8437
8605
|
];
|
|
@@ -8445,11 +8613,11 @@ async function issueReport({ root: root2, port: port2 }) {
|
|
|
8445
8613
|
|
|
8446
8614
|
// packages/server/src/lock.js
|
|
8447
8615
|
import { createHash } from "node:crypto";
|
|
8448
|
-
import { readFile as
|
|
8616
|
+
import { readFile as readFile7, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
8449
8617
|
import { readFileSync as readFileSync2, unlinkSync } from "node:fs";
|
|
8450
8618
|
import { tmpdir } from "node:os";
|
|
8451
|
-
import { join as
|
|
8452
|
-
var lockPath = (root2) =>
|
|
8619
|
+
import { join as join7, resolve as resolve5 } from "node:path";
|
|
8620
|
+
var lockPath = (root2) => join7(tmpdir(), `diacode-${createHash("sha256").update(resolve5(root2)).digest("hex").slice(0, 16)}.lock`);
|
|
8453
8621
|
function alive(pid) {
|
|
8454
8622
|
try {
|
|
8455
8623
|
process.kill(pid, 0);
|
|
@@ -8464,7 +8632,7 @@ function alive(pid) {
|
|
|
8464
8632
|
async function holder(root2) {
|
|
8465
8633
|
let info;
|
|
8466
8634
|
try {
|
|
8467
|
-
info = JSON.parse(await
|
|
8635
|
+
info = JSON.parse(await readFile7(lockPath(root2), "utf8"));
|
|
8468
8636
|
} catch {
|
|
8469
8637
|
return null;
|
|
8470
8638
|
}
|
|
@@ -8484,7 +8652,7 @@ async function takeLock(root2, about) {
|
|
|
8484
8652
|
const info = { pid: process.pid, port: about.port, version: about.version, root: resolve5(root2), startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
8485
8653
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
8486
8654
|
try {
|
|
8487
|
-
await
|
|
8655
|
+
await writeFile4(path, JSON.stringify(info), { flag: "wx" });
|
|
8488
8656
|
const sweep = () => {
|
|
8489
8657
|
try {
|
|
8490
8658
|
if (JSON.parse(readFileSync2(path, "utf8")).pid === process.pid) unlinkSync(path);
|
|
@@ -8496,7 +8664,7 @@ async function takeLock(root2, about) {
|
|
|
8496
8664
|
release: async () => {
|
|
8497
8665
|
process.off("exit", sweep);
|
|
8498
8666
|
try {
|
|
8499
|
-
if (JSON.parse(await
|
|
8667
|
+
if (JSON.parse(await readFile7(path, "utf8")).pid === process.pid) await unlink(path);
|
|
8500
8668
|
} catch {
|
|
8501
8669
|
}
|
|
8502
8670
|
}
|
|
@@ -8517,7 +8685,7 @@ async function takeLock(root2, about) {
|
|
|
8517
8685
|
throw new Error(`could not take the lock ${path}`);
|
|
8518
8686
|
}
|
|
8519
8687
|
|
|
8520
|
-
// packages/server/bin/
|
|
8688
|
+
// packages/server/bin/diacode.js
|
|
8521
8689
|
var args = process.argv.slice(2);
|
|
8522
8690
|
var cmd = invocation();
|
|
8523
8691
|
var usage = [
|
|
@@ -8538,6 +8706,9 @@ var usage = [
|
|
|
8538
8706
|
" --report prints the findings with what the server has noticed, paths replaced, to paste into an issue",
|
|
8539
8707
|
` ${cmd} import <file.plan.md | file.md | file.mmd> [--root <repo>] [--id <plan-id>] [--title <title>]`,
|
|
8540
8708
|
" bring in a Cursor plan, markdown with a Mermaid block, or a bare Mermaid file",
|
|
8709
|
+
` ${cmd} migrate [--root <repo>]`,
|
|
8710
|
+
" a repository set up by DiaCode 0.2 (then called DcurseD): move its plans from .dcursed/ to .diacode/ and take the old",
|
|
8711
|
+
" entries out of the agents' settings; then run init again. (init does this too, first.)",
|
|
8541
8712
|
` ${cmd} --version`
|
|
8542
8713
|
].join("\n");
|
|
8543
8714
|
var option = (name2, fallback) => {
|
|
@@ -8566,7 +8737,22 @@ if (args[0] === "--version" || args[0] === "-v" || args[0] === "version") {
|
|
|
8566
8737
|
const report = await diagnose({ root, ...option("port") ? { port } : {} });
|
|
8567
8738
|
console.log(formatReport(report));
|
|
8568
8739
|
process.exitCode = report.problems ? 1 : 0;
|
|
8740
|
+
} else if (args[0] === "migrate") {
|
|
8741
|
+
const found = await legacyFound(root);
|
|
8742
|
+
if (!found.length) console.log(`Nothing to migrate: ${root} has nothing under the old DcurseD name.`);
|
|
8743
|
+
else {
|
|
8744
|
+
for (const line of await migrate(root)) console.log(line);
|
|
8745
|
+
console.log(`
|
|
8746
|
+
Now connect your agent again, so that it uses the new name: ${cmd} init <opencode|claude-code|cursor|antigravity|all>
|
|
8747
|
+
and restart its session.`);
|
|
8748
|
+
}
|
|
8569
8749
|
} else if (args[0] === "serve") {
|
|
8750
|
+
if (await legacyFound(root).then((f) => f.some((l) => l.startsWith("the .dcursed/")))) {
|
|
8751
|
+
console.error(`This folder still keeps its plans in .dcursed/, where DiaCode 0.2 (then called DcurseD) put them.
|
|
8752
|
+
Move them first: ${cmd} migrate${root === resolve6(".") ? "" : ` --root ${root}`}
|
|
8753
|
+
then connect your agent again: ${cmd} init <agent>`);
|
|
8754
|
+
process.exit(1);
|
|
8755
|
+
}
|
|
8570
8756
|
const origins = args.flatMap((a, i) => a === "--allow-origin" && args[i + 1] ? [args[i + 1]] : []);
|
|
8571
8757
|
const server = createServer({
|
|
8572
8758
|
root,
|
|
@@ -8608,7 +8794,7 @@ Pick another one: ${cmd} serve --port ${port + 1} (and ${cmd} init <harness>
|
|
|
8608
8794
|
const lock = await takeLock(root, { port: actual, version: VERSION });
|
|
8609
8795
|
if ("held" in lock) {
|
|
8610
8796
|
await server.close();
|
|
8611
|
-
console.error(`The plan server for this folder is already running: http://127.0.0.1:${lock.held.port}/ (pid ${lock.held.pid},
|
|
8797
|
+
console.error(`The plan server for this folder is already running: http://127.0.0.1:${lock.held.port}/ (pid ${lock.held.pid}, diacode ${lock.held.version}).
|
|
8612
8798
|
Two servers on one folder would overwrite each other, so this one did not start.
|
|
8613
8799
|
Use that one, or stop it first (Ctrl-C in its terminal, or kill ${lock.held.pid}) and run this again.`);
|
|
8614
8800
|
process.exit(1);
|
|
@@ -8637,6 +8823,10 @@ Use that one, or stop it first (Ctrl-C in its terminal, or kill ${lock.held.pid}
|
|
|
8637
8823
|
console.error("--accept-edits is for adding it; `init claude-code --remove` takes it out again.");
|
|
8638
8824
|
process.exit(1);
|
|
8639
8825
|
}
|
|
8826
|
+
if (!remove && (await legacyFound(root)).length) {
|
|
8827
|
+
console.log("\u2500\u2500 moving from DcurseD (DiaCode 0.2)");
|
|
8828
|
+
for (const line of await migrate(root)) console.log(line);
|
|
8829
|
+
}
|
|
8640
8830
|
for (const h of which) {
|
|
8641
8831
|
console.log(`\u2500\u2500 ${h}`);
|
|
8642
8832
|
if (remove) {
|