aegisone 1.0.34 → 1.0.35

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 (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,230 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * Minimal git worktree introspection: where the repo root is, and what is
10
- * dirty right now with a content hash per path.
11
- *
12
- * Ported from the upstream engine reference (ESM → CommonJS). `turn-guard.js`
13
- * uses `gitRoot` and `gitStatusSnapshot`; the queue now hosts the commit path
14
- * too, so `foreignChanges` and `scopedCommit` are carried over as well — they
15
- * were deliberately absent while nothing here queued work, because a copy of
16
- * code nothing calls is a copy that drifts unnoticed.
17
- *
18
- * ATTRIBUTION IS TWO CONDITIONS, NOT ONE. "Dirty before AND byte-identical
19
- * now" only excludes work that nobody touched — it cannot see a concurrent
20
- * writer who edits a file *during* the task window, because that file is no
21
- * longer byte-identical and so looks like ours. Commit 96fb64f swept exactly
22
- * such a file (desktop/electron-builder.yml, edited by another live session)
23
- * into an unrelated commit that way. So `scopedCommit` also requires positive
24
- * attribution: a path is staged only if the caller reports that THIS task's own
25
- * tool layer wrote it (`written`). Everything else dirty — foreign, or merely
26
- * unattributed — is left alone and reported.
27
- */
28
-
29
- const fs = require('node:fs');
30
- const path = require('node:path');
31
- const crypto = require('node:crypto');
32
- const { spawnSync } = require('node:child_process');
33
-
34
- /** The repo root for `cwd`, or null if it isn't inside a git work tree. */
35
- function gitRoot(cwd) {
36
- const r = spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8' });
37
- return r.status === 0 ? r.stdout.trim() : null;
38
- }
39
-
40
- /**
41
- * Hash a path's worktree content, so "already dirty before the task ran" can
42
- * be told apart from "this task changed it". `absent` covers deletions;
43
- * non-files (a submodule, a directory) compare by kind.
44
- */
45
- function contentHash(cwd, rel) {
46
- try {
47
- const st = fs.lstatSync(path.join(cwd, rel));
48
- if (!st.isFile()) return st.isDirectory() ? 'nonfile:dir' : 'nonfile:other';
49
- return crypto.createHash('sha1').update(fs.readFileSync(path.join(cwd, rel))).digest('hex');
50
- } catch {
51
- return 'absent';
52
- }
53
- }
54
-
55
- /**
56
- * Every path git reports as dirty right now, mapped to its content hash.
57
- * `--no-renames` matters: in `-z` porcelain a rename emits the old name as a
58
- * second NUL-terminated token, which we would otherwise hash as a change.
59
- * Untracked files are included, since that is exactly how concurrent work
60
- * usually arrives. Returns null if `cwd` is not a usable git repo.
61
- */
62
- function gitStatusSnapshot(cwd) {
63
- // Run from the repo root: porcelain reports paths root-relative, so hashing
64
- // must resolve them against the same directory.
65
- const root = gitRoot(cwd);
66
- if (!root) return null;
67
- const r = spawnSync(
68
- 'git',
69
- ['status', '--porcelain=v1', '-z', '--untracked-files=all', '--no-renames'],
70
- { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 },
71
- );
72
- if (r.status !== 0) return null;
73
- const snap = new Map();
74
- for (const rec of r.stdout.split('\0')) {
75
- if (rec.length < 4) continue;
76
- const p = rec.slice(3);
77
- snap.set(p, contentHash(root, p));
78
- }
79
- return snap;
80
- }
81
-
82
- /**
83
- * Paths that were dirty *before* and are byte-identical now: another agent's
84
- * in-flight work, not ours. These must never be committed.
85
- *
86
- * Byte-identical is the test, not "was dirty": a path that was dirty before and
87
- * that this task then EDITED has a different hash, so it is ours to commit. Only
88
- * untouched foreign work is excluded.
89
- */
90
- function foreignChanges(cwd, before) {
91
- if (!before) return [];
92
- const now = gitStatusSnapshot(cwd);
93
- if (!now) return [];
94
- const out = [];
95
- for (const [p, hash] of now) {
96
- if (before.has(p) && before.get(p) === hash) out.push(p);
97
- }
98
- return out;
99
- }
100
-
101
- /**
102
- * A path the caller reported writing, as repo-root-relative POSIX text.
103
- *
104
- * The tool layer reports what the MODEL asked for (`file_path` as typed), which
105
- * may be absolute or relative to the task's own working directory — not
106
- * necessarily this process's `cwd`. Returns '' for anything outside the repo:
107
- * a write that cannot be attributed to a path git reports is not something this
108
- * function may guess about.
109
- */
110
- function toRepoRelative(root, base, p) {
111
- const raw = String(p == null ? '' : p).trim();
112
- if (!raw) return '';
113
- const abs = path.isAbsolute(raw) ? raw : path.resolve(base || root, raw);
114
- const rel = path.relative(root, abs);
115
- if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return '';
116
- return rel.split(path.sep).join('/');
117
- }
118
-
119
- /** The repo-relative set of paths the task's own tool layer reported writing. */
120
- function writtenSet(root, base, written) {
121
- const out = new Set();
122
- for (const p of written || []) {
123
- const rel = toRepoRelative(root, base, p);
124
- if (rel) out.add(rel);
125
- }
126
- return out;
127
- }
128
-
129
- /**
130
- * Split the current dirty set by attribution. `ours` is what this task wrote
131
- * and changed; `left` is everything else git reports as dirty — a peer's
132
- * in-flight work, plus our own changes we cannot positively attribute (a file a
133
- * shell command created names no path in the tool call, so it is reported, not
134
- * assumed).
135
- *
136
- * @returns {null|{root:string, ours:string[], left:string[], written:Set<string>}}
137
- */
138
- function attributedChanges(cwd, { before, written } = {}) {
139
- const root = gitRoot(cwd);
140
- if (!root) return null;
141
- const now = gitStatusSnapshot(cwd);
142
- if (!now) return null;
143
- const mine = writtenSet(root, cwd, written);
144
- const ours = [];
145
- const left = [];
146
- for (const [p, hash] of now) {
147
- // "Differs from the pre-task snapshot": new since then, or the bytes moved.
148
- const changed = !(before && before.has(p) && before.get(p) === hash);
149
- if (changed && mine.has(p)) ours.push(p);
150
- else left.push(p);
151
- }
152
- return { root, ours, left, written: mine };
153
- }
154
-
155
- /**
156
- * Commit only the changes this task is known to have made.
157
- *
158
- * The rule, in one line: stage a dirty path only if it DIFFERS from the
159
- * pre-task snapshot AND this task's tool layer reports writing it. Two
160
- * conditions, because either alone is unsafe: "changed since the snapshot"
161
- * sweeps a concurrent writer who edits mid-run, and "was dirty before and is
162
- * byte-identical now" cannot be the only exclusion because it sees only the
163
- * writer who stopped.
164
- *
165
- * `before` is the `gitStatusSnapshot(cwd)` taken immediately before the task
166
- * ran and `written` the paths the caller's tool layer wrote during it; without
167
- * either there is no basis for attribution, and the only safe move is to refuse
168
- * (or stage nothing) — `git add -A` here would commit a concurrent agent's
169
- * half-finished edit under this task's message.
170
- *
171
- * @returns {{ok?:boolean,skipped?:boolean,reason?:string,error?:string,
172
- * message?:string,staged?:number,paths?:string[],foreign?:string[],
173
- * identicalForeign?:string[]}}
174
- */
175
- function scopedCommit(cwd, { message, before, written } = {}) {
176
- if (!gitRoot(cwd)) return { skipped: true, reason: 'not a git repo' };
177
-
178
- // No basis for attribution — refuse rather than sweep.
179
- if (!before) {
180
- return { ok: false, error: 'no pre-task snapshot; refusing to sweep the working tree' };
181
- }
182
-
183
- const attributed = attributedChanges(cwd, { before, written });
184
- if (!attributed) return { skipped: true, reason: 'not a git repo' };
185
- const { root, ours, left } = attributed;
186
-
187
- if (!ours.length) {
188
- const untouched = foreignChanges(cwd, before);
189
- return {
190
- ok: true,
191
- skipped: true,
192
- foreign: left,
193
- identicalForeign: untouched,
194
- reason: left.length
195
- ? `no changes of our own (left ${left.length} change(s) this task did not write)`
196
- : 'no changes',
197
- };
198
- }
199
-
200
- // pathspec-from-file keeps an arbitrarily long (or space/NUL-bearing) list
201
- // safe — a 400-file commit is fine, a path with a newline in it is not.
202
- const add = spawnSync('git', ['add', '-A', '--pathspec-from-file=-', '--pathspec-file-nul'], {
203
- cwd: root,
204
- encoding: 'utf8',
205
- input: ours.join('\0'),
206
- });
207
- if (add.status !== 0) return { ok: false, error: add.stderr || 'git add failed' };
208
-
209
- const commit = spawnSync('git', ['commit', '-m', message], { cwd: root, encoding: 'utf8' });
210
- if (commit.status !== 0) {
211
- // "nothing to commit" is a success for our purposes: the changes we staged
212
- // were already committed by somebody else, and the task's work is done.
213
- if (/nothing to commit|no changes added/i.test(commit.stdout + commit.stderr)) {
214
- return { ok: true, skipped: true, foreign: left, reason: 'no changes' };
215
- }
216
- return { ok: false, error: commit.stderr || commit.stdout };
217
- }
218
- return { ok: true, message, foreign: left, paths: ours, staged: ours.length };
219
- }
220
-
221
- module.exports = {
222
- gitRoot,
223
- contentHash,
224
- gitStatusSnapshot,
225
- foreignChanges,
226
- toRepoRelative,
227
- writtenSet,
228
- attributedChanges,
229
- scopedCommit,
230
- };
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),crypto=require("node:crypto"),{spawnSync:spawnSync}=require("node:child_process");function gitRoot(t){const e=spawnSync("git",["rev-parse","--show-toplevel"],{cwd:t,encoding:"utf8"});return 0===e.status?e.stdout.trim():null}function contentHash(t,e){try{const n=fs.lstatSync(path.join(t,e));return n.isFile()?crypto.createHash("sha1").update(fs.readFileSync(path.join(t,e))).digest("hex"):n.isDirectory()?"nonfile:dir":"nonfile:other"}catch{return"absent"}}function gitStatusSnapshot(t){const e=gitRoot(t);if(!e)return null;const n=spawnSync("git",["status","--porcelain=v1","-z","--untracked-files=all","--no-renames"],{cwd:e,encoding:"utf8",maxBuffer:67108864});if(0!==n.status)return null;const o=new Map;for(const t of n.stdout.split("\0")){if(t.length<4)continue;const n=t.slice(3);o.set(n,contentHash(e,n))}return o}function foreignChanges(t,e){if(!e)return[];const n=gitStatusSnapshot(t);if(!n)return[];const o=[];for(const[t,s]of n)e.has(t)&&e.get(t)===s&&o.push(t);return o}function toRepoRelative(t,e,n){const o=String(null==n?"":n).trim();if(!o)return"";const s=path.isAbsolute(o)?o:path.resolve(e||t,o),r=path.relative(t,s);return!r||r.startsWith("..")||path.isAbsolute(r)?"":r.split(path.sep).join("/")}function writtenSet(t,e,n){const o=new Set;for(const s of n||[]){const n=toRepoRelative(t,e,s);n&&o.add(n)}return o}function attributedChanges(t,{before:e,written:n}={}){const o=gitRoot(t);if(!o)return null;const s=gitStatusSnapshot(t);if(!s)return null;const r=writtenSet(o,t,n),i=[],a=[];for(const[t,n]of s)e&&e.has(t)&&e.get(t)===n||!r.has(t)?a.push(t):i.push(t);return{root:o,ours:i,left:a,written:r}}function scopedCommit(t,{message:e,before:n,written:o}={}){if(!gitRoot(t))return{skipped:!0,reason:"not a git repo"};if(!n)return{ok:!1,error:"no pre-task snapshot; refusing to sweep the working tree"};const s=attributedChanges(t,{before:n,written:o});if(!s)return{skipped:!0,reason:"not a git repo"};const{root:r,ours:i,left:a}=s;if(!i.length)return{ok:!0,skipped:!0,foreign:a,identicalForeign:foreignChanges(t,n),reason:a.length?`no changes of our own (left ${a.length} change(s) this task did not write)`:"no changes"};const c=spawnSync("git",["add","-A","--pathspec-from-file=-","--pathspec-file-nul"],{cwd:r,encoding:"utf8",input:i.join("\0")});if(0!==c.status)return{ok:!1,error:c.stderr||"git add failed"};const u=spawnSync("git",["commit","-m",e],{cwd:r,encoding:"utf8"});return 0!==u.status?/nothing to commit|no changes added/i.test(u.stdout+u.stderr)?{ok:!0,skipped:!0,foreign:a,reason:"no changes"}:{ok:!1,error:u.stderr||u.stdout}:{ok:!0,message:e,foreign:a,paths:i,staged:i.length}}module.exports={gitRoot:gitRoot,contentHash:contentHash,gitStatusSnapshot:gitStatusSnapshot,foreignChanges:foreignChanges,toRepoRelative:toRepoRelative,writtenSet:writtenSet,attributedChanges:attributedChanges,scopedCommit:scopedCommit};