fix: preserve decision diary summary

Keep diary summary as an independent Decision Center field when body content is supplied from --body-file, and cover the CLI/backend contract.
This commit is contained in:
AgentRun Artificer
2026-06-11 17:35:35 +08:00
parent 49c3145439
commit fc3a095858
5 changed files with 195 additions and 15 deletions
+25 -7
View File
@@ -151,7 +151,7 @@ function readMarkdownFile(path: string): { absolutePath: string; markdown: strin
return { absolutePath, markdown };
}
function bodyFromArgs(args: string[], command: string): { body: string; bodySource: Record<string, string> } {
function optionalBodyFromArgs(args: string[], command: string): { body: string | undefined; bodySource: Record<string, string> } {
const body = optionValue(args, ["--body"]);
const bodyFile = optionValue(args, ["--body-file", "--markdown-file"]);
const markdownFile = optionValue(args, ["--file"]);
@@ -163,6 +163,12 @@ function bodyFromArgs(args: string[], command: string): { body: string; bodySour
const { absolutePath, markdown } = readMarkdownFile(file);
return { body: markdown, bodySource: { kind: "file", path: absolutePath } };
}
return { body: undefined, bodySource: { kind: "none" } };
}
function bodyFromArgs(args: string[], command: string): { body: string; bodySource: Record<string, string> } {
const { body, bodySource } = optionalBodyFromArgs(args, command);
if (body !== undefined) return { body, bodySource };
throw new Error(`${command} requires --body text or --body-file path`);
}
@@ -407,14 +413,18 @@ async function todayDiaryAsync(fetcher: (path: string, init?: { method?: string;
function diaryEditPayload(args: string[], command: string): { key: string; payload: Record<string, unknown>; bodySource: Record<string, string> } {
const key = positionalArgs(args)[0];
if (!key) throw new Error(`${command} requires entry id or YYYY-MM-DD date`);
const { body, bodySource } = bodyFromArgs(args, command);
const payload: Record<string, unknown> = { body };
const { body, bodySource } = optionalBodyFromArgs(args, command);
const payload: Record<string, unknown> = {};
const title = optionValue(args, ["--title"]);
const summary = optionValue(args, ["--summary"]);
const sourceFile = optionValue(args, ["--source-file", "--source-path", "--source"]);
if (body !== undefined) payload.body = body;
if (title !== undefined) payload.title = title;
if (summary !== undefined) payload.summary = summary;
if (sourceFile !== undefined) payload.sourceFile = sourceFile;
const tags = splitList(optionValues(args, ["--tag", "--tags"]));
if (tags.length > 0) payload.tags = tags;
if (Object.keys(payload).length === 0) throw new Error(`${command} requires --body text, --body-file path, --summary, --title, --source-file, or --tag`);
return { key, payload, bodySource };
}
@@ -429,26 +439,34 @@ async function editDiaryAsync(args: string[], fetcher: (path: string, init?: { m
}
function editTodayDiary(args: string[]): unknown {
const { body, bodySource } = bodyFromArgs(args, "decision diary today --edit");
const payload: Record<string, unknown> = { body };
const { body, bodySource } = optionalBodyFromArgs(args, "decision diary today --edit");
const payload: Record<string, unknown> = {};
const title = optionValue(args, ["--title"]);
const summary = optionValue(args, ["--summary"]);
const sourceFile = optionValue(args, ["--source-file", "--source-path", "--source"]);
if (body !== undefined) payload.body = body;
if (title !== undefined) payload.title = title;
if (summary !== undefined) payload.summary = summary;
if (sourceFile !== undefined) payload.sourceFile = sourceFile;
const tags = splitList(optionValues(args, ["--tag", "--tags"]));
if (tags.length > 0) payload.tags = tags;
if (Object.keys(payload).length === 0) throw new Error("decision diary today --edit requires --body text, --body-file path, --summary, --title, --source-file, or --tag");
return { bodySource, result: unwrapProxyResponse(decisionProxy("/api/diary/today", { method: "PUT", body: payload })) };
}
async function editTodayDiaryAsync(args: string[], fetcher: (path: string, init?: { method?: string; body?: unknown }) => Promise<unknown>): Promise<unknown> {
const { body, bodySource } = bodyFromArgs(args, "decision diary today --edit");
const payload: Record<string, unknown> = { body };
const { body, bodySource } = optionalBodyFromArgs(args, "decision diary today --edit");
const payload: Record<string, unknown> = {};
const title = optionValue(args, ["--title"]);
const summary = optionValue(args, ["--summary"]);
const sourceFile = optionValue(args, ["--source-file", "--source-path", "--source"]);
if (body !== undefined) payload.body = body;
if (title !== undefined) payload.title = title;
if (summary !== undefined) payload.summary = summary;
if (sourceFile !== undefined) payload.sourceFile = sourceFile;
const tags = splitList(optionValues(args, ["--tag", "--tags"]));
if (tags.length > 0) payload.tags = tags;
if (Object.keys(payload).length === 0) throw new Error("decision diary today --edit requires --body text, --body-file path, --summary, --title, --source-file, or --tag");
return { bodySource, result: unwrapProxyResponse(await decisionProxyAsync(fetcher, "/api/diary/today", { method: "PUT", body: payload })) };
}