@intra-mart/accel 2.0.0 → 3.0.0-dev.202611201537

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.
Files changed (69) hide show
  1. package/README.md +9 -3
  2. package/assets/githooks/.githooks/pre-commit/pre-commit_en +71 -32
  3. package/assets/githooks/.githooks/pre-commit/pre-commit_ja +67 -33
  4. package/assets/githooks/.githooks/pre-commit/pre-commit_zh_CN +66 -32
  5. package/assets/runtime/ensure.mjs +27 -16
  6. package/dist/asset/deployer.d.ts +0 -2
  7. package/dist/asset/deployer.js +1 -6
  8. package/dist/asset/installer.d.ts +18 -2
  9. package/dist/asset/installer.js +94 -17
  10. package/dist/commands/attach-existing-files.d.ts +7 -0
  11. package/dist/commands/attach-existing-files.js +47 -1
  12. package/dist/commands/attach.d.ts +2 -0
  13. package/dist/commands/attach.js +20 -4
  14. package/dist/commands/deploy.d.ts +5 -1
  15. package/dist/commands/deploy.js +10 -3
  16. package/dist/commands/detach.d.ts +3 -1
  17. package/dist/commands/detach.js +16 -4
  18. package/dist/commands/init.d.ts +2 -0
  19. package/dist/commands/init.js +8 -3
  20. package/dist/commands/login.d.ts +8 -0
  21. package/dist/commands/login.js +13 -1
  22. package/dist/commands/mobile/attach.js +2 -3
  23. package/dist/commands/mobile/init.js +5 -2
  24. package/dist/commands/mobile/shared.d.ts +1 -1
  25. package/dist/commands/mobile/shared.js +5 -2
  26. package/dist/commands/switch.d.ts +2 -0
  27. package/dist/commands/switch.js +2 -2
  28. package/dist/commands/update.d.ts +2 -0
  29. package/dist/commands/update.js +1 -1
  30. package/dist/git/config-file.d.ts +10 -2
  31. package/dist/git/config-file.js +177 -94
  32. package/dist/git/config-scopes.d.ts +17 -0
  33. package/dist/git/config-scopes.js +33 -0
  34. package/dist/git/index-file.js +23 -4
  35. package/dist/git/read-capped.d.ts +1 -0
  36. package/dist/git/read-capped.js +6 -3
  37. package/dist/git/repo-discovery.d.ts +26 -0
  38. package/dist/git/repo-discovery.js +213 -0
  39. package/dist/git/untracked.d.ts +1 -0
  40. package/dist/git/untracked.js +23 -1
  41. package/dist/git/worktree-status.js +26 -21
  42. package/dist/i18n/en.js +72 -6
  43. package/dist/i18n/ja.js +72 -6
  44. package/dist/i18n/zh_CN.js +72 -6
  45. package/dist/interactive/credentials-prompts.d.ts +4 -1
  46. package/dist/interactive/credentials-prompts.js +2 -1
  47. package/dist/interactive/hook-confirm.d.ts +2 -0
  48. package/dist/interactive/hook-confirm.js +16 -0
  49. package/dist/lib.d.ts +1 -0
  50. package/dist/utils/command-exists.d.ts +5 -0
  51. package/dist/utils/command-exists.js +7 -6
  52. package/dist/utils/external-command.d.ts +0 -1
  53. package/dist/utils/external-command.js +1 -29
  54. package/dist/utils/githooks-remove.d.ts +27 -0
  55. package/dist/utils/githooks-remove.js +196 -0
  56. package/dist/utils/githooks-state.d.ts +80 -0
  57. package/dist/utils/githooks-state.js +364 -0
  58. package/dist/utils/githooks-sync.d.ts +11 -2
  59. package/dist/utils/githooks-sync.js +360 -68
  60. package/dist/utils/managed-marker.d.ts +1 -0
  61. package/dist/utils/managed-marker.js +1 -0
  62. package/dist/utils/mcp-generate.d.ts +5 -1
  63. package/dist/utils/mcp-generate.js +13 -4
  64. package/dist/utils/output-tail.d.ts +11 -0
  65. package/dist/utils/output-tail.js +29 -0
  66. package/dist/utils/runtime-ensure.js +10 -4
  67. package/package.json +1 -1
  68. package/dist/git/repo-layout.d.ts +0 -5
  69. package/dist/git/repo-layout.js +0 -44
