@cirtium/acent-connect 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -71,6 +71,10 @@ Running `npx @cirtium/acent-connect@latest` without a subcommand starts this sam
71
71
 
72
72
  ## Update
73
73
 
74
+ When Acent finds a newer public release, it can show a notice in your coding
75
+ tool after an Acent action completes. The notice includes update instructions
76
+ for your installation.
77
+
74
78
  Run from any folder to update all plugins installed through the Acent CLI:
75
79
 
76
80
  ```sh
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acent",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
5
5
  "mcpServers": "./mcp-claude.json",
6
6
  "hooks": "./hooks/claude.json"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acent",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
5
5
  "skills": "./skills/",
6
6
  "mcpServers": "./mcp-codex.json",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acent",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
5
5
  "author": {
6
6
  "name": "Cirtium"
@@ -111,7 +111,7 @@ export async function accessToken(config, directory) {
111
111
  }
112
112
  throw new Error("Acent is busy. Try again shortly.")
113
113
  }
114
- async function atomicJson(path, value) {
114
+ export async function atomicJson(path, value) {
115
115
  const temporary = `${path}.${random()}.tmp`
116
116
  await writeFile(temporary, JSON.stringify(value), { mode: 0o600, flag: "wx" })
117
117
  await rename(temporary, path)
@@ -203,7 +203,7 @@ async function acquireLock(directory) {
203
203
  }
204
204
  return true
205
205
  }
206
- async function lock(directory, operation) {
206
+ export async function lock(directory, operation) {
207
207
  const file = join(directory, ".lock")
208
208
  // Concurrent hooks leave their queued events to the active drainer.
209
209
  if (!(await acquireLock(directory))) return false
@@ -0,0 +1,305 @@
1
+ import { spawn } from "node:child_process"
2
+ import { randomUUID } from "node:crypto"
3
+ import { once } from "node:events"
4
+ import {
5
+ access,
6
+ link,
7
+ mkdir,
8
+ readFile,
9
+ realpath,
10
+ rename,
11
+ rm,
12
+ writeFile,
13
+ } from "node:fs/promises"
14
+ import { join } from "node:path"
15
+ import { fileURLToPath } from "node:url"
16
+ import { bridgeGitEnvironment, runProcess } from "./bridge-runners.mjs"
17
+
18
+ const worker = fileURLToPath(import.meta.url)
19
+ const commandTimeout = 120_000
20
+
21
+ function checkCommands(commands, minimum) {
22
+ if (
23
+ !Array.isArray(commands) ||
24
+ commands.length < minimum ||
25
+ commands.length > 12 ||
26
+ !commands.every(
27
+ (check) =>
28
+ typeof check?.command === "string" &&
29
+ check.command.trim() &&
30
+ check.command.length <= 512 &&
31
+ !/[\x00-\x1f]/.test(check.command) &&
32
+ Array.isArray(check.args) &&
33
+ check.args.length <= 48 &&
34
+ check.args.every(
35
+ (arg) =>
36
+ typeof arg === "string" && arg.length <= 8192 && !arg.includes("\0")
37
+ )
38
+ )
39
+ ) {
40
+ throw new Error("Provide supported test executables and literal arguments.")
41
+ }
42
+ return commands.map(({ command, args }) => ({ command, args }))
43
+ }
44
+
45
+ export function bridgeCheckPlan({ commands, setupCommands }) {
46
+ return {
47
+ commands: checkCommands(commands, 1),
48
+ setupCommands:
49
+ setupCommands === undefined ? undefined : checkCommands(setupCommands, 0),
50
+ }
51
+ }
52
+
53
+ async function readCheckFile(path) {
54
+ try {
55
+ return JSON.parse(await readFile(path, "utf8"))
56
+ } catch (error) {
57
+ if (error.code === "ENOENT") return null
58
+ throw error
59
+ }
60
+ }
61
+
62
+ function checkWorkerAlive(pid) {
63
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false
64
+ try {
65
+ process.kill(process.platform === "win32" ? pid : -pid, 0)
66
+ return true
67
+ } catch (error) {
68
+ return error.code === "EPERM"
69
+ }
70
+ }
71
+
72
+ export async function bridgeCheckState(directory) {
73
+ const owner = await readCheckFile(join(directory, "owner.json"))
74
+ if (checkWorkerAlive(owner?.pid)) return { status: "running" }
75
+ const result = await readCheckFile(join(directory, "result.json"))
76
+ if (result) return { status: "completed", ...result }
77
+ return { status: owner ? "interrupted" : "unstarted" }
78
+ }
79
+
80
+ export async function startBridgeCheckWorker(directory) {
81
+ const child = spawn(process.execPath, [worker, directory], {
82
+ detached: process.platform !== "win32",
83
+ stdio: "ignore",
84
+ windowsHide: true,
85
+ })
86
+ await once(child, "spawn")
87
+ child.unref()
88
+ }
89
+
90
+ async function checkSandbox(cwd, scratch) {
91
+ const git = join(cwd, ".git")
92
+ if (process.platform === "darwin") {
93
+ const profile = [
94
+ "(version 1)",
95
+ "(allow default)",
96
+ "(deny file-write*)",
97
+ '(allow file-write* (literal "/dev/null")',
98
+ ` (subpath ${JSON.stringify(cwd)})`,
99
+ ` (subpath ${JSON.stringify(scratch)}))`,
100
+ // Git reads this metadata after the check sandbox has closed.
101
+ `(deny file-write* (subpath ${JSON.stringify(git)}))`,
102
+ ].join("\n")
103
+ return ["/usr/bin/sandbox-exec", ["-p", profile]]
104
+ }
105
+ if (process.platform === "linux") {
106
+ const binary = "/usr/bin/bwrap"
107
+ await access(binary)
108
+ return [
109
+ binary,
110
+ [
111
+ "--ro-bind",
112
+ "/",
113
+ "/",
114
+ "--dev",
115
+ "/dev",
116
+ "--proc",
117
+ "/proc",
118
+ "--unshare-pid",
119
+ "--die-with-parent",
120
+ "--bind",
121
+ cwd,
122
+ cwd,
123
+ "--bind",
124
+ scratch,
125
+ scratch,
126
+ "--ro-bind",
127
+ git,
128
+ git,
129
+ "--chdir",
130
+ cwd,
131
+ "--",
132
+ ],
133
+ ]
134
+ }
135
+ throw new Error(
136
+ "Write-isolated Bridge checks are unavailable on this platform."
137
+ )
138
+ }
139
+
140
+ async function dependencySetup(cwd) {
141
+ if (
142
+ !(await readCheckFile(join(cwd, "package-lock.json"))) &&
143
+ !(await readCheckFile(join(cwd, "npm-shrinkwrap.json")))
144
+ )
145
+ return []
146
+ const manifest = await readCheckFile(join(cwd, "package.json"))
147
+ if (
148
+ !manifest ||
149
+ (manifest.packageManager && !manifest.packageManager.startsWith("npm@"))
150
+ )
151
+ return []
152
+ if (
153
+ !manifest.workspaces &&
154
+ ![
155
+ "dependencies",
156
+ "devDependencies",
157
+ "optionalDependencies",
158
+ "peerDependencies",
159
+ ].some((key) => Object.keys(manifest[key] ?? {}).length)
160
+ )
161
+ return []
162
+ return [
163
+ {
164
+ command: "npm",
165
+ args: ["ci", "--ignore-scripts", "--no-audit", "--no-fund"],
166
+ },
167
+ ]
168
+ }
169
+
170
+ async function runCheckCommands(request, directory, signal) {
171
+ const cwd = await realpath(request.cwd)
172
+ const temporary = join(directory, "temp")
173
+ await mkdir(temporary, { mode: 0o700 })
174
+ const scratch = await realpath(temporary)
175
+ const [sandbox, prefix] = await checkSandbox(cwd, scratch)
176
+ const env = {
177
+ ...bridgeGitEnvironment(),
178
+ ACENT_BRIDGE_WORKER: "1",
179
+ TMPDIR: scratch,
180
+ TMP: scratch,
181
+ TEMP: scratch,
182
+ XDG_CACHE_HOME: join(scratch, "cache"),
183
+ npm_config_cache: join(scratch, "npm"),
184
+ }
185
+ async function runCheck({ command, args }) {
186
+ let deadline
187
+ const run = runProcess(sandbox, [...prefix, command, ...args], {
188
+ cwd,
189
+ env,
190
+ signal,
191
+ timeout: commandTimeout,
192
+ maxBytes: 4 * 1024 * 1024,
193
+ })
194
+ // A descendant retaining stdout can keep the spawn open after its leader
195
+ // exits. The worker closes its process group once it has saved the result.
196
+ const result = await Promise.race([
197
+ run,
198
+ new Promise((resolve) => {
199
+ deadline = setTimeout(
200
+ () => resolve({ failure: "timed_out" }),
201
+ commandTimeout + 1500
202
+ )
203
+ }),
204
+ ]).finally(() => clearTimeout(deadline))
205
+ const outcome = result.code === 0 && !result.failure ? "passed" : "failed"
206
+ return {
207
+ name: [command, ...args].join(" ").slice(0, 1500),
208
+ outcome,
209
+ evidence: [
210
+ result.failure ?? `Exit code ${result.code}`,
211
+ result.stderr || result.stdout,
212
+ ]
213
+ .filter(Boolean)
214
+ .join("\n")
215
+ .slice(-1500),
216
+ }
217
+ }
218
+ async function runCommands(commands) {
219
+ const results = []
220
+ for (const command of commands) {
221
+ if (signal.aborted) break
222
+ const result = await runCheck(command)
223
+ results.push(result)
224
+ if (result.outcome === "failed") break
225
+ }
226
+ return results
227
+ }
228
+ const setup = await runCommands(
229
+ request.setupCommands ?? (await dependencySetup(cwd))
230
+ )
231
+ const checks = setup.some(({ outcome }) => outcome === "failed")
232
+ ? []
233
+ : await runCommands(request.commands)
234
+ return { checks, setup }
235
+ }
236
+
237
+ async function superviseChecks(directory) {
238
+ const ownerPath = join(directory, "owner.json")
239
+ const candidate = join(directory, randomUUID() + ".owner")
240
+ // Ask the filesystem to elect one worker even when the next proxy starts
241
+ // before the previous proxy's detached worker gets scheduled.
242
+ try {
243
+ await writeFile(candidate, JSON.stringify({ pid: process.pid }), {
244
+ mode: 0o600,
245
+ })
246
+ await link(candidate, ownerPath)
247
+ } catch (error) {
248
+ if (["EEXIST", "ENOENT"].includes(error.code)) return
249
+ throw error
250
+ } finally {
251
+ await rm(candidate, { force: true })
252
+ }
253
+ const abort = new AbortController()
254
+ let watcher
255
+ let result
256
+ try {
257
+ const request = await readCheckFile(join(directory, "request.json"))
258
+ if (!request) throw new Error("Bridge check request is unavailable.")
259
+ if (request.cancelFile && (await readCheckFile(request.cancelFile))) {
260
+ result = { cancelled: true }
261
+ return
262
+ }
263
+ const cancelled = new Promise((resolve) => {
264
+ const check = async () => {
265
+ if (request.cancelFile && (await readCheckFile(request.cancelFile))) {
266
+ abort.abort()
267
+ resolve({ cancelled: true })
268
+ }
269
+ }
270
+ const poll = () =>
271
+ void check().catch(() => {
272
+ abort.abort()
273
+ resolve({ error: "Could not read the check cancellation request." })
274
+ })
275
+ if (request.cancelFile) {
276
+ poll()
277
+ watcher = setInterval(poll, 100)
278
+ }
279
+ })
280
+ result = await Promise.race([
281
+ runCheckCommands(request, directory, abort.signal),
282
+ cancelled,
283
+ ])
284
+ } catch (error) {
285
+ result = { error: error.message }
286
+ } finally {
287
+ clearInterval(watcher)
288
+ // Persist results before exiting so another proxy can consume this attempt.
289
+ const pending = join(directory, "result.pending.json")
290
+ try {
291
+ await writeFile(pending, JSON.stringify(result), { mode: 0o600 })
292
+ await rename(pending, join(directory, "result.json"))
293
+ } finally {
294
+ if (process.platform !== "win32") {
295
+ try {
296
+ process.kill(-process.pid, "SIGKILL")
297
+ } catch (error) {
298
+ if (error.code !== "ESRCH") throw error
299
+ }
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ if (process.argv[1] === worker) await superviseChecks(process.argv[2])
@@ -0,0 +1,233 @@
1
+ import { randomUUID } from "node:crypto"
2
+ import { rm } from "node:fs/promises"
3
+ import { join } from "node:path"
4
+ import {
5
+ bridgeCheckPlan,
6
+ bridgeCheckState,
7
+ startBridgeCheckWorker,
8
+ } from "./bridge-checks.mjs"
9
+ import {
10
+ appliedBridgeChanges,
11
+ bridgeFileVersions,
12
+ changedBridgePaths,
13
+ mismatchedBridgePaths,
14
+ projectFileVersions,
15
+ projectSnapshot,
16
+ } from "./bridge-workspace.mjs"
17
+
18
+ export function createBridgeFinalizer({
19
+ readJson,
20
+ writeJson,
21
+ lock,
22
+ isId,
23
+ safeIds,
24
+ }) {
25
+ return async function finalize(folder, projectDir, coordination, args) {
26
+ const { ids, reviewId, reviewOutcome, action } = args
27
+ if (
28
+ !safeIds(ids) ||
29
+ !isId(reviewId) ||
30
+ !["cleared", "changes_requested"].includes(reviewOutcome) ||
31
+ (action !== undefined && action !== "cancel") ||
32
+ (args.setupCommands !== undefined && args.commands === undefined)
33
+ )
34
+ throw new Error("Provide applied task IDs and the independent review ID.")
35
+ const plan = args.commands === undefined ? undefined : bridgeCheckPlan(args)
36
+ const jobDir = join(projectDir, reviewId)
37
+ const directory = join(jobDir, "verification")
38
+ const record = join(jobDir, "verification.json")
39
+ const taskIds = [...ids].sort()
40
+ const getJob = (id) => readJson(join(projectDir, id, "job.json"), null)
41
+
42
+ return lock(directory, async () => {
43
+ const review = await getJob(reviewId)
44
+ if (
45
+ review?.kind !== "review" ||
46
+ review.status !== "completed" ||
47
+ !ids.every((id) => review.dependsOn?.includes(id))
48
+ )
49
+ return { status: "review_required", ids }
50
+ const tasks = await Promise.all(ids.map(getJob))
51
+ if (tasks.some((task) => task?.status !== "applied"))
52
+ return { status: "integration_required", ids }
53
+ const baseline = await readJson(join(jobDir, "baseline.json"), null)
54
+ if (!baseline) return { status: "review_required", ids }
55
+
56
+ const base = { ids: taskIds, reviewId, reviewSummary: review.summary }
57
+ let stored = await readJson(record, null)
58
+ if (stored?.version !== 2) stored = null
59
+ const sameTasks = JSON.stringify(stored?.ids) === JSON.stringify(taskIds)
60
+ const active = stored?.status === "checks_running"
61
+ if (active && !sameTasks)
62
+ return { ...base, status: "verification_in_progress" }
63
+ const publicResult = ({
64
+ status,
65
+ checks,
66
+ setup,
67
+ details,
68
+ paths,
69
+ checkedAt,
70
+ }) => ({
71
+ ...base,
72
+ status,
73
+ checks,
74
+ setup,
75
+ details,
76
+ paths,
77
+ checkedAt,
78
+ })
79
+ const applied = appliedBridgeChanges(tasks)
80
+ const readStalePaths = async () =>
81
+ changedBridgePaths(baseline.files, await bridgeFileVersions(folder))
82
+ async function checkOriginal() {
83
+ const stale = await readStalePaths()
84
+ if (stale.length) return { status: "review_stale", paths: stale }
85
+ const drift = await mismatchedBridgePaths(folder, applied)
86
+ if (drift.length) return { status: "integration_changed", paths: drift }
87
+ }
88
+
89
+ if (action === "cancel") {
90
+ if (!active)
91
+ return publicResult(sameTasks ? stored : { status: "checks_pending" })
92
+ await writeJson(join(directory, stored.attempt, "cancel.json"), {
93
+ requestedAt: Date.now(),
94
+ })
95
+ return publicResult({ status: "cancelling" })
96
+ }
97
+ if (reviewOutcome === "changes_requested") {
98
+ if (active)
99
+ await writeJson(join(directory, stored.attempt, "cancel.json"), {
100
+ requestedAt: Date.now(),
101
+ })
102
+ else
103
+ await writeJson(record, {
104
+ version: 2,
105
+ ids: taskIds,
106
+ status: "changes_requested",
107
+ })
108
+ return publicResult({ status: "changes_requested" })
109
+ }
110
+ if (
111
+ active &&
112
+ plan &&
113
+ JSON.stringify(stored.plan) !== JSON.stringify(plan)
114
+ )
115
+ return { ...base, status: "verification_in_progress" }
116
+ if (!active) {
117
+ const drift = await lock(coordination, checkOriginal)
118
+ if (drift) return { ...base, ...drift }
119
+ if (
120
+ !plan ||
121
+ (sameTasks &&
122
+ stored?.status === "verified" &&
123
+ JSON.stringify(stored.plan) === JSON.stringify(plan))
124
+ )
125
+ return publicResult(sameTasks ? stored : { status: "checks_pending" })
126
+ stored = {
127
+ version: 2,
128
+ ids: taskIds,
129
+ status: "checks_running",
130
+ attempt: randomUUID(),
131
+ plan,
132
+ }
133
+ await writeJson(record, stored)
134
+ }
135
+
136
+ const attemptDir = join(directory, stored.attempt)
137
+ const work = join(attemptDir, "work")
138
+ const cancelFile = join(attemptDir, "cancel.json")
139
+ const requestFile = join(attemptDir, "request.json")
140
+ const outcome = await bridgeCheckState(attemptDir)
141
+ if (outcome.status === "running") return publicResult(stored)
142
+
143
+ const cleanup = () =>
144
+ rm(attemptDir, { recursive: true, force: true }).catch(() => {})
145
+ async function saveResult(status, details, paths) {
146
+ const result = {
147
+ ...stored,
148
+ status,
149
+ details,
150
+ paths,
151
+ checks: outcome.checks,
152
+ setup: outcome.setup,
153
+ checkedAt: Date.now(),
154
+ }
155
+ await writeJson(record, result)
156
+ return publicResult(result)
157
+ }
158
+ async function complete(status, details, paths) {
159
+ const result = await saveResult(status, details, paths)
160
+ await cleanup()
161
+ return result
162
+ }
163
+
164
+ try {
165
+ if (outcome.cancelled || (await readJson(cancelFile, null)))
166
+ return await complete("cancelled")
167
+ if (outcome.status === "unstarted") {
168
+ if (!(await readJson(requestFile, null))) {
169
+ await rm(attemptDir, { recursive: true, force: true })
170
+ await projectSnapshot(folder, work, async (snapshot) => {
171
+ const changed = changedBridgePaths(baseline.files, snapshot.files)
172
+ if (!changed.length)
173
+ await writeJson(requestFile, {
174
+ cwd: work,
175
+ cancelFile,
176
+ ...stored.plan,
177
+ snapshot,
178
+ })
179
+ })
180
+ const request = await readJson(requestFile, null)
181
+ if (!request) {
182
+ const stale = await lock(coordination, readStalePaths)
183
+ return await complete(
184
+ "review_stale",
185
+ { reason: "snapshot_changed" },
186
+ stale
187
+ )
188
+ }
189
+ }
190
+ await startBridgeCheckWorker(attemptDir)
191
+ return publicResult(stored)
192
+ }
193
+ if (outcome.status === "interrupted" || outcome.error)
194
+ return await complete("checks_failed", {
195
+ reason: outcome.error ? "checks_unavailable" : "checks_interrupted",
196
+ error: outcome.error,
197
+ })
198
+ if (outcome.setup?.some(({ outcome }) => outcome === "failed"))
199
+ return await complete("checks_failed", {
200
+ reason: "dependency_setup_failed",
201
+ })
202
+ if (
203
+ outcome.checks.length !== stored.plan.commands.length ||
204
+ outcome.checks.some(({ outcome }) => outcome !== "passed")
205
+ )
206
+ return await complete("checks_failed")
207
+ const { snapshot } = await readJson(requestFile, null)
208
+ const changed = changedBridgePaths(
209
+ snapshot.files,
210
+ await projectFileVersions(work)
211
+ )
212
+ if (changed.length)
213
+ return await complete("checks_failed", {
214
+ reason: "checks_modified_candidate",
215
+ paths: changed,
216
+ })
217
+ const result = await lock(coordination, async () => {
218
+ const drift = await checkOriginal()
219
+ return drift
220
+ ? saveResult(drift.status, undefined, drift.paths)
221
+ : saveResult("verified")
222
+ })
223
+ await cleanup()
224
+ return result
225
+ } catch (error) {
226
+ return complete("checks_failed", {
227
+ reason: "checks_unavailable",
228
+ error: error.message,
229
+ })
230
+ }
231
+ })
232
+ }
233
+ }