| name | session-sync |
| description | Quick-sync session work to specs/*.md and project-tech.json |
| argument-hint | [-y|--yes] ["what was done"] |
| allowed-tools | request_user_input, Read, Write, Edit, Bash, Glob, Grep |
Session Sync
One-shot update specs/*.md + project-tech.json from current session context.
Design: Scan context -> extract -> write. No interactive wizards.
Usage
$session-sync
$session-sync -y
$session-sync "Added JWT auth flow"
$session-sync -y "Fixed N+1 query"
Process
Step 1: Gather Context
|- git diff --stat HEAD~3..HEAD (recent changes)
|- Active session folder (.workflow/.lite-plan/*) if exists
+- User summary ($ARGUMENTS or auto-generate from git log)
Step 2: Extract Updates
|- Guidelines: conventions / constraints / learnings
+- Tech: development_index entry
Step 3: Preview & Confirm (skip if --yes)
Step 4: Write both files
Step 5: One-line confirmation
Implementation
Step 1: Gather Context
const AUTO_YES = "$ARGUMENTS".includes('--yes') || "$ARGUMENTS".includes('-y')
const userSummary = "$ARGUMENTS".replace(/--yes|-y/g, '').trim()
const gitStat = Bash('git diff --stat HEAD~3..HEAD 2>/dev/null || git diff --stat HEAD 2>/dev/null')
const gitLog = Bash('git log --oneline -5')
const sessionFolders = Glob('.workflow/.lite-plan/*/plan.json')
let sessionContext = null
if (sessionFolders.length > 0) {
const latest = sessionFolders[sessionFolders.length - 1]
sessionContext = JSON.parse(Read(latest))
}
const summary = userSummary
|| sessionContext?.summary
|| gitLog.split('\n')[0].replace(/^[a-f0-9]+ /, '')
Step 2: Extract Updates
Analyze context and produce two update payloads. Use LLM reasoning (current agent) -- no CLI calls.
const existingSpecs = Bash('ccw spec load --dimension specs 2>/dev/null || echo ""')
const guidelineUpdates = []
function detectCategory(text) {
text = text.toLowerCase()
if (/\b(fix|bug|error|crash)\b/.test(text)) return 'bugfix'
if (/\b(refactor|cleanup|reorganize)\b/.test(text)) return 'refactor'
if (/\b(doc|readme|comment)\b/.test(text)) return 'docs'
if (/\b(add|new|create|implement)\b/.test(text)) return 'feature'
return 'enhancement'
}
function () {
dirs = gitStat.() || []
counts = {}
dirs.( {
seg = d.().().(-, -)[] ||
counts[seg] = (counts[seg] || ) +
})
.(counts).( b[] - a[])[]?.[] ||
}
techEntry = {
: summary.(, ),
: (gitStat),
: ().().()[],
: summary.(, ),
: ,
: sessionContext ? sessionFolders[sessionFolders. - ].()?.[] :
}
Step 3: Preview & Confirm
console.log(`
-- Sync Preview --
Guidelines (${guidelineUpdates.length} items):
${guidelineUpdates.map(g => ` [${g.type}/${g.category}] ${g.text}`).join('\n') || ' (none)'}
Tech [${detectCategory(summary)}]:
${techEntry.title}
Target files:
.ccw/specs/*.md
.workflow/project-tech.json
`)
if (!AUTO_YES) {
const answer = functions.request_user_input({
questions: [{
header: "确认同步",
id: "confirm_sync",
question: "Apply these updates? (modify/skip items if needed)",
options: [
{ label: "Apply(Recommended)", description: "Apply all extracted updates to specs and project-tech.json" },
{ label: "Cancel", description: "Abort sync, no changes made" }
]
}]
})
if (answer.answers.confirm_sync.answers[0] !== "Apply(Recommended)") {
console.log('Sync cancelled.')
return
}
}
Step 4: Write
if (guidelineUpdates.length > 0) {
const specFileMap = {
convention: '.ccw/specs/coding-conventions.md',
constraint: '.ccw/specs/architecture-constraints.md',
learning: '.ccw/specs/coding-conventions.md'
}
for (const g of guidelineUpdates) {
const targetFile = specFileMap[g.type]
const existing = Read(targetFile)
const ruleText = g.type === 'learning'
? `- [${g.category}] ${g.text} (learned: ${new Date().toISOString().split('T')[0]})`
: `- [${g.category}] ${g.text}`
if (!existing.includes(g.text)) {
const newContent = existing.trimEnd() + '\n' + ruleText + '\n'
Write(targetFile, newContent)
}
}
Bash('ccw spec rebuild')
}
techPath =
tech = .((techPath))
(!tech.) {
tech. = { : [], : [], : [], : [], : [] }
}
category = (summary)
tech.[category].(techEntry)
tech.. = ().()
(techPath, .(tech, , ))
Step 5: Confirm
Synced: ${guidelineUpdates.length} guidelines + 1 tech entry [${category}]
Error Handling
| Error | Resolution |
|---|
| File missing | Create scaffold (same as $spec-setup Step 4) |
| No git history | Use user summary or session context only |
| No meaningful updates | Skip guidelines, still add tech entry |
| Duplicate entry | Skip silently (dedup check in Step 4) |
Related Commands
$spec-setup - Initialize project with specs scaffold
$spec-add - Interactive wizard to create individual specs with scope selection
$workflow-plan - Start planning with initialized project context