@@ -1,91 +1,383 @@
1
- import { chmod, lstat, mkdir, readdir, writeFile } from "node:fs/promises";
2
- import { dirname, isAbsolute, join, relative } from "node:path";
3
- import { readConfigValue, writeConfigValue } from "../git/config-file.js";
4
- import { readTextFileCapped } from "../git/read-capped.js";
5
- import { resolveRepoLayout } from "../git/repo-layout.js";
6
- import { createFsAssetTree } from "../asset/asset-tree.js";
7
- import { walkAssetDir } from "../asset/walker.js";
8
- import { emptyEvalContext } from "../core/eval-context.js";
9
- import { getAssetsGithooksRoot } from "../core/paths.js";
1
+ import { mkdir, readdir, realpath } from "node:fs/promises";
2
+ import { join, resolve } from "node:path";
3
+ import { comparablePath, discoverRepository, } from "../git/repo-discovery.js";
4
+ import { isCancelledError } from "../core/errors.js";
10
5
  import { getMessage } from "../i18n/index.js";
6
+ import { classifyDir, classifyFile, classifyLegacy, displayRelative, hasLinkedWorktrees, hasRemainingHooksPath, INTEGRATION_ATTRIBUTES, INTEGRATION_DIR, INTEGRATION_SCRIPT, integrationPaths, isRunnableManagedHook, listActiveHooks, loadHookAssets, manualUnsetGuidance, readHooksPathDefinitions, remainingHooksPaths, removeDirIfEmpty, removeManagedFiles, resolveHooksPathDir, toUnsetFailure, unsetFailureText, unsetLocalHooksPath, writeFileAtomic, } from "./githooks-state.js";
11
7
  import { detectLocale } from "./locale-detect.js";
8
+ import { sanitizeDisplayText } from "./sanitize-text.js";
12
9
  import { readSettingsSafe } from "./settings-io.js";
