@codewalla_india/openspec 1.0.4 → 1.0.5

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.
@@ -15,6 +15,22 @@ import { readRegistrySnapshot } from '../../core/store/registry.js';
15
15
  import { readProjectConfig } from '../../core/project-config.js';
16
16
  import { checkComprehensionGate, ComprehensionPassError, recordComprehensionPass, } from '../../core/comprehension/index.js';
17
17
  import { validateChangeExists, validateSchemaExists, } from './shared.js';
18
+ function buildArtifactPresence(contextFiles, pendingTaskCount) {
19
+ return {
20
+ hasPlan: (contextFiles.plan?.length ?? 0) > 0,
21
+ hasProposal: (contextFiles.proposal?.length ?? 0) > 0,
22
+ hasDesign: (contextFiles.design?.length ?? 0) > 0,
23
+ hasSpecs: (contextFiles.specs?.length ?? 0) > 0,
24
+ hasTasks: pendingTaskCount > 0 || (contextFiles.tasks?.length ?? 0) > 0,
25
+ };
26
+ }
27
+ function resolvePlanPath(contextFiles, changeDir) {
28
+ if (contextFiles.plan?.[0]) {
29
+ return contextFiles.plan[0];
30
+ }
31
+ const fallback = path.join(changeDir, 'plan.md');
32
+ return fs.existsSync(fallback) ? fallback : null;
33
+ }
18
34
  // -----------------------------------------------------------------------------
19
35
  // Artifact Instructions Command
20
36
  // -----------------------------------------------------------------------------
