Skip to content

Commit fe1515b

Browse files
Claudeclaude
authored andcommitted
feat: ship closing payload schema with init and session_start
Agents frequently guess wrong field names for closing-payload.json, causing validation failures on session_close. Two fixes: 1. gitmem init now creates .gitmem/closing-payload-template.json with exact field names (survives context compaction) 2. session_start/refresh results include closing_payload_schema so agents have the schema in-context without reading a file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 69fb223 commit fe1515b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

bin/init-wizard.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,36 @@ async function stepMemoryStore() {
506506
}
507507
}
508508

509+
// Closing payload template — agents read this before writing closing-payload.json
510+
const templatePath = join(gitmemDir, "closing-payload-template.json");
511+
if (!existsSync(templatePath)) {
512+
writeJson(templatePath, {
513+
closing_reflection: {
514+
what_broke: "",
515+
what_took_longer: "",
516+
do_differently: "",
517+
what_worked: "",
518+
wrong_assumption: "",
519+
scars_applied: [],
520+
institutional_memory_items: "",
521+
collaborative_dynamic: "",
522+
rapport_notes: ""
523+
},
524+
task_completion: {
525+
questions_displayed_at: "ISO-8601 timestamp",
526+
reflection_completed_at: "ISO-8601 timestamp",
527+
human_asked_at: "ISO-8601 timestamp",
528+
human_response_at: "ISO-8601 timestamp",
529+
human_response: "no corrections | actual corrections text"
530+
},
531+
human_corrections: "",
532+
scars_to_record: [],
533+
learnings_created: [],
534+
open_threads: [],
535+
decisions: []
536+
});
537+
}
538+
509539
console.log(
510540
` Created .gitmem/ with ${starterScars.length} starter scars` +
511541
(added < starterScars.length

src/tools/session-start.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ import type {
5050
ThreadObject,
5151
} from "../types/index.js";
5252

53+
/**
54+
* Closing payload schema — returned in session_start/refresh so agents
55+
* know the exact field names for closing-payload.json without guessing.
56+
*/
57+
const CLOSING_PAYLOAD_SCHEMA: Record<string, unknown> = {
58+
closing_reflection: {
59+
what_broke: "Q1: What broke that you didn't expect?",
60+
what_took_longer: "Q2: What took longer than it should have?",
61+
do_differently: "Q3: What would you do differently next time?",
62+
what_worked: "Q4: What pattern or approach worked well?",
63+
wrong_assumption: "Q5: What assumption was wrong?",
64+
scars_applied: ["Q6: scar titles applied"],
65+
institutional_memory_items: "Q7: What to capture as institutional memory?",
66+
},
67+
task_completion: {
68+
questions_displayed_at: "ISO-8601",
69+
reflection_completed_at: "ISO-8601",
70+
human_asked_at: "ISO-8601",
71+
human_response_at: "ISO-8601",
72+
human_response: "human's corrections or 'no corrections'",
73+
},
74+
human_corrections: "",
75+
scars_to_record: [],
76+
learnings_created: [],
77+
open_threads: [],
78+
decisions: [],
79+
};
80+
5381
// Supabase record types
5482
interface SessionRecord {
5583
id: string;
@@ -539,6 +567,7 @@ async function sessionStartFree(
539567
...(freeMergedThreads.length > 0 && { open_threads: freeMergedThreads }),
540568
recent_decisions: decisions,
541569
gitmem_dir: getGitmemDir(),
570+
closing_payload_schema: CLOSING_PAYLOAD_SCHEMA,
542571
project,
543572
performance,
544573
};
@@ -1027,6 +1056,7 @@ export async function sessionStart(
10271056
recent_decisions: decisions,
10281057
...(recordingPath && { recording_path: recordingPath }),
10291058
gitmem_dir: getGitmemDir(),
1059+
closing_payload_schema: CLOSING_PAYLOAD_SCHEMA,
10301060
project,
10311061
performance,
10321062
};
@@ -1195,6 +1225,7 @@ export async function sessionRefresh(
11951225
recent_decisions: decisions,
11961226
// Rapport disabled — not injected into session context
11971227
...(recordingPath && { recording_path: recordingPath }),
1228+
closing_payload_schema: CLOSING_PAYLOAD_SCHEMA,
11981229
project,
11991230
performance,
12001231
};

src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ export interface SessionStartResult {
206206
recording_path?: string;
207207
/** Resolved .gitmem directory path — use for closing-payload.json writes */
208208
gitmem_dir?: string;
209+
/** Closing payload schema — exact field names for closing-payload.json */
210+
closing_payload_schema?: Record<string, unknown>;
209211
/** Project namespace for this session */
210212
project?: string;
211213
/** Pre-formatted display string for consistent CLI output */

0 commit comments

Comments
 (0)