13
- const MANAGED_MARKER = "@accel-cli-managed";
14
- const HOOKS_PATH = ".githooks";
15
- const HOOK_FILE_REL = ".githooks/pre-commit";
16
- const MAX_HOOK_FILE_BYTES = 1024 * 1024;
17
- const readFileSafe = (filePath) => readTextFileCapped(filePath, MAX_HOOK_FILE_BYTES);
18
- const isInside = (parent, child) => {
19
- const rel = relative(parent, child);
20
- return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
10
+ const HOOK_MODE = 0o755;
11
+ const errorMessage = (err) => err instanceof Error ? err.message : String(err);
12
+ const message = (ctx, key, params) => getMessage(key, ctx.locale, params);
13
+ const shown = (path) => sanitizeDisplayText(path);
14
+ const reportUpdateError = (ctx, result) => {
15
+ if (result.updateError === undefined)
16
+ return;
17
+ ctx.warn(message(ctx, "gitHooks.updateFailed", {
18
+ path: shown(result.hookPath),
19
+ message: shown(result.updateError),
20
+ }));
21
21
  };
22
- const listForeignFiles = async (hooksDir) => {
23
- const foreign = [];
24
- for (const entry of await readdir(hooksDir, { withFileTypes: true })) {
25
- if (!entry.isFile()) {
26
- foreign.push(entry.name);
22
+ const refreshIntegrationScripts = async (ctx, exclude) => {
23
+ const paths = integrationPaths(ctx.projectDir);
24
+ const present = [];
25
+ if ((await classifyDir(paths.dir)) !== "directory")
26
+ return present;
27
+ for (const path of [paths.primary, paths.alt]) {
28
+ if (path === exclude)
29
+ continue;
30
+ if ((await classifyFile(path)) !== "managed")
27
31
  continue;
32
+ present.push(path);
33
+ try {
34
+ await writeFileAtomic(path, ctx.assets.script, HOOK_MODE);
28
35
  }
29
- const content = await readFileSafe(join(hooksDir, entry.name));
30
- if (content === null || !content.includes(MANAGED_MARKER)) {
31
- foreign.push(entry.name);
36
+ catch (err) {
37
+ ctx.warn(message(ctx, "gitHooks.updateFailed", {
38
+ path: shown(path),
39
+ message: shown(errorMessage(err)),
40
+ }));
32
41
  }
33
42
  }
34
- return foreign;
43
+ if ((await classifyFile(paths.attributes)) === "managed") {
44
+ await writeFileAtomic(paths.attributes, ctx.assets.gitattributes).catch(() => { });
45
+ }
46
+ return present;
35
47
  };
36
- export const syncGitHooks = async (projectDir, opts) => {
37
- const settings = await readSettingsSafe(projectDir);
38
- if (settings?.gitHooks === false)
48
+ const placeIntegrationScript = async (ctx, hooksPathTargetsProject) => {
49
+ const paths = integrationPaths(ctx.projectDir);
50
+ const dirState = await classifyDir(paths.dir);
51
+ if (dirState === "other")
52
+ return { kind: "blocked" };
53
+ const primaryState = await classifyFile(paths.primary);
54
+ const altState = await classifyFile(paths.alt);
55
+ let target;
56
+ if (!hooksPathTargetsProject && primaryState !== "foreign") {
57
+ target = paths.primary;
58
+ }
59
+ else if (altState !== "foreign") {
60
+ target = paths.alt;
61
+ }
62
+ else {
63
+ return { kind: "blocked" };
64
+ }
65
+ try {
66
+ if (dirState === "absent")
67
+ await mkdir(paths.dir);
68
+ await writeFileAtomic(target, ctx.assets.script, HOOK_MODE);
69
+ if (target === paths.primary &&
70
+ (await classifyFile(paths.attributes)) !== "foreign") {
71
+ await writeFileAtomic(paths.attributes, ctx.assets.gitattributes);
72
+ }
73
+ }
74
+ catch (err) {
75
+ return { kind: "failed", path: target, error: errorMessage(err) };
76
+ }
77
+ await refreshIntegrationScripts(ctx);
78
+ return { kind: "placed", path: target };
79
+ };
80
+ const reportCannotPlace = async (ctx, result) => {
81
+ const integration = await placeIntegrationScript(ctx, result.hooksPathTargetsProject ?? false);
82
+ let guidance;
83
+ if (integration.kind === "placed") {
84
+ const script = shown(displayRelative(ctx.displayRoot, integration.path));
85
+ guidance =
86
+ result.guidance === "copyOrRun" && result.hookPath !== undefined
87
+ ? message(ctx, "gitHooks.guidance.copyOrRun", {
88
+ source: shown(integration.path),
89
+ script,
90
+ hookPath: shown(result.hookPath),
91
+ })
92
+ : message(ctx, "gitHooks.guidance.runScript", { script });
93
+ }
94
+ else if (integration.kind === "failed") {
95
+ guidance = message(ctx, "gitHooks.guidance.scriptWriteFailed", {
96
+ path: shown(integration.path),
97
+ message: shown(integration.error),
98
+ });
99
+ }
100
+ else {
101
+ guidance = message(ctx, "gitHooks.guidance.noScript", {
102
+ dir: shown(displayRelative(ctx.displayRoot, integrationPaths(ctx.projectDir).dir)),
103
+ });
104
+ }
105
+ ctx.warn(`${result.reason}\n${guidance}`);
106
+ };
107
+ const tryPlace = async (ctx, layout, definitions) => {
108
+ const effective = definitions[definitions.length - 1];
109
+ if (effective !== undefined) {
110
+ const targetsProject = comparablePath(resolveHooksPathDir(effective.value, layout.worktreeRoot, ctx.env)) === comparablePath(join(ctx.projectDir, INTEGRATION_DIR));
111
+ return {
112
+ kind: "cannot",
113
+ reason: message(ctx, "gitHooks.reason.hooksPathSet", {
114
+ value: shown(effective.value),
115
+ }),
116
+ guidance: "runScript",
117
+ hooksPathTargetsProject: targetsProject,
118
+ };
119
+ }
120
+ const hooksDir = join(layout.commonDir, "hooks");
121
+ const unsupportedDir = () => ({
122
+ kind: "cannot",
123
+ reason: message(ctx, "gitHooks.reason.hooksDirUnsupported", {
124
+ path: shown(hooksDir),
125
+ }),
126
+ guidance: "runScript",
127
+ });
128
+ let dirState = await classifyDir(hooksDir);
129
+ if (dirState === "other")
130
+ return unsupportedDir();
131
+ const hookPath = join(hooksDir, "pre-commit");
132
+ const foreign = () => ({
133
+ kind: "cannot",
134
+ reason: message(ctx, "gitHooks.reason.foreignHook", {
135
+ path: shown(hookPath),
136
+ }),
137
+ guidance: "runScript",
138
+ });
139
+ const writeFailed = (err) => ({
140
+ kind: "cannot",
141
+ reason: message(ctx, "gitHooks.reason.writeFailed", {
142
+ path: shown(hookPath),
143
+ message: shown(errorMessage(err)),
144
+ }),
145
+ guidance: "runScript",
146
+ writeFailed: true,
147
+ });
148
+ const state = await classifyFile(hookPath);
149
+ if (state === "foreign")
150
+ return foreign();
151
+ if (state === "managed") {
152
+ try {
153
+ await writeFileAtomic(hookPath, ctx.assets.script, HOOK_MODE);
154
+ }
155
+ catch (err) {
156
+ return { kind: "placed", isNew: false, hookPath, updateError: errorMessage(err) };
157
+ }
158
+ return { kind: "placed", isNew: false, hookPath };
159
+ }
160
+ if (layout.projectRel !== "") {
161
+ if (ctx.confirm === undefined) {
162
+ return {
163
+ kind: "cannot",
164
+ reason: message(ctx, "gitHooks.reason.parentRepoNoConfirm", {
165
+ repositoryRoot: shown(layout.worktreeRoot),
166
+ }),
167
+ guidance: "copyOrRun",
168
+ hookPath,
169
+ };
170
+ }
171
+ const accepted = await ctx.confirm({
172
+ hookPath,
173
+ repositoryRoot: layout.worktreeRoot,
174
+ });
175
+ if (!accepted) {
176
+ return {
177
+ kind: "cannot",
178
+ reason: message(ctx, "gitHooks.reason.parentRepoDeclined"),
179
+ guidance: "copyOrRun",
180
+ hookPath,
181
+ };
182
+ }
183
+ const dirAfterConfirm = await classifyDir(hooksDir);
184
+ if (dirAfterConfirm === "other")
185
+ return unsupportedDir();
186
+ if ((await classifyFile(hookPath)) === "foreign")
187
+ return foreign();
188
+ dirState = dirAfterConfirm;
189
+ }
190
+ try {
191
+ if (dirState === "absent")
192
+ await mkdir(hooksDir);
193
+ await writeFileAtomic(hookPath, ctx.assets.script, HOOK_MODE);
194
+ }
195
+ catch (err) {
196
+ return writeFailed(err);
197
+ }
198
+ return { kind: "placed", isNew: true, hookPath };
199
+ };
200
+ const cleanLegacyDir = async (dir, keep, onError) => {
201
+ if ((await classifyDir(dir)) !== "directory")
202
+ return false;
203
+ const names = await readdir(dir).catch(() => []);
204
+ await removeManagedFiles(names.filter((name) => !keep.has(name)).map((name) => join(dir, name)), onError);
205
+ return removeDirIfEmpty(dir);
206
+ };
207
+ const migrateLegacy = async (ctx, layout, definitions, legacyDir) => {
208
+ const configPath = join(layout.commonDir, "config");
209
+ const others = definitions.filter((d) => d.scope !== "local");
210
+ const remaining = remainingHooksPaths(definitions);
211
+ const hooksDir = join(layout.commonDir, "hooks");
212
+ const reenabled = hasRemainingHooksPath(remaining) ? [] : await listActiveHooks(hooksDir);
213
+ const legacyCheckWasActive = await isRunnableManagedHook(join(legacyDir, INTEGRATION_SCRIPT));
214
+ const result = await tryPlace(ctx, layout, others);
215
+ const stop = async (failure) => {
216
+ const legacyEntries = await readdir(legacyDir).catch(() => []);
217
+ const guidance = await manualUnsetGuidance({
218
+ mode: "migration",
219
+ locale: ctx.locale,
220
+ failure,
221
+ repoRoot: layout.worktreeRoot,
222
+ configPath,
223
+ placedHookPath: result.kind === "placed" ? result.hookPath : undefined,
224
+ legacyCheckActive: legacyCheckWasActive,
225
+ legacyDirHasFiles: legacyEntries.length > 0,
226
+ legacyScriptExists: legacyEntries.includes(INTEGRATION_SCRIPT),
227
+ remaining,
228
+ reenabled,
229
+ worktreesExist: layout.linkedWorktree || (await hasLinkedWorktrees(layout.commonDir)),
230
+ });
231
+ ctx.warn([
232
+ message(ctx, "gitHooks.migrationStopped", {
233
+ message: unsetFailureText(failure, ctx.locale, ctx.displayRoot),
234
+ }),
235
+ message(ctx, legacyCheckWasActive
236
+ ? "gitHooks.migrationStopped.active"
237
+ : "gitHooks.migrationStopped.unprotected"),
238
+ ...(guidance === "retry"
239
+ ? [message(ctx, "gitHooks.migrationStopped.retry")]
240
+ : guidance),
241
+ ].join("\n"));
242
+ if (result.kind === "placed")
243
+ reportUpdateError(ctx, result);
244
+ };
245
+ if (result.kind === "cannot" && result.writeFailed === true) {
246
+ await stop({ kind: "other", message: result.reason });
247
+ return;
248
+ }
249
+ let unset;
250
+ try {
251
+ unset = await unsetLocalHooksPath(configPath);
252
+ }
253
+ catch (err) {
254
+ await stop(toUnsetFailure(err));
39
255
  return;
40
- const layout = await resolveRepoLayout(projectDir);
41
- if (layout === null)
256
+ }
257
+ if (!unset) {
258
+ await stop({ kind: "remains" });
42
259
  return;
43
- const configPath = join(layout.commonDir, "config");
44
- const locale = settings?.locale ?? detectLocale();
45
- const tree = createFsAssetTree(getAssetsGithooksRoot());
46
- const entries = await walkAssetDir(tree, emptyEvalContext({ locale }));
47
- for (const entry of entries) {
48
- const destPath = join(projectDir, entry.relativePath);
49
- const destStats = await lstat(destPath).catch(() => null);
50
- if (destStats !== null && !destStats.isFile()) {
51
- opts.warn(getMessage("warning.gitHooksUserFile", locale, {
52
- path: entry.relativePath,
260
+ }
261
+ if (result.kind === "placed") {
262
+ ctx.info(message(ctx, "gitHooks.placed", { path: shown(result.hookPath) }));
263
+ reportUpdateError(ctx, result);
264
+ }
265
+ const cleanupFailed = (err) => {
266
+ ctx.warn(message(ctx, "gitHooks.unexpectedError", {
267
+ message: shown(errorMessage(err)),
268
+ }));
269
+ };
270
+ if (result.kind === "placed") {
271
+ const removedDir = await cleanLegacyDir(legacyDir, new Set(), cleanupFailed);
272
+ const lines = [message(ctx, "gitHooks.migrated")];
273
+ if (removedDir)
274
+ lines.push(message(ctx, "gitHooks.migrated.removedDir"));
275
+ if (reenabled.length > 0) {
276
+ lines.push(message(ctx, "gitHooks.migrated.reenabled", {
277
+ hooks: reenabled.join(", "),
53
278
  }));
54
- continue;
55
279
  }
56
- const existing = destStats === null ? null : await readFileSafe(destPath);
57
- if (existing !== null && !existing.includes(MANAGED_MARKER)) {
58
- opts.warn(getMessage("warning.gitHooksUserFile", locale, {
59
- path: entry.relativePath,
280
+ if (removedDir) {
281
+ lines.push(message(ctx, "gitHooks.migrated.teamNotice"));
282
+ lines.push(message(ctx, "gitHooks.migrated.removeCall", {
283
+ path: `${INTEGRATION_DIR}/${INTEGRATION_SCRIPT}`,
60
284
  }));
61
- continue;
62
- }
63
- const content = (await tree.readFile(entry.sourceRelPath)).replace(/\r\n/g, "\n");
64
- await mkdir(dirname(destPath), { recursive: true });
65
- await writeFile(destPath, content, "utf-8");
66
- if (entry.relativePath === HOOK_FILE_REL) {
67
- await chmod(destPath, 0o755);
68
285
  }
286
+ ctx.info(lines.join("\n"));
287
+ return;
288
+ }
289
+ await cleanLegacyDir(legacyDir, new Set([INTEGRATION_SCRIPT, INTEGRATION_ATTRIBUTES]), cleanupFailed);
290
+ const lines = [message(ctx, "gitHooks.legacySettingRemoved")];
291
+ if (reenabled.length > 0) {
292
+ lines.push(message(ctx, "gitHooks.migrated.reenabled", { hooks: reenabled.join(", ") }));
293
+ }
294
+ if (legacyCheckWasActive) {
295
+ lines.push(message(ctx, "gitHooks.migrated.checkDisabled"));
296
+ }
297
+ ctx.info(lines.join("\n"));
298
+ await reportCannotPlace(ctx, result);
299
+ };
300
+ export const syncGitHooks = async (projectDirInput, opts) => {
301
+ const settings = await readSettingsSafe(projectDirInput);
302
+ if (settings?.gitHooks === false)
303
+ return;
304
+ const locale = settings?.locale ?? detectLocale();
305
+ try {
306
+ await syncWithLocale(projectDirInput, opts, locale);
69
307
  }
70
- const genuineWorktree = isInside(join(layout.commonDir, "worktrees"), layout.gitDir);
71
- if (!isInside(projectDir, layout.commonDir) && !genuineWorktree) {
72
- opts.warn(getMessage("warning.gitHooksLayoutSuspicious", locale, {
73
- path: layout.commonDir,
308
+ catch (err) {
309
+ if (isCancelledError(err))
310
+ throw err;
311
+ opts.warn(getMessage("gitHooks.unexpectedError", locale, {
312
+ message: shown(errorMessage(err)),
74
313
  }));
314
+ }
315
+ };
316
+ const syncWithLocale = async (projectDirInput, opts, locale) => {
317
+ const env = opts.env ?? process.env;
318
+ const projectDir = await realpath(projectDirInput).catch(() => resolve(projectDirInput));
319
+ const discovery = await discoverRepository(projectDir, { env });
320
+ if (discovery.kind === "none")
321
+ return;
322
+ const ctx = {
323
+ projectDir,
324
+ locale,
325
+ info: opts.info ?? (() => { }),
326
+ warn: opts.warn,
327
+ confirm: opts.confirmHookPlacement,
328
+ env,
329
+ assets: await loadHookAssets(locale),
330
+ displayRoot: discovery.kind === "found"
331
+ ? discovery.layout.worktreeRoot
332
+ : discovery.worktreeRoot,
333
+ };
334
+ if (discovery.kind === "unverified") {
335
+ await reportCannotPlace(ctx, {
336
+ kind: "cannot",
337
+ reason: message(ctx, "gitHooks.reason.unverified", {
338
+ path: shown(discovery.gitPath),
339
+ }),
340
+ guidance: "runScript",
341
+ });
75
342
  return;
76
343
  }
77
- const current = await readConfigValue(configPath, "core", "hooksPath");
78
- if (current === undefined || current === "") {
79
- const foreign = await listForeignFiles(join(projectDir, HOOKS_PATH));
80
- if (foreign.length > 0) {
81
- opts.warn(getMessage("warning.gitHooksForeignFiles", locale, {
82
- files: foreign.join(", "),
83
- }));
84
- return;
344
+ const layout = discovery.layout;
345
+ const definitions = await readHooksPathDefinitions(layout, env);
346
+ const legacy = await classifyLegacy(layout, definitions);
347
+ if (legacy.kind === "migratable" && definitions.at(-1)?.scope === "local") {
348
+ await migrateLegacy(ctx, layout, definitions, legacy.dir);
349
+ return;
350
+ }
351
+ if (legacy.kind === "protected") {
352
+ if (layout.projectRel === "") {
353
+ try {
354
+ await writeFileAtomic(legacy.scriptPath, ctx.assets.script, HOOK_MODE);
355
+ }
356
+ catch (err) {
357
+ ctx.warn(message(ctx, "gitHooks.updateFailed", {
358
+ path: shown(legacy.scriptPath),
359
+ message: shown(errorMessage(err)),
360
+ }));
361
+ }
85
362
  }
86
- await writeConfigValue(configPath, "core", "hooksPath", HOOKS_PATH);
363
+ await refreshIntegrationScripts(ctx, legacy.scriptPath);
364
+ return;
365
+ }
366
+ const result = await tryPlace(ctx, layout, definitions);
367
+ if (result.kind === "cannot") {
368
+ await reportCannotPlace(ctx, result);
369
+ return;
87
370
  }
88
- else if (current !== HOOKS_PATH) {
89
- opts.warn(getMessage("warning.gitHooksPathConflict", locale, { current }));
371
+ if (result.isNew) {
372
+ ctx.info(message(ctx, "gitHooks.placed", { path: shown(result.hookPath) }));
373
+ }
374
+ reportUpdateError(ctx, result);
375
+ const kept = await refreshIntegrationScripts(ctx);
376
+ if (result.isNew) {
377
+ for (const path of kept) {
378
+ ctx.info(message(ctx, "gitHooks.integrationScriptKept", {
379
+ path: shown(displayRelative(ctx.displayRoot, path)),
380
+ }));
381
+ }
90
382
  }
91
383
  };
@@ -0,0 +1 @@
1
+ export declare const MANAGED_MARKER = "@accel-cli-managed";
@@ -0,0 +1 @@
1
+ export const MANAGED_MARKER = "@accel-cli-managed";
@@ -1,4 +1,5 @@
1
1
  import type { AccelCredentials } from "../core/types.js";
2
+ import { type ConfirmHookPlacement } from "./githooks-sync.js";
2
3
  export type ManagedSetting = {
3
4
  path: string[];
4
5
  value: unknown;
@@ -26,8 +27,11 @@ export declare const removeManagedMcpEntries: (projectDir: string, opts?: {
26
27
  export declare const persistCredentialsAndGenerateMcp: (projectDir: string, creds: AccelCredentials, opts?: {
27
28
  info?: (msg: string) => void;
28
29
  warn?: (msg: string) => void;
30
+ confirmHookPlacement?: ConfirmHookPlacement;
29
31
  }) => Promise<void>;
30
32
  export declare const generateMcpConfigsBestEffort: (projectDir: string, logger: McpLogSink, impl?: typeof generateMcpConfigs) => Promise<void>;
31
33
  export declare const removeManagedMcpEntriesBestEffort: (projectDir: string, logger: McpLogSink, impl?: typeof removeManagedMcpEntries) => Promise<void>;
32
- export declare const createPersistCredentialsWithMcp: (logger: McpLogSink) => (projectDir: string, creds: AccelCredentials) => Promise<void>;
34
+ export declare const createPersistCredentialsWithMcp: (logger: McpLogSink, hookOpts?: {
35
+ confirmHookPlacement?: ConfirmHookPlacement;
36
+ }) => (projectDir: string, creds: AccelCredentials) => Promise<void>;
33
37
  export {};
@@ -8,6 +8,7 @@ import { persistCredentials, readCredentials } from "./credentials.js";
8
8
  import { ensureGitignoreEntry } from "./gitignore.js";
9
9
  import { MCP_STATE_GITIGNORE_ENTRY } from "../core/gitignore-entries.js";
10
10
  import { syncGitHooks } from "./githooks-sync.js";
11
+ import { isCancelledError } from "../core/errors.js";
11
12
  import { detectLocale } from "./locale-detect.js";
12
13
  import { sanitizeDisplayText } from "./sanitize-text.js";
13
14
  import { ACCEL_DIR, ensureAccelDir, readSettingsSafe } from "./settings-io.js";
@@ -503,19 +504,26 @@ export const removeManagedMcpEntries = async (projectDir, opts = {}) => {
503
504
  }
504
505
  };
505
506
  export const persistCredentialsAndGenerateMcp = async (projectDir, creds, opts = {}) => {
507
+ const { confirmHookPlacement, ...log } = opts;
506
508
  await persistCredentials(projectDir, creds);
507
509
  try {
508
510
  await generateMcpConfigs(projectDir, {
509
- ...opts,
511
+ ...log,
510
512
  credentialsConfirmed: true,
511
513
  });
512
514
  }
513
515
  catch {
514
516
  }
515
517
  try {
516
- await syncGitHooks(projectDir, { warn: opts.warn ?? noop });
518
+ await syncGitHooks(projectDir, {
519
+ info: log.info ?? noop,
520
+ warn: log.warn ?? noop,
521
+ confirmHookPlacement,
522
+ });
517
523
  }
518
- catch {
524
+ catch (err) {
525
+ if (isCancelledError(err))
526
+ throw err;
519
527
  }
520
528
  };
521
529
  export const generateMcpConfigsBestEffort = async (projectDir, logger, impl = generateMcpConfigs) => {
@@ -538,7 +546,8 @@ export const removeManagedMcpEntriesBestEffort = async (projectDir, logger, impl
538
546
  catch {
539
547
  }
540
548
  };
541
- export const createPersistCredentialsWithMcp = (logger) => (projectDir, creds) => persistCredentialsAndGenerateMcp(projectDir, creds, {
549
+ export const createPersistCredentialsWithMcp = (logger, hookOpts = {}) => (projectDir, creds) => persistCredentialsAndGenerateMcp(projectDir, creds, {
542
550
  info: (msg) => logger.info(msg),
543
551
  warn: (msg) => logger.warn(msg),
552
+ confirmHookPlacement: hookOpts.confirmHookPlacement,
544
553
  });
@@ -0,0 +1,11 @@
1
+ export declare const OUTPUT_TAIL_LINES = 200;
2
+ export declare const MAX_LINE_LENGTH = 4096;
3
+ export declare const FAILURE_TAIL_LINES = 20;
4
+ export declare const createLineTail: (limit: number) => {
5
+ createSink: () => {
6
+ write: (chunk: string) => void;
7
+ flush: () => void;
8
+ };
9
+ lines: () => string[];
10
+ };
11
+ export declare const formatOutputTail: (outputTail: readonly string[]) => string;
@@ -0,0 +1,29 @@
1
+ import { sanitizeDisplayBlock } from "./sanitize-text.js";
2
+ export const OUTPUT_TAIL_LINES = 200;
3
+ export const MAX_LINE_LENGTH = 4096;
4
+ export const FAILURE_TAIL_LINES = 20;
5
+ export const createLineTail = (limit) => {
6
+ const lines = [];
7
+ const push = (line) => {
8
+ lines.push(line);
9
+ if (lines.length > limit)
10
+ lines.shift();
11
+ };
12
+ const createSink = () => {
13
+ let partial = "";
14
+ return {
15
+ write: (chunk) => {
16
+ const parts = (partial + chunk).split(/\r\n|\n/);
17
+ partial = (parts.pop() ?? "").slice(-MAX_LINE_LENGTH);
18
+ parts.forEach((line) => push(line.slice(-MAX_LINE_LENGTH)));
19
+ },
20
+ flush: () => {
21
+ if (partial !== "")
22
+ push(partial);
23
+ partial = "";
24
+ },
25
+ };
26
+ };
27
+ return { createSink, lines: () => [...lines] };
28
+ };
29
+ export const formatOutputTail = (outputTail) => sanitizeDisplayBlock(outputTail.slice(-FAILURE_TAIL_LINES).join("\n"));
@@ -10,11 +10,11 @@ import { readTextFileCapped } from "../git/read-capped.js";
10
10
  import { getMessage } from "../i18n/index.js";
11
11
  import { ensureGitignoreEntries } from "./gitignore.js";
12
12
  import { detectLocale } from "./locale-detect.js";
13
+ import { MANAGED_MARKER } from "./managed-marker.js";
13
14
  import { isSafeRelPath } from "./safe-rel-path.js";
14
15
  import { sanitizeDisplayBlock, sanitizeDisplayText } from "./sanitize-text.js";
15
16
  import { readSettingsSafe } from "./settings-io.js";
16
17
  const execFileAsync = promisify(execFile);
17
- const MANAGED_MARKER = "@accel-cli-managed";
18
18
  const ENSURE_SCRIPT_NAME = "ensure.mjs";
19
19
  const MAX_SCRIPT_BYTES = 1024 * 1024;
20
20
  const MAX_HOOK_FILE_BYTES = 1024 * 1024;
@@ -118,9 +118,15 @@ export const runEnsure = async (projectDir, opts = {}) => {
118
118
  }
119
119
  const stdout = typeof e.stdout === "string" ? e.stdout : "";
120
120
  const stderr = typeof e.stderr === "string" ? e.stderr : "";
121
- const detail = (stdout.trim().length > 0 ? stdout : stderr).trimEnd();
122
- warn(getMessage("dependencies.ensureFailed", locale) +
123
- (detail.length > 0 ? `\n${sanitizeDisplayBlock(detail)}` : ""));
121
+ const guidance = sanitizeDisplayBlock(stdout.trimEnd());
122
+ if (guidance.trim().length > 0) {
123
+ warn(guidance);
124
+ }
125
+ else {
126
+ const detail = sanitizeDisplayBlock(stderr.trimEnd());
127
+ warn(getMessage("dependencies.ensureFailed", locale) +
128
+ (detail.trim().length > 0 ? `\n${detail}` : ""));
129
+ }
124
130
  return {
125
131
  ran: true,
126
132
  exitCode: typeof e.code === "number" ? e.code : 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intra-mart/accel",
3
- "version": "2.0.0",
3
+ "version": "3.0.0-dev.202611201537",
4
4
  "type": "module",
5
5
  "description": "CLI tool for intra-mart Accel Platform development",
6
6
  "author": "INTRAMART CORPORATION",
@@ -1,5 +0,0 @@
1
- export type RepoLayout = {
2
- gitDir: string;
3
- commonDir: string;
4
- };
5
- export declare const resolveRepoLayout: (projectDir: string) => Promise<RepoLayout | null>;
@@ -1,44 +0,0 @@
1
- import { lstat, readFile } from "node:fs/promises";
2
- import { isAbsolute, join, resolve } from "node:path";
3
- export const resolveRepoLayout = async (projectDir) => {
4
- const dotGit = join(projectDir, ".git");
5
- let stats;
6
- try {
7
- stats = await lstat(dotGit);
8
- }
9
- catch {
10
- return null;
11
- }
12
- let gitDir;
13
- if (stats.isDirectory()) {
14
- gitDir = dotGit;
15
- }
16
- else if (stats.isFile()) {
17
- const content = await readFile(dotGit, "utf-8").catch(() => null);
18
- if (content === null)
19
- return null;
20
- const match = /^gitdir:[ \t]*(.+?)[ \t\r]*$/m.exec(content);
21
- if (match === null || match[1].length === 0)
22
- return null;
23
- gitDir = isAbsolute(match[1]) ? match[1] : resolve(projectDir, match[1]);
24
- try {
25
- if (!(await lstat(gitDir)).isDirectory())
26
- return null;
27
- }
28
- catch {
29
- return null;
30
- }
31
- }
32
- else {
33
- return null;
34
- }
35
- let commonDir = gitDir;
36
- const commonRef = await readFile(join(gitDir, "commondir"), "utf-8").catch(() => null);
37
- if (commonRef !== null) {
38
- const target = commonRef.trim();
39
- if (target.length === 0)
40
- return null;
41
- commonDir = isAbsolute(target) ? target : resolve(gitDir, target);
42
- }
43
- return { gitDir, commonDir };
44
- };