@omacode/micromanager 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +30 -2
- package/THIRD_PARTY.md +100 -0
- package/decider/.python-version +1 -0
- package/decider/README.md +35 -0
- package/decider/decider/__init__.py +1 -0
- package/decider/decider/server.py +327 -0
- package/decider/pyproject.toml +34 -0
- package/decider/uv.lock +1255 -0
- package/dist/agenda.js +51 -0
- package/dist/agents.js +58 -0
- package/dist/artifact/handoff.js +281 -0
- package/dist/ask.js +200 -0
- package/dist/backends.js +219 -0
- package/dist/backlog.js +414 -0
- package/dist/bench.js +427 -0
- package/dist/board.js +1 -0
- package/dist/brief.js +202 -0
- package/dist/browser.js +679 -0
- package/dist/budget.js +61 -0
- package/dist/catalog.js +187 -0
- package/dist/checkchange.js +145 -0
- package/dist/checkpoint.js +94 -0
- package/dist/cli.js +764 -0
- package/dist/comfy-gate.js +258 -0
- package/dist/compact.js +142 -0
- package/dist/config.js +344 -0
- package/dist/context/capture.js +1 -0
- package/dist/context/digest.js +1 -0
- package/dist/context/embed.js +1 -0
- package/dist/context/index.js +2 -0
- package/dist/context/ledger.js +1 -0
- package/dist/context/manager.js +1 -0
- package/dist/context/memory.js +1 -0
- package/dist/context/policy.js +1 -0
- package/dist/context/prices.js +1 -0
- package/dist/context/recall.js +1 -0
- package/dist/context/rules.js +1 -0
- package/dist/context/search.js +1 -0
- package/dist/context/status.js +1 -0
- package/dist/context/store.js +1 -0
- package/dist/context/summary.js +1 -0
- package/dist/context/tokens.js +1 -0
- package/dist/context/tools.js +1 -0
- package/dist/continuation.js +184 -0
- package/dist/contract.js +294 -0
- package/dist/contractround.js +178 -0
- package/dist/control.js +1 -0
- package/dist/creative-tools.js +237 -0
- package/dist/dataset.js +175 -0
- package/dist/decide.js +676 -0
- package/dist/decider.js +171 -0
- package/dist/design-shell.js +448 -0
- package/dist/design.js +1410 -0
- package/dist/desktop.js +44 -0
- package/dist/egress.js +156 -0
- package/dist/eval.js +60 -0
- package/dist/evolver.js +302 -0
- package/dist/features.js +193 -0
- package/dist/followups.js +32 -0
- package/dist/forms.js +195 -0
- package/dist/gate.js +108 -0
- package/dist/gatebox.js +46 -0
- package/dist/grants.js +189 -0
- package/dist/graph.js +65 -0
- package/dist/guard/index.js +1 -0
- package/dist/guard/wire.js +1 -0
- package/dist/helpers.js +85 -0
- package/dist/hooks.js +158 -0
- package/dist/image-models.js +117 -0
- package/dist/integration.js +3 -0
- package/dist/journal.js +1 -0
- package/dist/look.js +363 -0
- package/dist/memory.js +1 -0
- package/dist/mode.js +97 -0
- package/dist/native.js +3348 -0
- package/dist/nogit.js +259 -0
- package/dist/outcomes.js +148 -0
- package/dist/permission.js +35 -0
- package/dist/pick.js +89 -0
- package/dist/pipelines.js +262 -0
- package/dist/plan.js +641 -0
- package/dist/plandoc.js +211 -0
- package/dist/plugin.js +4736 -0
- package/dist/policy.js +58 -0
- package/dist/pools.js +1 -0
- package/dist/preview.js +274 -0
- package/dist/profile.js +165 -0
- package/dist/progress.js +1 -0
- package/dist/promote.js +313 -0
- package/dist/redact.js +1 -0
- package/dist/registry.js +179 -0
- package/dist/riskscore.js +126 -0
- package/dist/roles.js +1 -0
- package/dist/routing.js +1 -0
- package/dist/runner.js +1892 -0
- package/dist/sandbox.js +3 -0
- package/dist/sandboxgate.js +90 -0
- package/dist/scheduler.js +170 -0
- package/dist/services-main.js +131 -0
- package/dist/services.js +265 -0
- package/dist/session.js +241 -0
- package/dist/setup.js +423 -0
- package/dist/shell/decide.js +1 -0
- package/dist/shell/index.js +2 -0
- package/dist/shell/sandbox.js +1 -0
- package/dist/shell/wire.js +1 -0
- package/dist/skills.js +103 -0
- package/dist/state.js +1 -0
- package/dist/store.js +1 -0
- package/dist/switcher.js +1 -0
- package/dist/synth.js +418 -0
- package/dist/tools.js +477 -0
- package/dist/trials.js +223 -0
- package/dist/usage.js +1 -0
- package/dist/wait.js +167 -0
- package/dist/watchdog.js +476 -0
- package/dist/web-guidance.js +43 -0
- package/dist/which.js +20 -0
- package/dist/worktree/git.js +545 -0
- package/dist/writeguard.js +311 -0
- package/evolver/mm_evolve/__init__.py +1 -0
- package/evolver/mm_evolve/entry.py +3 -0
- package/evolver/mm_evolve/evaluator.py +119 -0
- package/evolver/mm_evolve/llm.py +76 -0
- package/evolver/mm_evolve/run.py +89 -0
- package/evolver/mm_evolve/spec.py +62 -0
- package/evolver/pyproject.toml +21 -0
- package/evolver/uv.lock +772 -0
- package/package.json +74 -4
- package/skills/THIRD_PARTY.md +58 -0
- package/skills/code-review/SKILL.md +46 -0
- package/skills/deck/SKILL.md +98 -0
- package/skills/deliberate/SKILL.md +39 -0
- package/skills/design/SKILL.md +150 -0
- package/skills/diagnosing-bugs/SKILL.md +75 -0
- package/skills/image/SKILL.md +66 -0
- package/skills/orchestrator/SKILL.md +107 -0
- package/skills/receiving-code-review/SKILL.md +36 -0
- package/skills/research/SKILL.md +18 -0
- package/skills/tdd/SKILL.md +56 -0
- package/skills/tdd/mocking.md +59 -0
- package/skills/tdd/tests.md +77 -0
- package/skills/verification-before-completion/SKILL.md +50 -0
- package/skills/video/SKILL.md +97 -0
- package/skills/web/SKILL.md +60 -0
package/dist/backends.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Decision backends per node (design.md §20): the cloud decision client, the local GLiNER decision server, Open-Jev,
|
|
2
|
+
// or rules. The decider has exactly two modes, "local" and "cloud" (D11): the mode decides the class of backend a
|
|
3
|
+
// node uses, and `default`/`nodes` only name a backend per node within what the mode allows. All speak the same wire
|
|
4
|
+
// format, so one client (src/decider.ts) serves them; only URL, model and key differ.
|
|
5
|
+
//
|
|
6
|
+
// In cloud mode every node may ask the cloud, but only for a session that opted in (A2-T5). The opt-in is a value of
|
|
7
|
+
// the session, not of the job or the machine: a session that has not opted in never reaches the egress gate at all,
|
|
8
|
+
// its decisions are answered on this machine, and the journal says so. The guards need a second, explicit answer for
|
|
9
|
+
// that session, and a sensitive payload cannot be overridden at all (src/egress.ts).
|
|
10
|
+
//
|
|
11
|
+
// Every decision is journalled here, with the state, the questions and the answers (A2-T2b). A payload for another
|
|
12
|
+
// machine passes the egress gate inside that client (src/egress.ts), so the entry also carries the redacted text that
|
|
13
|
+
// left and the gate's verdict.
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
import { serviceToken, serviceUrl } from "@omacode/core/services";
|
|
16
|
+
import { RULEBOOK_VERSION } from "./catalog.js";
|
|
17
|
+
import { EgressRefused, summary, unredactableText } from "./egress.js";
|
|
18
|
+
import { cloudApiKey, DecisionClient } from "./decider.js";
|
|
19
|
+
import { record } from "./journal.js";
|
|
20
|
+
import { findTool } from "./which.js";
|
|
21
|
+
// Guards start on GLiNER, everything else follows the mode: the cloud client in "cloud", and in "local" the cloud
|
|
22
|
+
// default is demoted to the local chain. G0 stays on this machine, in either mode, unless its session overrides that.
|
|
23
|
+
export const DEFAULT_BACKENDS = {
|
|
24
|
+
mode: "local",
|
|
25
|
+
default: "cloud",
|
|
26
|
+
nodes: { G0: "gliner", "G0.injection": "gliner", G: "gliner" },
|
|
27
|
+
urls: {
|
|
28
|
+
cloud: "https://api.typesafe.ai/v1/systemone",
|
|
29
|
+
// The container hands its own address in (@omacode/core/services); on a desktop this is the fixed port.
|
|
30
|
+
gliner: `${serviceUrl("decider")}/v1/systemone`,
|
|
31
|
+
openjev: "http://127.0.0.1:8782/v1/systemone",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const LOCAL = new Set(["gliner", "openjev", "rules"]);
|
|
35
|
+
// The guard nodes: injection and sensitive on a job's or task's text (G0) and the same guards on the text a
|
|
36
|
+
// worker reads (G0.injection; design.md §14 calls the whole node G). They stay on this machine in both modes unless the
|
|
37
|
+
// session's user overrode that for that session alone (A2-T5), and no other node's opt-in carries them along.
|
|
38
|
+
const GUARD_NODES = new Set(["G0", "G0.injection", "G"]);
|
|
39
|
+
export class RulesBackend {
|
|
40
|
+
// Answers nothing: every caller falls back to its code default, as without a decision client.
|
|
41
|
+
async ask() {
|
|
42
|
+
return { answers: {}, model: "rules", latencyMs: 0 };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// The key belongs to the cloud client, so only "cloud" mode reads it (A2-T2): a local-mode start touches neither
|
|
46
|
+
// JEV_API_KEY nor the keyring. `read` is the seam a test uses to prove that nothing is touched.
|
|
47
|
+
export function cloudKey(config, read = cloudApiKey) {
|
|
48
|
+
return config.mode === "cloud" ? read() : undefined;
|
|
49
|
+
}
|
|
50
|
+
// The one construction site of the cloud client (D19). Local mode, no key and no cloud URL each mean "no client",
|
|
51
|
+
// and none of them reads a key or a cloud URL from anywhere else. The gate travels with the client (A2-T6): a caller
|
|
52
|
+
// without a confirm function builds a client that can reach nothing at all.
|
|
53
|
+
export function cloudClient(config, key, fetcher, egress) {
|
|
54
|
+
if (config.mode !== "cloud" || !key)
|
|
55
|
+
return undefined;
|
|
56
|
+
const url = config.urls.cloud;
|
|
57
|
+
if (!url)
|
|
58
|
+
return undefined;
|
|
59
|
+
return new DecisionClient(key, { url, fetch: fetcher, ...(egress ? { egress } : {}) });
|
|
60
|
+
}
|
|
61
|
+
// A backend exists only where an asker was built. Open-Jev is optional and off when its server is not installed, so
|
|
62
|
+
// the backend list names the reason (backendNotes) instead of silently leaving a hole in the fallback chain.
|
|
63
|
+
//
|
|
64
|
+
// Every client built here carries the same gate. The local servers are loopback URLs, so the gate is not consulted for
|
|
65
|
+
// them; a "local" server named by a LAN or public address is remote, and then it is previewed and confirmed like the
|
|
66
|
+
// cloud one instead of leaving unremarked.
|
|
67
|
+
export function makeAskers(config, key, fetcher, installed = (name) => findTool(name) !== undefined, egress) {
|
|
68
|
+
const out = { rules: new RulesBackend() };
|
|
69
|
+
const cloud = cloudClient(config, key, fetcher, egress);
|
|
70
|
+
if (cloud)
|
|
71
|
+
out.cloud = cloud;
|
|
72
|
+
// Local servers take any key, except the container's, which wants its token; their timeout is short so a dead server
|
|
73
|
+
// costs little.
|
|
74
|
+
// GLiNER answers three guards in about 0.4 s on the CPU; 5 s leaves room for a loaded machine.
|
|
75
|
+
if (config.urls.gliner)
|
|
76
|
+
out.gliner = new DecisionClient(serviceToken() ?? "local", { url: config.urls.gliner, model: "gliner", timeoutMs: 5000, fetch: fetcher, ...(egress ? { egress } : {}) });
|
|
77
|
+
// An Open-Jev server is a Python console script: installed means that program is on PATH, the same test the plugin
|
|
78
|
+
// uses for any local tool it did not place itself (src/which.ts).
|
|
79
|
+
if (config.urls.openjev && installed("openjev"))
|
|
80
|
+
out.openjev = new DecisionClient("local", { url: config.urls.openjev, model: "openjev", timeoutMs: 5000, fetch: fetcher, ...(egress ? { egress } : {}) });
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
// A decider that can reach nothing (src/runner.ts without a decision model): rules only, no URL, so no client is built
|
|
84
|
+
// and the egress gate is never even consulted.
|
|
85
|
+
export function rulesDecider(journal) {
|
|
86
|
+
return new Decider({ mode: "local", default: "rules", nodes: {}, urls: {} }, { rules: new RulesBackend() }, journal);
|
|
87
|
+
}
|
|
88
|
+
// Why a backend is off, in one line, for the plugin's start log: a missing optional server is a state to state.
|
|
89
|
+
export function backendNotes(config, installed = (name) => findTool(name) !== undefined) {
|
|
90
|
+
const notes = [];
|
|
91
|
+
if (config.urls.openjev && !installed("openjev")) {
|
|
92
|
+
notes.push("openjev: no Open-Jev server installed here (no `openjev` on PATH), so the local backend is off");
|
|
93
|
+
}
|
|
94
|
+
if (config.mode === "cloud" && !config.urls.cloud)
|
|
95
|
+
notes.push("cloud mode, but no cloud URL is configured: every question goes to the user");
|
|
96
|
+
return notes;
|
|
97
|
+
}
|
|
98
|
+
export class Decider {
|
|
99
|
+
#config;
|
|
100
|
+
#askers;
|
|
101
|
+
#journal;
|
|
102
|
+
#consent;
|
|
103
|
+
constructor(config, askers, journal = record, consent) {
|
|
104
|
+
this.#config = config;
|
|
105
|
+
this.#askers = askers;
|
|
106
|
+
this.#journal = journal;
|
|
107
|
+
this.#consent = consent;
|
|
108
|
+
}
|
|
109
|
+
// The backend a node uses: its configured one, kept local when it has to be, rules when nothing else is there.
|
|
110
|
+
// This is the mode's answer, before any per-session consent: ask() asks the session and falls back when it has not
|
|
111
|
+
// opted in.
|
|
112
|
+
backendFor(node, localOnly = false, guards = false) {
|
|
113
|
+
const wanted = this.#config.nodes[node] ?? this.#config.default;
|
|
114
|
+
// Local mode demotes a cloud override to the local chain: nothing leaves the machine there (D11, D21). The
|
|
115
|
+
// guards stay local in cloud mode too unless this session overrode that, and a local-only job never sends anything.
|
|
116
|
+
const local = this.#config.mode === "local" || localOnly || (GUARD_NODES.has(node) && !guards);
|
|
117
|
+
if (!local)
|
|
118
|
+
return this.#askers[wanted] ? wanted : "rules";
|
|
119
|
+
const chain = LOCAL.has(wanted) ? [wanted, "gliner", "openjev", "rules"] : ["gliner", "openjev", "rules"];
|
|
120
|
+
return chain.find((b) => this.#askers[b] !== undefined) ?? "rules";
|
|
121
|
+
}
|
|
122
|
+
async ask(node, state, questions, options = {}) {
|
|
123
|
+
const id = randomUUID();
|
|
124
|
+
const text = JSON.stringify(state);
|
|
125
|
+
// The backend the mode names, and — for the cloud — the session's opt-in. A session that has not opted in never
|
|
126
|
+
// reaches the egress gate: it is answered on this machine and the journal says why (A2-T5). A guard node's
|
|
127
|
+
// configured backend is local, so only the session's explicit guard answer can take it to the cloud.
|
|
128
|
+
const guard = GUARD_NODES.has(node);
|
|
129
|
+
const modeCloud = this.#config.mode === "cloud" && !options.localOnly && this.#askers.cloud !== undefined;
|
|
130
|
+
const cloudWanted = modeCloud && (options.cloudAnswers || guard || this.backendFor(node, options.localOnly, true) === "cloud");
|
|
131
|
+
let consent;
|
|
132
|
+
let overridden;
|
|
133
|
+
let backend;
|
|
134
|
+
if (cloudWanted) {
|
|
135
|
+
consent = this.#consent
|
|
136
|
+
? await this.#consent.allows(options.session, options.job)
|
|
137
|
+
: { allow: false, guards: false, why: "no channel to ask for a cloud opt-in, so the decision stays local" };
|
|
138
|
+
if (guard) {
|
|
139
|
+
// The guards need the session's second answer, and an unredactable payload cannot be overridden at all: it stays
|
|
140
|
+
// on this machine even for a session whose user let the guards go (A2-T5). An unredactable payload is one that
|
|
141
|
+
// carries a `sensitive` guard flag, or a nontrivial text the redaction left untouched; the gate marks it the
|
|
142
|
+
// same way, and this path agrees before any preview.
|
|
143
|
+
const blocked = unredactableText(text);
|
|
144
|
+
overridden = !consent.allow
|
|
145
|
+
? consent.why
|
|
146
|
+
: !consent.guards
|
|
147
|
+
? "the guards stay local in this session"
|
|
148
|
+
: blocked.unredactable
|
|
149
|
+
? `the guard override is refused: ${blocked.why}`
|
|
150
|
+
: undefined;
|
|
151
|
+
backend = overridden === undefined ? "cloud" : this.backendFor(node, true);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// The permission path keeps its own default when the session has not opted in: A2b measures the local model on
|
|
155
|
+
// permission cases, but the gate has not passed (cloudAnswers), so rules answer nothing rather than guessing.
|
|
156
|
+
backend = consent.allow ? "cloud" : options.cloudAnswers ? "rules" : this.backendFor(node, true);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
backend = options.cloudAnswers ? "rules" : this.backendFor(node, options.localOnly);
|
|
161
|
+
}
|
|
162
|
+
const context = { node, ...(options.job ? { job: options.job } : {}), ...(options.task ? { task: options.task } : {}), ...(options.session ? { session: options.session } : {}) };
|
|
163
|
+
const shadowName = this.#config.shadow;
|
|
164
|
+
// Shadow mode is the label factory for the local model (D19): in cloud mode the local backend answers beside the
|
|
165
|
+
// cloud one and is only journaled. In local mode nothing may leave the machine, so there is no second request. A
|
|
166
|
+
// cloud-only node has no shadow either: the local model was never measured on it.
|
|
167
|
+
const shadowAllowed = this.#config.mode === "cloud" && !options.cloudAnswers && shadowName && shadowName !== backend && this.#askers[shadowName] && (LOCAL.has(shadowName) || !options.localOnly);
|
|
168
|
+
const shadow = shadowAllowed ? this.#askers[shadowName].ask(text, questions, context).catch((err) => err) : undefined;
|
|
169
|
+
let decision;
|
|
170
|
+
let error;
|
|
171
|
+
let refused;
|
|
172
|
+
try {
|
|
173
|
+
decision = await this.#askers[backend].ask(text, questions, context);
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
error = err instanceof Error ? err.message : String(err);
|
|
177
|
+
// A cloud call the egress gate kept local did not fail: it never happened, and the journal says which of the two.
|
|
178
|
+
if (err instanceof EgressRefused)
|
|
179
|
+
refused = summary(err.outcome);
|
|
180
|
+
decision = await new RulesBackend().ask();
|
|
181
|
+
}
|
|
182
|
+
const shadowResult = shadow ? await shadow : undefined;
|
|
183
|
+
// One entry kind for every decision ("decision"), with what A2-T2b needs to reproduce a permission case: the mode,
|
|
184
|
+
// the request, the text that actually left (redacted), and the gate's verdict. A2-T5 adds what the session allowed
|
|
185
|
+
// and whether any text left at all, so a decision that stayed home is legible as such. A local answer has no `sent`
|
|
186
|
+
// and no `egress`: nothing left the machine.
|
|
187
|
+
this.#journal({
|
|
188
|
+
kind: "decision",
|
|
189
|
+
id,
|
|
190
|
+
node,
|
|
191
|
+
job: options.job,
|
|
192
|
+
task: options.task,
|
|
193
|
+
mode: this.#config.mode,
|
|
194
|
+
backend: error ? "rules" : backend,
|
|
195
|
+
rulebook: RULEBOOK_VERSION,
|
|
196
|
+
sentText: decision.sent !== undefined,
|
|
197
|
+
error,
|
|
198
|
+
state,
|
|
199
|
+
questions,
|
|
200
|
+
answers: decision.answers,
|
|
201
|
+
model: decision.model,
|
|
202
|
+
latencyMs: decision.latencyMs,
|
|
203
|
+
...(options.request ? { request: options.request } : {}),
|
|
204
|
+
...(consent ? { consent: overridden ?? (consent.allow ? (consent.guards ? "cloud+guards" : "cloud") : consent.why) } : {}),
|
|
205
|
+
...(decision.sent !== undefined ? { sent: decision.sent } : {}),
|
|
206
|
+
...((decision.egress ?? refused) ? { egress: decision.egress ?? refused } : {}),
|
|
207
|
+
...(shadowResult && shadowName
|
|
208
|
+
? shadowResult instanceof Error
|
|
209
|
+
? { shadow: { backend: shadowName, error: shadowResult.message } }
|
|
210
|
+
: { shadow: { backend: shadowName, answers: shadowResult.answers, latencyMs: shadowResult.latencyMs } }
|
|
211
|
+
: {}),
|
|
212
|
+
});
|
|
213
|
+
return { id, backend: error ? "rules" : backend, decision, error };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// A label for a journaled decision: the user's answer, an override, or an outcome observed later (design.md §15).
|
|
217
|
+
export function label(decisionId, question, value, source, journal = record) {
|
|
218
|
+
journal({ kind: "label", decision: decisionId, question, value, source });
|
|
219
|
+
}
|
package/dist/backlog.js
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// The job backlog (design.md §25, P6): jobs that wait, one Markdown file each in <project>/<state dir>/backlog/,
|
|
2
|
+
// committed with the project. A job's follow-ups that nobody started and a trial whose attempts all failed become
|
|
3
|
+
// drafts here when the job ends, so nothing found on the way is lost with the session; the user or the micromanager
|
|
4
|
+
// starts an item later with plan_job backlog:<slug>, or as todos.
|
|
5
|
+
//
|
|
6
|
+
// Items are jobs, never a job's internal tasks: those are short-lived and live in the job file. The format is the same
|
|
7
|
+
// for every backend: a YAML front matter (a small subset: scalars, lists of scalars, lists of one-level maps, and
|
|
8
|
+
// JSON values) and a Markdown body; the GitHub backend (P7) puts the same text into an issue.
|
|
9
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { exec } from "./integration.js";
|
|
13
|
+
import { checkProblem } from "./plan.js";
|
|
14
|
+
import { scrub } from "./redact.js";
|
|
15
|
+
import { failureDigest } from "./trials.js";
|
|
16
|
+
import { stateDir } from "./store.js";
|
|
17
|
+
const STATUSES = new Set(["draft", "ready", "running", "done", "dropped"]);
|
|
18
|
+
const KINDS = new Set(["build", "fix", "optimize"]);
|
|
19
|
+
export function backlogDir(project) {
|
|
20
|
+
return join(project, stateDir(project), "backlog");
|
|
21
|
+
}
|
|
22
|
+
function scalar(text) {
|
|
23
|
+
const t = text.trim();
|
|
24
|
+
if (t === "" || t === "~" || t === "null")
|
|
25
|
+
return null;
|
|
26
|
+
if (t === "true" || t === "false")
|
|
27
|
+
return t === "true";
|
|
28
|
+
if (/^-?\d+(\.\d+)?$/.test(t))
|
|
29
|
+
return Number(t);
|
|
30
|
+
if (t.startsWith('"') || t.startsWith("{") || t.startsWith("[")) {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(t);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return t;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (t.startsWith("'") && t.endsWith("'") && t.length > 1)
|
|
39
|
+
return t.slice(1, -1).replace(/''/g, "'");
|
|
40
|
+
return t.replace(/\s+#.*$/, ""); // a comment after a plain value
|
|
41
|
+
}
|
|
42
|
+
// The subset of YAML the backlog writes, read back: "key: value", "key:" followed by "- item" lines, and an item that is
|
|
43
|
+
// a map of its own ("- text: …" with "verify: …" indented below it).
|
|
44
|
+
export function parseFrontMatter(text) {
|
|
45
|
+
const out = {};
|
|
46
|
+
let list;
|
|
47
|
+
let map;
|
|
48
|
+
for (const raw of text.split("\n")) {
|
|
49
|
+
if (!raw.trim() || raw.trim().startsWith("#"))
|
|
50
|
+
continue;
|
|
51
|
+
const indent = raw.length - raw.trimStart().length;
|
|
52
|
+
const line = raw.trim();
|
|
53
|
+
if (indent === 0) {
|
|
54
|
+
const m = line.match(/^([\w-]+):\s*(.*)$/);
|
|
55
|
+
if (!m)
|
|
56
|
+
continue;
|
|
57
|
+
list = undefined;
|
|
58
|
+
map = undefined;
|
|
59
|
+
if (m[2] === "")
|
|
60
|
+
out[m[1]] = list = [];
|
|
61
|
+
else
|
|
62
|
+
out[m[1]] = scalar(m[2]);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!list)
|
|
66
|
+
continue;
|
|
67
|
+
if (line.startsWith("- ")) {
|
|
68
|
+
const item = line.slice(2);
|
|
69
|
+
const kv = item.match(/^([\w-]+):\s+(.*)$|^([\w-]+):$/);
|
|
70
|
+
if (kv && !item.startsWith('"')) {
|
|
71
|
+
map = { [kv[1] ?? kv[3]]: scalar(kv[2] ?? "") };
|
|
72
|
+
list.push(map);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
map = undefined;
|
|
76
|
+
list.push(scalar(item));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (map) {
|
|
80
|
+
const kv = line.match(/^([\w-]+):\s*(.*)$/);
|
|
81
|
+
if (kv)
|
|
82
|
+
map[kv[1]] = scalar(kv[2]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
// A string as the front matter writes it: plain when YAML reads it back as the same string, else JSON (a valid YAML
|
|
88
|
+
// double-quoted scalar).
|
|
89
|
+
function plain(s) {
|
|
90
|
+
return /^[\w][\w ./@+()-]*$/.test(s) && !/^(true|false|null|~|-?\d+(\.\d+)?)$/.test(s) && !/\s$/.test(s) ? s : JSON.stringify(s);
|
|
91
|
+
}
|
|
92
|
+
export function renderItem(item) {
|
|
93
|
+
const lines = [
|
|
94
|
+
"---",
|
|
95
|
+
`title: ${plain(item.title)}`,
|
|
96
|
+
`status: ${item.status}`,
|
|
97
|
+
`order: ${item.order}`,
|
|
98
|
+
`kind: ${item.kind}`,
|
|
99
|
+
`origin: ${item.origin}`,
|
|
100
|
+
...(item.from ? [`from: ${plain(item.from)}`] : []),
|
|
101
|
+
...(item.job ? [`job: ${plain(item.job)}`] : []),
|
|
102
|
+
...(item.issue ? [`issue: ${plain(item.issue)}`] : []),
|
|
103
|
+
`created: ${item.created}`,
|
|
104
|
+
];
|
|
105
|
+
if (item.acceptance.length) {
|
|
106
|
+
lines.push("acceptance:");
|
|
107
|
+
for (const a of item.acceptance)
|
|
108
|
+
lines.push(` - text: ${plain(a.text)}`, ...(a.verify ? [` verify: ${plain(a.verify)}`] : []));
|
|
109
|
+
}
|
|
110
|
+
if (item.checks.length)
|
|
111
|
+
lines.push("checks:", ...item.checks.map((c) => ` - ${plain(c)}`));
|
|
112
|
+
if (item.fitness)
|
|
113
|
+
lines.push(`fitness: ${JSON.stringify(item.fitness)}`);
|
|
114
|
+
lines.push("---", "", item.body.trim(), "");
|
|
115
|
+
return lines.join("\n");
|
|
116
|
+
}
|
|
117
|
+
// An item from its file's text; errors name what is wrong instead.
|
|
118
|
+
export function parseItem(text, slug) {
|
|
119
|
+
const m = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
120
|
+
if (!m)
|
|
121
|
+
return { errors: [`${slug}: no front matter between --- lines`] };
|
|
122
|
+
const f = parseFrontMatter(m[1]);
|
|
123
|
+
const errors = [];
|
|
124
|
+
const title = typeof f.title === "string" ? f.title.trim() : "";
|
|
125
|
+
if (!title)
|
|
126
|
+
errors.push(`${slug}: title is missing`);
|
|
127
|
+
const status = STATUSES.has(f.status) ? f.status : f.status === undefined ? "draft" : undefined;
|
|
128
|
+
if (!status)
|
|
129
|
+
errors.push(`${slug}: status must be one of ${[...STATUSES].join(", ")}`);
|
|
130
|
+
const kind = KINDS.has(f.kind) ? f.kind : f.kind === undefined ? "build" : undefined;
|
|
131
|
+
if (!kind)
|
|
132
|
+
errors.push(`${slug}: kind must be one of ${[...KINDS].join(", ")}`);
|
|
133
|
+
const acceptance = (Array.isArray(f.acceptance) ? f.acceptance : []).flatMap((a) => {
|
|
134
|
+
if (typeof a === "string")
|
|
135
|
+
return [{ text: a }];
|
|
136
|
+
if (a && typeof a === "object" && !Array.isArray(a) && typeof a.text === "string")
|
|
137
|
+
return [{ text: a.text, ...(typeof a.verify === "string" && a.verify ? { verify: a.verify } : {}) }];
|
|
138
|
+
return [];
|
|
139
|
+
});
|
|
140
|
+
const checks = (Array.isArray(f.checks) ? f.checks : []).filter((c) => typeof c === "string" && c.trim() !== "");
|
|
141
|
+
const fitness = f.fitness && typeof f.fitness === "object" && !Array.isArray(f.fitness) ? f.fitness : undefined;
|
|
142
|
+
if (errors.length)
|
|
143
|
+
return { errors };
|
|
144
|
+
return {
|
|
145
|
+
item: {
|
|
146
|
+
slug,
|
|
147
|
+
title,
|
|
148
|
+
status: status,
|
|
149
|
+
order: typeof f.order === "number" ? f.order : 100,
|
|
150
|
+
kind: kind,
|
|
151
|
+
origin: f.origin === "later" || f.origin === "trial-failed" ? f.origin : "user",
|
|
152
|
+
...(typeof f.from === "string" ? { from: f.from } : {}),
|
|
153
|
+
...(typeof f.job === "string" ? { job: f.job } : {}),
|
|
154
|
+
...(typeof f.issue === "string" ? { issue: f.issue } : {}),
|
|
155
|
+
acceptance,
|
|
156
|
+
checks,
|
|
157
|
+
...(fitness ? { fitness } : {}),
|
|
158
|
+
created: typeof f.created === "string" ? f.created : String(f.created ?? ""),
|
|
159
|
+
body: m[2].trim(),
|
|
160
|
+
},
|
|
161
|
+
errors,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export const localBackend = {
|
|
165
|
+
list(project) {
|
|
166
|
+
const dir = backlogDir(project);
|
|
167
|
+
if (!existsSync(dir))
|
|
168
|
+
return [];
|
|
169
|
+
return readdirSync(dir)
|
|
170
|
+
.filter((f) => f.endsWith(".md"))
|
|
171
|
+
.flatMap((f) => parseItem(readFileSync(join(dir, f), "utf8"), f.slice(0, -3)).item ?? [])
|
|
172
|
+
.sort(byTurn);
|
|
173
|
+
},
|
|
174
|
+
get(project, slug) {
|
|
175
|
+
const path = join(backlogDir(project), `${slug}.md`);
|
|
176
|
+
return existsSync(path) ? parseItem(readFileSync(path, "utf8"), slug).item : undefined;
|
|
177
|
+
},
|
|
178
|
+
save(project, item) {
|
|
179
|
+
const path = join(backlogDir(project), `${item.slug}.md`);
|
|
180
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
181
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
182
|
+
writeFileSync(tmp, renderItem(item));
|
|
183
|
+
renameSync(tmp, path);
|
|
184
|
+
return path;
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
// What runs first: the open items before the closed ones, ready before draft, then by order, then the oldest.
|
|
188
|
+
const RANK = { running: 0, ready: 1, draft: 2, done: 3, dropped: 4 };
|
|
189
|
+
export function byTurn(a, b) {
|
|
190
|
+
return RANK[a.status] - RANK[b.status] || a.order - b.order || a.created.localeCompare(b.created) || a.slug.localeCompare(b.slug);
|
|
191
|
+
}
|
|
192
|
+
// A file name from a title: lowercase words joined by dashes, at most six of them, unique among taken.
|
|
193
|
+
export function slugOf(title, taken) {
|
|
194
|
+
const base = title.toLowerCase().replace(/[äöüß]/g, (c) => ({ ä: "ae", ö: "oe", ü: "ue", ß: "ss" })[c]).split(/[^a-z0-9]+/).filter(Boolean).slice(0, 6).join("-") || "item";
|
|
195
|
+
let slug = base;
|
|
196
|
+
for (let n = 2; taken.has(slug); n++)
|
|
197
|
+
slug = `${base}-${n}`;
|
|
198
|
+
return slug;
|
|
199
|
+
}
|
|
200
|
+
// --- drafts at a job's end --------------------------------------------------------------------------------------
|
|
201
|
+
function today(now) {
|
|
202
|
+
return now.toISOString().slice(0, 10);
|
|
203
|
+
}
|
|
204
|
+
// A follow-up a worker reported that no task of its job took up.
|
|
205
|
+
export function draftFromLater(l, job, taken, now = new Date()) {
|
|
206
|
+
return {
|
|
207
|
+
slug: slugOf(l.what, taken),
|
|
208
|
+
title: l.what.slice(0, 120),
|
|
209
|
+
status: "draft",
|
|
210
|
+
order: 100,
|
|
211
|
+
kind: /\b(fix|bug|broken|fails?|crash)/i.test(l.what) ? "fix" : "build",
|
|
212
|
+
origin: "later",
|
|
213
|
+
from: `${job.id}/${l.from}`,
|
|
214
|
+
acceptance: [],
|
|
215
|
+
checks: [],
|
|
216
|
+
created: today(now),
|
|
217
|
+
body: [`## Goal\n${l.what}`, l.why ? `## Why\n${l.why}` : "", l.files.length ? `## Files\n${l.files.join(", ")}` : "", `Found by ${l.from} of ${job.id} (${job.goal.split("\n")[0].slice(0, 120)}).`].filter(Boolean).join("\n\n"),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// A task whose trial failed on every attempt (k = 0) and that nothing did over: too big or too unclear for one worker,
|
|
221
|
+
// so it comes back as a job of its own, with what each attempt hit.
|
|
222
|
+
export function draftFromTrial(job, head, failed, checks, taken, now = new Date()) {
|
|
223
|
+
const title = head.title.replace(/ \(attempt \d+\/\d+\)$/, "");
|
|
224
|
+
return {
|
|
225
|
+
slug: slugOf(title, taken),
|
|
226
|
+
title: title.slice(0, 120),
|
|
227
|
+
status: "draft",
|
|
228
|
+
order: 100,
|
|
229
|
+
kind: head.contract ? "optimize" : "build",
|
|
230
|
+
origin: "trial-failed",
|
|
231
|
+
from: `${job.id}/${head.id}`,
|
|
232
|
+
acceptance: [],
|
|
233
|
+
checks: [...checks],
|
|
234
|
+
created: today(now),
|
|
235
|
+
body: [`## Goal\n${head.description}`, `## What the ${failed.length} attempts hit\n${failureDigest(failed)}`, "Split it into smaller tasks before it runs again."].join("\n\n"),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// The goal plan_job plans from, for an item: its title, body, acceptance points and checks in words the planner reads.
|
|
239
|
+
export function goalOf(item) {
|
|
240
|
+
return [
|
|
241
|
+
item.title,
|
|
242
|
+
item.body,
|
|
243
|
+
item.acceptance.length ? `Acceptance:\n${item.acceptance.map((a) => `- ${a.text}${a.verify ? ` (checked with: ${a.verify})` : ""}`).join("\n")}` : "",
|
|
244
|
+
item.checks.length ? `Checks: ${item.checks.join("; ")}` : "",
|
|
245
|
+
item.fitness ? `Fitness contract to define first with the contract tool: ${JSON.stringify(item.fitness)}` : "",
|
|
246
|
+
`(backlog item ${item.slug})`,
|
|
247
|
+
].filter(Boolean).join("\n\n");
|
|
248
|
+
}
|
|
249
|
+
// --- the backlog tool -------------------------------------------------------------------------------------------
|
|
250
|
+
// The micromanager's backlog tool: list, show, add or set an item. Returns its answer.
|
|
251
|
+
// add takes {"title", "kind", "goal", "acceptance": [{"text", "verify"}], "checks": [...], "fitness": {...}, "order",
|
|
252
|
+
// "status"}; set takes "status=ready" or "order=10".
|
|
253
|
+
export function backlogTool(project, action, slug, value, backend = localBackend, now = new Date()) {
|
|
254
|
+
const a = action.trim().toLowerCase();
|
|
255
|
+
const items = backend.list(project);
|
|
256
|
+
if (a === "" || a === "list") {
|
|
257
|
+
const open = items.filter((i) => i.status !== "done" && i.status !== "dropped");
|
|
258
|
+
const closed = items.length - open.length;
|
|
259
|
+
if (!items.length)
|
|
260
|
+
return `The backlog of this project is empty (${relativeDir(project)}/).`;
|
|
261
|
+
return [
|
|
262
|
+
`Backlog (${relativeDir(project)}/), in the order it runs:`,
|
|
263
|
+
...open.map((i) => `- ${i.slug} [${i.status}, ${i.kind}, order ${i.order}] ${i.title}${i.job ? ` (job ${i.job})` : ""}${i.origin !== "user" ? ` · from ${i.from ?? i.origin}` : ""}`),
|
|
264
|
+
closed ? `${closed} done or dropped.` : "",
|
|
265
|
+
"Start one with plan_job and the goal backlog:<slug>, or write its tasks as todos.",
|
|
266
|
+
].filter(Boolean).join("\n");
|
|
267
|
+
}
|
|
268
|
+
if (a === "show") {
|
|
269
|
+
const item = backend.get(project, slug.trim());
|
|
270
|
+
return item ? renderItem(item) : `There is no backlog item ${slug.trim()}.`;
|
|
271
|
+
}
|
|
272
|
+
if (a === "add") {
|
|
273
|
+
let o;
|
|
274
|
+
try {
|
|
275
|
+
o = JSON.parse(value);
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
return `Not added: value is no JSON object (${err instanceof Error ? err.message : String(err)}).`;
|
|
279
|
+
}
|
|
280
|
+
const title = typeof o.title === "string" ? o.title.trim() : "";
|
|
281
|
+
if (!title)
|
|
282
|
+
return "Not added: an item needs a title.";
|
|
283
|
+
const kind = KINDS.has(o.kind) ? o.kind : "build";
|
|
284
|
+
const checks = (Array.isArray(o.checks) ? o.checks : []).map(String).map((c) => c.trim()).filter(Boolean);
|
|
285
|
+
const bad = checks.map(checkProblem).find(Boolean);
|
|
286
|
+
if (bad)
|
|
287
|
+
return `Not added: ${bad}`;
|
|
288
|
+
const item = {
|
|
289
|
+
slug: slugOf(title, new Set(items.map((i) => i.slug))),
|
|
290
|
+
title: title.slice(0, 120),
|
|
291
|
+
status: o.status === "ready" ? "ready" : "draft",
|
|
292
|
+
order: typeof o.order === "number" ? o.order : 100,
|
|
293
|
+
kind,
|
|
294
|
+
origin: "user",
|
|
295
|
+
acceptance: (Array.isArray(o.acceptance) ? o.acceptance : []).flatMap((x) => {
|
|
296
|
+
const p = (typeof x === "string" ? { text: x } : x);
|
|
297
|
+
return typeof p?.text === "string" && p.text.trim() ? [{ text: p.text.trim(), ...(typeof p.verify === "string" && p.verify.trim() ? { verify: p.verify.trim() } : {}) }] : [];
|
|
298
|
+
}),
|
|
299
|
+
checks,
|
|
300
|
+
...(o.fitness && typeof o.fitness === "object" && !Array.isArray(o.fitness) ? { fitness: o.fitness } : {}),
|
|
301
|
+
created: today(now),
|
|
302
|
+
body: `## Goal\n${typeof o.goal === "string" && o.goal.trim() ? o.goal.trim() : title}`,
|
|
303
|
+
};
|
|
304
|
+
if (kind === "optimize" && !item.fitness)
|
|
305
|
+
item.body += "\n\nNeeds a fitness contract before it can run: what is measured, which way is better, what must not get worse.";
|
|
306
|
+
return `Added ${item.slug} (${item.status}) to the backlog: ${backend.save(project, item)}.`;
|
|
307
|
+
}
|
|
308
|
+
if (a === "set") {
|
|
309
|
+
const item = backend.get(project, slug.trim());
|
|
310
|
+
if (!item)
|
|
311
|
+
return `There is no backlog item ${slug.trim()}.`;
|
|
312
|
+
const m = value.trim().match(/^(status|order)\s*=\s*(\S+)$/i);
|
|
313
|
+
if (!m)
|
|
314
|
+
return 'Not changed: value is "status=<draft|ready|running|done|dropped>" or "order=<number>".';
|
|
315
|
+
if (m[1].toLowerCase() === "status") {
|
|
316
|
+
if (!STATUSES.has(m[2]))
|
|
317
|
+
return `Not changed: status is one of ${[...STATUSES].join(", ")}.`;
|
|
318
|
+
item.status = m[2];
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
const n = Number(m[2]);
|
|
322
|
+
if (!Number.isFinite(n))
|
|
323
|
+
return "Not changed: order is a number.";
|
|
324
|
+
item.order = n;
|
|
325
|
+
}
|
|
326
|
+
backend.save(project, item);
|
|
327
|
+
return `${item.slug} is ${item.status}, order ${item.order}.`;
|
|
328
|
+
}
|
|
329
|
+
return 'action is "list", "show", "add" or "set".';
|
|
330
|
+
}
|
|
331
|
+
function relativeDir(project) {
|
|
332
|
+
return join(stateDir(project), "backlog");
|
|
333
|
+
}
|
|
334
|
+
// --- GitHub issues (P7, opt-in per repository) ------------------------------------------------------------------
|
|
335
|
+
// Issues labelled micromanager in a repository the user opted in ("githubBacklog" in omacode.jsonc). The body
|
|
336
|
+
// holds the same front matter and Markdown as a file; an issue without one is read as a draft with its text as goal.
|
|
337
|
+
// Reading is free. Writing happens only in publishIssue, after the user's yes in a form.
|
|
338
|
+
export const ISSUE_LABEL = "micromanager";
|
|
339
|
+
// The repository a project's GitHub remote names, as gh sees it; undefined without gh, a remote or a login.
|
|
340
|
+
export async function githubRepo(project, run = exec) {
|
|
341
|
+
const r = await run("gh", ["repo", "view", "--json", "nameWithOwner", "-q", ".nameWithOwner"], { cwd: project, timeoutMs: 15_000 });
|
|
342
|
+
const name = r.stdout.trim().toLowerCase();
|
|
343
|
+
return r.code === 0 && /^[\w.-]+\/[\w.-]+$/.test(name) ? name : undefined;
|
|
344
|
+
}
|
|
345
|
+
function issueItem(issue) {
|
|
346
|
+
const slug = `gh-${issue.number}`;
|
|
347
|
+
const parsed = issue.body ? parseItem(issue.body, slug).item : undefined;
|
|
348
|
+
const closed = String(issue.state ?? "").toUpperCase() === "CLOSED";
|
|
349
|
+
if (parsed)
|
|
350
|
+
return { ...parsed, title: issue.title || parsed.title, ...(closed ? { status: "done" } : {}), ...(issue.url ? { issue: issue.url } : {}) };
|
|
351
|
+
return { slug, title: issue.title, status: closed ? "done" : "draft", order: 100, kind: "build", origin: "user", acceptance: [], checks: [], created: "", body: `## Goal\n${issue.body?.trim() || issue.title}`, ...(issue.url ? { issue: issue.url } : {}) };
|
|
352
|
+
}
|
|
353
|
+
export async function githubIssues(project, repo, run = exec) {
|
|
354
|
+
const r = await run("gh", ["issue", "list", "--repo", repo, "--label", ISSUE_LABEL, "--state", "all", "--limit", "200", "--json", "number,title,body,state,url"], { cwd: project, timeoutMs: 30_000 });
|
|
355
|
+
if (r.code !== 0)
|
|
356
|
+
return { items: [], problem: `gh could not list the issues of ${repo}: ${r.stderr.trim().slice(0, 200) || `exit ${r.code}`}` };
|
|
357
|
+
try {
|
|
358
|
+
return { items: JSON.parse(r.stdout).map(issueItem).sort(byTurn) };
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return { items: [], problem: `gh answered no issue list for ${repo}` };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
export async function githubIssue(project, repo, number, run = exec) {
|
|
365
|
+
const r = await run("gh", ["issue", "view", String(number), "--repo", repo, "--json", "number,title,body,state,url"], { cwd: project, timeoutMs: 30_000 });
|
|
366
|
+
if (r.code !== 0)
|
|
367
|
+
return undefined;
|
|
368
|
+
try {
|
|
369
|
+
return issueItem(JSON.parse(r.stdout));
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
// A local item published as an issue, after the user's yes: the label made if it is missing, the issue created with
|
|
376
|
+
// the item's text as its body, and the item keeps the issue's address.
|
|
377
|
+
export async function publishIssue(project, item, repo, run = exec, backend = localBackend) {
|
|
378
|
+
await run("gh", ["label", "create", ISSUE_LABEL, "--repo", repo, "--color", "5319e7", "--description", "a job for the micromanager", "--force"], { cwd: project, timeoutMs: 30_000 });
|
|
379
|
+
const scratch = mkdtempSync(join(tmpdir(), "mm-issue-"));
|
|
380
|
+
try {
|
|
381
|
+
const body = join(scratch, "body.md");
|
|
382
|
+
// What goes to GitHub is redacted; the local item keeps its real title and body.
|
|
383
|
+
const safe = { ...item, title: scrub(item.title) };
|
|
384
|
+
writeFileSync(body, scrub(renderItem({ ...safe, issue: undefined })));
|
|
385
|
+
const r = await run("gh", ["issue", "create", "--repo", repo, "--title", safe.title, "--label", ISSUE_LABEL, "--body-file", body], { cwd: project, timeoutMs: 60_000 });
|
|
386
|
+
const url = r.stdout.trim().split("\n").find((l) => /^https:\/\/github\.com\//.test(l));
|
|
387
|
+
if (r.code !== 0 || !url)
|
|
388
|
+
return { problem: `gh issue create failed: ${r.stderr.trim().slice(0, 200) || `exit ${r.code}`}` };
|
|
389
|
+
backend.save(project, { ...item, issue: url });
|
|
390
|
+
return { url };
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const PUBLISH = { yes: "Publish it", no: "Keep it local" };
|
|
397
|
+
// The question before anything goes to GitHub: an issue is published content.
|
|
398
|
+
export function publishForm(item, repo) {
|
|
399
|
+
return [{
|
|
400
|
+
header: `Publish ${item.slug}`.slice(0, 30),
|
|
401
|
+
question: `Publish backlog item ${item.slug} ("${item.title.slice(0, 100)}") as a GitHub issue in ${repo}, labelled ${ISSUE_LABEL}? Its whole text becomes the issue's body, visible to whoever can see the repository.`,
|
|
402
|
+
options: [
|
|
403
|
+
{ label: PUBLISH.yes, description: `gh issue create in ${repo}` },
|
|
404
|
+
{ label: PUBLISH.no, description: "Nothing leaves this machine" },
|
|
405
|
+
],
|
|
406
|
+
}];
|
|
407
|
+
}
|
|
408
|
+
export function readPublish(header, answers) {
|
|
409
|
+
const m = header.match(/^Publish (\S+)$/);
|
|
410
|
+
if (!m)
|
|
411
|
+
return undefined;
|
|
412
|
+
const a = answers.map((x) => x.trim().toLowerCase());
|
|
413
|
+
return { slug: m[1], ...(a.includes(PUBLISH.yes.toLowerCase()) ? { yes: true } : a.includes(PUBLISH.no.toLowerCase()) ? { yes: false } : {}) };
|
|
414
|
+
}
|