specweave 0.24.8 → 0.24.9
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.
- package/dist/src/cli/commands/init.d.ts.map +1 -1
- package/dist/src/cli/commands/init.js +3 -1
- package/dist/src/cli/commands/init.js.map +1 -1
- package/dist/src/cli/helpers/issue-tracker/github-multi-repo.d.ts.map +1 -1
- package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js +18 -2
- package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js.map +1 -1
- package/dist/src/core/repo-structure/git-error-handler.d.ts +1 -1
- package/dist/src/core/repo-structure/git-error-handler.d.ts.map +1 -1
- package/dist/src/core/repo-structure/git-provider.d.ts +1 -1
- package/dist/src/core/repo-structure/git-provider.d.ts.map +1 -1
- package/dist/src/core/repo-structure/platform-registry.d.ts.map +1 -1
- package/dist/src/core/repo-structure/platform-registry.js +20 -9
- package/dist/src/core/repo-structure/platform-registry.js.map +1 -1
- package/dist/src/core/repo-structure/prompt-consolidator.d.ts +13 -1
- package/dist/src/core/repo-structure/prompt-consolidator.d.ts.map +1 -1
- package/dist/src/core/repo-structure/prompt-consolidator.js +38 -5
- package/dist/src/core/repo-structure/prompt-consolidator.js.map +1 -1
- package/dist/src/core/repo-structure/providers/azure-devops-provider.d.ts +64 -0
- package/dist/src/core/repo-structure/providers/azure-devops-provider.d.ts.map +1 -0
- package/dist/src/core/repo-structure/providers/azure-devops-provider.js +263 -0
- package/dist/src/core/repo-structure/providers/azure-devops-provider.js.map +1 -0
- package/dist/src/core/repo-structure/providers/bitbucket-provider.d.ts +12 -11
- package/dist/src/core/repo-structure/providers/bitbucket-provider.d.ts.map +1 -1
- package/dist/src/core/repo-structure/providers/bitbucket-provider.js +164 -30
- package/dist/src/core/repo-structure/providers/bitbucket-provider.js.map +1 -1
- package/dist/src/core/repo-structure/providers/gitlab-provider.d.ts +10 -9
- package/dist/src/core/repo-structure/providers/gitlab-provider.d.ts.map +1 -1
- package/dist/src/core/repo-structure/providers/gitlab-provider.js +182 -28
- package/dist/src/core/repo-structure/providers/gitlab-provider.js.map +1 -1
- package/dist/src/core/repo-structure/providers/index.d.ts +3 -1
- package/dist/src/core/repo-structure/providers/index.d.ts.map +1 -1
- package/dist/src/core/repo-structure/providers/index.js +10 -2
- package/dist/src/core/repo-structure/providers/index.js.map +1 -1
- package/dist/src/core/repo-structure/providers/local-provider.d.ts +61 -0
- package/dist/src/core/repo-structure/providers/local-provider.d.ts.map +1 -0
- package/dist/src/core/repo-structure/providers/local-provider.js +148 -0
- package/dist/src/core/repo-structure/providers/local-provider.js.map +1 -0
- package/dist/src/core/repo-structure/repo-structure-manager.d.ts +11 -1
- package/dist/src/core/repo-structure/repo-structure-manager.d.ts.map +1 -1
- package/dist/src/core/repo-structure/repo-structure-manager.js +268 -84
- package/dist/src/core/repo-structure/repo-structure-manager.js.map +1 -1
- package/package.json +1 -1
- package/plugins/specweave/agents/pm/AGENT.md.bak +1893 -0
- package/plugins/specweave/hooks/docs-changed.sh.backup +79 -0
- package/plugins/specweave/hooks/human-input-required.sh.backup +75 -0
- package/plugins/specweave/hooks/lib/migrate-increment-work.sh.bak +245 -0
- package/plugins/specweave/hooks/lib/sync-spec-content.sh.bak +149 -0
- package/plugins/specweave/hooks/lib/validate-spec-status.sh.bak +163 -0
- package/plugins/specweave/hooks/post-first-increment.sh.backup +61 -0
- package/plugins/specweave/hooks/post-first-increment.sh.bak +61 -0
- package/plugins/specweave/hooks/post-increment-change.sh.backup +98 -0
- package/plugins/specweave/hooks/post-increment-completion.sh.backup +231 -0
- package/plugins/specweave/hooks/post-increment-planning.sh.backup +1048 -0
- package/plugins/specweave/hooks/post-increment-status-change.sh.backup +147 -0
- package/plugins/specweave/hooks/post-spec-update.sh.backup +158 -0
- package/plugins/specweave/hooks/post-spec-update.sh.bak +158 -0
- package/plugins/specweave/hooks/post-task-completion.sh +69 -175
- package/plugins/specweave/hooks/post-user-story-complete.sh.backup +179 -0
- package/plugins/specweave/hooks/post-user-story-complete.sh.bak +179 -0
- package/plugins/specweave/hooks/pre-command-deduplication.sh.backup +83 -0
- package/plugins/specweave/hooks/pre-command-deduplication.sh.bak +83 -0
- package/plugins/specweave/hooks/pre-implementation.sh.backup +67 -0
- package/plugins/specweave/hooks/pre-task-completion.sh.backup +194 -0
- package/plugins/specweave/hooks/pre-tool-use.sh.backup +133 -0
- package/plugins/specweave/hooks/user-prompt-submit.sh.backup +386 -0
- package/plugins/specweave/hooks/user-prompt-submit.sh.bak +386 -0
- package/plugins/specweave/lib/hooks/auto-transition.js.bak +50 -0
- package/plugins/specweave/lib/hooks/auto-transition.ts.bak +84 -0
- package/plugins/specweave/lib/hooks/consolidated-sync.js +183 -0
- package/plugins/specweave/lib/hooks/git-diff-analyzer.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/git-diff-analyzer.d.ts.bak +89 -0
- package/plugins/specweave/lib/hooks/git-diff-analyzer.js.bak +142 -0
- package/plugins/specweave/lib/hooks/git-diff-analyzer.ts.bak +269 -0
- package/plugins/specweave/lib/hooks/invoke-translator-skill.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/invoke-translator-skill.d.ts.bak +60 -0
- package/plugins/specweave/lib/hooks/invoke-translator-skill.js.bak +155 -0
- package/plugins/specweave/lib/hooks/invoke-translator-skill.ts.bak +264 -0
- package/plugins/specweave/lib/hooks/prepare-reflection-context.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/prepare-reflection-context.d.ts.bak +42 -0
- package/plugins/specweave/lib/hooks/prepare-reflection-context.js.bak +110 -0
- package/plugins/specweave/lib/hooks/prepare-reflection-context.ts.bak +178 -0
- package/plugins/specweave/lib/hooks/reflection-config-loader.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-config-loader.d.ts.bak +45 -0
- package/plugins/specweave/lib/hooks/reflection-config-loader.js.bak +92 -0
- package/plugins/specweave/lib/hooks/reflection-config-loader.ts.bak +156 -0
- package/plugins/specweave/lib/hooks/reflection-parser.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-parser.d.ts.bak +33 -0
- package/plugins/specweave/lib/hooks/reflection-parser.js.bak +301 -0
- package/plugins/specweave/lib/hooks/reflection-parser.ts.bak +484 -0
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.d.ts.bak +56 -0
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.js.bak +182 -0
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.ts.bak +306 -0
- package/plugins/specweave/lib/hooks/reflection-storage.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-storage.d.ts.bak +64 -0
- package/plugins/specweave/lib/hooks/reflection-storage.js.bak +231 -0
- package/plugins/specweave/lib/hooks/reflection-storage.ts.bak +369 -0
- package/plugins/specweave/lib/hooks/run-self-reflection.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/run-self-reflection.d.ts.bak +43 -0
- package/plugins/specweave/lib/hooks/run-self-reflection.js.bak +132 -0
- package/plugins/specweave/lib/hooks/run-self-reflection.ts.bak +258 -0
- package/plugins/specweave/lib/hooks/sync-cache.js.bak +294 -0
- package/plugins/specweave/lib/hooks/sync-living-docs.d.js.bak +1 -0
- package/plugins/specweave/lib/hooks/sync-living-docs.d.ts.bak +27 -0
- package/plugins/specweave/lib/hooks/sync-living-docs.js.bak +339 -0
- package/plugins/specweave/lib/hooks/sync-us-tasks.js.bak +476 -0
- package/plugins/specweave/lib/hooks/translate-file.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/translate-file.d.ts.bak +59 -0
- package/plugins/specweave/lib/hooks/translate-file.js.bak +289 -0
- package/plugins/specweave/lib/hooks/translate-file.ts.bak +428 -0
- package/plugins/specweave/lib/hooks/translate-living-docs.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/translate-living-docs.d.ts.bak +13 -0
- package/plugins/specweave/lib/hooks/translate-living-docs.js.bak +119 -0
- package/plugins/specweave/lib/hooks/translate-living-docs.ts.bak +224 -0
- package/plugins/specweave/lib/hooks/update-ac-status.js.bak +51 -0
- package/plugins/specweave/lib/hooks/update-ac-status.ts.bak +103 -0
- package/plugins/specweave/lib/hooks/update-tasks-md.d.js.bak +1 -0
- package/plugins/specweave/lib/hooks/update-tasks-md.d.ts.bak +29 -0
- package/plugins/specweave/lib/hooks/update-tasks-md.js.bak +296 -0
- package/plugins/specweave/lib/hooks/update-tasks-md.ts.bak +489 -0
- package/plugins/specweave-ado/hooks/post-living-docs-update.sh.backup +353 -0
- package/plugins/specweave-ado/hooks/post-task-completion.sh.backup +172 -0
- package/plugins/specweave-ado/lib/ado-multi-project-sync.js +1 -0
- package/plugins/specweave-ado/lib/enhanced-ado-sync.js +170 -0
- package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +424 -0
- package/plugins/specweave-github/hooks/post-task-completion.sh.backup +258 -0
- package/plugins/specweave-jira/hooks/post-task-completion.sh.backup +172 -0
- package/plugins/specweave-jira/lib/enhanced-jira-sync.js +3 -3
- package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +540 -0
- package/plugins/specweave-release/hooks/post-task-completion.sh.backup +110 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translator Skill Invocation Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides programmatic invocation of the translator skill for automated translation.
|
|
5
|
+
* Used by hooks and CLI scripts to translate content without manual intervention.
|
|
6
|
+
*
|
|
7
|
+
* @see plugins/specweave/skills/translator/SKILL.md
|
|
8
|
+
* @see plugins/specweave/commands/translate.md
|
|
9
|
+
*/
|
|
10
|
+
import { type SupportedLanguage } from '../../../../src/utils/translation.js';
|
|
11
|
+
/**
|
|
12
|
+
* Translation result
|
|
13
|
+
*/
|
|
14
|
+
export interface TranslationResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
sourceLanguage: SupportedLanguage;
|
|
17
|
+
targetLanguage: SupportedLanguage;
|
|
18
|
+
originalContent: string;
|
|
19
|
+
translatedContent?: string;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Invokes translator skill to translate content
|
|
24
|
+
*
|
|
25
|
+
* This function integrates with the translator skill by:
|
|
26
|
+
* 1. Preparing translation prompt
|
|
27
|
+
* 2. Writing prompt to a temp file
|
|
28
|
+
* 3. Outputting instructions for Claude to process
|
|
29
|
+
* 4. Returning the translated content
|
|
30
|
+
*
|
|
31
|
+
* In an automated context (hooks), this provides clear instructions.
|
|
32
|
+
* In an interactive context, the translator skill can auto-activate.
|
|
33
|
+
*
|
|
34
|
+
* @param content - Content to translate
|
|
35
|
+
* @param sourceLang - Source language
|
|
36
|
+
* @param targetLang - Target language
|
|
37
|
+
* @returns Translation result
|
|
38
|
+
*/
|
|
39
|
+
export declare function invokeTranslatorSkill(content: string, sourceLang: SupportedLanguage, targetLang?: SupportedLanguage): Promise<TranslationResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Translate a file using translator skill
|
|
42
|
+
*
|
|
43
|
+
* @param filePath - Path to file to translate
|
|
44
|
+
* @param targetLang - Target language
|
|
45
|
+
* @returns Translation result
|
|
46
|
+
*/
|
|
47
|
+
export declare function translateFile(filePath: string, targetLang?: SupportedLanguage): Promise<TranslationResult & {
|
|
48
|
+
filePath: string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Batch translate multiple files
|
|
52
|
+
*
|
|
53
|
+
* @param filePaths - Array of file paths
|
|
54
|
+
* @param targetLang - Target language
|
|
55
|
+
* @returns Array of translation results
|
|
56
|
+
*/
|
|
57
|
+
export declare function batchTranslateFiles(filePaths: string[], targetLang?: SupportedLanguage): Promise<Array<TranslationResult & {
|
|
58
|
+
filePath: string;
|
|
59
|
+
}>>;
|
|
60
|
+
//# sourceMappingURL=invoke-translator-skill.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import {
|
|
3
|
+
detectLanguage,
|
|
4
|
+
prepareTranslation,
|
|
5
|
+
postProcessTranslation,
|
|
6
|
+
getLanguageName
|
|
7
|
+
} from "../../../../dist/src/utils/translation.js";
|
|
8
|
+
async function invokeTranslatorSkill(content, sourceLang, targetLang = "en") {
|
|
9
|
+
try {
|
|
10
|
+
const prepared = prepareTranslation(content, sourceLang, targetLang);
|
|
11
|
+
const result = {
|
|
12
|
+
success: true,
|
|
13
|
+
sourceLanguage: sourceLang,
|
|
14
|
+
targetLanguage: targetLang,
|
|
15
|
+
originalContent: content,
|
|
16
|
+
translatedContent: await performTranslation(prepared.prompt, prepared.preserved)
|
|
17
|
+
};
|
|
18
|
+
return result;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
sourceLanguage: sourceLang,
|
|
24
|
+
targetLanguage: targetLang,
|
|
25
|
+
originalContent: content,
|
|
26
|
+
error: errorMessage
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function performTranslation(prompt, preserved) {
|
|
31
|
+
const contentMatch = prompt.match(/SOURCE DOCUMENT[^\n]*:\n---\n([\s\S]*?)\n---/);
|
|
32
|
+
const contentToTranslate = contentMatch ? contentMatch[1] : "";
|
|
33
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
34
|
+
if (apiKey) {
|
|
35
|
+
console.log(`
|
|
36
|
+
\u{1F916} Translating via Anthropic API (Haiku model)...`);
|
|
37
|
+
try {
|
|
38
|
+
const Anthropic = await import("@anthropic-ai/sdk").then((m) => m.default);
|
|
39
|
+
const anthropic = new Anthropic({
|
|
40
|
+
apiKey
|
|
41
|
+
});
|
|
42
|
+
const message = await anthropic.messages.create({
|
|
43
|
+
model: "claude-3-haiku-20240307",
|
|
44
|
+
max_tokens: 8e3,
|
|
45
|
+
messages: [
|
|
46
|
+
{
|
|
47
|
+
role: "user",
|
|
48
|
+
content: prompt
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
const translatedContent = message.content[0].type === "text" ? message.content[0].text : contentToTranslate;
|
|
53
|
+
console.log(`\u2705 Translation complete via API`);
|
|
54
|
+
console.log(` Input tokens: ${message.usage.input_tokens}`);
|
|
55
|
+
console.log(` Output tokens: ${message.usage.output_tokens}`);
|
|
56
|
+
console.log(` Cost: ~$${((message.usage.input_tokens * 0.25 + message.usage.output_tokens * 1.25) / 1e6).toFixed(4)}
|
|
57
|
+
`);
|
|
58
|
+
return postProcessTranslation(translatedContent, preserved);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(`
|
|
61
|
+
\u274C API translation failed: ${error.message}`);
|
|
62
|
+
console.error(` Falling back to manual translation instructions
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const isInteractive = process.env.CLAUDE_CODE_SESSION === "true";
|
|
67
|
+
if (isInteractive) {
|
|
68
|
+
console.log("\n" + "=".repeat(80));
|
|
69
|
+
console.log("\u{1F310} TRANSLATION REQUEST (translator skill will auto-activate)");
|
|
70
|
+
console.log("=".repeat(80));
|
|
71
|
+
console.log(prompt);
|
|
72
|
+
console.log("=".repeat(80));
|
|
73
|
+
console.log("\u{1F4A1} Tip: Set ANTHROPIC_API_KEY for fully automatic translation\n");
|
|
74
|
+
return postProcessTranslation(
|
|
75
|
+
`<!-- \u26A0\uFE0F TRANSLATION REQUESTED - Awaiting translator skill activation -->
|
|
76
|
+
|
|
77
|
+
${contentToTranslate}`,
|
|
78
|
+
preserved
|
|
79
|
+
);
|
|
80
|
+
} else {
|
|
81
|
+
console.error("\n\u26A0\uFE0F AUTO-TRANSLATION REQUIRES ONE OF:");
|
|
82
|
+
console.error(" Option A (Recommended): Set ANTHROPIC_API_KEY environment variable");
|
|
83
|
+
console.error(" Option B: Run /specweave:translate <file-path>");
|
|
84
|
+
console.error(" Option C: Manually translate the content\n");
|
|
85
|
+
return postProcessTranslation(
|
|
86
|
+
`<!-- \u26A0\uFE0F AUTO-TRANSLATION PENDING -->
|
|
87
|
+
<!-- Set ANTHROPIC_API_KEY for automatic translation -->
|
|
88
|
+
<!-- Or run: /specweave:translate to complete -->
|
|
89
|
+
<!-- Original content below -->
|
|
90
|
+
|
|
91
|
+
${contentToTranslate}`,
|
|
92
|
+
preserved
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function translateFile(filePath, targetLang = "en") {
|
|
97
|
+
if (!await fs.pathExists(filePath)) {
|
|
98
|
+
throw new Error(`File not found: ${filePath}`);
|
|
99
|
+
}
|
|
100
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
101
|
+
const detection = detectLanguage(content);
|
|
102
|
+
const sourceLang = detection.language;
|
|
103
|
+
if (sourceLang === targetLang) {
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
filePath,
|
|
107
|
+
sourceLanguage: sourceLang,
|
|
108
|
+
targetLanguage: targetLang,
|
|
109
|
+
originalContent: content,
|
|
110
|
+
translatedContent: content
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const result = await invokeTranslatorSkill(content, sourceLang, targetLang);
|
|
114
|
+
if (result.success && result.translatedContent) {
|
|
115
|
+
await fs.writeFile(filePath, result.translatedContent, "utf-8");
|
|
116
|
+
console.log(`\u2705 Translated: ${filePath} (${getLanguageName(sourceLang)} \u2192 ${getLanguageName(targetLang)})`);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
...result,
|
|
120
|
+
filePath
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function batchTranslateFiles(filePaths, targetLang = "en") {
|
|
124
|
+
const results = [];
|
|
125
|
+
console.log(`
|
|
126
|
+
\u{1F310} Batch translating ${filePaths.length} file(s) to ${getLanguageName(targetLang)}...
|
|
127
|
+
`);
|
|
128
|
+
for (const filePath of filePaths) {
|
|
129
|
+
try {
|
|
130
|
+
const result = await translateFile(filePath, targetLang);
|
|
131
|
+
results.push(result);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
134
|
+
console.error(`\u274C Failed to translate ${filePath}: ${errorMessage}`);
|
|
135
|
+
results.push({
|
|
136
|
+
success: false,
|
|
137
|
+
filePath,
|
|
138
|
+
sourceLanguage: "unknown",
|
|
139
|
+
targetLanguage: targetLang,
|
|
140
|
+
originalContent: "",
|
|
141
|
+
error: errorMessage
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const successful = results.filter((r) => r.success).length;
|
|
146
|
+
console.log(`
|
|
147
|
+
\u{1F4CA} Batch translation complete: ${successful}/${filePaths.length} files translated
|
|
148
|
+
`);
|
|
149
|
+
return results;
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
batchTranslateFiles,
|
|
153
|
+
invokeTranslatorSkill,
|
|
154
|
+
translateFile
|
|
155
|
+
};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translator Skill Invocation Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides programmatic invocation of the translator skill for automated translation.
|
|
5
|
+
* Used by hooks and CLI scripts to translate content without manual intervention.
|
|
6
|
+
*
|
|
7
|
+
* @see plugins/specweave/skills/translator/SKILL.md
|
|
8
|
+
* @see plugins/specweave/commands/translate.md
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import {
|
|
14
|
+
detectLanguage,
|
|
15
|
+
prepareTranslation,
|
|
16
|
+
postProcessTranslation,
|
|
17
|
+
getLanguageName,
|
|
18
|
+
type SupportedLanguage,
|
|
19
|
+
} from '../../../../dist/src/utils/translation.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Translation result
|
|
23
|
+
*/
|
|
24
|
+
export interface TranslationResult {
|
|
25
|
+
success: boolean;
|
|
26
|
+
sourceLanguage: SupportedLanguage;
|
|
27
|
+
targetLanguage: SupportedLanguage;
|
|
28
|
+
originalContent: string;
|
|
29
|
+
translatedContent?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Invokes translator skill to translate content
|
|
35
|
+
*
|
|
36
|
+
* This function integrates with the translator skill by:
|
|
37
|
+
* 1. Preparing translation prompt
|
|
38
|
+
* 2. Writing prompt to a temp file
|
|
39
|
+
* 3. Outputting instructions for Claude to process
|
|
40
|
+
* 4. Returning the translated content
|
|
41
|
+
*
|
|
42
|
+
* In an automated context (hooks), this provides clear instructions.
|
|
43
|
+
* In an interactive context, the translator skill can auto-activate.
|
|
44
|
+
*
|
|
45
|
+
* @param content - Content to translate
|
|
46
|
+
* @param sourceLang - Source language
|
|
47
|
+
* @param targetLang - Target language
|
|
48
|
+
* @returns Translation result
|
|
49
|
+
*/
|
|
50
|
+
export async function invokeTranslatorSkill(
|
|
51
|
+
content: string,
|
|
52
|
+
sourceLang: SupportedLanguage,
|
|
53
|
+
targetLang: SupportedLanguage = 'en'
|
|
54
|
+
): Promise<TranslationResult> {
|
|
55
|
+
try {
|
|
56
|
+
// Prepare translation
|
|
57
|
+
const prepared = prepareTranslation(content, sourceLang, targetLang);
|
|
58
|
+
|
|
59
|
+
// For now, we use a practical approach:
|
|
60
|
+
// Output the translation request clearly so it can be processed
|
|
61
|
+
|
|
62
|
+
const result: TranslationResult = {
|
|
63
|
+
success: true,
|
|
64
|
+
sourceLanguage: sourceLang,
|
|
65
|
+
targetLanguage: targetLang,
|
|
66
|
+
originalContent: content,
|
|
67
|
+
translatedContent: await performTranslation(prepared.prompt, prepared.preserved),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
sourceLanguage: sourceLang,
|
|
76
|
+
targetLanguage: targetLang,
|
|
77
|
+
originalContent: content,
|
|
78
|
+
error: errorMessage,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Performs the actual translation using Anthropic API
|
|
85
|
+
*
|
|
86
|
+
* PRODUCTION IMPLEMENTATION:
|
|
87
|
+
* 1. Checks for ANTHROPIC_API_KEY in environment
|
|
88
|
+
* 2. If available: Uses Anthropic API directly (fully automatic)
|
|
89
|
+
* 3. If not available: Provides clear instructions for manual translation
|
|
90
|
+
*
|
|
91
|
+
* @param prompt - Translation prompt
|
|
92
|
+
* @param preserved - Preserved content structure
|
|
93
|
+
* @returns Translated content
|
|
94
|
+
*/
|
|
95
|
+
async function performTranslation(
|
|
96
|
+
prompt: string,
|
|
97
|
+
preserved: any
|
|
98
|
+
): Promise<string> {
|
|
99
|
+
// Extract content for processing
|
|
100
|
+
const contentMatch = prompt.match(/SOURCE DOCUMENT[^\n]*:\n---\n([\s\S]*?)\n---/);
|
|
101
|
+
const contentToTranslate = contentMatch ? contentMatch[1] : '';
|
|
102
|
+
|
|
103
|
+
// Check if ANTHROPIC_API_KEY is available
|
|
104
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
105
|
+
|
|
106
|
+
if (apiKey) {
|
|
107
|
+
// Fully automatic translation using Anthropic API
|
|
108
|
+
console.log(`\n🤖 Translating via Anthropic API (Haiku model)...`);
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
// Dynamic import of Anthropic SDK (allows graceful fallback if not installed)
|
|
112
|
+
const Anthropic = await import('@anthropic-ai/sdk').then(m => m.default);
|
|
113
|
+
|
|
114
|
+
const anthropic = new Anthropic({
|
|
115
|
+
apiKey,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const message = await anthropic.messages.create({
|
|
119
|
+
model: 'claude-3-haiku-20240307',
|
|
120
|
+
max_tokens: 8000,
|
|
121
|
+
messages: [
|
|
122
|
+
{
|
|
123
|
+
role: 'user',
|
|
124
|
+
content: prompt,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Extract translated content from response
|
|
130
|
+
const translatedContent = message.content[0].type === 'text'
|
|
131
|
+
? message.content[0].text
|
|
132
|
+
: contentToTranslate;
|
|
133
|
+
|
|
134
|
+
console.log(`✅ Translation complete via API`);
|
|
135
|
+
console.log(` Input tokens: ${message.usage.input_tokens}`);
|
|
136
|
+
console.log(` Output tokens: ${message.usage.output_tokens}`);
|
|
137
|
+
console.log(` Cost: ~$${((message.usage.input_tokens * 0.25 + message.usage.output_tokens * 1.25) / 1000000).toFixed(4)}\n`);
|
|
138
|
+
|
|
139
|
+
return postProcessTranslation(translatedContent, preserved);
|
|
140
|
+
} catch (error: any) {
|
|
141
|
+
console.error(`\n❌ API translation failed: ${error.message}`);
|
|
142
|
+
console.error(` Falling back to manual translation instructions\n`);
|
|
143
|
+
// Fall through to manual instructions
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Fallback: Manual translation instructions
|
|
148
|
+
const isInteractive = process.env.CLAUDE_CODE_SESSION === 'true';
|
|
149
|
+
|
|
150
|
+
if (isInteractive) {
|
|
151
|
+
// In Claude Code environment, output translation request
|
|
152
|
+
console.log('\n' + '='.repeat(80));
|
|
153
|
+
console.log('🌐 TRANSLATION REQUEST (translator skill will auto-activate)');
|
|
154
|
+
console.log('='.repeat(80));
|
|
155
|
+
console.log(prompt);
|
|
156
|
+
console.log('='.repeat(80));
|
|
157
|
+
console.log('💡 Tip: Set ANTHROPIC_API_KEY for fully automatic translation\n');
|
|
158
|
+
|
|
159
|
+
return postProcessTranslation(
|
|
160
|
+
`<!-- ⚠️ TRANSLATION REQUESTED - Awaiting translator skill activation -->\n\n${contentToTranslate}`,
|
|
161
|
+
preserved
|
|
162
|
+
);
|
|
163
|
+
} else {
|
|
164
|
+
// Non-interactive environment - provide clear instructions
|
|
165
|
+
console.error('\n⚠️ AUTO-TRANSLATION REQUIRES ONE OF:');
|
|
166
|
+
console.error(' Option A (Recommended): Set ANTHROPIC_API_KEY environment variable');
|
|
167
|
+
console.error(' Option B: Run /specweave:translate <file-path>');
|
|
168
|
+
console.error(' Option C: Manually translate the content\n');
|
|
169
|
+
|
|
170
|
+
return postProcessTranslation(
|
|
171
|
+
`<!-- ⚠️ AUTO-TRANSLATION PENDING -->\n<!-- Set ANTHROPIC_API_KEY for automatic translation -->\n<!-- Or run: /specweave:translate to complete -->\n<!-- Original content below -->\n\n${contentToTranslate}`,
|
|
172
|
+
preserved
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Translate a file using translator skill
|
|
179
|
+
*
|
|
180
|
+
* @param filePath - Path to file to translate
|
|
181
|
+
* @param targetLang - Target language
|
|
182
|
+
* @returns Translation result
|
|
183
|
+
*/
|
|
184
|
+
export async function translateFile(
|
|
185
|
+
filePath: string,
|
|
186
|
+
targetLang: SupportedLanguage = 'en'
|
|
187
|
+
): Promise<TranslationResult & { filePath: string }> {
|
|
188
|
+
// Read file
|
|
189
|
+
if (!await fs.pathExists(filePath)) {
|
|
190
|
+
throw new Error(`File not found: ${filePath}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
194
|
+
|
|
195
|
+
// Detect source language
|
|
196
|
+
const detection = detectLanguage(content);
|
|
197
|
+
const sourceLang = detection.language;
|
|
198
|
+
|
|
199
|
+
// Check if already in target language
|
|
200
|
+
if (sourceLang === targetLang) {
|
|
201
|
+
return {
|
|
202
|
+
success: true,
|
|
203
|
+
filePath,
|
|
204
|
+
sourceLanguage: sourceLang,
|
|
205
|
+
targetLanguage: targetLang,
|
|
206
|
+
originalContent: content,
|
|
207
|
+
translatedContent: content,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Translate
|
|
212
|
+
const result = await invokeTranslatorSkill(content, sourceLang, targetLang);
|
|
213
|
+
|
|
214
|
+
// Write back if successful
|
|
215
|
+
if (result.success && result.translatedContent) {
|
|
216
|
+
await fs.writeFile(filePath, result.translatedContent, 'utf-8');
|
|
217
|
+
console.log(`✅ Translated: ${filePath} (${getLanguageName(sourceLang)} → ${getLanguageName(targetLang)})`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
...result,
|
|
222
|
+
filePath,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Batch translate multiple files
|
|
228
|
+
*
|
|
229
|
+
* @param filePaths - Array of file paths
|
|
230
|
+
* @param targetLang - Target language
|
|
231
|
+
* @returns Array of translation results
|
|
232
|
+
*/
|
|
233
|
+
export async function batchTranslateFiles(
|
|
234
|
+
filePaths: string[],
|
|
235
|
+
targetLang: SupportedLanguage = 'en'
|
|
236
|
+
): Promise<Array<TranslationResult & { filePath: string }>> {
|
|
237
|
+
const results: Array<TranslationResult & { filePath: string }> = [];
|
|
238
|
+
|
|
239
|
+
console.log(`\n🌐 Batch translating ${filePaths.length} file(s) to ${getLanguageName(targetLang)}...\n`);
|
|
240
|
+
|
|
241
|
+
for (const filePath of filePaths) {
|
|
242
|
+
try {
|
|
243
|
+
const result = await translateFile(filePath, targetLang);
|
|
244
|
+
results.push(result);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
247
|
+
console.error(`❌ Failed to translate ${filePath}: ${errorMessage}`);
|
|
248
|
+
results.push({
|
|
249
|
+
success: false,
|
|
250
|
+
filePath,
|
|
251
|
+
sourceLanguage: 'unknown',
|
|
252
|
+
targetLanguage: targetLang,
|
|
253
|
+
originalContent: '',
|
|
254
|
+
error: errorMessage,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Summary
|
|
260
|
+
const successful = results.filter(r => r.success).length;
|
|
261
|
+
console.log(`\n📊 Batch translation complete: ${successful}/${filePaths.length} files translated\n`);
|
|
262
|
+
|
|
263
|
+
return results;
|
|
264
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepare Reflection Context
|
|
3
|
+
*
|
|
4
|
+
* Prepares context for reflection and saves to temp file
|
|
5
|
+
* Used by post-task-completion hook to prepare for reflection invocation
|
|
6
|
+
*
|
|
7
|
+
* @module prepare-reflection-context
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Prepare reflection context and save to temp file
|
|
11
|
+
* This allows the hook to prepare data without actually invoking the agent
|
|
12
|
+
*
|
|
13
|
+
* @param incrementId Increment identifier
|
|
14
|
+
* @param taskId Task identifier
|
|
15
|
+
* @param projectRoot Project root directory (optional)
|
|
16
|
+
* @returns Path to saved context file or null if reflection should be skipped
|
|
17
|
+
*/
|
|
18
|
+
export declare function prepareReflectionContext(incrementId: string, taskId: string, projectRoot?: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Check if reflection context exists for an increment
|
|
21
|
+
*
|
|
22
|
+
* @param incrementId Increment identifier
|
|
23
|
+
* @param projectRoot Project root directory (optional)
|
|
24
|
+
* @returns True if context file exists
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasReflectionContext(incrementId: string, projectRoot?: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Read reflection context from file
|
|
29
|
+
*
|
|
30
|
+
* @param incrementId Increment identifier
|
|
31
|
+
* @param projectRoot Project root directory (optional)
|
|
32
|
+
* @returns Context data or null if not found
|
|
33
|
+
*/
|
|
34
|
+
export declare function readReflectionContext(incrementId: string, projectRoot?: string): any | null;
|
|
35
|
+
/**
|
|
36
|
+
* Clear reflection context after reflection completes
|
|
37
|
+
*
|
|
38
|
+
* @param incrementId Increment identifier
|
|
39
|
+
* @param projectRoot Project root directory (optional)
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearReflectionContext(incrementId: string, projectRoot?: string): void;
|
|
42
|
+
//# sourceMappingURL=prepare-reflection-context.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createReflectionContext } from "./run-self-reflection";
|
|
4
|
+
import { getModifiedFilesSummary } from "./git-diff-analyzer";
|
|
5
|
+
function prepareReflectionContext(incrementId, taskId, projectRoot) {
|
|
6
|
+
try {
|
|
7
|
+
const context = createReflectionContext(incrementId, taskId, projectRoot);
|
|
8
|
+
if (!context.config.enabled || context.modifiedFiles.length === 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const rootDir = projectRoot || process.cwd();
|
|
12
|
+
const tempDir = path.join(rootDir, ".specweave", "increments", incrementId, "logs", "reflections", ".temp");
|
|
13
|
+
fs.mkdirpSync(tempDir);
|
|
14
|
+
const contextFile = path.join(tempDir, "reflection-context.json");
|
|
15
|
+
const fileStats = getModifiedFilesSummary(context.modifiedFiles);
|
|
16
|
+
const contextData = {
|
|
17
|
+
incrementId: context.incrementId,
|
|
18
|
+
taskId: context.taskId,
|
|
19
|
+
modifiedFiles: context.modifiedFiles.map((f) => ({
|
|
20
|
+
file: f.file,
|
|
21
|
+
linesAdded: f.linesAdded,
|
|
22
|
+
linesRemoved: f.linesRemoved
|
|
23
|
+
// Exclude diff content to save space
|
|
24
|
+
})),
|
|
25
|
+
fileSummary: {
|
|
26
|
+
count: fileStats.count,
|
|
27
|
+
linesAdded: fileStats.linesAdded,
|
|
28
|
+
linesRemoved: fileStats.linesRemoved
|
|
29
|
+
},
|
|
30
|
+
config: context.config,
|
|
31
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
32
|
+
};
|
|
33
|
+
fs.writeJsonSync(contextFile, contextData, { spaces: 2 });
|
|
34
|
+
return contextFile;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(`Failed to prepare reflection context: ${error.message}`);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function hasReflectionContext(incrementId, projectRoot) {
|
|
41
|
+
const rootDir = projectRoot || process.cwd();
|
|
42
|
+
const contextFile = path.join(
|
|
43
|
+
rootDir,
|
|
44
|
+
".specweave",
|
|
45
|
+
"increments",
|
|
46
|
+
incrementId,
|
|
47
|
+
"logs",
|
|
48
|
+
"reflections",
|
|
49
|
+
".temp",
|
|
50
|
+
"reflection-context.json"
|
|
51
|
+
);
|
|
52
|
+
return fs.existsSync(contextFile);
|
|
53
|
+
}
|
|
54
|
+
function readReflectionContext(incrementId, projectRoot) {
|
|
55
|
+
const rootDir = projectRoot || process.cwd();
|
|
56
|
+
const contextFile = path.join(
|
|
57
|
+
rootDir,
|
|
58
|
+
".specweave",
|
|
59
|
+
"increments",
|
|
60
|
+
incrementId,
|
|
61
|
+
"logs",
|
|
62
|
+
"reflections",
|
|
63
|
+
".temp",
|
|
64
|
+
"reflection-context.json"
|
|
65
|
+
);
|
|
66
|
+
if (!fs.existsSync(contextFile)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return fs.readJsonSync(contextFile);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function clearReflectionContext(incrementId, projectRoot) {
|
|
76
|
+
const rootDir = projectRoot || process.cwd();
|
|
77
|
+
const tempDir = path.join(
|
|
78
|
+
rootDir,
|
|
79
|
+
".specweave",
|
|
80
|
+
"increments",
|
|
81
|
+
incrementId,
|
|
82
|
+
"logs",
|
|
83
|
+
"reflections",
|
|
84
|
+
".temp"
|
|
85
|
+
);
|
|
86
|
+
if (fs.existsSync(tempDir)) {
|
|
87
|
+
fs.removeSync(tempDir);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (require.main === module) {
|
|
91
|
+
const incrementId = process.argv[2];
|
|
92
|
+
const taskId = process.argv[3];
|
|
93
|
+
if (!incrementId || !taskId) {
|
|
94
|
+
console.error("Usage: node prepare-reflection-context.js <increment-id> <task-id>");
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
const contextFile = prepareReflectionContext(incrementId, taskId);
|
|
98
|
+
if (contextFile) {
|
|
99
|
+
console.log(`Reflection context prepared: ${contextFile}`);
|
|
100
|
+
console.log("\u2728 Reflection ready. Run /specweave:reflect to analyze your work.");
|
|
101
|
+
} else {
|
|
102
|
+
console.log("Reflection skipped (disabled or no changes).");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
clearReflectionContext,
|
|
107
|
+
hasReflectionContext,
|
|
108
|
+
prepareReflectionContext,
|
|
109
|
+
readReflectionContext
|
|
110
|
+
};
|