sw-plan 0.1.14 → 0.1.16

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.
@@ -0,0 +1,408 @@
1
+ import { readFileSync, writeFileSync, existsSync, createWriteStream, mkdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { QuestionsOutputSchema, runStructuredStage, setAllowedSessionDir, } from './index.js';
4
+ import z from 'zod';
5
+ // Schema for sections output
6
+ const SectionsOutputSchema = z.object({
7
+ sections: z.array(z.object({
8
+ sectionId: z.string().describe('Unique section identifier (lowercase, hyphenated, e.g., "executive-summary"). This will be used as the directory name.'),
9
+ title: z.string().describe('Section title'),
10
+ description: z.string().describe('Brief description of what this section should contain'),
11
+ })).describe('List of document sections to generate'),
12
+ });
13
+ // Schema for section variant output
14
+ const SectionVariantOutputSchema = z.object({
15
+ outputFilePath: z.string().describe('The relative path to the file where the section variant was written')
16
+ });
17
+ /**
18
+ * Compile2 - Multi-stage document compilation
19
+ * Stage 1: Generate sections list
20
+ * Stage 2: Ask clarifying questions
21
+ * Stage 3: Generate 3 variants per section (with refinement pass)
22
+ */
23
+ export class Compile2Runner {
24
+ logStream;
25
+ options;
26
+ docTypeLabels = {
27
+ 'design-doc': 'Technical Design Document',
28
+ 'brd': 'BRD (Business Requirements Document)',
29
+ 'prd': 'PRD (Product Requirements Document)',
30
+ 'rfp': 'RFP (Request for Proposal)',
31
+ 'sow': 'SOW (Statement of Work)',
32
+ 'technical-spec': 'Technical Specification',
33
+ 'user-story': 'User Stories',
34
+ };
35
+ docQuestions = {
36
+ 'brd': [
37
+ 'What problem are we solving?',
38
+ 'Who is it for?',
39
+ 'Why does it matter (business impact)?',
40
+ 'What does success look like (metrics / outcomes)?',
41
+ 'What must the solution do (requirements)?',
42
+ 'What constraints exist (tech, legal, timeline, budget)?',
43
+ 'What is explicitly out of scope?',
44
+ 'How will we know it\'s done (acceptance criteria)?',
45
+ ],
46
+ };
47
+ constructor(options) {
48
+ this.options = options;
49
+ // Set up log file
50
+ const logFilePath = options.logFile || join(options.cwd, 'compile.log');
51
+ this.logStream = createWriteStream(logFilePath, { flags: 'a' });
52
+ }
53
+ log(message) {
54
+ const timestamp = new Date().toISOString();
55
+ this.logStream.write(`[${timestamp}] ${message}\n`);
56
+ }
57
+ /**
58
+ * Build the prompt for generating document sections
59
+ */
60
+ generateSectionsPrompt(filePath, docType) {
61
+ const docLabel = this.docTypeLabels[docType] || 'Document';
62
+ const docQuestions = this.docQuestions[docType] || this.docQuestions['brd'];
63
+ return `You are a senior technical manager analyzing meeting notes to structure a ${docLabel}.
64
+
65
+ The transcript is in a file at: ${filePath}
66
+
67
+ Your task:
68
+ 1. Read the transcript file
69
+ 2. Analyze the content
70
+ 3. **Propose document sections** - Generate a list of 3-8 sections that should be included in the ${docLabel}
71
+
72
+ The purpose of this document is to answer these questions:
73
+ ${docQuestions.join('\n')}
74
+
75
+ Based on the transcript content, propose sections that will comprehensively cover all aspects mentioned.
76
+
77
+ IMPORTANT:
78
+ - Each section must have a sectionId (lowercase, hyphenated, e.g., "executive-summary", "problem-statement")
79
+ - The sectionId will be used as a directory name, so it must be filesystem-safe
80
+ - Each section should have a clear title and description
81
+ - Sections should follow a logical flow
82
+ - Consider the document type (${docLabel}) when structuring sections
83
+ - Make sections specific to the content discussed in the transcript
84
+
85
+ Output your response as structured JSON with a "sections" array. Each section must have "sectionId", "title", and "description" fields.`;
86
+ }
87
+ /**
88
+ * Build the prompt for asking clarifying questions based on approved sections
89
+ */
90
+ askQuestionsPrompt(filePath, sections, docType) {
91
+ const docLabel = this.docTypeLabels[docType] || 'Document';
92
+ const sectionTitles = sections.map(s => `- ${s.title}`).join('\n');
93
+ return `You are a senior technical manager creating a ${docLabel} from meeting notes.
94
+
95
+ The transcript is in a file at: ${filePath}
96
+
97
+ The document will have these sections:
98
+ ${sectionTitles}
99
+
100
+ Your task:
101
+ 1. Read the transcript file
102
+ 2. Analyze the content against the planned sections
103
+ 3. **Ask clarifying questions** - You MUST ask 1-4 clarifying questions about:
104
+ - Specific requirements or constraints for the implementation
105
+ - Preferences for third-party services vs self-hosted solutions
106
+ - Authentication methods or existing auth patterns to maintain
107
+ - Data storage preferences or existing database patterns
108
+ - Any breaking changes they're willing to accept
109
+ - Scale expectations (current users, growth plans)
110
+ - Budget constraints (API costs, infrastructure)
111
+ - Any gaps or ambiguities in the sections that need clarification
112
+
113
+ IMPORTANT:
114
+ - You MUST ask at least 1 question - questions are REQUIRED
115
+ - Do NOT ask contradictory questions. Questions must be logically consistent with each other.
116
+ - You MUST AVOID migrations at all cost, ALWAYS try to make things work side-by-side.
117
+ - Act like you're a founder and do it in a simplest way as possible, just make sure it works.
118
+ - ALWAYS use Context7 MCP for retrieving up to date documentation for the library or SDK before integration
119
+
120
+ ## Output Format
121
+
122
+ Output your questions in this EXACT JSON format:
123
+
124
+ \`\`\`json
125
+ {
126
+ "questions": [
127
+ {
128
+ "question": "Your question text?",
129
+ "options": ["Option 1", "Option 2", "Option 3"],
130
+ "additionalInfo": "Optional context about why this matters"
131
+ }
132
+ ]
133
+ }
134
+ \`\`\`
135
+
136
+ Rules:
137
+ - You MUST provide at least 1 question (1-4 questions is ideal)
138
+ - NEVER use vague options like "Not sure", "Recommend me", "Let you decide", "Other", or "I don't know"
139
+ - Each option MUST be a specific implementation approach, tool, or technology`;
140
+ }
141
+ /**
142
+ * Build the prompt for generating a section variant
143
+ */
144
+ buildSectionVariantPrompt(section, variantNumber, transcriptFile, sections, clarifications, docType, targetDir) {
145
+ const docLabel = this.docTypeLabels[docType] || 'Document';
146
+ const sectionContext = sections.map(s => `- ${s.title}: ${s.description}`).join('\n');
147
+ return `You are a technical writer creating a ${docLabel} from meeting notes.
148
+
149
+ The transcript is in a file at: ${transcriptFile}
150
+ Clarifications: ${clarifications}
151
+
152
+ Document sections context:
153
+ ${sectionContext}
154
+
155
+ Your task:
156
+ Write the "${section.title}" section (Variant ${variantNumber} of 3) for the ${docLabel}.
157
+
158
+ Section description: ${section.description}
159
+
160
+ CRITICAL REQUIREMENTS - WRITING STYLE:
161
+ - Write in SHORT, DIRECT sentences - no elaborate or flowery language
162
+ - State facts directly without explanation or context
163
+ - Use bullet points where appropriate
164
+ - Maximum 2-3 SHORT paragraphs (3-4 sentences each)
165
+ - NO introductory phrases, NO transition words, NO filler text
166
+ - Get straight to the point - first sentence should contain key information
167
+
168
+ CRITICAL REQUIREMENTS - CONTENT:
169
+ - This is variant ${variantNumber} - use a slightly different structure or emphasis than other variants
170
+ - Read the transcript file for context
171
+ - Use ONLY specific facts from the transcript and clarifications
172
+ - If information isn't in the transcript/clarifications, DON'T include it
173
+ - NO generic statements, NO assumptions, NO speculation
174
+ - NO boilerplate text or standard document language
175
+ - Focus ONLY on what was actually discussed
176
+
177
+ TECHNICAL REQUIREMENTS:
178
+ - Write ONLY this section, not the entire document
179
+ - Write the section to a markdown file named "variant-${variantNumber}.md" in the current directory (${targetDir})
180
+ - You can ONLY write files to the current directory - writing outside this directory will fail
181
+
182
+ After writing the section, return the relative path to the output file in the structured output.`;
183
+ }
184
+ /**
185
+ * Build the prompt for refining a section variant
186
+ */
187
+ refineSectionVariantPrompt(section, variantNumber, sectionFile, transcriptFile, clarifications, docType, targetDir) {
188
+ const docLabel = this.docTypeLabels[docType] || 'Document';
189
+ return `You are a technical editor refining a section of a ${docLabel}.
190
+
191
+ The section draft is in a file at: ${sectionFile}
192
+ The transcript is in a file at: ${transcriptFile}
193
+ Clarifications: ${clarifications}
194
+
195
+ Your task:
196
+ Refine the "${section.title}" section (Variant ${variantNumber}) to be MORE CONCISE and FACT-BASED.
197
+
198
+ Section description: ${section.description}
199
+
200
+ CRITICAL REQUIREMENTS - AGGRESSIVE EDITING:
201
+ - Read the draft and CUT IT DOWN by at least 30-40%
202
+ - Remove ALL unnecessary words - every word must earn its place
203
+ - Replace elaborate sentences with short, direct statements
204
+ - Remove ALL introductory phrases, filler text, and transitions
205
+ - Remove ALL generic statements and boilerplate language
206
+ - Keep ONLY specific facts from the transcript and clarifications
207
+ - If something isn't a concrete fact from the source material, DELETE IT
208
+ - Maximum 2-3 SHORT paragraphs (3-4 sentences each)
209
+
210
+ VERIFICATION:
211
+ - Every statement must be directly traceable to the transcript or clarifications
212
+ - NO assumptions, NO elaborations, NO context-setting
213
+ - NO "will", "should", "could" - only concrete facts about what IS
214
+
215
+ TECHNICAL REQUIREMENTS:
216
+ - Write the refined section to a markdown file named "variant-${variantNumber}.md" in the current directory (${targetDir})
217
+ - You can ONLY write files to the current directory - writing outside this directory will fail
218
+
219
+ After writing the refined section, return the relative path to the output file in the structured output.`;
220
+ }
221
+ /**
222
+ * Run the compile2 process
223
+ */
224
+ async run() {
225
+ try {
226
+ this.log('Starting compile2 command');
227
+ this.log(`Transcript file: ${this.options.transcriptFile}`);
228
+ this.log(`Doc type: ${this.options.docType}`);
229
+ this.log(`CWD: ${this.options.cwd}`);
230
+ // Set up write validation hook to ensure agent can't write outside session directory
231
+ setAllowedSessionDir(this.options.cwd);
232
+ this.log(`Write validation enabled for session directory: ${this.options.cwd}`);
233
+ // Determine which stage we're at by checking for input files
234
+ const userSectionsPath = join(this.options.cwd, 'inputs', 'user_sections.json');
235
+ const answersPath = join(this.options.cwd, 'inputs', 'answers.json');
236
+ const hasUserSections = existsSync(userSectionsPath);
237
+ const hasAnswers = existsSync(answersPath);
238
+ this.log(`Checking stage: hasUserSections=${hasUserSections}, hasAnswers=${hasAnswers}`);
239
+ if (!hasUserSections) {
240
+ // Stage 1: Generate sections
241
+ return await this.handleSectionsGeneration();
242
+ }
243
+ else if (!hasAnswers) {
244
+ // Stage 2: Ask questions (sections approved, no answers yet)
245
+ return await this.handleQuestions();
246
+ }
247
+ else {
248
+ // Stage 3: Generate variants (sections + answers provided)
249
+ return await this.handleVariantGeneration();
250
+ }
251
+ }
252
+ catch (error) {
253
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
254
+ const errorStack = error instanceof Error ? error.stack : '';
255
+ this.log(`ERROR: ${errorMessage}`);
256
+ if (errorStack) {
257
+ this.log(`Stack trace: ${errorStack}`);
258
+ }
259
+ this.logStream.end();
260
+ throw error;
261
+ }
262
+ }
263
+ /**
264
+ * Stage 1: Generate document sections
265
+ */
266
+ async handleSectionsGeneration() {
267
+ if (!process.env.ANTHROPIC_API_KEY) {
268
+ throw new Error('ANTHROPIC_API_KEY environment variable is required');
269
+ }
270
+ this.log('Stage 1: Generating document sections...');
271
+ const sectionsPrompt = this.generateSectionsPrompt(this.options.transcriptFile, this.options.docType);
272
+ // Call Claude SDK to generate sections
273
+ const result = await runStructuredStage(sectionsPrompt, SectionsOutputSchema, this.options.cwd, 'json', this.options.sessionId);
274
+ // Save sections to file
275
+ const sectionsFilePath = this.options.sectionsFile || join(this.options.cwd, 'sections.json');
276
+ const sectionsData = {
277
+ sessionId: result.sessionId,
278
+ sections: result.output.sections || []
279
+ };
280
+ writeFileSync(sectionsFilePath, JSON.stringify(sectionsData, null, 2), 'utf-8');
281
+ this.log(`Sections saved to: ${sectionsFilePath}`);
282
+ this.log(`Generated ${sectionsData.sections.length} sections`);
283
+ this.logStream.end();
284
+ return {
285
+ type: 'sections_saved',
286
+ sectionsFile: sectionsFilePath,
287
+ sessionId: result.sessionId,
288
+ sectionCount: sectionsData.sections.length,
289
+ };
290
+ }
291
+ /**
292
+ * Stage 2: Ask clarifying questions based on approved sections
293
+ */
294
+ async handleQuestions() {
295
+ if (!process.env.ANTHROPIC_API_KEY) {
296
+ throw new Error('ANTHROPIC_API_KEY environment variable is required');
297
+ }
298
+ this.log('Stage 2: Asking clarifying questions...');
299
+ // Read user approved sections from file
300
+ const userSectionsPath = join(this.options.cwd, 'inputs', 'user_sections.json');
301
+ const sections = JSON.parse(readFileSync(userSectionsPath, 'utf-8'));
302
+ this.log(`Using ${sections.length} approved sections from ${userSectionsPath}`);
303
+ const questionsPrompt = this.askQuestionsPrompt(this.options.transcriptFile, sections, this.options.docType);
304
+ // Call Claude SDK to get questions
305
+ const result = await runStructuredStage(questionsPrompt, QuestionsOutputSchema, this.options.cwd, 'json', this.options.sessionId);
306
+ // Save questions to file
307
+ const questionsFilePath = this.options.questionsFile || join(this.options.cwd, 'questions.json');
308
+ const questionsData = {
309
+ sessionId: result.sessionId,
310
+ questions: result.output.questions || []
311
+ };
312
+ writeFileSync(questionsFilePath, JSON.stringify(questionsData, null, 2), 'utf-8');
313
+ this.log(`Questions saved to: ${questionsFilePath}`);
314
+ this.log(`Generated ${questionsData.questions.length} questions`);
315
+ this.logStream.end();
316
+ return {
317
+ type: 'questions_saved',
318
+ questionsFile: questionsFilePath,
319
+ sessionId: result.sessionId,
320
+ questionCount: questionsData.questions.length,
321
+ };
322
+ }
323
+ /**
324
+ * Stage 3: Generate 3 variants per section with refinement pass
325
+ */
326
+ async handleVariantGeneration() {
327
+ if (!process.env.ANTHROPIC_API_KEY) {
328
+ throw new Error('ANTHROPIC_API_KEY environment variable is required');
329
+ }
330
+ this.log('Stage 3: Generating section variants...');
331
+ // Read user sections and answers from input files
332
+ const userSectionsPath = join(this.options.cwd, 'inputs', 'user_sections.json');
333
+ const answersPath = join(this.options.cwd, 'inputs', 'answers.json');
334
+ const sections = JSON.parse(readFileSync(userSectionsPath, 'utf-8'));
335
+ const answers = JSON.parse(readFileSync(answersPath, 'utf-8'));
336
+ this.log(`Generating 3 variants for ${sections.length} sections`);
337
+ this.log(`Using answers from ${answersPath}`);
338
+ // Convert answers array to string format for prompts
339
+ const clarifications = answers.map((a) => `Q: ${a.question}\nA: ${a.answer}`).join('\n\n');
340
+ let totalVariants = 0;
341
+ // Create sections directory
342
+ const sectionsBaseDir = join(this.options.cwd, 'sections');
343
+ if (!existsSync(sectionsBaseDir)) {
344
+ mkdirSync(sectionsBaseDir, { recursive: true });
345
+ this.log(`Created sections directory: ${sectionsBaseDir}`);
346
+ }
347
+ // Prepare all directories first
348
+ for (let i = 0; i < sections.length; i++) {
349
+ const section = sections[i];
350
+ const sectionId = section.sectionId;
351
+ // Create section directory under sections/
352
+ const sectionDir = join(sectionsBaseDir, sectionId);
353
+ if (!existsSync(sectionDir)) {
354
+ mkdirSync(sectionDir, { recursive: true });
355
+ }
356
+ // Create refined subdirectory
357
+ const refinedDir = join(sectionDir, 'refined');
358
+ if (!existsSync(refinedDir)) {
359
+ mkdirSync(refinedDir, { recursive: true });
360
+ }
361
+ this.log(`Prepared directories for section: ${section.title}`);
362
+ }
363
+ // Generate all variants in parallel
364
+ const variantTasks = [];
365
+ for (let i = 0; i < sections.length; i++) {
366
+ const section = sections[i];
367
+ const sectionId = section.sectionId;
368
+ const sectionDir = join(sectionsBaseDir, sectionId);
369
+ const refinedDir = join(sectionDir, 'refined');
370
+ // Generate 3 variants for this section
371
+ for (let variantNum = 1; variantNum <= 3; variantNum++) {
372
+ const task = (async () => {
373
+ this.log(`Starting generation: ${section.title} - Variant ${variantNum}/3`);
374
+ // Pass 1: Generate initial variant in section directory
375
+ const generatePrompt = this.buildSectionVariantPrompt(section, variantNum, this.options.transcriptFile, sections, clarifications, this.options.docType, sectionDir);
376
+ const generateResult = await runStructuredStage(generatePrompt, SectionVariantOutputSchema, sectionDir, 'json', this.options.sessionId);
377
+ const initialFilePath = join(sectionDir, `variant-${variantNum}.md`);
378
+ this.log(` Initial draft complete: ${section.title} - Variant ${variantNum}`);
379
+ // Pass 2: Refine the variant in refined subdirectory
380
+ const refinePrompt = this.refineSectionVariantPrompt(section, variantNum, initialFilePath, this.options.transcriptFile, clarifications, this.options.docType, refinedDir);
381
+ await runStructuredStage(refinePrompt, SectionVariantOutputSchema, refinedDir, 'json', this.options.sessionId);
382
+ this.log(` Refinement complete: ${section.title} - Variant ${variantNum}`);
383
+ return 1; // Return 1 for counting
384
+ })();
385
+ variantTasks.push(task);
386
+ }
387
+ }
388
+ this.log(`\nGenerating ${variantTasks.length} variants in parallel...`);
389
+ // Wait for all variants to complete
390
+ const results = await Promise.all(variantTasks);
391
+ totalVariants = results.reduce((sum, count) => sum + count, 0);
392
+ this.log(`\nCompleted: Generated ${totalVariants} variants for ${sections.length} sections`);
393
+ this.logStream.end();
394
+ return {
395
+ type: 'variants_generated',
396
+ variantsDir: this.options.cwd,
397
+ variantCount: totalVariants,
398
+ };
399
+ }
400
+ }
401
+ /**
402
+ * Factory function to create and run a Compile2Runner
403
+ */
404
+ export async function runCompile2(options) {
405
+ const runner = new Compile2Runner(options);
406
+ return await runner.run();
407
+ }
408
+ //# sourceMappingURL=compile2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile2.js","sourceRoot":"","sources":["../compile2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC3F,OAAO,EAAuB,IAAI,EAAE,MAAM,MAAM,CAAC;AACjD,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAIlB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,CAAC,MAAM,KAAK,CAAC;AAuBpB,6BAA6B;AAC7B,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,MAAM,CAAC;QACP,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wHAAwH,CAAC;QACxJ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;QAC3C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uDAAuD,CAAC;KAC1F,CAAC,CACH,CAAC,QAAQ,CAAC,uCAAuC,CAAC;CACpD,CAAC,CAAC;AAIH,oCAAoC;AACpC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qEAAqE,CAAC;CAC3G,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACjB,SAAS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AC,CAAC,wBAAwB;gBACpC,CAAC,CAAC,EAAE,CAAC;gBAEL,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,gBAAgB,YAAY,CAAC,MAAM,0BAA0B,CAAC,CAAC;QAExE,oCAAoC;QACpC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChD,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC;QAE/D,IAAI,CAAC,GAAG,CAAC,0BAA0B,aAAa,iBAAiB,QAAQ,CAAC,MAAM,WAAW,CAAC,CAAC;QAC7F,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QAErB,OAAO;YACL,IAAI,EAAE,oBAAoB;YAC1B,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;YAC7B,YAAY,EAAE,aAAa;SAC5B,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAwB;IACxD,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;AAC5B,CAAC"}
package/dist/docs.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { type QuestionsOutput } from './index.js';
2
+ interface ClarifyingResult {
3
+ questions: QuestionsOutput;
4
+ sessionId: string;
5
+ }
6
+ /**
7
+ * Document Compiler - Converts transcripts/notes into structured documents
8
+ */
9
+ export declare class DocumentCompiler {
10
+ private outputMode;
11
+ private cwd;
12
+ private docTypeLabels;
13
+ private docQuestions;
14
+ constructor(cwd: string, outputMode?: 'json' | 'pretty');
15
+ /**
16
+ * Build the prompt for asking clarifying questions for the document
17
+ */
18
+ private askQuestionsPrompt;
19
+ /**
20
+ * Build the prompt for document compilation from file
21
+ */
22
+ private buildDocumentPrompt;
23
+ private refineDocumentPrompt;
24
+ clarify(transcriptFilePath: string, docType: string): Promise<ClarifyingResult>;
25
+ /**
26
+ * Generate a document from transcript file and return the output file path
27
+ */
28
+ compile(sessionId: string, clarifications: string, transcriptFilePath: string, docType: string): Promise<string>;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../docs.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EAKrB,MAAM,YAAY,CAAC;AAEpB,UAAU,gBAAgB;IACxB,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAoBD;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,aAAa,CAQnB;IAEF,OAAO,CAAC,YAAY,CAYlB;gBAEU,GAAG,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,GAAG,QAAiB;IAK/D;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsD1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,oBAAoB;IAyBtB,OAAO,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwBrF;;OAEG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA+CvH"}
package/dist/docs.js ADDED
@@ -0,0 +1,199 @@
1
+ import z from 'zod';
2
+ import { QuestionsOutputSchema, runStructuredStage, getLastWrittenFilePath, resetLastWrittenFilePath, } from './index.js';
3
+ /**
4
+ * Output stage change message
5
+ */
6
+ function outputStage(stage, outputMode) {
7
+ const stageMessage = { type: 'stage', stage };
8
+ if (outputMode === 'json') {
9
+ console.log(JSON.stringify(stageMessage));
10
+ }
11
+ else {
12
+ console.error(`\n=== Stage: ${stage} ===\n`);
13
+ }
14
+ }
15
+ // Schema for document compilation output
16
+ const DocumentOutputSchema = z.object({
17
+ outputFilePath: z.string().describe('The relative path to the file where the document was written')
18
+ });
19
+ /**
20
+ * Document Compiler - Converts transcripts/notes into structured documents
21
+ */
22
+ export class DocumentCompiler {
23
+ outputMode;
24
+ cwd;
25
+ docTypeLabels = {
26
+ 'design-doc': 'Technical Design Document',
27
+ 'brd': 'BRD (Business Requirements Document)',
28
+ 'prd': 'PRD (Product Requirements Document)',
29
+ 'rfp': 'RFP (Request for Proposal)',
30
+ 'sow': 'SOW (Statement of Work)',
31
+ 'technical-spec': 'Technical Specification',
32
+ 'user-story': 'User Stories',
33
+ };
34
+ docQuestions = {
35
+ 'brd': [
36
+ 'What problem are we solving?',
37
+ 'Who is it for?',
38
+ 'Why does it matter (business impact)?',
39
+ 'What does success look like (metrics / outcomes)?',
40
+ 'What must the solution do (requirements)?',
41
+ 'What constraints exist (tech, legal, timeline, budget)?',
42
+ 'What is explicitly out of scope?',
43
+ 'How will we know it\'s done (acceptance criteria)?',
44
+ ],
45
+ };
46
+ constructor(cwd, outputMode = 'json') {
47
+ this.cwd = cwd;
48
+ this.outputMode = outputMode;
49
+ }
50
+ /**
51
+ * Build the prompt for asking clarifying questions for the document
52
+ */
53
+ askQuestionsPrompt(filePath, docType) {
54
+ const docLabel = this.docTypeLabels[docType] || 'Document';
55
+ const docQuestions = this.docQuestions[docType] || this.docQuestions['brd'];
56
+ return `You are a senior technical manager creating a ${docLabel} from meeting notes.
57
+
58
+ The transcript is in a file at: ${filePath}
59
+
60
+ Your task:
61
+ 1. Read the transcript file
62
+ 2. Analyze the content
63
+ 3. **Ask clarifying questions** - You MUST ask 1-4 clarifying questions about:
64
+ - Specific requirements or constraints for the implementation
65
+ - Preferences for third-party services vs self-hosted solutions
66
+ - Authentication methods or existing auth patterns to maintain
67
+ - Data storage preferences or existing database patterns
68
+ - Any breaking changes they're willing to accept
69
+ - Scale expectations (current users, growth plans)
70
+ - Budget constraints (API costs, infrastructure)
71
+
72
+ The purpose of this document is to answer these questions:
73
+ ${docQuestions.join('\n')}
74
+ If any of these are unclear from the transcript ask for clarification.
75
+
76
+ IMPORTANT:
77
+ - You MUST ask at least 1 question - questions are REQUIRED
78
+ - Do NOT ask contradictory questions. Questions must be logically consistent with each other.
79
+ - You MUST AVOID migrations at all cost, ALWAYS try to make things work side-by-side.
80
+ - Act like you're a founder and do it in a simplest way as possible, just make sure it works.
81
+ - ALWAYS use Context7 MCP for retrieving up to date documentation for the library or SDK before integration
82
+
83
+ ## Output Format
84
+
85
+ Output your questions in this EXACT JSON format:
86
+
87
+ \`\`\`json
88
+ {
89
+ "questions": [
90
+ {
91
+ "question": "Your question text?",
92
+ "options": ["Option 1", "Option 2", "Option 3"],
93
+ "additionalInfo": "Optional context about why this matters"
94
+ }
95
+ ]
96
+ }
97
+ \`\`\`
98
+
99
+ Rules:
100
+ - You MUST provide at least 1 question (1-4 questions is ideal)
101
+ - NEVER use vague options like "Not sure", "Recommend me", "Let you decide", "Other", or "I don't know"
102
+ - Each option MUST be a specific implementation approach, tool, or technology`;
103
+ }
104
+ /**
105
+ * Build the prompt for document compilation from file
106
+ */
107
+ buildDocumentPrompt(clarifications, filePath, docType) {
108
+ const docLabel = this.docTypeLabels[docType] || 'Document';
109
+ const docQuestions = this.docQuestions[docType] || this.docQuestions['brd'];
110
+ return `You are a senior technical manager creating a ${docLabel} from meeting notes.
111
+
112
+ The transcript is in a file at: ${filePath}
113
+ Clarifications: ${clarifications}
114
+
115
+ Your task:
116
+ 1. Read the transcript file
117
+ 2. Analyze the content and clarifications
118
+ 3. Write a structured ${docLabel} to a file based on clarifications
119
+
120
+ The purpose of this document is to answer these questions:
121
+ ${docQuestions.join('\n')}
122
+ Make sure to create a document focused on answering these questions.
123
+ The document should be comprehensive but concise and follow standard ${docLabel} structure.
124
+
125
+ IMPORTANT:
126
+ - Do NOT ask any questions. All clarifications were already gathered. Generate the plan based on the context.
127
+ - Don't include details that are not mentioned in the transcript.
128
+ - Don't generate document date, add a placeholder.
129
+ - Don't make decisions by yourself.
130
+
131
+ After writing the document, return the relative path to the output file in the structured output.`;
132
+ }
133
+ refineDocumentPrompt(clarifications, filePath, transcriptFilePath, docType) {
134
+ const docLabel = this.docTypeLabels[docType] || 'Document';
135
+ const docQuestions = this.docQuestions[docType] || this.docQuestions['brd'];
136
+ return `You are a technical consultant working on a ${docLabel} and meeting notes.
137
+
138
+ The document is in a file at: ${filePath}
139
+ The transcript is in a file at: ${transcriptFilePath}
140
+ Clarifications: ${clarifications}
141
+
142
+ Your task:
143
+ 1. Read the document
144
+ 2. Analyze the content and clarifications
145
+ 3. Refine the document, make it more concise and verify against the meeting notes transcript.
146
+
147
+ The purpose of this document is to answer these questions:
148
+ ${docQuestions.join('\n')}
149
+ Make sure that the document is focused on answering these questions.
150
+
151
+ IMPORTANT:
152
+ - Do NOT ask any questions. All clarifications were already gathered. Generate the plan based on the context.
153
+
154
+ Write the refined document to a new path, and return the relative path to the output file in the structured output.`;
155
+ }
156
+ async clarify(transcriptFilePath, docType) {
157
+ if (!process.env.ANTHROPIC_API_KEY) {
158
+ throw new Error('ANTHROPIC_API_KEY environment variable is required');
159
+ }
160
+ outputStage('start', this.outputMode);
161
+ const questionsPrompt = this.askQuestionsPrompt(transcriptFilePath, docType);
162
+ const result = await runStructuredStage(questionsPrompt, QuestionsOutputSchema, this.cwd, this.outputMode);
163
+ outputStage('questions', this.outputMode);
164
+ return {
165
+ questions: result.output,
166
+ sessionId: result.sessionId,
167
+ };
168
+ }
169
+ /**
170
+ * Generate a document from transcript file and return the output file path
171
+ */
172
+ async compile(sessionId, clarifications, transcriptFilePath, docType) {
173
+ if (!process.env.ANTHROPIC_API_KEY) {
174
+ throw new Error('ANTHROPIC_API_KEY environment variable is required');
175
+ }
176
+ // Reset to ensure we capture the fresh write
177
+ resetLastWrittenFilePath();
178
+ outputStage('plan1', this.outputMode);
179
+ const buildPrompt = this.buildDocumentPrompt(clarifications, transcriptFilePath, docType);
180
+ await runStructuredStage(buildPrompt, DocumentOutputSchema, this.cwd, this.outputMode, sessionId);
181
+ // Get the actual file path from the Write tool call
182
+ const initialFilePath = getLastWrittenFilePath();
183
+ if (!initialFilePath) {
184
+ throw new Error('No file was written during document generation');
185
+ }
186
+ // Reset for the refinement stage
187
+ resetLastWrittenFilePath();
188
+ const prompt = this.refineDocumentPrompt(clarifications, initialFilePath, transcriptFilePath, docType);
189
+ await runStructuredStage(prompt, DocumentOutputSchema, this.cwd, this.outputMode);
190
+ // Get the actual refined file path from the Write tool call
191
+ const refinedFilePath = getLastWrittenFilePath();
192
+ if (!refinedFilePath) {
193
+ throw new Error('No file was written during document refinement');
194
+ }
195
+ outputStage('complete', this.outputMode);
196
+ return refinedFilePath;
197
+ }
198
+ }
199
+ //# sourceMappingURL=docs.js.map