claude-code-vietnamese-fix 1.0.0 → 1.1.0
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/package.json +1 -1
- package/patch-vietnamese-ime.js +52 -0
package/package.json
CHANGED
package/patch-vietnamese-ime.js
CHANGED
|
@@ -145,6 +145,47 @@ function patchContent(content) {
|
|
|
145
145
|
return { success: true, alreadyPatched: false, content: patched };
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// --- Auto-install SessionStart hook ---
|
|
149
|
+
|
|
150
|
+
const HOOK_COMMAND = "npx claude-code-vietnamese-fix --silent";
|
|
151
|
+
|
|
152
|
+
function installHook(silent) {
|
|
153
|
+
const homeDir = process.env.USERPROFILE || process.env.HOME || "";
|
|
154
|
+
const settingsPath = path.join(homeDir, ".claude", "settings.json");
|
|
155
|
+
|
|
156
|
+
let settings = {};
|
|
157
|
+
if (fs.existsSync(settingsPath)) {
|
|
158
|
+
try { settings = JSON.parse(fs.readFileSync(settingsPath, "utf8")); } catch { return; }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Check if hook already exists
|
|
162
|
+
const hooks = settings.hooks?.SessionStart || [];
|
|
163
|
+
for (const entry of hooks) {
|
|
164
|
+
for (const h of (entry.hooks || [])) {
|
|
165
|
+
if (h.command && h.command.includes("claude-code-vietnamese-fix")) return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Add hook to existing SessionStart entry or create new one
|
|
170
|
+
if (!settings.hooks) settings.hooks = {};
|
|
171
|
+
if (!settings.hooks.SessionStart) settings.hooks.SessionStart = [];
|
|
172
|
+
|
|
173
|
+
const matcher = "startup|resume|clear|compact";
|
|
174
|
+
let target = settings.hooks.SessionStart.find((e) => e.matcher === matcher);
|
|
175
|
+
if (!target) {
|
|
176
|
+
target = { matcher, hooks: [] };
|
|
177
|
+
settings.hooks.SessionStart.push(target);
|
|
178
|
+
}
|
|
179
|
+
target.hooks.push({ type: "command", command: HOOK_COMMAND });
|
|
180
|
+
|
|
181
|
+
// Ensure .claude dir exists
|
|
182
|
+
const claudeDir = path.join(homeDir, ".claude");
|
|
183
|
+
if (!fs.existsSync(claudeDir)) fs.mkdirSync(claudeDir, { recursive: true });
|
|
184
|
+
|
|
185
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf8");
|
|
186
|
+
if (!silent) console.log("Hook installed: auto-patch on SessionStart");
|
|
187
|
+
}
|
|
188
|
+
|
|
148
189
|
// --- Backup & restore ---
|
|
149
190
|
|
|
150
191
|
function backupPath(cliPath) { return cliPath + ".bak"; }
|
|
@@ -180,6 +221,14 @@ function main() {
|
|
|
180
221
|
console.log(`Target: ${cliPath}`);
|
|
181
222
|
console.log(`Status: ${patched ? "PATCHED" : "NOT PATCHED"}`);
|
|
182
223
|
console.log(`Backup: ${fs.existsSync(backupPath(cliPath)) ? "EXISTS" : "NONE"}`);
|
|
224
|
+
const homeDir = process.env.USERPROFILE || process.env.HOME || "";
|
|
225
|
+
const sp = path.join(homeDir, ".claude", "settings.json");
|
|
226
|
+
let hookInstalled = false;
|
|
227
|
+
try {
|
|
228
|
+
const s = JSON.parse(fs.readFileSync(sp, "utf8"));
|
|
229
|
+
hookInstalled = JSON.stringify(s).includes("claude-code-vietnamese-fix");
|
|
230
|
+
} catch {}
|
|
231
|
+
console.log(`Hook: ${hookInstalled ? "INSTALLED" : "NOT INSTALLED"}`);
|
|
183
232
|
process.exit(0);
|
|
184
233
|
}
|
|
185
234
|
|
|
@@ -214,6 +263,9 @@ function main() {
|
|
|
214
263
|
|
|
215
264
|
fs.writeFileSync(cliPath, result.content, "latin1");
|
|
216
265
|
console.log("Patched: " + cliPath);
|
|
266
|
+
|
|
267
|
+
// Auto-install SessionStart hook for auto-patching after updates
|
|
268
|
+
installHook(opts.silent);
|
|
217
269
|
}
|
|
218
270
|
|
|
219
271
|
main();
|