agentplane 0.3.23 → 0.3.24
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/dist/.build-manifest.json +47 -12
- package/dist/cli.js +309 -309
- package/dist/commands/guard/impl/commit-refresh.d.ts +25 -0
- package/dist/commands/guard/impl/commit-refresh.d.ts.map +1 -0
- package/dist/commands/guard/impl/commit-refresh.js +116 -0
- package/dist/commands/guard/impl/commit-stage.d.ts +21 -0
- package/dist/commands/guard/impl/commit-stage.d.ts.map +1 -0
- package/dist/commands/guard/impl/commit-stage.js +43 -0
- package/dist/commands/guard/impl/commit.d.ts.map +1 -1
- package/dist/commands/guard/impl/commit.js +10 -150
- package/dist/commands/release/apply.preflight.d.ts +4 -29
- package/dist/commands/release/apply.preflight.d.ts.map +1 -1
- package/dist/commands/release/apply.preflight.git.d.ts +7 -0
- package/dist/commands/release/apply.preflight.git.d.ts.map +1 -0
- package/dist/commands/release/apply.preflight.git.js +138 -0
- package/dist/commands/release/apply.preflight.js +4 -369
- package/dist/commands/release/apply.preflight.package.d.ts +7 -0
- package/dist/commands/release/apply.preflight.package.d.ts.map +1 -0
- package/dist/commands/release/apply.preflight.package.js +69 -0
- package/dist/commands/release/apply.preflight.plan.d.ts +16 -0
- package/dist/commands/release/apply.preflight.plan.d.ts.map +1 -0
- package/dist/commands/release/apply.preflight.plan.js +92 -0
- package/dist/commands/release/apply.preflight.publish.d.ts +4 -0
- package/dist/commands/release/apply.preflight.publish.d.ts.map +1 -0
- package/dist/commands/release/apply.preflight.publish.js +81 -0
- package/dist/commands/task/migrate-doc.d.ts.map +1 -1
- package/dist/commands/task/migrate-doc.js +25 -248
- package/dist/commands/task/migrate-doc.readme.d.ts +8 -0
- package/dist/commands/task/migrate-doc.readme.d.ts.map +1 -0
- package/dist/commands/task/migrate-doc.readme.js +225 -0
- package/package.json +3 -3
|
@@ -1,239 +1,16 @@
|
|
|
1
1
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { loadConfig } from "@agentplaneorg/core/config";
|
|
4
|
+
import { gitEnv } from "@agentplaneorg/core/git";
|
|
5
|
+
import { execFileAsync } from "@agentplaneorg/core/process";
|
|
4
6
|
import { resolveProject } from "@agentplaneorg/core/project";
|
|
5
|
-
import { atomicWriteFile } from "@agentplaneorg/core/fs";
|
|
6
|
-
import { ensureDocSections, extractTaskDoc, mergeTaskDoc, normalizeTaskDoc, parseTaskReadme, renderTaskDocFromSections, renderTaskReadme, setMarkdownSection, taskDocToSectionMap, } from "@agentplaneorg/core/tasks";
|
|
7
7
|
import { mapCoreError } from "../../cli/error-map.js";
|
|
8
8
|
import { exitCodeForError } from "../../cli/exit-codes.js";
|
|
9
9
|
import { fileExists, getPathKind } from "../../cli/fs-utils.js";
|
|
10
10
|
import { successMessage } from "../../cli/output.js";
|
|
11
11
|
import { CliError } from "../../shared/errors.js";
|
|
12
|
-
import { execFileAsync } from "@agentplaneorg/core/process";
|
|
13
|
-
import { gitEnv } from "@agentplaneorg/core/git";
|
|
14
12
|
import { exportTaskProjectionSnapshot, loadCommandContext, } from "../shared/task-backend.js";
|
|
15
|
-
import {
|
|
16
|
-
import { defaultTaskDocV3 } from "./doc-template.js";
|
|
17
|
-
const V3_CANONICAL_ORDER = [
|
|
18
|
-
"Summary",
|
|
19
|
-
"Scope",
|
|
20
|
-
"Plan",
|
|
21
|
-
"Verify Steps",
|
|
22
|
-
"Verification",
|
|
23
|
-
"Rollback Plan",
|
|
24
|
-
"Findings",
|
|
25
|
-
];
|
|
26
|
-
const HUMAN_TEXT_SECTIONS = new Set(["summary", "context", "scope", "plan", "findings", "notes"]);
|
|
27
|
-
function isRecord(value) {
|
|
28
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
29
|
-
}
|
|
30
|
-
function normalizeRevision(value) {
|
|
31
|
-
return Number.isInteger(value) && typeof value === "number" && value > 0 ? value : null;
|
|
32
|
-
}
|
|
33
|
-
function normalizeCanonicalSections(value) {
|
|
34
|
-
if (!isRecord(value))
|
|
35
|
-
return null;
|
|
36
|
-
const out = {};
|
|
37
|
-
for (const [title, text] of Object.entries(value)) {
|
|
38
|
-
const normalizedTitle = title.trim();
|
|
39
|
-
if (!normalizedTitle || typeof text !== "string")
|
|
40
|
-
continue;
|
|
41
|
-
out[normalizedTitle] = text.replaceAll("\r\n", "\n").trimEnd();
|
|
42
|
-
}
|
|
43
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
44
|
-
}
|
|
45
|
-
function normalizeSectionKey(section) {
|
|
46
|
-
return section.trim().replaceAll(/\s+/g, " ").toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
function parseMarkdownSections(doc) {
|
|
49
|
-
const lines = doc.replaceAll("\r\n", "\n").split("\n");
|
|
50
|
-
const sections = [];
|
|
51
|
-
let current = null;
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
const match = /^##\s+(.*)$/.exec(line.trim());
|
|
54
|
-
if (match) {
|
|
55
|
-
if (current) {
|
|
56
|
-
current.text = current.text.trimEnd();
|
|
57
|
-
sections.push(current);
|
|
58
|
-
}
|
|
59
|
-
current = { title: (match[1] ?? "").trim(), text: "" };
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (current) {
|
|
63
|
-
current.text = current.text.length > 0 ? `${current.text}\n${line}` : line;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (current) {
|
|
67
|
-
current.text = current.text.trimEnd();
|
|
68
|
-
sections.push(current);
|
|
69
|
-
}
|
|
70
|
-
return sections;
|
|
71
|
-
}
|
|
72
|
-
function renderMarkdownSections(sections) {
|
|
73
|
-
return sections
|
|
74
|
-
.map((section) => {
|
|
75
|
-
const text = section.text.trimEnd();
|
|
76
|
-
return text ? `## ${section.title}\n\n${text}` : `## ${section.title}\n`;
|
|
77
|
-
})
|
|
78
|
-
.join("\n\n")
|
|
79
|
-
.trimEnd();
|
|
80
|
-
}
|
|
81
|
-
function normalizeLiteralNewlinesInHumanSection(title, text) {
|
|
82
|
-
if (!HUMAN_TEXT_SECTIONS.has(normalizeSectionKey(title)))
|
|
83
|
-
return text.trimEnd();
|
|
84
|
-
return decodeEscapedTaskTextNewlines(text).trimEnd();
|
|
85
|
-
}
|
|
86
|
-
function firstSectionText(sections, title) {
|
|
87
|
-
const target = normalizeSectionKey(title);
|
|
88
|
-
return sections.find((section) => normalizeSectionKey(section.title) === target)?.text ?? null;
|
|
89
|
-
}
|
|
90
|
-
function mergeObservationText(doc, version) {
|
|
91
|
-
const preferred = extractTaskObservationSection(doc, version)?.trim() ?? "";
|
|
92
|
-
const notes = extractDocSection(doc, "Notes")?.trim() ?? "";
|
|
93
|
-
const findings = extractDocSection(doc, "Findings")?.trim() ?? "";
|
|
94
|
-
const out = [];
|
|
95
|
-
for (const candidate of [preferred, findings, notes]) {
|
|
96
|
-
if (!candidate)
|
|
97
|
-
continue;
|
|
98
|
-
if (out.includes(candidate))
|
|
99
|
-
continue;
|
|
100
|
-
out.push(candidate);
|
|
101
|
-
}
|
|
102
|
-
return out.join("\n\n").trim();
|
|
103
|
-
}
|
|
104
|
-
function migrateDocToV3(opts) {
|
|
105
|
-
const currentSections = parseMarkdownSections(opts.doc);
|
|
106
|
-
const defaultSections = parseMarkdownSections(defaultTaskDocV3({ title: opts.title, description: opts.description }));
|
|
107
|
-
const emitted = new Set();
|
|
108
|
-
const nextSections = [];
|
|
109
|
-
const observationText = mergeObservationText(opts.doc, 2);
|
|
110
|
-
for (const title of V3_CANONICAL_ORDER) {
|
|
111
|
-
const key = normalizeSectionKey(title);
|
|
112
|
-
const currentText = firstSectionText(currentSections, title);
|
|
113
|
-
const defaultText = firstSectionText(defaultSections, title) ?? "";
|
|
114
|
-
let nextText = currentText ?? defaultText;
|
|
115
|
-
if (title === "Verification") {
|
|
116
|
-
nextText = normalizeVerificationSectionLayout(currentText ?? defaultText, 3);
|
|
117
|
-
}
|
|
118
|
-
if (title === "Findings") {
|
|
119
|
-
nextText = observationText || defaultText;
|
|
120
|
-
}
|
|
121
|
-
if (nextText === null)
|
|
122
|
-
continue;
|
|
123
|
-
nextText = normalizeLiteralNewlinesInHumanSection(title, nextText);
|
|
124
|
-
nextSections.push({ title, text: nextText.trimEnd() });
|
|
125
|
-
emitted.add(key);
|
|
126
|
-
if (title === "Findings")
|
|
127
|
-
emitted.add("notes");
|
|
128
|
-
}
|
|
129
|
-
for (const section of currentSections) {
|
|
130
|
-
const key = normalizeSectionKey(section.title);
|
|
131
|
-
if (emitted.has(key))
|
|
132
|
-
continue;
|
|
133
|
-
nextSections.push({ title: section.title, text: section.text.trimEnd() });
|
|
134
|
-
emitted.add(key);
|
|
135
|
-
}
|
|
136
|
-
return renderMarkdownSections(nextSections);
|
|
137
|
-
}
|
|
138
|
-
function ensurePlanApprovalFrontmatter(frontmatter) {
|
|
139
|
-
const raw = frontmatter.plan_approval;
|
|
140
|
-
if (isRecord(raw) && typeof raw.state === "string")
|
|
141
|
-
return;
|
|
142
|
-
frontmatter.plan_approval = {
|
|
143
|
-
state: "pending",
|
|
144
|
-
updated_at: null,
|
|
145
|
-
updated_by: null,
|
|
146
|
-
note: null,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function ensureVerificationFrontmatter(frontmatter) {
|
|
150
|
-
const raw = frontmatter.verification;
|
|
151
|
-
if (isRecord(raw) && typeof raw.state === "string")
|
|
152
|
-
return;
|
|
153
|
-
frontmatter.verification = {
|
|
154
|
-
state: "pending",
|
|
155
|
-
updated_at: null,
|
|
156
|
-
updated_by: null,
|
|
157
|
-
note: null,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
const DATE_ONLY_ON_RE = /\bon (\d{4}-\d{2}-\d{2})(?!T)\b/g;
|
|
161
|
-
function isIsoTimestamp(value) {
|
|
162
|
-
if (!value.includes("T") || !value.endsWith("Z"))
|
|
163
|
-
return false;
|
|
164
|
-
const ms = Date.parse(value);
|
|
165
|
-
return Number.isFinite(ms);
|
|
166
|
-
}
|
|
167
|
-
function normalizeNoteTimestamp(opts) {
|
|
168
|
-
if (!isIsoTimestamp(opts.updatedAt))
|
|
169
|
-
return opts.note;
|
|
170
|
-
const updatedDate = opts.updatedAt.slice(0, 10);
|
|
171
|
-
return opts.note.replaceAll(DATE_ONLY_ON_RE, (match, date) => {
|
|
172
|
-
if (date !== updatedDate)
|
|
173
|
-
return match;
|
|
174
|
-
return `on ${opts.updatedAt}`;
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
function normalizeFrontmatterNoteTimestamps(frontmatter) {
|
|
178
|
-
const plan = frontmatter.plan_approval;
|
|
179
|
-
if (isRecord(plan) && typeof plan.note === "string" && typeof plan.updated_at === "string") {
|
|
180
|
-
plan.note = normalizeNoteTimestamp({ note: plan.note, updatedAt: plan.updated_at });
|
|
181
|
-
}
|
|
182
|
-
const verification = frontmatter.verification;
|
|
183
|
-
if (isRecord(verification) &&
|
|
184
|
-
typeof verification.note === "string" &&
|
|
185
|
-
typeof verification.updated_at === "string") {
|
|
186
|
-
verification.note = normalizeNoteTimestamp({
|
|
187
|
-
note: verification.note,
|
|
188
|
-
updatedAt: verification.updated_at,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
async function migrateTaskReadmeDoc(opts) {
|
|
193
|
-
const originalRaw = await readFile(opts.readmePath, "utf8");
|
|
194
|
-
const original = originalRaw.endsWith("\n") ? originalRaw : `${originalRaw}\n`;
|
|
195
|
-
const parsed = parseTaskReadme(original);
|
|
196
|
-
const frontmatter = { ...parsed.frontmatter };
|
|
197
|
-
ensurePlanApprovalFrontmatter(frontmatter);
|
|
198
|
-
ensureVerificationFrontmatter(frontmatter);
|
|
199
|
-
normalizeFrontmatterNoteTimestamps(frontmatter);
|
|
200
|
-
const canonicalSections = normalizeCanonicalSections(frontmatter.sections);
|
|
201
|
-
const required = opts.config.tasks.doc.required_sections;
|
|
202
|
-
const extracted = extractTaskDoc(parsed.body);
|
|
203
|
-
const baseDoc = canonicalSections === null
|
|
204
|
-
? extracted || parsed.body
|
|
205
|
-
: renderTaskDocFromSections(canonicalSections);
|
|
206
|
-
let nextDoc = normalizeTaskDoc(ensureDocSections(baseDoc, required));
|
|
207
|
-
const docVersion = normalizeTaskDocVersion(frontmatter.doc_version);
|
|
208
|
-
if (docVersion === 2) {
|
|
209
|
-
frontmatter.doc_version = 3;
|
|
210
|
-
nextDoc = migrateDocToV3({
|
|
211
|
-
title: typeof frontmatter.title === "string" ? frontmatter.title : "",
|
|
212
|
-
description: typeof frontmatter.description === "string" ? frontmatter.description : "",
|
|
213
|
-
doc: nextDoc,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
const verificationSection = extractDocSection(nextDoc, "Verification");
|
|
218
|
-
const normalizedVerification = normalizeVerificationSectionLayout(verificationSection, docVersion);
|
|
219
|
-
nextDoc = setMarkdownSection(nextDoc, "Verification", normalizedVerification);
|
|
220
|
-
for (const sectionTitle of ["Summary", "Context", "Scope", "Plan", "Findings", "Notes"]) {
|
|
221
|
-
const sectionText = extractDocSection(nextDoc, sectionTitle);
|
|
222
|
-
if (sectionText == null)
|
|
223
|
-
continue;
|
|
224
|
-
nextDoc = setMarkdownSection(nextDoc, sectionTitle, normalizeLiteralNewlinesInHumanSection(sectionTitle, sectionText));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const nextBody = extracted ? mergeTaskDoc(parsed.body, nextDoc) : nextDoc;
|
|
228
|
-
frontmatter.sections = taskDocToSectionMap(nextDoc);
|
|
229
|
-
frontmatter.revision = normalizeRevision(frontmatter.revision) ?? 1;
|
|
230
|
-
const rendered = renderTaskReadme(frontmatter, nextBody);
|
|
231
|
-
const next = rendered.endsWith("\n") ? rendered : `${rendered}\n`;
|
|
232
|
-
if (next === original)
|
|
233
|
-
return { changed: false };
|
|
234
|
-
await atomicWriteFile(opts.readmePath, next, "utf8");
|
|
235
|
-
return { changed: true };
|
|
236
|
-
}
|
|
13
|
+
import { migrateTaskReadmeDoc } from "./migrate-doc.readme.js";
|
|
237
14
|
async function resolveReadmePaths(opts) {
|
|
238
15
|
if (!opts.params.all) {
|
|
239
16
|
return opts.params.taskIds.map((taskId) => path.join(opts.tasksDir, taskId, "README.md"));
|
|
@@ -251,6 +28,28 @@ async function resolveReadmePaths(opts) {
|
|
|
251
28
|
}
|
|
252
29
|
return out;
|
|
253
30
|
}
|
|
31
|
+
async function canStageGitPath(gitRoot, relPath) {
|
|
32
|
+
try {
|
|
33
|
+
await execFileAsync("git", ["ls-files", "--error-unmatch", "--", relPath], {
|
|
34
|
+
cwd: gitRoot,
|
|
35
|
+
env: gitEnv(),
|
|
36
|
+
});
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Continue below: untracked paths may still be stageable when they are not ignored.
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await execFileAsync("git", ["check-ignore", "--quiet", "--", relPath], {
|
|
44
|
+
cwd: gitRoot,
|
|
45
|
+
env: gitEnv(),
|
|
46
|
+
});
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
254
53
|
async function exportProjectionSnapshotIfChanged(opts) {
|
|
255
54
|
if (!(opts.ctx.taskBackend.exportProjectionSnapshot || opts.ctx.taskBackend.exportTasksJson)) {
|
|
256
55
|
return [];
|
|
@@ -276,28 +75,6 @@ async function exportProjectionSnapshotIfChanged(opts) {
|
|
|
276
75
|
return [];
|
|
277
76
|
return (await canStageGitPath(opts.resolvedGitRoot, relOutputPath)) ? [relOutputPath] : [];
|
|
278
77
|
}
|
|
279
|
-
async function canStageGitPath(gitRoot, relPath) {
|
|
280
|
-
try {
|
|
281
|
-
await execFileAsync("git", ["ls-files", "--error-unmatch", "--", relPath], {
|
|
282
|
-
cwd: gitRoot,
|
|
283
|
-
env: gitEnv(),
|
|
284
|
-
});
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
// Continue below: untracked paths may still be stageable when they are not ignored.
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
await execFileAsync("git", ["check-ignore", "--quiet", "--", relPath], {
|
|
292
|
-
cwd: gitRoot,
|
|
293
|
-
env: gitEnv(),
|
|
294
|
-
});
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
catch {
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
78
|
export async function migrateTaskDocsInWorkspace(opts) {
|
|
302
79
|
const resolved = opts.resolvedProject ??
|
|
303
80
|
(await resolveProject({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-doc.readme.d.ts","sourceRoot":"","sources":["../../../src/commands/task/migrate-doc.readme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AA4NnE,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;CAC1B,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAuDhC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { atomicWriteFile } from "@agentplaneorg/core/fs";
|
|
3
|
+
import { ensureDocSections, extractTaskDoc, mergeTaskDoc, normalizeTaskDoc, parseTaskReadme, renderTaskDocFromSections, renderTaskReadme, setMarkdownSection, taskDocToSectionMap, } from "@agentplaneorg/core/tasks";
|
|
4
|
+
import { decodeEscapedTaskTextNewlines, extractDocSection, extractTaskObservationSection, normalizeTaskDocVersion, normalizeVerificationSectionLayout, } from "./shared/docs.js";
|
|
5
|
+
import { defaultTaskDocV3 } from "./doc-template.js";
|
|
6
|
+
const V3_CANONICAL_ORDER = [
|
|
7
|
+
"Summary",
|
|
8
|
+
"Scope",
|
|
9
|
+
"Plan",
|
|
10
|
+
"Verify Steps",
|
|
11
|
+
"Verification",
|
|
12
|
+
"Rollback Plan",
|
|
13
|
+
"Findings",
|
|
14
|
+
];
|
|
15
|
+
const HUMAN_TEXT_SECTIONS = new Set(["summary", "context", "scope", "plan", "findings", "notes"]);
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
function normalizeRevision(value) {
|
|
20
|
+
return Number.isInteger(value) && typeof value === "number" && value > 0 ? value : null;
|
|
21
|
+
}
|
|
22
|
+
function normalizeCanonicalSections(value) {
|
|
23
|
+
if (!isRecord(value))
|
|
24
|
+
return null;
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const [title, text] of Object.entries(value)) {
|
|
27
|
+
const normalizedTitle = title.trim();
|
|
28
|
+
if (!normalizedTitle || typeof text !== "string")
|
|
29
|
+
continue;
|
|
30
|
+
out[normalizedTitle] = text.replaceAll("\r\n", "\n").trimEnd();
|
|
31
|
+
}
|
|
32
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
33
|
+
}
|
|
34
|
+
function normalizeSectionKey(section) {
|
|
35
|
+
return section.trim().replaceAll(/\s+/g, " ").toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
function parseMarkdownSections(doc) {
|
|
38
|
+
const lines = doc.replaceAll("\r\n", "\n").split("\n");
|
|
39
|
+
const sections = [];
|
|
40
|
+
let current = null;
|
|
41
|
+
for (const line of lines) {
|
|
42
|
+
const match = /^##\s+(.*)$/.exec(line.trim());
|
|
43
|
+
if (match) {
|
|
44
|
+
if (current) {
|
|
45
|
+
current.text = current.text.trimEnd();
|
|
46
|
+
sections.push(current);
|
|
47
|
+
}
|
|
48
|
+
current = { title: (match[1] ?? "").trim(), text: "" };
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (current) {
|
|
52
|
+
current.text = current.text.length > 0 ? `${current.text}\n${line}` : line;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (current) {
|
|
56
|
+
current.text = current.text.trimEnd();
|
|
57
|
+
sections.push(current);
|
|
58
|
+
}
|
|
59
|
+
return sections;
|
|
60
|
+
}
|
|
61
|
+
function renderMarkdownSections(sections) {
|
|
62
|
+
return sections
|
|
63
|
+
.map((section) => {
|
|
64
|
+
const text = section.text.trimEnd();
|
|
65
|
+
return text ? `## ${section.title}\n\n${text}` : `## ${section.title}\n`;
|
|
66
|
+
})
|
|
67
|
+
.join("\n\n")
|
|
68
|
+
.trimEnd();
|
|
69
|
+
}
|
|
70
|
+
function normalizeLiteralNewlinesInHumanSection(title, text) {
|
|
71
|
+
if (!HUMAN_TEXT_SECTIONS.has(normalizeSectionKey(title)))
|
|
72
|
+
return text.trimEnd();
|
|
73
|
+
return decodeEscapedTaskTextNewlines(text).trimEnd();
|
|
74
|
+
}
|
|
75
|
+
function firstSectionText(sections, title) {
|
|
76
|
+
const target = normalizeSectionKey(title);
|
|
77
|
+
return sections.find((section) => normalizeSectionKey(section.title) === target)?.text ?? null;
|
|
78
|
+
}
|
|
79
|
+
function mergeObservationText(doc, version) {
|
|
80
|
+
const preferred = extractTaskObservationSection(doc, version)?.trim() ?? "";
|
|
81
|
+
const notes = extractDocSection(doc, "Notes")?.trim() ?? "";
|
|
82
|
+
const findings = extractDocSection(doc, "Findings")?.trim() ?? "";
|
|
83
|
+
const out = [];
|
|
84
|
+
for (const candidate of [preferred, findings, notes]) {
|
|
85
|
+
if (!candidate)
|
|
86
|
+
continue;
|
|
87
|
+
if (out.includes(candidate))
|
|
88
|
+
continue;
|
|
89
|
+
out.push(candidate);
|
|
90
|
+
}
|
|
91
|
+
return out.join("\n\n").trim();
|
|
92
|
+
}
|
|
93
|
+
function migrateDocToV3(opts) {
|
|
94
|
+
const currentSections = parseMarkdownSections(opts.doc);
|
|
95
|
+
const defaultSections = parseMarkdownSections(defaultTaskDocV3({ title: opts.title, description: opts.description }));
|
|
96
|
+
const emitted = new Set();
|
|
97
|
+
const nextSections = [];
|
|
98
|
+
const observationText = mergeObservationText(opts.doc, 2);
|
|
99
|
+
for (const title of V3_CANONICAL_ORDER) {
|
|
100
|
+
const key = normalizeSectionKey(title);
|
|
101
|
+
const currentText = firstSectionText(currentSections, title);
|
|
102
|
+
const defaultText = firstSectionText(defaultSections, title) ?? "";
|
|
103
|
+
let nextText = currentText ?? defaultText;
|
|
104
|
+
if (title === "Verification") {
|
|
105
|
+
nextText = normalizeVerificationSectionLayout(currentText ?? defaultText, 3);
|
|
106
|
+
}
|
|
107
|
+
if (title === "Findings") {
|
|
108
|
+
nextText = observationText || defaultText;
|
|
109
|
+
}
|
|
110
|
+
if (nextText === null)
|
|
111
|
+
continue;
|
|
112
|
+
nextText = normalizeLiteralNewlinesInHumanSection(title, nextText);
|
|
113
|
+
nextSections.push({ title, text: nextText.trimEnd() });
|
|
114
|
+
emitted.add(key);
|
|
115
|
+
if (title === "Findings")
|
|
116
|
+
emitted.add("notes");
|
|
117
|
+
}
|
|
118
|
+
for (const section of currentSections) {
|
|
119
|
+
const key = normalizeSectionKey(section.title);
|
|
120
|
+
if (emitted.has(key))
|
|
121
|
+
continue;
|
|
122
|
+
nextSections.push({ title: section.title, text: section.text.trimEnd() });
|
|
123
|
+
emitted.add(key);
|
|
124
|
+
}
|
|
125
|
+
return renderMarkdownSections(nextSections);
|
|
126
|
+
}
|
|
127
|
+
function ensurePlanApprovalFrontmatter(frontmatter) {
|
|
128
|
+
const raw = frontmatter.plan_approval;
|
|
129
|
+
if (isRecord(raw) && typeof raw.state === "string")
|
|
130
|
+
return;
|
|
131
|
+
frontmatter.plan_approval = {
|
|
132
|
+
state: "pending",
|
|
133
|
+
updated_at: null,
|
|
134
|
+
updated_by: null,
|
|
135
|
+
note: null,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function ensureVerificationFrontmatter(frontmatter) {
|
|
139
|
+
const raw = frontmatter.verification;
|
|
140
|
+
if (isRecord(raw) && typeof raw.state === "string")
|
|
141
|
+
return;
|
|
142
|
+
frontmatter.verification = {
|
|
143
|
+
state: "pending",
|
|
144
|
+
updated_at: null,
|
|
145
|
+
updated_by: null,
|
|
146
|
+
note: null,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const DATE_ONLY_ON_RE = /\bon (\d{4}-\d{2}-\d{2})(?!T)\b/g;
|
|
150
|
+
function isIsoTimestamp(value) {
|
|
151
|
+
if (!value.includes("T") || !value.endsWith("Z"))
|
|
152
|
+
return false;
|
|
153
|
+
const ms = Date.parse(value);
|
|
154
|
+
return Number.isFinite(ms);
|
|
155
|
+
}
|
|
156
|
+
function normalizeNoteTimestamp(opts) {
|
|
157
|
+
if (!isIsoTimestamp(opts.updatedAt))
|
|
158
|
+
return opts.note;
|
|
159
|
+
const updatedDate = opts.updatedAt.slice(0, 10);
|
|
160
|
+
return opts.note.replaceAll(DATE_ONLY_ON_RE, (match, date) => {
|
|
161
|
+
if (date !== updatedDate)
|
|
162
|
+
return match;
|
|
163
|
+
return `on ${opts.updatedAt}`;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function normalizeFrontmatterNoteTimestamps(frontmatter) {
|
|
167
|
+
const plan = frontmatter.plan_approval;
|
|
168
|
+
if (isRecord(plan) && typeof plan.note === "string" && typeof plan.updated_at === "string") {
|
|
169
|
+
plan.note = normalizeNoteTimestamp({ note: plan.note, updatedAt: plan.updated_at });
|
|
170
|
+
}
|
|
171
|
+
const verification = frontmatter.verification;
|
|
172
|
+
if (isRecord(verification) &&
|
|
173
|
+
typeof verification.note === "string" &&
|
|
174
|
+
typeof verification.updated_at === "string") {
|
|
175
|
+
verification.note = normalizeNoteTimestamp({
|
|
176
|
+
note: verification.note,
|
|
177
|
+
updatedAt: verification.updated_at,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
export async function migrateTaskReadmeDoc(opts) {
|
|
182
|
+
const originalRaw = await readFile(opts.readmePath, "utf8");
|
|
183
|
+
const original = originalRaw.endsWith("\n") ? originalRaw : `${originalRaw}\n`;
|
|
184
|
+
const parsed = parseTaskReadme(original);
|
|
185
|
+
const frontmatter = { ...parsed.frontmatter };
|
|
186
|
+
ensurePlanApprovalFrontmatter(frontmatter);
|
|
187
|
+
ensureVerificationFrontmatter(frontmatter);
|
|
188
|
+
normalizeFrontmatterNoteTimestamps(frontmatter);
|
|
189
|
+
const canonicalSections = normalizeCanonicalSections(frontmatter.sections);
|
|
190
|
+
const required = opts.config.tasks.doc.required_sections;
|
|
191
|
+
const extracted = extractTaskDoc(parsed.body);
|
|
192
|
+
const baseDoc = canonicalSections === null
|
|
193
|
+
? extracted || parsed.body
|
|
194
|
+
: renderTaskDocFromSections(canonicalSections);
|
|
195
|
+
let nextDoc = normalizeTaskDoc(ensureDocSections(baseDoc, required));
|
|
196
|
+
const docVersion = normalizeTaskDocVersion(frontmatter.doc_version);
|
|
197
|
+
if (docVersion === 2) {
|
|
198
|
+
frontmatter.doc_version = 3;
|
|
199
|
+
nextDoc = migrateDocToV3({
|
|
200
|
+
title: typeof frontmatter.title === "string" ? frontmatter.title : "",
|
|
201
|
+
description: typeof frontmatter.description === "string" ? frontmatter.description : "",
|
|
202
|
+
doc: nextDoc,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const verificationSection = extractDocSection(nextDoc, "Verification");
|
|
207
|
+
const normalizedVerification = normalizeVerificationSectionLayout(verificationSection, docVersion);
|
|
208
|
+
nextDoc = setMarkdownSection(nextDoc, "Verification", normalizedVerification);
|
|
209
|
+
for (const sectionTitle of ["Summary", "Context", "Scope", "Plan", "Findings", "Notes"]) {
|
|
210
|
+
const sectionText = extractDocSection(nextDoc, sectionTitle);
|
|
211
|
+
if (sectionText == null)
|
|
212
|
+
continue;
|
|
213
|
+
nextDoc = setMarkdownSection(nextDoc, sectionTitle, normalizeLiteralNewlinesInHumanSection(sectionTitle, sectionText));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const nextBody = extracted ? mergeTaskDoc(parsed.body, nextDoc) : nextDoc;
|
|
217
|
+
frontmatter.sections = taskDocToSectionMap(nextDoc);
|
|
218
|
+
frontmatter.revision = normalizeRevision(frontmatter.revision) ?? 1;
|
|
219
|
+
const rendered = renderTaskReadme(frontmatter, nextBody);
|
|
220
|
+
const next = rendered.endsWith("\n") ? rendered : `${rendered}\n`;
|
|
221
|
+
if (next === original)
|
|
222
|
+
return { changed: false };
|
|
223
|
+
await atomicWriteFile(opts.readmePath, next, "utf8");
|
|
224
|
+
return { changed: true };
|
|
225
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentplane",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.24",
|
|
4
4
|
"description": "Agent Plane CLI for task workflows, recipes, and project automation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentplane",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"prepublishOnly": "node ../../scripts/enforce-github-publish.mjs && npm run prepack"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@agentplaneorg/core": "0.3.
|
|
60
|
-
"@agentplaneorg/recipes": "0.3.
|
|
59
|
+
"@agentplaneorg/core": "0.3.24",
|
|
60
|
+
"@agentplaneorg/recipes": "0.3.24",
|
|
61
61
|
"@clack/prompts": "^1.2.0",
|
|
62
62
|
"yauzl": "^2.10.0",
|
|
63
63
|
"zod": "^3",
|