iskills 0.2.60 → 0.2.63

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 (131) hide show
  1. package/AGENT-CLI.md +63 -0
  2. package/README.md +24 -17
  3. package/README.zh-CN.md +24 -17
  4. package/bin/command-route.mjs +15 -0
  5. package/bin/iskills.js +14 -7
  6. package/dist/src/cli.js +4 -12
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/commands/agent/arguments.d.ts +10 -0
  9. package/dist/src/commands/agent/arguments.js +60 -0
  10. package/dist/src/commands/agent/arguments.js.map +1 -0
  11. package/dist/src/commands/agent/index.d.ts +1 -0
  12. package/dist/src/commands/agent/index.js +778 -0
  13. package/dist/src/commands/agent/index.js.map +1 -0
  14. package/dist/src/commands/browser-actions.js +42 -12
  15. package/dist/src/commands/browser-actions.js.map +1 -1
  16. package/dist/src/commands/create.js +3 -3
  17. package/dist/src/commands/create.js.map +1 -1
  18. package/dist/src/commands/index.d.ts +0 -3
  19. package/dist/src/commands/index.js +0 -33
  20. package/dist/src/commands/index.js.map +1 -1
  21. package/dist/src/commands/library.d.ts +1 -0
  22. package/dist/src/commands/library.js +82 -120
  23. package/dist/src/commands/library.js.map +1 -1
  24. package/dist/src/commands/mcp.d.ts +1 -3
  25. package/dist/src/commands/mcp.js +7 -240
  26. package/dist/src/commands/mcp.js.map +1 -1
  27. package/dist/src/domain/agent-collection-write.d.ts +2 -0
  28. package/dist/src/domain/agent-collection-write.js +204 -0
  29. package/dist/src/domain/agent-collection-write.js.map +1 -0
  30. package/dist/src/domain/agent-mcp-write.d.ts +23 -0
  31. package/dist/src/domain/agent-mcp-write.js +927 -0
  32. package/dist/src/domain/agent-mcp-write.js.map +1 -0
  33. package/dist/src/domain/agent-read.d.ts +38 -0
  34. package/dist/src/domain/agent-read.js +524 -0
  35. package/dist/src/domain/agent-read.js.map +1 -0
  36. package/dist/src/domain/agent-skill-write.d.ts +34 -0
  37. package/dist/src/domain/agent-skill-write.js +926 -0
  38. package/dist/src/domain/agent-skill-write.js.map +1 -0
  39. package/dist/src/domain/agent-write.d.ts +9 -0
  40. package/dist/src/domain/agent-write.js +127 -0
  41. package/dist/src/domain/agent-write.js.map +1 -0
  42. package/dist/src/domain/collection-write.d.ts +9 -2
  43. package/dist/src/domain/collection-write.js +175 -36
  44. package/dist/src/domain/collection-write.js.map +1 -1
  45. package/dist/src/domain/core.d.ts +12 -0
  46. package/dist/src/domain/core.js +57 -2
  47. package/dist/src/domain/core.js.map +1 -1
  48. package/dist/src/domain/cross-agent-install.js +3 -5
  49. package/dist/src/domain/cross-agent-install.js.map +1 -1
  50. package/dist/src/domain/errors.d.ts +1 -0
  51. package/dist/src/domain/errors.js +3 -0
  52. package/dist/src/domain/errors.js.map +1 -1
  53. package/dist/src/domain/git.d.ts +28 -2
  54. package/dist/src/domain/git.js +233 -84
  55. package/dist/src/domain/git.js.map +1 -1
  56. package/dist/src/domain/install-target.js +10 -1
  57. package/dist/src/domain/install-target.js.map +1 -1
  58. package/dist/src/domain/mcp/collection.d.ts +3 -0
  59. package/dist/src/domain/mcp/collection.js +26 -4
  60. package/dist/src/domain/mcp/collection.js.map +1 -1
  61. package/dist/src/domain/mcp/dialects/borrow.js +1 -5
  62. package/dist/src/domain/mcp/dialects/borrow.js.map +1 -1
  63. package/dist/src/domain/mcp/index.d.ts +1 -1
  64. package/dist/src/domain/mcp/index.js +1 -1
  65. package/dist/src/domain/mcp/index.js.map +1 -1
  66. package/dist/src/domain/mcp/io.js +1 -1
  67. package/dist/src/domain/mcp/io.js.map +1 -1
  68. package/dist/src/domain/mcp/location-write.d.ts +3 -0
  69. package/dist/src/domain/mcp/location-write.js +39 -0
  70. package/dist/src/domain/mcp/location-write.js.map +1 -0
  71. package/dist/src/domain/mcp/probe.d.ts +2 -0
  72. package/dist/src/domain/mcp/probe.js +2 -1
  73. package/dist/src/domain/mcp/probe.js.map +1 -1
  74. package/dist/src/domain/mcp/recipe.d.ts +1 -1
  75. package/dist/src/domain/mcp/recipe.js +6 -5
  76. package/dist/src/domain/mcp/recipe.js.map +1 -1
  77. package/dist/src/domain/mcp/secrets.js +12 -11
  78. package/dist/src/domain/mcp/secrets.js.map +1 -1
  79. package/dist/src/domain/mcp/types.d.ts +2 -0
  80. package/dist/src/domain/mcp/write.js +49 -35
  81. package/dist/src/domain/mcp/write.js.map +1 -1
  82. package/dist/src/domain/operation.d.ts +30 -0
  83. package/dist/src/domain/operation.js +107 -0
  84. package/dist/src/domain/operation.js.map +1 -0
  85. package/dist/src/domain/process.d.ts +3 -0
  86. package/dist/src/domain/process.js +81 -0
  87. package/dist/src/domain/process.js.map +1 -0
  88. package/dist/src/domain/tags.d.ts +11 -0
  89. package/dist/src/domain/tags.js +42 -0
  90. package/dist/src/domain/tags.js.map +1 -0
  91. package/dist/src/domain/user-config.js +9 -1
  92. package/dist/src/domain/user-config.js.map +1 -1
  93. package/dist/src/i18n/en.js +55 -29
  94. package/dist/src/i18n/en.js.map +1 -1
  95. package/dist/src/i18n/zh.d.ts +56 -30
  96. package/dist/src/i18n/zh.js +56 -30
  97. package/dist/src/i18n/zh.js.map +1 -1
  98. package/dist/src/ui/browser/browse-capabilities.js +7 -1
  99. package/dist/src/ui/browser/browse-capabilities.js.map +1 -1
  100. package/dist/src/ui/browser/browse-session.d.ts +2 -0
  101. package/dist/src/ui/browser/browse-session.js +4 -0
  102. package/dist/src/ui/browser/browse-session.js.map +1 -1
  103. package/dist/src/ui/browser/browser.js +41 -12
  104. package/dist/src/ui/browser/browser.js.map +1 -1
  105. package/dist/src/ui/browser/index.js +3 -1
  106. package/dist/src/ui/browser/index.js.map +1 -1
  107. package/dist/src/ui/browser/types.d.ts +6 -0
  108. package/dist/src/ui/footer/resolve-footer.js +3 -0
  109. package/dist/src/ui/footer/resolve-footer.js.map +1 -1
  110. package/dist/src/ui/footer/types.d.ts +1 -0
  111. package/dist/src/ui/import/review.d.ts +2 -1
  112. package/dist/src/ui/import/review.js +8 -3
  113. package/dist/src/ui/import/review.js.map +1 -1
  114. package/dist/src/ui/import/types.d.ts +1 -0
  115. package/dist/src/ui/mcp/browse-capabilities.d.ts +1 -0
  116. package/dist/src/ui/mcp/browse-capabilities.js +1 -0
  117. package/dist/src/ui/mcp/browse-capabilities.js.map +1 -1
  118. package/dist/src/ui/mcp/browser.d.ts +2 -1
  119. package/dist/src/ui/mcp/browser.js +33 -5
  120. package/dist/src/ui/mcp/browser.js.map +1 -1
  121. package/dist/src/ui/mcp/index.js +29 -2
  122. package/dist/src/ui/mcp/index.js.map +1 -1
  123. package/dist/src/ui/prompts/index.d.ts +1 -1
  124. package/dist/src/ui/prompts/index.js +1 -1
  125. package/dist/src/ui/prompts/index.js.map +1 -1
  126. package/dist/src/ui/prompts/present.d.ts +5 -1
  127. package/dist/src/ui/prompts/present.js +11 -2
  128. package/dist/src/ui/prompts/present.js.map +1 -1
  129. package/dist/src/ui/tui/hooks.js +4 -0
  130. package/dist/src/ui/tui/hooks.js.map +1 -1
  131. package/package.json +16 -13