@@ -298,13 +314,15 @@ export async function generateApplyInstructions(projectRoot, changeName, schemaN
298
314
  if (state === 'ready') {
299
315
  const specPaths = contextFiles.specs ?? [];
300
316
  const tasksPath = tracksFile && tracksFileExists ? path.join(changeDir, tracksFile) : null;
317
+ const planPath = resolvePlanPath(contextFiles, changeDir);
301
318
  const pendingTaskCount = tasks.filter((task) => !task.done).length;
302
- const gate = checkComprehensionGate(changeDir, specPaths, options.projectConfig ?? readProjectConfig(projectRoot), { tasksPath, pendingTaskCount });
319
+ const artifactPresence = buildArtifactPresence(contextFiles, pendingTaskCount);
320
+ const gate = checkComprehensionGate(changeDir, specPaths, options.projectConfig ?? readProjectConfig(projectRoot), { tasksPath, planPath, pendingTaskCount, artifactPresence });
303
321
  if (gate.active && !gate.passed && gate.info) {
304
322
  state = 'blocked';
305
323
  missingComprehension = true;
306
324
  comprehension = gate.info;
307
- instruction = `Complete the comprehension quiz in /opsx:apply before implementation (score ≥ ${gate.info.thresholdPercent}% on proposal, design, specs, and tasks).`;
325
+ instruction = `Complete the comprehension quiz in /opsx:apply before implementation (score ≥ ${gate.info.thresholdPercent}% on proposal, design, specs, plan, and tasks; plan receives the majority of questions per questionAllocation).`;
308
326
  }
309
327
  else if (gate.active && gate.info) {
310
328
  comprehension = gate.info;
@@ -359,15 +377,32 @@ export async function applyInstructionsCommand(options) {
359
377
  }
360
378
  const tracksFile = schema.apply?.tracks ?? null;
361
379
  const tasksPath = tracksFile ? path.join(changeDir, tracksFile) : null;
380
+ const planPath = fs.existsSync(path.join(changeDir, 'plan.md'))
381
+ ? path.join(changeDir, 'plan.md')
382
+ : null;
383
+ const pendingTaskCount = tasksPath && fs.existsSync(tasksPath)
384
+ ? parseTasksFile(fs.readFileSync(tasksPath, 'utf-8')).filter((t) => !t.done).length
385
+ : 0;
386
+ const contextFilesForPresence = {};
387
+ for (const artifact of schema.artifacts) {
388
+ const outputs = resolveArtifactOutputs(changeDir, artifact.generates);
389
+ if (outputs.length > 0) {
390
+ contextFilesForPresence[artifact.id] = outputs;
391
+ }
392
+ }
393
+ const artifactPresence = buildArtifactPresence(contextFilesForPresence, pendingTaskCount);
362
394
  try {
363
395
  const record = recordComprehensionPass({
364
396
  changeDir,
365
397
  specPaths,
366
398
  tasksPath,
399
+ planPath,
367
400
  projectConfig,
368
401
  scorePercent: options.score,
369
402
  attempt: options.attempt ?? 1,
370
403
  questionCount: options.questionCount ?? 0,
404
+ pendingTaskCount,
405
+ artifactPresence,
371
406
  });
372
407
  spinner?.stop();
373
408
  if (options.json) {
@@ -453,11 +488,17 @@ export function printApplyInstructionsText(instructions) {
453
488
  if (state === 'blocked' && missingComprehension && comprehension) {
454
489
  console.log('### ⚠️ Comprehension Required');
455
490
  console.log();
456
- console.log(`Pass the spec and task comprehension quiz (score ≥ ${comprehension.thresholdPercent}%) before implementation.`);
457
- console.log(`Questions: ${comprehension.questionCount}`);
491
+ console.log(`Pass the comprehension quiz (score ≥ ${comprehension.thresholdPercent}%) before implementation.`);
492
+ console.log(`Questions: ${comprehension.questionCount} (${comprehension.optionsPerQuestion} options each)`);
493
+ const allocationParts = Object.entries(comprehension.questionAllocation)
494
+ .filter(([, count]) => (count ?? 0) > 0)
495
+ .map(([category, count]) => `${category}×${count}`);
496
+ if (allocationParts.length > 0) {
497
+ console.log(`Allocation: ${allocationParts.join(', ')}`);
498
+ }
458
499
  console.log(`Specs: ${comprehension.requirementCount} requirements, ${comprehension.scenarioCount} scenarios; Tasks: ${comprehension.pendingTaskCount} pending`);
459
500
  if (comprehension.bestScorePercent !== undefined) {
460
- console.log(`Previous score: ${comprehension.bestScorePercent}% (specs changed — retake required)`);
501
+ console.log(`Previous score: ${comprehension.bestScorePercent}% (artifacts changed — retake required)`);
461
502
  }
462
503
  console.log('Complete the quiz via /opsx:apply.');
463
504
  console.log();
@@ -23,6 +23,8 @@ export interface ApplyComprehensionInfo {
23
23
  thresholdPercent: number;
24
24
  bestScorePercent?: number;
25
25
  questionCount: number;
26
+ questionAllocation: Record<string, number>;
27
+ optionsPerQuestion: number;
26
28
  requirementCount: number;
27
29
  scenarioCount: number;
28
30
  pendingTaskCount: number;
@@ -191,6 +191,25 @@ export const COMMAND_REGISTRY = [
191
191
  description: 'Schema override',
192
192
  takesValue: true,
193
193
  },
194
+ {
195
+ name: 'record-comprehension-pass',
196
+ description: 'Record a successful comprehension quiz pass (use with instructions apply)',
197
+ },
198
+ {
199
+ name: 'score',
200
+ description: 'Quiz score 0-100 (required with --record-comprehension-pass)',
201
+ takesValue: true,
202
+ },
203
+ {
204
+ name: 'attempt',
205
+ description: 'Quiz attempt number',
206
+ takesValue: true,
207
+ },
208
+ {
209
+ name: 'question-count',
210
+ description: 'Number of quiz questions taken',
211
+ takesValue: true,
212
+ },
194
213
  COMMON_FLAGS.json,
195
214
  COMMON_FLAGS.store,
196
215
  ],
@@ -1,5 +1,14 @@
1
+ export interface ApplyArtifactFingerprintInput {
2
+ specPaths: string[];
3
+ tasksPath?: string | null;
4
+ planPath?: string | null;
5
+ }
1
6
  /**
2
- * SHA-256 fingerprint of delta spec and optional tasks file contents.
7
+ * SHA-256 fingerprint of delta specs and optional plan/tasks file contents.
8
+ */
9
+ export declare function fingerprintApplyArtifacts(input: ApplyArtifactFingerprintInput): string;
10
+ /**
11
+ * @deprecated Use fingerprintApplyArtifacts
3
12
  */
4
13
  export declare function fingerprintSpecFiles(specPaths: string[], tasksPath?: string | null): string;
5
14
  //# sourceMappingURL=fingerprint.d.ts.map
@@ -1,25 +1,33 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
+ function hashFileContent(hash, label, filePath) {
4
+ hash.update(`${label}:`);
5
+ hash.update(filePath);
6
+ hash.update('\0');
7
+ hash.update(readFileSync(filePath, 'utf-8'));
8
+ hash.update('\0');
9
+ }
3
10
  /**
4
- * SHA-256 fingerprint of delta spec and optional tasks file contents.
11
+ * SHA-256 fingerprint of delta specs and optional plan/tasks file contents.
5
12
  */
6
- export function fingerprintSpecFiles(specPaths, tasksPath) {
7
- const sorted = [...specPaths].sort();
13
+ export function fingerprintApplyArtifacts(input) {
14
+ const sorted = [...input.specPaths].sort();
8
15
  const hash = createHash('sha256');
9
16
  for (const specPath of sorted) {
10
- hash.update('spec:');
11
- hash.update(specPath);
12
- hash.update('\0');
13
- hash.update(readFileSync(specPath, 'utf-8'));
14
- hash.update('\0');
17
+ hashFileContent(hash, 'spec', specPath);
15
18
  }
16
- if (tasksPath && existsSync(tasksPath)) {
17
- hash.update('tasks:');
18
- hash.update(tasksPath);
19
- hash.update('\0');
20
- hash.update(readFileSync(tasksPath, 'utf-8'));
21
- hash.update('\0');
19
+ if (input.planPath && existsSync(input.planPath)) {
20
+ hashFileContent(hash, 'plan', input.planPath);
21
+ }
22
+ if (input.tasksPath && existsSync(input.tasksPath)) {
23
+ hashFileContent(hash, 'tasks', input.tasksPath);
22
24
  }
23
25
  return hash.digest('hex');
24
26
  }
27
+ /**
28
+ * @deprecated Use fingerprintApplyArtifacts
29
+ */
30
+ export function fingerprintSpecFiles(specPaths, tasksPath) {
31
+ return fingerprintApplyArtifacts({ specPaths, tasksPath });
32
+ }
25
33
  //# sourceMappingURL=fingerprint.js.map
@@ -1,15 +1,18 @@
1
1
  import type { ProjectConfig } from '../project-config.js';
2
2
  import { type ComprehensionPassRecord } from './pass-record.js';
3
+ import { OPTIONS_PER_QUESTION, type ArtifactPresence, type QuestionAllocation } from './stats.js';
3
4
  export { DEFAULT_COMPREHENSION_CONFIG, resolveComprehensionConfig, type ComprehensionConfig, } from './config.js';
4
- export { fingerprintSpecFiles } from './fingerprint.js';
5
+ export { fingerprintApplyArtifacts, fingerprintSpecFiles } from './fingerprint.js';
5
6
  export { COMPREHENSION_PASS_FILENAME, COMPREHENSION_SESSION_FILENAME, buildPassRecord, deleteSessionRecord, isPassValid, readPassRecord, writePassRecord, type ComprehensionPassRecord, } from './pass-record.js';
6
- export { computeQuestionCount, computeSpecStats, countSpecStats, type SpecStats } from './stats.js';
7
+ export { computeQuestionAllocation, computeQuestionCount, computeSpecStats, countSpecStats, OPTIONS_PER_QUESTION, type ArtifactPresence, type QuestionAllocation, type QuestionCategory, type SpecStats, } from './stats.js';
7
8
  export interface ComprehensionGateInfo {
8
9
  required: boolean;
9
10
  passed: boolean;
10
11
  thresholdPercent: number;
11
12
  bestScorePercent?: number;
12
13
  questionCount: number;
14
+ questionAllocation: QuestionAllocation;
15
+ optionsPerQuestion: number;
13
16
  requirementCount: number;
14
17
  scenarioCount: number;
15
18
  pendingTaskCount: number;
@@ -17,7 +20,9 @@ export interface ComprehensionGateInfo {
17
20
  }
18
21
  export interface ComprehensionGateOptions {
19
22
  tasksPath?: string | null;
23
+ planPath?: string | null;
20
24
  pendingTaskCount?: number;
25
+ artifactPresence?: ArtifactPresence;
21
26
  }
22
27
  export interface ComprehensionGateResult {
23
28
  active: boolean;
@@ -40,10 +45,13 @@ export declare function recordComprehensionPass(input: {
40
45
  changeDir: string;
41
46
  specPaths: string[];
42
47
  tasksPath?: string | null;
48
+ planPath?: string | null;
43
49
  projectConfig: ProjectConfig | null | undefined;
44
50
  scorePercent: number;
45
51
  attempt: number;
46
52
  questionCount: number;
47
53
  pendingTaskCount?: number;
54
+ artifactPresence?: ArtifactPresence;
48
55
  }): ComprehensionPassRecord;
56
+ export { OPTIONS_PER_QUESTION as comprehensionOptionsPerQuestion };
49
57
  //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import { resolveComprehensionConfig } from './config.js';
2
- import { fingerprintSpecFiles } from './fingerprint.js';
2
+ import { fingerprintApplyArtifacts } from './fingerprint.js';
3
3
  import { buildPassRecord, deleteSessionRecord, isPassValid, readPassRecord, writePassRecord, } from './pass-record.js';
4
- import { computeSpecStats } from './stats.js';
4
+ import { computeSpecStats, OPTIONS_PER_QUESTION, } from './stats.js';
5
5
  export { DEFAULT_COMPREHENSION_CONFIG, resolveComprehensionConfig, } from './config.js';
6
- export { fingerprintSpecFiles } from './fingerprint.js';
6
+ export { fingerprintApplyArtifacts, fingerprintSpecFiles } from './fingerprint.js';
7
7
  export { COMPREHENSION_PASS_FILENAME, COMPREHENSION_SESSION_FILENAME, buildPassRecord, deleteSessionRecord, isPassValid, readPassRecord, writePassRecord, } from './pass-record.js';
8
- export { computeQuestionCount, computeSpecStats, countSpecStats } from './stats.js';
8
+ export { computeQuestionAllocation, computeQuestionCount, computeSpecStats, countSpecStats, OPTIONS_PER_QUESTION, } from './stats.js';
9
9
  /**
10
10
  * Evaluate whether apply is blocked by the comprehension gate.
11
11
  */
@@ -13,17 +13,19 @@ export function checkComprehensionGate(changeDir, specPaths, projectConfig, gate
13
13
  const config = resolveComprehensionConfig(projectConfig);
14
14
  const pendingTaskCount = gateOptions.pendingTaskCount ?? 0;
15
15
  const tasksPath = gateOptions.tasksPath ?? null;
16
+ const planPath = gateOptions.planPath ?? null;
17
+ const artifactPresence = gateOptions.artifactPresence ?? {};
16
18
  if (!config.enabled) {
17
19
  return { active: false, passed: true };
18
20
  }
19
21
  if (specPaths.length === 0) {
20
22
  return { active: false, passed: true };
21
23
  }
22
- const stats = computeSpecStats(specPaths, config, pendingTaskCount);
24
+ const stats = computeSpecStats(specPaths, config, pendingTaskCount, artifactPresence);
23
25
  if (stats.requirementCount === 0) {
24
26
  return { active: false, passed: true };
25
27
  }
26
- const fingerprint = fingerprintSpecFiles(specPaths, tasksPath);
28
+ const fingerprint = fingerprintApplyArtifacts({ specPaths, tasksPath, planPath });
27
29
  const record = readPassRecord(changeDir);
28
30
  const passed = isPassValid(record, fingerprint);
29
31
  const info = {
@@ -31,6 +33,8 @@ export function checkComprehensionGate(changeDir, specPaths, projectConfig, gate
31
33
  passed,
32
34
  thresholdPercent: config.thresholdPercent,
33
35
  questionCount: stats.questionCount,
36
+ questionAllocation: stats.questionAllocation,
37
+ optionsPerQuestion: stats.optionsPerQuestion,
34
38
  requirementCount: stats.requirementCount,
35
39
  scenarioCount: stats.scenarioCount,
36
40
  pendingTaskCount: stats.pendingTaskCount,
@@ -62,8 +66,12 @@ export function recordComprehensionPass(input) {
62
66
  }
63
67
  const stats = input.questionCount > 0
64
68
  ? { questionCount: input.questionCount }
65
- : computeSpecStats(input.specPaths, config, input.pendingTaskCount ?? 0);
66
- const fingerprint = fingerprintSpecFiles(input.specPaths, input.tasksPath);
69
+ : computeSpecStats(input.specPaths, config, input.pendingTaskCount ?? 0, input.artifactPresence ?? {});
70
+ const fingerprint = fingerprintApplyArtifacts({
71
+ specPaths: input.specPaths,
72
+ tasksPath: input.tasksPath,
73
+ planPath: input.planPath,
74
+ });
67
75
  const record = buildPassRecord({
68
76
  scorePercent: input.scorePercent,
69
77
  thresholdPercent: config.thresholdPercent,
@@ -75,4 +83,5 @@ export function recordComprehensionPass(input) {
75
83
  deleteSessionRecord(input.changeDir);
76
84
  return record;
77
85
  }
86
+ export { OPTIONS_PER_QUESTION as comprehensionOptionsPerQuestion };
78
87
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,27 @@
1
1
  import type { ComprehensionConfig } from './config.js';
2
+ export declare const OPTIONS_PER_QUESTION = 3;
3
+ export type QuestionCategory = 'plan' | 'specs' | 'design' | 'proposal' | 'tasks';
4
+ export type QuestionAllocation = Partial<Record<QuestionCategory, number>>;
5
+ export interface ArtifactPresence {
6
+ hasPlan?: boolean;
7
+ hasProposal?: boolean;
8
+ hasDesign?: boolean;
9
+ hasSpecs?: boolean;
10
+ hasTasks?: boolean;
11
+ }
2
12
  export interface SpecStats {
3
13
  requirementCount: number;
4
14
  scenarioCount: number;
5
15
  pendingTaskCount: number;
6
16
  questionCount: number;
17
+ questionAllocation: QuestionAllocation;
18
+ optionsPerQuestion: number;
7
19
  }
20
+ /**
21
+ * Distribute quiz questions across artifact categories.
22
+ * When plan exists, plan receives ceil(total/2) — strictly more than any other category.
23
+ */
24
+ export declare function computeQuestionAllocation(total: number, presence: ArtifactPresence): QuestionAllocation;
8
25
  /**
9
26
  * Count requirements and scenarios across delta spec files.
10
27
  */
@@ -14,5 +31,5 @@ export declare function countSpecStats(specPaths: string[]): Pick<SpecStats, 're
14
31
  * clamp(min, max, round(req * 0.6 + scenarios * 0.15 + pendingTasks * 0.15)).
15
32
  */
16
33
  export declare function computeQuestionCount(requirementCount: number, scenarioCount: number, pendingTaskCount: number, config: Pick<ComprehensionConfig, 'minQuestions' | 'maxQuestions'>): number;
17
- export declare function computeSpecStats(specPaths: string[], config: Pick<ComprehensionConfig, 'minQuestions' | 'maxQuestions'>, pendingTaskCount?: number): SpecStats;
34
+ export declare function computeSpecStats(specPaths: string[], config: Pick<ComprehensionConfig, 'minQuestions' | 'maxQuestions'>, pendingTaskCount?: number, presence?: ArtifactPresence): SpecStats;
18
35
  //# sourceMappingURL=stats.d.ts.map
@@ -1,6 +1,89 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { parseDeltaSpec } from '../parsers/requirement-blocks.js';
3
3
  const SCENARIO_HEADER_REGEX = /^####\s*Scenario:/gim;
4
+ export const OPTIONS_PER_QUESTION = 3;
5
+ const NON_PLAN_PRIORITY = ['specs', 'design', 'proposal', 'tasks'];
6
+ function isCategoryPresent(category, presence) {
7
+ switch (category) {
8
+ case 'plan':
9
+ return presence.hasPlan === true;
10
+ case 'specs':
11
+ return presence.hasSpecs === true;
12
+ case 'design':
13
+ return presence.hasDesign === true;
14
+ case 'proposal':
15
+ return presence.hasProposal === true;
16
+ case 'tasks':
17
+ return presence.hasTasks === true;
18
+ default:
19
+ return false;
20
+ }
21
+ }
22
+ function sumAllocation(allocation) {
23
+ return Object.values(allocation).reduce((sum, n) => sum + (n ?? 0), 0);
24
+ }
25
+ /**
26
+ * Distribute quiz questions across artifact categories.
27
+ * When plan exists, plan receives ceil(total/2) — strictly more than any other category.
28
+ */
29
+ export function computeQuestionAllocation(total, presence) {
30
+ if (total <= 0) {
31
+ return {};
32
+ }
33
+ if (presence.hasPlan) {
34
+ const allocation = {};
35
+ const planQuota = Math.ceil(total / 2);
36
+ allocation.plan = planQuota;
37
+ let remainder = total - planQuota;
38
+ for (const category of NON_PLAN_PRIORITY) {
39
+ if (remainder <= 0) {
40
+ break;
41
+ }
42
+ if (!isCategoryPresent(category, presence)) {
43
+ continue;
44
+ }
45
+ allocation[category] = (allocation[category] ?? 0) + 1;
46
+ remainder--;
47
+ }
48
+ const presentOthers = NON_PLAN_PRIORITY.filter((category) => isCategoryPresent(category, presence));
49
+ let index = 0;
50
+ while (remainder > 0 && presentOthers.length > 0) {
51
+ const category = presentOthers[index % presentOthers.length];
52
+ allocation[category] = (allocation[category] ?? 0) + 1;
53
+ remainder--;
54
+ index++;
55
+ }
56
+ return allocation;
57
+ }
58
+ return computeQuestionAllocationEven(total, presence);
59
+ }
60
+ /**
61
+ * Even split when plan is absent: at least one per present category, extras specs-first.
62
+ */
63
+ function computeQuestionAllocationEven(total, presence) {
64
+ const present = NON_PLAN_PRIORITY.filter((category) => isCategoryPresent(category, presence));
65
+ if (present.length === 0) {
66
+ return {};
67
+ }
68
+ const allocation = {};
69
+ let assigned = 0;
70
+ for (const category of present) {
71
+ if (assigned >= total) {
72
+ break;
73
+ }
74
+ allocation[category] = 1;
75
+ assigned++;
76
+ }
77
+ let remainder = total - assigned;
78
+ let index = 0;
79
+ while (remainder > 0) {
80
+ const category = present[index % present.length];
81
+ allocation[category] = (allocation[category] ?? 0) + 1;
82
+ remainder--;
83
+ index++;
84
+ }
85
+ return allocation;
86
+ }
4
87
  function countScenariosInBlock(raw) {
5
88
  const matches = raw.match(SCENARIO_HEADER_REGEX);
6
89
  return matches?.length ?? 0;
@@ -33,9 +116,18 @@ export function computeQuestionCount(requirementCount, scenarioCount, pendingTas
33
116
  const raw = Math.round(requirementCount * 0.6 + scenarioCount * 0.15 + pendingTaskCount * 0.15);
34
117
  return clamp(config.minQuestions, config.maxQuestions, raw);
35
118
  }
36
- export function computeSpecStats(specPaths, config, pendingTaskCount = 0) {
119
+ export function computeSpecStats(specPaths, config, pendingTaskCount = 0, presence = {}) {
37
120
  const { requirementCount, scenarioCount } = countSpecStats(specPaths);
38
121
  const questionCount = computeQuestionCount(requirementCount, scenarioCount, pendingTaskCount, config);
39
- return { requirementCount, scenarioCount, pendingTaskCount, questionCount };
122
+ const questionAllocation = computeQuestionAllocation(questionCount, presence);
123
+ const allocationTotal = sumAllocation(questionAllocation);
124
+ return {
125
+ requirementCount,
126
+ scenarioCount,
127
+ pendingTaskCount,
128
+ questionCount: allocationTotal > 0 ? allocationTotal : questionCount,
129
+ questionAllocation,
130
+ optionsPerQuestion: OPTIONS_PER_QUESTION,
131
+ };
40
132
  }
41
133
  //# sourceMappingURL=stats.js.map
@@ -58,7 +58,7 @@ ${COMPREHENSION_QUIZ_GUIDANCE}
58
58
 
59
59
  After comprehension is passed (or not required), read every file path listed under \`contextFiles\` from the apply instructions output.
60
60
  The files depend on the schema being used:
61
- - **spec-driven**: proposal, specs, design, tasks
61
+ - **spec-driven**: proposal, specs, design, plan, tasks
62
62
  - Other schemas: follow the contextFiles from CLI output
63
63
 
64
64
  6. **Show current progress**
@@ -227,7 +227,7 @@ ${COMPREHENSION_QUIZ_GUIDANCE}
227
227
 
228
228
  After comprehension is passed (or not required), read every file path listed under \`contextFiles\` from the apply instructions output.
229
229
  The files depend on the schema being used:
230
- - **spec-driven**: proposal, specs, design, tasks
230
+ - **spec-driven**: proposal, specs, design, plan, tasks
231
231
  - Other schemas: follow the contextFiles from CLI output
232
232
 
233
233
  6. **Show current progress**
@@ -4,6 +4,6 @@
4
4
  * Interpolated into apply skill and slash command templates so agents run
5
5
  * a spec comprehension gate before implementation.
6
6
  */
7
- export declare const COMPREHENSION_QUIZ_GUIDANCE = "4. **Comprehension quiz (required before implementation)**\n\n After `openspec instructions apply --change \"<name>\" --json`, check comprehension status:\n\n - If `missingComprehension` is true OR `comprehension.required && !comprehension.passed`:\n - Do NOT edit application source code or mark task checkboxes yet\n - Read `contextFiles.proposal`, `contextFiles.design`, `contextFiles.specs`, and `contextFiles.tasks` (or the `tasks` array in apply JSON)\n - Use `comprehension.questionCount` from the JSON as the number of questions\n\n **Generate questions**\n - Create exactly `comprehension.questionCount` multiple-choice questions\n - Each question MUST map to one artifact category:\n - **Proposal**: motivation, scope, or impact from `proposal.md`\n - **Design**: decisions, trade-offs, or approach from `design.md`\n - **Specs**: a `### Requirement:` or `#### Scenario:` from delta specs\n - **Tasks**: conceptual understanding of the implementation plan from pending (unchecked) tasks\n - When proposal, design, specs (with requirements), and pending tasks all exist, include at least one question from each category; fill remaining slots from any category\n - Do NOT use completed tasks as question sources\n - Each question: 4 options (1 correct from the source substance, 3 plausible distractors from other proposal/design/requirements/scenarios/task substance in the change)\n\n **Task question quality**\n - Test scope, approach, dependencies, sequencing rationale, or alignment with proposal/design\n - **Forbidden**: task numbers, checklist order, \"which task says X verbatim\", or answers identifiable only by task index or checkbox position\n - Good: \"What is the primary file where quiz rules are centralized?\" (answer from task substance)\n - Bad: \"Which task number updates `comprehension-guidance.ts`?\" or \"What is the exact text of task 2.1?\"\n\n **Present and grade**\n - Present each question in chat with labeled options (A/B/C/D or 1\u20134)\n - Ask ONE question at a time; after each, STOP and wait for the user's answer before the next question\n - NEVER select answers yourself, infer what the user would pick, or call `--record-comprehension-pass` until the user has answered every question\n - On Cursor, you may use the **AskUserQuestion tool** instead of plain chat for this step.\n - Grade: `score_percent = round(correct / question_count * 100)`\n - Pass when `score_percent >= comprehension.thresholdPercent` (default 80)\n\n **On failure (score below threshold)**\n - Announce score and that a new quiz is required\n - Update `.comprehension-session.yaml` in the change dir with `used_sources` from this attempt\n - Generate a NEW question set using different proposal/design/requirement/scenario/task sources (avoid `used_sources`)\n - Retry until pass\n\n **On pass**\n ```bash\n openspec instructions apply --change \"<name>\" --record-comprehension-pass --score <score> --attempt <n> --question-count <count> --json\n ```\n - Re-run `openspec instructions apply --change \"<name>\" --json`\n - Confirm `state` is `\"ready\"` and `comprehension.passed` is true before continuing\n\n **Output template**\n ```\n ## Applying: <change-name> \u2014 comprehension check\n\n Proposal, design, specs (<requirementCount> requirements, <scenarioCount> scenarios), tasks (<pendingTaskCount> pending) \u2192 <questionCount> questions\n\n Question 1/N: ...\n ...\n \u2713 Comprehension passed (<score>%, attempt <n>)\n ```\n\n Then continue to step 5 (show progress) and implementation.";
7
+ export declare const COMPREHENSION_QUIZ_GUIDANCE = "4. **Comprehension quiz (required before implementation)**\n\n After `openspec instructions apply --change \"<name>\" --json`, check comprehension status:\n\n - If `missingComprehension` is true OR `comprehension.required && !comprehension.passed`:\n - Do NOT edit application source code or mark task checkboxes yet\n - Read `contextFiles.proposal`, `contextFiles.design`, `contextFiles.specs`, `contextFiles.plan`, and `contextFiles.tasks` (or the `tasks` array in apply JSON)\n - Use `comprehension.questionCount` and `comprehension.questionAllocation` from the JSON\n\n **Generate questions**\n - Create exactly `comprehension.questionCount` multiple-choice questions\n - **Follow `comprehension.questionAllocation`** \u2014 generate the exact count per category (e.g. plan\u00D74, specs\u00D71); do not invent your own split\n - Each question maps to one artifact category:\n - **Proposal**: motivation, scope, or impact from `proposal.md`\n - **Design**: decisions, trade-offs, or approach from `design.md`\n - **Specs**: a `### Requirement:` or `#### Scenario:` from delta specs\n - **Plan**: code map, file targets, test plan, sequencing, or alignment with design from `plan.md`\n - **Tasks**: conceptual understanding of the implementation approach from pending (unchecked) tasks\n - Do NOT use completed tasks as question sources\n - Each question: **3 options** (`comprehension.optionsPerQuestion`, default 3) \u2014 1 correct from source substance, 2 plausible distractors from other proposal/design/spec/plan/task substance in the change\n\n **Plan question quality**\n - Test code map, file targets, test plan, sequencing, or alignment with design\n - **Forbidden**: section numbers, verbatim headings, trivia answerable without reading plan substance\n\n **Task question quality**\n - Test scope, approach, dependencies, sequencing rationale, or alignment with proposal/design/plan\n - **Forbidden**: task numbers, checklist order, \"which task says X verbatim\", or answers identifiable only by task index or checkbox position\n - Good: \"What is the primary file where quiz rules are centralized?\" (answer from task substance)\n - Bad: \"Which task number updates `comprehension-guidance.ts`?\" or \"What is the exact text of task 2.1?\"\n\n **Present and grade**\n - Present each question in chat with labeled options (A/B/C/D or 1\u20134)\n - Ask ONE question at a time; after each, STOP and wait for the user's answer before the next question\n - NEVER select answers yourself, infer what the user would pick, or call `--record-comprehension-pass` until the user has answered every question\n - On Cursor, you may use the **AskUserQuestion tool** instead of plain chat for this step.\n - Grade: `score_percent = round(correct / question_count * 100)`\n - Pass when `score_percent >= comprehension.thresholdPercent` (default 80)\n\n **On failure (score below threshold)**\n - Announce score and that a new quiz is required\n - Update `.comprehension-session.yaml` in the change dir with `used_sources` from this attempt\n - Generate a NEW question set using different proposal/design/spec/plan/task sources (avoid `used_sources`)\n - Retry until pass\n\n **On pass**\n ```bash\n openspec instructions apply --change \"<name>\" --record-comprehension-pass --score <score> --attempt <n> --question-count <count> --json\n ```\n - Re-run `openspec instructions apply --change \"<name>\" --json`\n - Confirm `state` is `\"ready\"` and `comprehension.passed` is true before continuing\n\n **Output template**\n ```\n ## Applying: <change-name> \u2014 comprehension check\n\n plan\u00D7N, specs\u00D7N, design\u00D7N, proposal\u00D7N, tasks\u00D7N \u2192 <questionCount> questions (3 options each)\n\n Question 1/N: ...\n ...\n \u2713 Comprehension passed (<score>%, attempt <n>)\n ```\n\n Then continue to step 5 (show progress) and implementation.";
8
8
  export declare const COMPREHENSION_APPLY_GUARDRAIL = "- NEVER implement code or mark tasks while `missingComprehension` is true\n- NEVER skip the comprehension quiz when the apply JSON requires it\n- NEVER answer comprehension quiz questions yourself \u2014 the human developer must answer every question\n- NEVER call `--record-comprehension-pass` until the user has answered every question\n- If the user asks to skip the quiz, refuse and explain they must pass or set comprehension.enabled: false in openspec/config.yaml";
9
9
  //# sourceMappingURL=comprehension-guidance.d.ts.map
@@ -11,22 +11,27 @@ export const COMPREHENSION_QUIZ_GUIDANCE = `4. **Comprehension quiz (required be
11
11
 
12
12
  - If \`missingComprehension\` is true OR \`comprehension.required && !comprehension.passed\`:
13
13
  - Do NOT edit application source code or mark task checkboxes yet
14
- - Read \`contextFiles.proposal\`, \`contextFiles.design\`, \`contextFiles.specs\`, and \`contextFiles.tasks\` (or the \`tasks\` array in apply JSON)
15
- - Use \`comprehension.questionCount\` from the JSON as the number of questions
14
+ - Read \`contextFiles.proposal\`, \`contextFiles.design\`, \`contextFiles.specs\`, \`contextFiles.plan\`, and \`contextFiles.tasks\` (or the \`tasks\` array in apply JSON)
15
+ - Use \`comprehension.questionCount\` and \`comprehension.questionAllocation\` from the JSON
16
16
 
17
17
  **Generate questions**
18
18
  - Create exactly \`comprehension.questionCount\` multiple-choice questions
19
- - Each question MUST map to one artifact category:
19
+ - **Follow \`comprehension.questionAllocation\`** generate the exact count per category (e.g. plan×4, specs×1); do not invent your own split
20
+ - Each question maps to one artifact category:
20
21
  - **Proposal**: motivation, scope, or impact from \`proposal.md\`
21
22
  - **Design**: decisions, trade-offs, or approach from \`design.md\`
22
23
  - **Specs**: a \`### Requirement:\` or \`#### Scenario:\` from delta specs
23
- - **Tasks**: conceptual understanding of the implementation plan from pending (unchecked) tasks
24
- - When proposal, design, specs (with requirements), and pending tasks all exist, include at least one question from each category; fill remaining slots from any category
24
+ - **Plan**: code map, file targets, test plan, sequencing, or alignment with design from \`plan.md\`
25
+ - **Tasks**: conceptual understanding of the implementation approach from pending (unchecked) tasks
25
26
  - Do NOT use completed tasks as question sources
26
- - Each question: 4 options (1 correct from the source substance, 3 plausible distractors from other proposal/design/requirements/scenarios/task substance in the change)
27
+ - Each question: **3 options** (\`comprehension.optionsPerQuestion\`, default 3) — 1 correct from source substance, 2 plausible distractors from other proposal/design/spec/plan/task substance in the change
28
+
29
+ **Plan question quality**
30
+ - Test code map, file targets, test plan, sequencing, or alignment with design
31
+ - **Forbidden**: section numbers, verbatim headings, trivia answerable without reading plan substance
27
32
 
28
33
  **Task question quality**
29
- - Test scope, approach, dependencies, sequencing rationale, or alignment with proposal/design
34
+ - Test scope, approach, dependencies, sequencing rationale, or alignment with proposal/design/plan
30
35
  - **Forbidden**: task numbers, checklist order, "which task says X verbatim", or answers identifiable only by task index or checkbox position
31
36
  - Good: "What is the primary file where quiz rules are centralized?" (answer from task substance)
32
37
  - Bad: "Which task number updates \`comprehension-guidance.ts\`?" or "What is the exact text of task 2.1?"
@@ -36,7 +41,7 @@ export const COMPREHENSION_QUIZ_GUIDANCE = `4. **Comprehension quiz (required be
36
41
  **On failure (score below threshold)**
37
42
  - Announce score and that a new quiz is required
38
43
  - Update \`.comprehension-session.yaml\` in the change dir with \`used_sources\` from this attempt
39
- - Generate a NEW question set using different proposal/design/requirement/scenario/task sources (avoid \`used_sources\`)
44
+ - Generate a NEW question set using different proposal/design/spec/plan/task sources (avoid \`used_sources\`)
40
45
  - Retry until pass
41
46
 
42
47
  **On pass**
@@ -50,7 +55,7 @@ export const COMPREHENSION_QUIZ_GUIDANCE = `4. **Comprehension quiz (required be
50
55
  \`\`\`
51
56
  ## Applying: <change-name> — comprehension check
52
57
 
53
- Proposal, design, specs (<requirementCount> requirements, <scenarioCount> scenarios), tasks (<pendingTaskCount> pending) → <questionCount> questions
58
+ plan×N, specs×N, design×N, proposal×N, tasks×N → <questionCount> questions (3 options each)
54
59
 
55
60
  Question 1/N: ...
56
61
  ...
@@ -95,7 +95,7 @@ The artifact types and their purpose depend on the schema. Use the \`instruction
95
95
 
96
96
  Common artifact patterns:
97
97
 
98
- **spec-driven schema** (proposal → specs → design → tasks):
98
+ **spec-driven schema** (proposal → specs → design → plan → tasks):
99
99
  - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact.
100
100
  - The Capabilities section is critical - each capability listed will need a spec file.
101
101
  - **specs/<capability>/spec.md**: Create one spec per capability listed in the proposal's Capabilities section (use the capability name, not the change name).
@@ -216,7 +216,7 @@ The artifact types and their purpose depend on the schema. Use the \`instruction
216
216
 
217
217
  Common artifact patterns:
218
218
 
219
- **spec-driven schema** (proposal → specs → design → tasks):
219
+ **spec-driven schema** (proposal → specs → design → plan → tasks):
220
220
  - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact.
221
221
  - The Capabilities section is critical - each capability listed will need a spec file.
222
222
  - **specs/<capability>/spec.md**: Create one spec per capability listed in the proposal's Capabilities section (use the capability name, not the change name).
@@ -47,7 +47,7 @@ I'll walk you through a complete change cycle—from idea to implementation—us
47
47
  1. Pick a small, real task in your codebase
48
48
  2. Explore the problem briefly
49
49
  3. Create a change (the container for our work)
50
- 4. Build the artifacts: proposal → specs → design → tasks
50
+ 4. Build the artifacts: proposal → specs → design → plan → tasks
51
51
  5. Implement the tasks
52
52
  6. Archive the completed change
53
53
 
@@ -170,7 +170,7 @@ Now let's create a change to hold our work.
170
170
  \`\`\`
171
171
  ## Creating a Change
172
172
 
173
- A "change" in OpenSpec is a container for all the thinking and planning around a piece of work. It lives at the \`changeRoot\` reported by \`openspec status --change "<name>" --json\` and holds your artifacts—proposal, specs, design, tasks.
173
+ A "change" in OpenSpec is a container for all the thinking and planning around a piece of work. It lives at the \`changeRoot\` reported by \`openspec status --change "<name>" --json\` and holds your artifacts—proposal, specs, design, plan, tasks.
174
174
 
175
175
  Let me create one for our task.
176
176
  \`\`\`
@@ -4,12 +4,13 @@ import { PROMPT_CLARIFY, PROMPT_OPEN_ENDED } from './user-prompt-guidance.js';
4
4
  export function getOpsxProposeSkillTemplate() {
5
5
  return {
6
6
  name: 'openspec-propose',
7
- description: 'Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.',
7
+ description: 'Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, plan, and tasks ready for implementation.',
8
8
  instructions: `Propose a new change - create the change and generate all artifacts in one step.
9
9
 
10
10
  I'll create a change with artifacts:
11
11
  - proposal.md (what & why)
12
12
  - design.md (how)
13
+ - plan.md (file-level implementation plan)
13
14
  - tasks.md (implementation steps)
14
15
 
15
16
  When ready to implement, run /opsx:apply
@@ -125,6 +126,7 @@ export function getOpsxProposeCommandTemplate() {
125
126
  I'll create a change with artifacts:
126
127
  - proposal.md (what & why)
127
128
  - design.md (how)
129
+ - plan.md (file-level implementation plan)
128
130
  - tasks.md (implementation steps)
129
131
 
130
132
  When ready to implement, run /opsx:apply
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codewalla_india/openspec",
3
- "version": "1.0.04",
3
+ "version": "1.0.05",
4
4
  "description": "AI-native system for spec-driven development",
5
5
  "keywords": [
6
6
  "openspec",
@@ -1,6 +1,6 @@
1
1
  name: spec-driven
2
2
  version: 1
3
- description: Default OpenSpec workflow - proposal → specs → design → tasks
3
+ description: Default OpenSpec workflow - proposal → specs → design → plan → tasks
4
4
  artifacts:
5
5
  - id: proposal
6
6
  generates: proposal.md
@@ -24,7 +24,7 @@ artifacts:
24
24
  Keep it concise (1-2 pages). Focus on the "why" not the "how" -
25
25
  implementation details belong in design.md.
26
26
 
27
- This is the foundation - specs, design, and tasks all build on this.
27
+ This is the foundation - specs, design, plan, and tasks all build on this.
28
28
  requires: []
29
29
 
30
30
  - id: specs
@@ -110,6 +110,26 @@ artifacts:
110
110
  requires:
111
111
  - proposal
112
112
 
113
+ - id: plan
114
+ generates: plan.md
115
+ description: File-level implementation plan with code map
116
+ template: plan.md
117
+ instruction: |
118
+ Create a concrete implementation plan from design and specs.
119
+
120
+ Sections:
121
+ - **Code map**: Files to create, modify, or delete
122
+ - **Implementation order**: Sequenced steps at file/module level
123
+ - **Test plan**: How to verify the change
124
+ - **Risks**: Known risks with mitigations ([Risk] → Mitigation)
125
+ - **Done definition**: Objective criteria for completion
126
+
127
+ Do NOT restate behavioral requirements — link to specs.
128
+ Do NOT duplicate design decisions — reference design.md.
129
+ requires:
130
+ - specs
131
+ - design
132
+
113
133
  - id: tasks
114
134
  generates: tasks.md
115
135
  description: Implementation checklist with trackable tasks
@@ -139,14 +159,17 @@ artifacts:
139
159
  - [ ] 2.2 Add CSV formatting utilities
140
160
  ```
141
161
 
142
- Reference specs for what needs to be built, design for how to build it.
162
+ Derive tasks from plan.md code map. Reference specs for what to build,
163
+ design for architectural decisions, and plan for file-level targets.
164
+ Include file/module references where helpful.
143
165
  Each task should be verifiable - you know when it's done.
144
166
  requires:
145
167
  - specs
146
168
  - design
169
+ - plan
147
170
 
148
171
  apply:
149
- requires: [tasks]
172
+ requires: [plan, tasks]
150
173
  tracks: tasks.md
151
174
  instruction: |
152
175
  Read context files, work through pending tasks, mark complete as you go.
@@ -0,0 +1,19 @@
1
+ ## Code Map
2
+
3
+ <!-- files to create/modify/delete -->
4
+
5
+ ## Implementation Order
6
+
7
+ <!-- sequenced steps at file/module level -->
8
+
9
+ ## Test Plan
10
+
11
+ <!-- how to verify -->
12
+
13
+ ## Risks
14
+
15
+ <!-- [Risk] → Mitigation -->
16
+
17
+ ## Done Definition
18
+
19
+ <!-- objective completion criteria -->