{"record":{"id":"b85403a837650af0","repo":"affaan-m/ECC","slug":"empty-stdin","errorCode":null,"errorMessage":"empty stdin","messagePattern":"empty stdin","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/ck/commands/save.mjs","lineNumber":34,"sourceCode":" * exit 0: success  exit 1: error\n */\n\nimport { readFileSync, mkdirSync, writeFileSync } from 'fs';\nimport { resolve } from 'path';\nimport {\n  readProjects, writeProjects, loadContext, saveContext,\n  today, shortId, gitSummary, nativeMemoryDir,\n  CURRENT_SESSION,\n} from './shared.mjs';\n\nconst isInit = process.argv.includes('--init');\nconst cwd    = process.env.PWD || process.cwd();\n\n// ── Read JSON from stdin ──────────────────────────────────────────────────────\nlet input;\ntry {\n  const raw = readFileSync(0, 'utf8').trim();\n  if (!raw) throw new Error('empty stdin');\n  input = JSON.parse(raw);\n} catch (e) {\n  console.error(`ck save: invalid JSON on stdin — ${e.message}`);\n  console.log('Expected schema (save):  {\"summary\":\"...\",\"leftOff\":\"...\",\"nextSteps\":[\"...\"],\"decisions\":[{\"what\":\"...\",\"why\":\"...\"}],\"blockers\":[\"...\"]}');\n  console.log('Expected schema (--init): {\"name\":\"...\",\"path\":\"...\",\"description\":\"...\",\"stack\":[\"...\"],\"goal\":\"...\",\"constraints\":[\"...\"]}');\n  process.exit(1);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// INIT MODE: first-time project registration\n// ─────────────────────────────────────────────────────────────────────────────\nif (isInit) {\n  const { name, path: projectPath, description, stack, goal, constraints, repo } = input;\n\n  if (!name || !projectPath) {\n    console.log('ck init: name and path are required.');\n    process.exit(1);\n  }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/ck/commands/save.mjs#L16-L52","documentation":"ck save reads its session payload as JSON from stdin; when the raw stdin is empty (or whitespace only) it throws 'empty stdin', which the surrounding catch reports as 'invalid JSON on stdin' along with the expected schemas and exits 1. The script requires the caller to pipe a complete JSON document.","triggerScenarios":"Running `node skills/ck/commands/save.mjs` interactively without piping input; the upstream command in a pipe produced no output (e.g. a failed hook or empty transcript); redirecting from an empty file.","commonSituations":"Hook configured to pipe session data but the generator emitted nothing; running the script manually in a terminal and typing nothing before Ctrl-D; a previous pipeline stage crashed silently leaving stdin empty.","solutions":["Pipe a JSON document matching the save schema into the command, e.g. echo '{\"summary\":\"...\",\"leftOff\":\"...\",\"nextSteps\":[],\"decisions\":[],\"blockers\":[]}' | node skills/ck/commands/save.mjs","If using --init, pipe the init schema instead ({\"name\",\"path\",\"description\",\"stack\",\"goal\",\"constraints\"})","Check the upstream producer in your pipeline — fix why it emitted no output","For interactive testing, use `cat payload.json | node save.mjs` rather than running bare"],"exampleFix":"// before (nothing on stdin)\n$ node save.mjs\n\n// after\n$ cat session.json | node save.mjs   # session.json: {\"summary\":\"...\",\"leftOff\":\"...\",\"nextSteps\":[\"...\"],\"decisions\":[],\"blockers\":[]}","handlingStrategy":"validation","validationCode":"const raw = readFileSync(0, 'utf8').trim();\nif (!raw) { console.error('ck save: no JSON received on stdin'); process.exit(1); }\nJSON.parse(raw);","typeGuard":null,"tryCatchPattern":"let input; try { input = JSON.parse(readFileSync(0,'utf8')); } catch { /* print schema and exit 1 */ }","preventionTips":["Always invoke via a pipe or redirect: cat payload.json | save.mjs","Verify the upstream generator actually emitted output (check its exit status) before piping","Validate payload JSON against the save/init schema in the producing script"],"tags":["stdin","cli","json"],"backgroundTag":"stdin-empty","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}