@@ -1,14 +1,104 @@
1
1
  import { execFile, execFileSync } from 'node:child_process';
2
- import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
2
+ import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
- import { dirname, join, sep } from 'node:path';
4
+ import { dirname, join, resolve, sep } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
- import { assertSkillName, baselinePath, clearDirectory, collectionPaths, collectionGitAddPaths, collectionGitStatusPaths, commitCollection, copyDirectoryContents, errorMessage, ensureCollection, exists, parseGitSource, readMetadata, readState, sourceSkillFile, validateSkillTree, writeMetadata, writeState, } from './core.js';
6
+ import { assertSkillName, baselinePath, clearDirectory, collectionPaths, collectionGitPresentAddPaths, collectionGitStatusPaths, commitCollection, copyDirectoryContents, errorMessage, ensureCollection, exists, parseGitSource, readMetadata, readState, sourceSkillFile, validateSkillTree, writeMetadata, writeState, } from './core.js';
7
7
  import { installMergedCollectionSkill, removeFromCollection, } from './collection-write.js';
8
8
  import { DomainError, domainNotify } from './errors.js';
9
9
  import { recordRunLog } from './run-log.js';
10
+ import { runGit } from './process.js';
10
11
  export function git(args) {
11
- return execFileSync('git', args, { encoding: 'utf8' }).trim();
12
+ return execFileSync('git', args, { encoding: 'utf8', timeout: 120_000, env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never' } }).trim();
13
+ }
14
+ const PRIVATE_EXCLUDE_BEGIN = '# iskills private skills begin';
15
+ const PRIVATE_EXCLUDE_END = '# iskills private skills end';
16
+ /** Read the local-only privacy manifest. Invalid data must never silently allow a push. */
17
+ export async function readPrivateSkillNames(root = collectionPaths().root) {
18
+ let text;
19
+ try {
20
+ text = await readFile(join(root, '.local', 'private-skills.json'), 'utf8');
21
+ }
22
+ catch (error) {
23
+ if (error.code === 'ENOENT')
24
+ return [];
25
+ throw error;
26
+ }
27
+ const value = JSON.parse(text);
28
+ if (!Array.isArray(value) || value.some((name) => typeof name !== 'string')) {
29
+ throw new Error('invalid private skills manifest');
30
+ }
31
+ return [...new Set(value.map(assertSkillName))];
32
+ }
33
+ function privateSkillPaths(names) {
34
+ return names.flatMap((name) => [`skills/${name}`, `metadata/${name}.json`]);
35
+ }
36
+ /** Exclusion pathspecs for collection add/status, including previously tracked paths. */
37
+ export function privateSkillExcludePathspecs(names) {
38
+ const escapeGlob = (name) => name.replace(/[?*\[\\]/g, (char) => `[${char === '\\' ? '\\\\' : char}]`);
39
+ return names.map(assertSkillName).flatMap((name) => [
40
+ `:(top,exclude,glob)skills/${escapeGlob(name)}/**`,
41
+ `:(top,exclude,glob)metadata/${escapeGlob(name)}.json`,
42
+ ]);
43
+ }
44
+ /** Update local Git ignores and stage removal of private files without deleting them on disk.
45
+ * Call before every collection Git add/status, after persisting the privacy manifest.
46
+ */
47
+ export async function preparePrivateSkillsForGit(root = collectionPaths().root) {
48
+ const names = await readPrivateSkillNames(root);
49
+ const excludePath = resolve(root, await runGit(['-C', root, 'rev-parse', '--git-path', 'info/exclude']));
50
+ let existing = '';
51
+ try {
52
+ existing = await readFile(excludePath, 'utf8');
53
+ }
54
+ catch (error) {
55
+ if (error.code !== 'ENOENT')
56
+ throw error;
57
+ }
58
+ const begin = existing.indexOf(PRIVATE_EXCLUDE_BEGIN);
59
+ const end = existing.indexOf(PRIVATE_EXCLUDE_END);
60
+ if ((begin === -1) !== (end === -1) || (begin !== -1 && end < begin)) {
61
+ throw new Error('invalid private skills Git exclude block');
62
+ }
63
+ if (begin !== -1)
64
+ existing = existing.slice(0, begin) + existing.slice(end + PRIVATE_EXCLUDE_END.length).replace(/^\r?\n/, '');
65
+ const escapePattern = (path) => path.replace(/([\\*?\[\]])/g, '\\$1').replace(/ +$/, (spaces) => '\\ '.repeat(spaces.length));
66
+ const patterns = names.flatMap((name) => [`/${escapePattern(`skills/${name}`)}/**`, `/${escapePattern(`metadata/${name}.json`)}`]);
67
+ const block = [PRIVATE_EXCLUDE_BEGIN, ...patterns, PRIVATE_EXCLUDE_END, ''].join('\n');
68
+ const next = `${existing}${existing && !existing.endsWith('\n') ? '\n' : ''}${block}`;
69
+ if (next !== await readFile(excludePath, 'utf8').catch((error) => {
70
+ if (error.code === 'ENOENT')
71
+ return '';
72
+ throw error;
73
+ })) {
74
+ await mkdir(dirname(excludePath), { recursive: true });
75
+ await writeFile(excludePath, next);
76
+ }
77
+ const paths = [...privateSkillPaths(names), '.local/private-skills.json'];
78
+ if (paths.length) {
79
+ await runGit(['-C', root, 'rm', '-r', '--cached', '--force', '--ignore-unmatch', '--', ...paths.map((path) => `:(top,literal)${path}`)]);
80
+ }
81
+ return privateSkillExcludePathspecs(names);
82
+ }
83
+ async function assertPrivateTreeSafe(root, commit) {
84
+ const paths = privateSkillPaths(await readPrivateSkillNames(root));
85
+ if (!paths.length)
86
+ return;
87
+ const found = await runGit(['-C', root, 'ls-tree', '-r', '--name-only', commit, '--', ...paths.map((path) => `:(top,literal)${path}`)]);
88
+ if (found)
89
+ throw new Error('remote contains a private skill; refusing to overwrite local files');
90
+ }
91
+ /** Refuse to transmit any new commit whose tree contains a currently private skill. */
92
+ async function assertPrivateHistorySafe(root, head, remoteHead) {
93
+ const paths = privateSkillPaths(await readPrivateSkillNames(root));
94
+ if (!paths.length)
95
+ return;
96
+ const commits = (await runGit(['-C', root, 'rev-list', head, ...(remoteHead ? [`^${remoteHead}`] : [])])).split('\n').filter(Boolean);
97
+ for (const commit of commits) {
98
+ const found = await runGit(['-C', root, 'ls-tree', '-r', '--name-only', commit, '--', ...paths.map((path) => `:(top,literal)${path}`)]);
99
+ if (found)
100
+ throw new Error('private skill exists in commits that would be pushed; remove it from the outgoing history first');
101
+ }
12
102
  }
13
103
  const remoteHeadCache = new Map();
14
104
  function remoteBranchHead(url, ref) {
@@ -56,15 +146,15 @@ export async function checkGitSkillUpdates(skills) {
56
146
  failed: results.filter((skill) => !skill.remote).length,
57
147
  };
58
148
  }
59
- export async function initCollectionGit() {
149
+ export async function initCollectionGit(signal) {
60
150
  const { root } = await ensureCollection();
61
151
  const gitDir = join(root, '.git');
62
152
  const created = !(await exists(gitDir));
63
153
  try {
64
154
  if (created)
65
- git(['-C', root, 'init', '--quiet', '-b', 'main']);
155
+ await runGit(['-C', root, 'init', '--quiet', '-b', 'main'], signal);
66
156
  try {
67
- git(['-C', root, 'rev-parse', '--verify', '--quiet', 'HEAD']);
157
+ await runGit(['-C', root, 'rev-parse', '--verify', '--quiet', 'HEAD'], signal);
68
158
  return false;
69
159
  }
70
160
  catch { }
@@ -74,14 +164,17 @@ export async function initCollectionGit() {
74
164
  ]) {
75
165
  let value = '';
76
166
  try {
77
- value = git(['-C', root, 'config', '--get', key]);
167
+ value = await runGit(['-C', root, 'config', '--get', key], signal);
78
168
  }
79
169
  catch { }
80
170
  if (!value)
81
- git(['-C', root, 'config', key, fallback]);
171
+ await runGit(['-C', root, 'config', key, fallback], signal);
82
172
  }
83
- git(['-C', root, 'add', '-A', '--', ...(await collectionGitAddPaths(root))]);
84
- git(['-C', root, 'commit', '--quiet', '-m', 'initialize skill collection']);
173
+ const privateExcludes = await preparePrivateSkillsForGit(root);
174
+ const addPaths = await collectionGitPresentAddPaths(root, privateExcludes);
175
+ if (addPaths.length)
176
+ await runGit(['-C', root, 'add', '-A', '--', ...addPaths, ...privateExcludes], signal);
177
+ await runGit(['-C', root, 'commit', '--quiet', '-m', 'initialize skill collection'], signal);
85
178
  return true;
86
179
  }
87
180
  catch (error) {
@@ -204,19 +297,19 @@ export async function cloneGitSource(input) {
204
297
  throw new DomainError('git.cloneFailed', { error: errorMessage(error) });
205
298
  }
206
299
  }
207
- function gitObjectExists(repository, object) {
300
+ async function gitObjectExists(repository, object) {
208
301
  try {
209
- execFileSync('git', ['-C', repository, 'cat-file', '-e', object], { stdio: 'ignore' });
302
+ await runGit(['-C', repository, 'cat-file', '-e', object]);
210
303
  return true;
211
304
  }
212
305
  catch {
213
306
  return false;
214
307
  }
215
308
  }
216
- function detectRenamedSkillPath(repository, fromCommit, toCommit, sourcePath) {
309
+ export async function detectRenamedSkillPath(repository, fromCommit, toCommit, sourcePath) {
217
310
  let output = '';
218
311
  try {
219
- output = git(['-C', repository, 'diff', '--name-status', '-M', fromCommit, toCommit]);
312
+ output = await runGit(['-C', repository, 'diff', '--name-status', '-M', fromCommit, toCommit]);
220
313
  }
221
314
  catch {
222
315
  return sourcePath;
@@ -237,28 +330,26 @@ async function prepareDirectoryMerge(name, baseSkill, remoteSkill) {
237
330
  await Promise.all([mkdir(workspace, { recursive: true }), mkdir(paths.local, { recursive: true })]);
238
331
  await Promise.all([validateSkillTree(baseSkill), validateSkillTree(remoteSkill)]);
239
332
  await copyDirectoryContents(baseSkill, workspace);
240
- git(['-C', workspace, 'init', '--quiet', '-b', 'base']);
241
- git(['-C', workspace, 'config', 'user.name', 'Skill Collection']);
242
- git(['-C', workspace, 'config', 'user.email', 'iskills@localhost']);
243
- git(['-C', workspace, 'add', '-A']);
244
- git(['-C', workspace, 'commit', '--quiet', '-m', 'base']);
245
- const base = git(['-C', workspace, 'rev-parse', 'HEAD']);
246
- git(['-C', workspace, 'checkout', '--quiet', '-b', 'remote', base]);
333
+ await runGit(['-C', workspace, 'init', '--quiet', '-b', 'base']);
334
+ await runGit(['-C', workspace, 'config', 'user.name', 'Skill Collection']);
335
+ await runGit(['-C', workspace, 'config', 'user.email', 'iskills@localhost']);
336
+ await runGit(['-C', workspace, 'add', '-A']);
337
+ await runGit(['-C', workspace, 'commit', '--quiet', '-m', 'base']);
338
+ const base = await runGit(['-C', workspace, 'rev-parse', 'HEAD']);
339
+ await runGit(['-C', workspace, 'checkout', '--quiet', '-b', 'remote', base]);
247
340
  await clearDirectory(workspace, true);
248
341
  await copyDirectoryContents(remoteSkill, workspace);
249
- git(['-C', workspace, 'add', '-A']);
250
- git(['-C', workspace, 'commit', '--quiet', '--allow-empty', '-m', 'remote']);
251
- const remote = git(['-C', workspace, 'rev-parse', 'HEAD']);
252
- git(['-C', workspace, 'checkout', '--quiet', '-b', 'local', base]);
342
+ await runGit(['-C', workspace, 'add', '-A']);
343
+ await runGit(['-C', workspace, 'commit', '--quiet', '--allow-empty', '-m', 'remote']);
344
+ const remote = await runGit(['-C', workspace, 'rev-parse', 'HEAD']);
345
+ await runGit(['-C', workspace, 'checkout', '--quiet', '-b', 'local', base]);
253
346
  await clearDirectory(workspace, true);
254
347
  await copyDirectoryContents(join(paths.skills, name), workspace);
255
- git(['-C', workspace, 'add', '-A']);
256
- git(['-C', workspace, 'commit', '--quiet', '--allow-empty', '-m', 'local']);
348
+ await runGit(['-C', workspace, 'add', '-A']);
349
+ await runGit(['-C', workspace, 'commit', '--quiet', '--allow-empty', '-m', 'local']);
257
350
  let conflicted = false;
258
351
  try {
259
- execFileSync('git', ['-C', workspace, 'merge', '--quiet', '--no-edit', remote], {
260
- stdio: 'ignore',
261
- });
352
+ await runGit(['-C', workspace, 'merge', '--quiet', '--no-edit', remote]);
262
353
  }
263
354
  catch {
264
355
  conflicted = true;
@@ -269,7 +360,7 @@ let updateWorktreeSeq = 0;
269
360
  async function removeUpdateWorktrees(repository, trees) {
270
361
  for (const tree of trees) {
271
362
  try {
272
- git(['-C', repository, 'worktree', 'remove', '--force', tree]);
363
+ await runGit(['-C', repository, 'worktree', 'remove', '--force', tree]);
273
364
  }
274
365
  catch { }
275
366
  await rm(tree, { recursive: true, force: true });
@@ -282,9 +373,9 @@ async function prepareSourceMerge(name, repository, baseCommit, latestCommit, ol
282
373
  const remoteTree = join(root, `remote-${token}`);
283
374
  const added = [];
284
375
  try {
285
- git(['-C', repository, 'worktree', 'add', '--quiet', '--detach', baseTree, baseCommit]);
376
+ await runGit(['-C', repository, 'worktree', 'add', '--quiet', '--detach', baseTree, baseCommit]);
286
377
  added.push(baseTree);
287
- git(['-C', repository, 'worktree', 'add', '--quiet', '--detach', remoteTree, latestCommit]);
378
+ await runGit(['-C', repository, 'worktree', 'add', '--quiet', '--detach', remoteTree, latestCommit]);
288
379
  added.push(remoteTree);
289
380
  return await prepareDirectoryMerge(name, join(baseTree, oldPath), join(remoteTree, newPath));
290
381
  }
@@ -330,8 +421,9 @@ export async function finalizeResolvedConflicts() {
330
421
  finalized = true;
331
422
  }
332
423
  if (remaining.length !== state.conflicts.length) {
333
- state.conflicts = remaining;
334
- await writeState(state);
424
+ const latest = await readState();
425
+ latest.conflicts = remaining;
426
+ await writeState(latest);
335
427
  }
336
428
  if (finalized)
337
429
  await commitCollection('apply resolved source updates');
@@ -350,6 +442,7 @@ export async function backgroundCollectionSync() {
350
442
  let worktree;
351
443
  let worktreeRoot;
352
444
  try {
445
+ await preparePrivateSkillsForGit(paths.root);
353
446
  const remotes = git(['-C', paths.root, 'remote']).split(/\r?\n/).filter(Boolean);
354
447
  if (!remotes.includes('origin'))
355
448
  return;
@@ -357,8 +450,10 @@ export async function backgroundCollectionSync() {
357
450
  const localHead = git(['-C', paths.root, 'rev-parse', 'HEAD']);
358
451
  git(['-C', paths.root, 'fetch', '--quiet', 'origin']);
359
452
  const upstream = `refs/remotes/origin/${branch}`;
360
- if (!gitObjectExists(paths.root, upstream)) {
361
- git(['-C', paths.root, 'push', '--quiet', '-u', 'origin', branch]);
453
+ if (!(await gitObjectExists(paths.root, upstream))) {
454
+ await assertPrivateHistorySafe(paths.root, localHead);
455
+ // Push by branch name so `-u` binds the local branch's upstream (hash:ref does not).
456
+ git(['-C', paths.root, 'push', '--quiet', '--no-follow-tags', '-u', 'origin', `refs/heads/${branch}:refs/heads/${branch}`]);
362
457
  return;
363
458
  }
364
459
  const remoteHead = git(['-C', paths.root, 'rev-parse', upstream]);
@@ -390,8 +485,10 @@ export async function backgroundCollectionSync() {
390
485
  ]);
391
486
  if (currentHead !== localHead || dirty)
392
487
  return;
488
+ await assertPrivateHistorySafe(paths.root, mergedHead, remoteHead);
489
+ await assertPrivateTreeSafe(paths.root, mergedHead);
393
490
  git(['-C', paths.root, 'merge', '--quiet', '--ff-only', mergedHead]);
394
- git(['-C', paths.root, 'push', '--quiet', 'origin', branch]);
491
+ git(['-C', paths.root, 'push', '--quiet', '--no-follow-tags', 'origin', `${mergedHead}:refs/heads/${branch}`]);
395
492
  }
396
493
  catch {
397
494
  // Soft-fail background sync; no on-disk conflict cache.
@@ -411,7 +508,7 @@ async function cloneForSkillUpdate(url) {
411
508
  const temporary = await mkdtemp(join(tmpdir(), 'iskills-update-'));
412
509
  const repository = join(temporary, 'repository');
413
510
  try {
414
- git(['clone', '--quiet', '--no-checkout', url, repository]);
511
+ await runGit(['clone', '--quiet', '--no-checkout', '--', url, repository]);
415
512
  return { temporary, repository };
416
513
  }
417
514
  catch (error) {
@@ -460,32 +557,32 @@ async function applyGitSkillUpdate(skill, allowDelete, options, clones) {
460
557
  if (state.conflicts.some((conflict) => conflict.type === 'source' && conflict.skill === skill.name)) {
461
558
  return 'conflict';
462
559
  }
463
- const { clone, owned } = await acquireUpdateClone(gitSource.url, clones);
560
+ const { clone, owned } = options.clone ? { clone: options.clone, owned: false } : await acquireUpdateClone(gitSource.url, clones);
464
561
  const repository = clone.repository;
465
562
  try {
466
563
  const latestRef = gitSource.ref
467
564
  ? `refs/remotes/origin/${gitSource.ref}`
468
565
  : 'refs/remotes/origin/HEAD';
469
- if (!gitObjectExists(repository, latestRef) && gitSource.ref) {
470
- if (gitObjectExists(repository, `refs/tags/${gitSource.ref}`)) {
566
+ if (!(await gitObjectExists(repository, latestRef)) && gitSource.ref) {
567
+ if (await gitObjectExists(repository, `refs/tags/${gitSource.ref}`)) {
471
568
  metadata.source.refType = 'tag';
472
569
  await writeMetadata(metadata);
473
570
  return 'pinned';
474
571
  }
475
572
  throw new DomainError('git.branchMissing', { ref: gitSource.ref });
476
573
  }
477
- const latestCommit = git(['-C', repository, 'rev-parse', latestRef]);
574
+ const latestCommit = await runGit(['-C', repository, 'rev-parse', latestRef]);
478
575
  if (gitSource.ref)
479
576
  rememberRemoteBranchHead(gitSource.url, gitSource.ref, latestCommit);
480
577
  if (latestCommit === gitSource.commit)
481
578
  return 'unchanged';
482
- if (gitSource.commit && !gitObjectExists(repository, gitSource.commit)) {
579
+ if (gitSource.commit && !(await gitObjectExists(repository, gitSource.commit))) {
483
580
  throw new DomainError('git.commitMissing', { commit: gitSource.commit });
484
581
  }
485
582
  const newPath = gitSource.commit
486
- ? detectRenamedSkillPath(repository, gitSource.commit, latestCommit, gitSource.path ?? '.')
583
+ ? await detectRenamedSkillPath(repository, gitSource.commit, latestCommit, gitSource.path ?? '.')
487
584
  : gitSource.path;
488
- if (!gitObjectExists(repository, `${latestCommit}:${sourceSkillFile(newPath ?? '.')}`)) {
585
+ if (!(await gitObjectExists(repository, `${latestCommit}:${sourceSkillFile(newPath ?? '.')}`))) {
489
586
  if (!allowDelete) {
490
587
  const links = (await readState()).links.filter((link) => link.skill === skill.name);
491
588
  if (!options.confirmDelete) {
@@ -509,7 +606,7 @@ async function applyGitSkillUpdate(skill, allowDelete, options, clones) {
509
606
  throw new DomainError('git.missingBaseline');
510
607
  }
511
608
  const remoteTree = join(dirname(repository), `remote-${assertSkillName(skill.name)}-${process.pid}`);
512
- git(['-C', repository, 'worktree', 'add', '--quiet', '--detach', remoteTree, latestCommit]);
609
+ await runGit(['-C', repository, 'worktree', 'add', '--quiet', '--detach', remoteTree, latestCommit]);
513
610
  try {
514
611
  merge = await prepareDirectoryMerge(skill.name, baseline, join(remoteTree, newPath));
515
612
  }
@@ -520,7 +617,7 @@ async function applyGitSkillUpdate(skill, allowDelete, options, clones) {
520
617
  const nextSource = {
521
618
  ...gitSource,
522
619
  ref: gitSource.ref ||
523
- git(['-C', repository, 'symbolic-ref', '--short', latestRef]).replace('origin/', ''),
620
+ (await runGit(['-C', repository, 'symbolic-ref', '--short', latestRef])).replace('origin/', ''),
524
621
  path: newPath,
525
622
  commit: latestCommit,
526
623
  };
@@ -537,9 +634,9 @@ async function applyGitSkillUpdate(skill, allowDelete, options, clones) {
537
634
  return 'conflict';
538
635
  }
539
636
  await installMergedCollectionSkill(skill.name, merge.workspace, nextSource);
540
- await rm(merge.workspace, { recursive: true, force: true });
637
+ await rm(merge.workspace, { recursive: true, force: true }).catch((error) => domainNotify('domain.warnConflictCleanup', { error: errorMessage(error) }));
541
638
  if (baseline)
542
- await rm(baseline, { recursive: true, force: true });
639
+ await rm(baseline, { recursive: true, force: true }).catch((error) => domainNotify('domain.warnConflictCleanup', { error: errorMessage(error) }));
543
640
  await commitCollection(`update ${skill.name}`);
544
641
  return 'updated';
545
642
  }
@@ -575,12 +672,9 @@ export async function updateGitSkills(skills, allowDelete, options = {}) {
575
672
  }
576
673
  }
577
674
  /** Foreground git with captured stderr so DomainError can surface the real failure. */
578
- function gitForeground(args) {
675
+ async function gitForeground(args) {
579
676
  try {
580
- execFileSync('git', args, {
581
- encoding: 'utf8',
582
- stdio: ['ignore', 'pipe', 'pipe'],
583
- });
677
+ await runGit(args);
584
678
  }
585
679
  catch (error) {
586
680
  throw new Error(errorMessage(error));
@@ -594,19 +688,13 @@ async function abortLeftoverCollectionRebase(root) {
594
688
  if (!inProgress)
595
689
  return;
596
690
  try {
597
- gitForeground(['-C', root, 'rebase', '--abort']);
691
+ await gitForeground(['-C', root, 'rebase', '--abort']);
598
692
  }
599
693
  catch (error) {
600
694
  throw new Error(`collection git rebase in progress and could not abort: ${errorMessage(error)}`);
601
695
  }
602
696
  }
603
- /**
604
- * Foreground collection sync: commit pending managed paths, then merge origin in a
605
- * detached worktree and only ff-only apply to the live tree (same isolation model as
606
- * background sync). Never runs `pull --rebase` on the main collection, so a conflict
607
- * cannot leave skills/metadata mid-rebase.
608
- */
609
- async function foregroundCollectionSync() {
697
+ async function foregroundCollectionSync(progress) {
610
698
  const paths = collectionPaths();
611
699
  const root = paths.root;
612
700
  const lock = join(paths.local, 'git-sync.lock');
@@ -624,38 +712,79 @@ async function foregroundCollectionSync() {
624
712
  try {
625
713
  // Flush local WIP first so dirty skills/metadata never block sync.
626
714
  // Skip background child — this call is the sync.
627
- await commitCollection('sync pending collection changes', true, false);
715
+ try {
716
+ await preparePrivateSkillsForGit(root);
717
+ const before = await runGit(['-C', root, 'rev-parse', 'HEAD']);
718
+ await commitCollection('sync pending collection changes', true, false);
719
+ if (progress)
720
+ progress.stages.commit = before === await runGit(['-C', root, 'rev-parse', 'HEAD']) ? 'unchanged' : 'committed';
721
+ }
722
+ catch (error) {
723
+ if (progress)
724
+ progress.stages.commit = 'failed';
725
+ throw error;
726
+ }
628
727
  await abortLeftoverCollectionRebase(root);
629
- const remotes = git(['-C', root, 'remote']).split(/\r?\n/).filter(Boolean);
728
+ const remotes = (await runGit(['-C', root, 'remote'])).split(/\r?\n/).filter(Boolean);
630
729
  if (!remotes.includes('origin')) {
631
730
  throw new DomainError('git.syncFailed', { error: 'no origin remote' });
632
731
  }
633
- const branch = git(['-C', root, 'symbolic-ref', '--short', 'HEAD']);
634
- const localHead = git(['-C', root, 'rev-parse', 'HEAD']);
635
- gitForeground(['-C', root, 'fetch', 'origin']);
732
+ const branch = await runGit(['-C', root, 'symbolic-ref', '--short', 'HEAD']);
733
+ const localHead = await runGit(['-C', root, 'rev-parse', 'HEAD']);
734
+ try {
735
+ await gitForeground(['-C', root, 'fetch', 'origin']);
736
+ if (progress)
737
+ progress.stages.fetch = 'committed';
738
+ }
739
+ catch (error) {
740
+ if (progress)
741
+ progress.stages.fetch = 'failed';
742
+ throw error;
743
+ }
636
744
  const upstream = `refs/remotes/origin/${branch}`;
637
- if (!gitObjectExists(root, upstream)) {
638
- gitForeground(['-C', root, 'push', '-u', 'origin', branch]);
745
+ if (!(await gitObjectExists(root, upstream))) {
746
+ // Push by branch name so `-u` binds the local branch's upstream (hash:ref does not).
747
+ try {
748
+ await assertPrivateHistorySafe(root, localHead);
749
+ await gitForeground(['-C', root, 'push', '--no-follow-tags', '-u', 'origin', `refs/heads/${branch}:refs/heads/${branch}`]);
750
+ if (progress)
751
+ progress.stages.push = 'committed';
752
+ }
753
+ catch (error) {
754
+ if (progress)
755
+ progress.stages.push = 'failed';
756
+ throw error;
757
+ }
758
+ if (progress)
759
+ progress.stages.merge = 'unchanged';
639
760
  return;
640
761
  }
641
- const remoteHead = git(['-C', root, 'rev-parse', upstream]);
762
+ const remoteHead = await runGit(['-C', root, 'rev-parse', upstream]);
642
763
  if (remoteHead === localHead) {
764
+ if (progress) {
765
+ progress.stages.merge = 'unchanged';
766
+ progress.stages.push = 'unchanged';
767
+ }
643
768
  return;
644
769
  }
645
770
  worktreeRoot = await mkdtemp(join(tmpdir(), 'iskills-collection-sync-'));
646
771
  worktree = join(worktreeRoot, 'worktree');
647
- git(['-C', root, 'worktree', 'add', '--quiet', '--detach', worktree, localHead]);
648
- git(['-C', worktree, 'config', 'user.name', 'Skill Collection']);
649
- git(['-C', worktree, 'config', 'user.email', 'iskills@localhost']);
772
+ await runGit(['-C', root, 'worktree', 'add', '--quiet', '--detach', worktree, localHead]);
773
+ await runGit(['-C', worktree, 'config', 'user.name', 'Skill Collection']);
774
+ await runGit(['-C', worktree, 'config', 'user.email', 'iskills@localhost']);
650
775
  try {
651
- gitForeground(['-C', worktree, 'merge', '--no-edit', remoteHead]);
776
+ await gitForeground(['-C', worktree, 'merge', '--no-edit', remoteHead]);
652
777
  }
653
778
  catch {
779
+ if (progress) {
780
+ progress.stages.merge = 'failed';
781
+ progress.conflicts = (await runGit(['-C', worktree, 'diff', '--name-only', '--diff-filter=U'])).split('\n').filter(Boolean);
782
+ }
654
783
  throw new DomainError('git.conflictWithOrigin');
655
784
  }
656
- const mergedHead = git(['-C', worktree, 'rev-parse', 'HEAD']);
657
- const currentHead = git(['-C', root, 'rev-parse', 'HEAD']);
658
- const dirty = git([
785
+ const mergedHead = await runGit(['-C', worktree, 'rev-parse', 'HEAD']);
786
+ const currentHead = await runGit(['-C', root, 'rev-parse', 'HEAD']);
787
+ const dirty = await runGit([
659
788
  '-C',
660
789
  root,
661
790
  'status',
@@ -668,8 +797,28 @@ async function foregroundCollectionSync() {
668
797
  error: 'collection changed during sync',
669
798
  });
670
799
  }
671
- git(['-C', root, 'merge', '--quiet', '--ff-only', mergedHead]);
672
- gitForeground(['-C', root, 'push', 'origin', branch]);
800
+ try {
801
+ await assertPrivateHistorySafe(root, mergedHead, remoteHead);
802
+ await assertPrivateTreeSafe(root, mergedHead);
803
+ }
804
+ catch (error) {
805
+ if (progress)
806
+ progress.stages.push = 'failed';
807
+ throw error;
808
+ }
809
+ await runGit(['-C', root, 'merge', '--quiet', '--ff-only', mergedHead]);
810
+ if (progress)
811
+ progress.stages.merge = 'committed';
812
+ try {
813
+ await gitForeground(['-C', root, 'push', '--no-follow-tags', 'origin', `${mergedHead}:refs/heads/${branch}`]);
814
+ if (progress)
815
+ progress.stages.push = 'committed';
816
+ }
817
+ catch (error) {
818
+ if (progress)
819
+ progress.stages.push = 'failed';
820
+ throw error;
821
+ }
673
822
  }
674
823
  catch (error) {
675
824
  if (error instanceof DomainError)
@@ -679,7 +828,7 @@ async function foregroundCollectionSync() {
679
828
  finally {
680
829
  if (worktree && worktreeRoot) {
681
830
  try {
682
- git(['-C', root, 'worktree', 'remove', '--force', worktree]);
831
+ await runGit(['-C', root, 'worktree', 'remove', '--force', worktree], new AbortController().signal);
683
832
  }
684
833
  catch { }
685
834
  await rm(worktreeRoot, { recursive: true, force: true });
@@ -687,12 +836,12 @@ async function foregroundCollectionSync() {
687
836
  await rm(lock, { force: true });
688
837
  }
689
838
  }
690
- export async function syncCollection(background) {
839
+ export async function syncCollection(background, progress) {
691
840
  const { root } = collectionPaths();
692
841
  if (!(await exists(join(root, '.git'))))
693
842
  throw new DomainError('git.notARepo');
694
843
  if (background)
695
844
  return backgroundCollectionSync();
696
- return foregroundCollectionSync();
845
+ return foregroundCollectionSync(progress);
697
846
  }
698
847
  //# sourceMappingURL=git.js.map