@cirtium/acent-connect 0.4.1 → 1.0.1
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/acent/.claude-plugin/plugin.json +1 -1
- package/acent/.codex-plugin/plugin.json +1 -1
- package/acent/.cursor-plugin/plugin.json +1 -1
- package/acent/scripts/acent-connect.mjs +65 -49
- package/acent/scripts/antigravity-hook.mjs +1 -2
- package/acent/scripts/capture-activity.mjs +8 -6
- package/acent/scripts/capture-attachments.mjs +23 -8
- package/acent/scripts/capture-policy.mjs +89 -0
- package/acent/scripts/encrypted-capture.mjs +4 -108
- package/acent/scripts/hook.mjs +1 -1
- package/acent/scripts/mcp-proxy.mjs +4 -4
- package/acent/scripts/memory-instructions.mjs +1 -0
- package/acent/scripts/provide-diff.mjs +1 -1
- package/antigravity/plugin.json +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { capturePayload, isToolActivityHook } from "./capture-policy.mjs"
|
|
3
3
|
import { captureActivity } from "./capture-activity.mjs"
|
|
4
|
+
import { attachFiles } from "./capture-attachments.mjs"
|
|
4
5
|
/** Local connection/capture adapter. No AI calls; credentials never go to stdout. */
|
|
5
6
|
import { captureCodeChanges } from "./capture-code-changes.mjs"
|
|
6
7
|
import { captureCodexEvent } from "./codex-capture.mjs"
|
|
7
8
|
import { captureAntigravityEvent } from "./antigravity-capture.mjs"
|
|
8
|
-
import { attachFiles } from "./capture-attachments.mjs"
|
|
9
|
-
import { attachScreenshots } from "./capture-images.mjs"
|
|
10
9
|
import { createHash, randomBytes } from "node:crypto"
|
|
11
10
|
import {
|
|
12
11
|
mkdir,
|
|
@@ -246,13 +245,19 @@ async function token(config, directory) {
|
|
|
246
245
|
export async function drain(config, directory) {
|
|
247
246
|
return lock(directory, async () => {
|
|
248
247
|
const grant = await readCredentials(directory)
|
|
249
|
-
|
|
250
|
-
const queue =
|
|
248
|
+
if (!grant.client_id || grant.client_id.startsWith("ac_private_client_")) return
|
|
249
|
+
const queue = join(directory, "managed-queue", hash(grant.client_id))
|
|
251
250
|
const files = (await readdir(queue).catch(error => { if (error.code === "ENOENT") return []; throw error }))
|
|
252
251
|
.filter((file) => file.endsWith(".json"))
|
|
253
252
|
.sort()
|
|
254
253
|
if (!files.length) return
|
|
255
254
|
const access = await token(config, directory)
|
|
255
|
+
const headers = { Authorization: "Bearer " + access }
|
|
256
|
+
const policy = await request(config, "/api/external/managed", { headers })
|
|
257
|
+
if (!policy.enabled) {
|
|
258
|
+
for (const file of files) await unlink(join(queue, file))
|
|
259
|
+
return
|
|
260
|
+
}
|
|
256
261
|
const deferred = new Set()
|
|
257
262
|
// A code event can race its prompt upload. Retry it after queued prompts;
|
|
258
263
|
// never let an early 409 permanently block the request behind it.
|
|
@@ -260,22 +265,18 @@ export async function drain(config, directory) {
|
|
|
260
265
|
const payload = JSON.parse(
|
|
261
266
|
await readFile(join(queue, file), "utf8")
|
|
262
267
|
)
|
|
268
|
+
// An outbox entry belongs to the project approved at capture time.
|
|
269
|
+
if (payload.acent_destination !== policy.destination) continue
|
|
263
270
|
try {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
headers: {
|
|
272
|
-
|
|
273
|
-
"Content-Type": "application/json",
|
|
274
|
-
},
|
|
275
|
-
body: JSON.stringify({ source: config.tool, payload: await (async () => {
|
|
276
|
-
const attachments = await attachFiles(payload, config, access, request)
|
|
277
|
-
return attachments.enabled ? attachments.payload : await attachScreenshots(payload, config, access, request).catch(() => payload)
|
|
278
|
-
})() }),
|
|
271
|
+
const filtered = capturePayload(payload, policy.code === true, policy.activity === true)
|
|
272
|
+
if ((payload.acent_code_changes || payload.acent_activity) &&
|
|
273
|
+
!filtered.acent_code_changes?.length && !filtered.acent_activity?.length) {
|
|
274
|
+
await unlink(join(queue, file))
|
|
275
|
+
continue
|
|
276
|
+
}
|
|
277
|
+
await request(config, "/api/external/managed", {
|
|
278
|
+
method: "POST", headers: { ...headers, "Content-Type": "application/json" },
|
|
279
|
+
body: JSON.stringify({ id: hash(file), destination: policy.destination, at: Number(file.split("-")[0]), payload: filtered }),
|
|
279
280
|
})
|
|
280
281
|
} catch (error) {
|
|
281
282
|
if (error.status === 409 && error.code === "prompt_pending" && !deferred.has(file)) {
|
|
@@ -283,7 +284,12 @@ export async function drain(config, directory) {
|
|
|
283
284
|
files.push(file)
|
|
284
285
|
continue
|
|
285
286
|
}
|
|
286
|
-
if (error.
|
|
287
|
+
if (error.code === "destination_changed") continue
|
|
288
|
+
if (error.code === "capture_disabled") {
|
|
289
|
+
await unlink(join(queue, file))
|
|
290
|
+
continue
|
|
291
|
+
}
|
|
292
|
+
if (error.code === "invalid_token" || error.code === "insufficient_scope") {
|
|
287
293
|
const credentials = JSON.parse(
|
|
288
294
|
await readFile(join(directory, "credentials.json"), "utf8")
|
|
289
295
|
)
|
|
@@ -291,7 +297,7 @@ export async function drain(config, directory) {
|
|
|
291
297
|
...credentials,
|
|
292
298
|
captureBlocked: true,
|
|
293
299
|
})
|
|
294
|
-
|
|
300
|
+
|
|
295
301
|
await rm(join(directory, "code-capture"), { recursive: true, force: true })
|
|
296
302
|
for (const queued of await readdir(queue))
|
|
297
303
|
await unlink(join(queue, queued))
|
|
@@ -318,16 +324,14 @@ export async function connect(config, directory, open = openBrowser) {
|
|
|
318
324
|
await mkdir(connectionDirectory, { recursive: true, mode: 0o700 })
|
|
319
325
|
const completed = await lock(connectionDirectory, async () => {
|
|
320
326
|
const verifier = random()
|
|
321
|
-
|
|
327
|
+
|
|
322
328
|
const started = await request(config, "/api/external/setup/start", {
|
|
323
329
|
method: "POST", headers: { "Content-Type": "application/json" },
|
|
324
|
-
body: JSON.stringify({ tool: config.tool, folder: config.folder,
|
|
330
|
+
body: JSON.stringify({ tool: config.tool, folder: config.folder, managed: true, challenge: createHash("sha256").update(verifier).digest("base64url") }),
|
|
325
331
|
})
|
|
326
332
|
const url = new URL(started.authorization_url)
|
|
327
333
|
if (url.origin !== config.server || url.pathname !== "/oauth/authorize" || !url.searchParams.has("setup"))
|
|
328
334
|
throw new Error("Acent returned an invalid connection address.")
|
|
329
|
-
url.searchParams.set("device", pairing.publicKey)
|
|
330
|
-
url.hash = new URLSearchParams({ pairing: pairing.proof }).toString()
|
|
331
335
|
const expires = Math.min(Date.parse(started.expires_at), Date.now() + 15 * 60_000)
|
|
332
336
|
if (!Number.isFinite(expires) || expires <= Date.now() || !started.poll_token || !started.client_id)
|
|
333
337
|
throw new Error("Acent returned an invalid connection session.")
|
|
@@ -341,17 +345,11 @@ export async function connect(config, directory, open = openBrowser) {
|
|
|
341
345
|
if (tokens.status === "cancelled") throw new Error("Connection was cancelled.")
|
|
342
346
|
if (tokens.status === "issued") {
|
|
343
347
|
if (!tokens.access_token || !tokens.refresh_token) throw new Error("Connection response was incomplete. Request a new link.")
|
|
344
|
-
if (!
|
|
345
|
-
let captureKey, project
|
|
346
|
-
if (tokens.scope?.split(" ").includes("conversation:write")) {
|
|
347
|
-
const wrapped = await request(config, "/api/external/encrypted", { headers: { Authorization: "Bearer " + tokens.access_token } })
|
|
348
|
-
project = wrapped.project
|
|
349
|
-
captureKey = pairing.unwrap(wrapped.wrapped)
|
|
350
|
-
}
|
|
348
|
+
if (!started.client_id.startsWith("ac_managed_client_")) throw new Error("Update the server before connecting.")
|
|
351
349
|
let saved = false
|
|
352
350
|
for (let attempt = 0; attempt < 200 && !saved; attempt++) {
|
|
353
351
|
saved = await lock(directory, () => atomicJson(join(directory, "credentials.json"), {
|
|
354
|
-
...tokens,
|
|
352
|
+
...tokens, client_id: started.client_id, expiresAt: Date.now() + tokens.expires_in * 1000,
|
|
355
353
|
}))
|
|
356
354
|
if (!saved) await new Promise(resolve => setTimeout(resolve, 100))
|
|
357
355
|
}
|
|
@@ -387,7 +385,7 @@ export async function main(args = process.argv.slice(2), eventText) {
|
|
|
387
385
|
.then(JSON.parse)
|
|
388
386
|
.catch(() => null)
|
|
389
387
|
if (
|
|
390
|
-
!credentials ||
|
|
388
|
+
!credentials?.client_id || credentials.client_id.startsWith("ac_private_client_") ||
|
|
391
389
|
credentials.captureBlocked ||
|
|
392
390
|
!credentials.scope?.split(" ").includes("conversation:write")
|
|
393
391
|
)
|
|
@@ -412,20 +410,37 @@ export async function main(args = process.argv.slice(2), eventText) {
|
|
|
412
410
|
}))
|
|
413
411
|
if (Buffer.byteLength(content) > 2 * 1024 * 1024)
|
|
414
412
|
throw new Error("Event exceeds 2 MiB.")
|
|
415
|
-
const captureDirectory =
|
|
416
|
-
const
|
|
413
|
+
const captureDirectory = join(directory, "managed-capture", hash(credentials.client_id))
|
|
414
|
+
const access = await accessToken(config, directory)
|
|
415
|
+
const policy = await request(config, "/api/external/managed", { headers: { Authorization: "Bearer " + access } })
|
|
416
|
+
if (!policy.enabled) return
|
|
417
|
+
const code = policy.code === true
|
|
418
|
+
const activity = policy.activity === true
|
|
419
|
+
let payload = JSON.parse(content)
|
|
420
|
+
const hook = payload.acent_hook || payload.hook_event_name
|
|
421
|
+
const toolEvent = isToolActivityHook(hook)
|
|
422
|
+
if ((toolEvent && !activity && !code) || (hook === "afterFileEdit" && !code)) return
|
|
417
423
|
if (config.tool === "Codex" && !(await captureCodexEvent(payload, captureDirectory))) return
|
|
418
|
-
const toolEvent = ["PreToolUse", "PostToolUse", "PostToolUseFailure"].includes(payload.acent_hook || payload.hook_event_name)
|
|
419
424
|
if (config.tool === "Antigravity" && toolEvent) {
|
|
420
|
-
await captureAntigravityEvent(payload, captureDirectory).catch(
|
|
425
|
+
if (code) await captureAntigravityEvent(payload, captureDirectory).catch(() => {
|
|
421
426
|
payload.acent_request = null
|
|
422
|
-
console.error(
|
|
427
|
+
console.error("Acent request link unavailable.")
|
|
423
428
|
})
|
|
424
429
|
}
|
|
425
|
-
const codeEvent = await captureCodeChanges(payload, config, captureDirectory)
|
|
426
|
-
const activityEvent = await captureActivity(payload, config, captureDirectory)
|
|
427
|
-
|
|
430
|
+
const codeEvent = code && await captureCodeChanges(payload, config, captureDirectory)
|
|
431
|
+
const activityEvent = activity && await captureActivity(payload, config, captureDirectory, code)
|
|
432
|
+
const changes = code ? payload.acent_code_changes ?? [] : []
|
|
433
|
+
const toolActivities = activity ? payload.acent_activity ?? [] : []
|
|
434
|
+
if ((codeEvent || activityEvent || toolEvent) && !changes.length && !toolActivities.length) return
|
|
428
435
|
if (config.tool === "Antigravity" && !codeEvent && !activityEvent && !(await captureAntigravityEvent(payload, captureDirectory))) return
|
|
436
|
+
if (policy.attachments === true && !codeEvent && !activityEvent && !toolEvent) {
|
|
437
|
+
try {
|
|
438
|
+
payload = (await attachFiles(payload, config, access, request, policy.destination)).payload
|
|
439
|
+
} catch {
|
|
440
|
+
// Keep conversation capture available if file storage is temporarily down.
|
|
441
|
+
console.error("Acent could not save the attached files.")
|
|
442
|
+
}
|
|
443
|
+
}
|
|
429
444
|
if (codeEvent || activityEvent) {
|
|
430
445
|
// Forward only bounded, redacted activity and validated edit records; never the raw host envelope.
|
|
431
446
|
const minimal = {
|
|
@@ -440,16 +455,15 @@ export async function main(args = process.argv.slice(2), eventText) {
|
|
|
440
455
|
}
|
|
441
456
|
const events = codeEvent || activityEvent
|
|
442
457
|
? [
|
|
443
|
-
...
|
|
444
|
-
...
|
|
458
|
+
...changes.map(change => ({ ...payload, acent_activity: undefined, acent_code_changes: [change] })),
|
|
459
|
+
...toolActivities.map(record => ({ ...payload, acent_code_changes: undefined, acent_activity: [record] })),
|
|
445
460
|
]
|
|
446
461
|
: [payload]
|
|
447
462
|
if (events.some(event => Buffer.byteLength(JSON.stringify(event)) > 2 * 1024 * 1024))
|
|
448
463
|
throw new Error("Collected event exceeds 2 MiB.")
|
|
449
|
-
const
|
|
450
|
-
const queue = encrypted ? join(directory, "private-queue", hash(credentials.client_id)) : join(directory, "queue")
|
|
464
|
+
const queue = join(directory, "managed-queue", hash(credentials.client_id))
|
|
451
465
|
await mkdir(queue, { recursive: true, mode: 0o700 })
|
|
452
|
-
const packets =
|
|
466
|
+
const packets = events.map(event => ({ ...capturePayload(event, code, activity), acent_destination: policy.destination }))
|
|
453
467
|
const eventBytes = packets.reduce((sum, event) => sum + Buffer.byteLength(JSON.stringify(event)), 0)
|
|
454
468
|
async function capacityError() {
|
|
455
469
|
const files = (await readdir(queue)).filter(file => file.endsWith(".json"))
|
|
@@ -493,6 +507,8 @@ export async function main(args = process.argv.slice(2), eventText) {
|
|
|
493
507
|
}),
|
|
494
508
|
})
|
|
495
509
|
await unlink(file)
|
|
510
|
+
await rm(join(directory, "managed-capture"), {recursive:true, force:true})
|
|
511
|
+
await rm(join(directory, "managed-queue"), {recursive:true, force:true})
|
|
496
512
|
await rm(join(directory, "paired-capture"), {recursive:true, force:true})
|
|
497
513
|
await rm(join(directory, "private-queue"), { recursive: true, force: true })
|
|
498
514
|
await rm(join(directory, "code-capture"), { recursive: true, force: true })
|
|
@@ -504,6 +520,6 @@ export async function main(args = process.argv.slice(2), eventText) {
|
|
|
504
520
|
}
|
|
505
521
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
506
522
|
main().catch((error) => {
|
|
507
|
-
console.error(
|
|
523
|
+
console.error("Acent request failed.")
|
|
508
524
|
process.exitCode = 1
|
|
509
525
|
})
|
|
@@ -10,7 +10,6 @@ try {
|
|
|
10
10
|
}
|
|
11
11
|
const payload = JSON.parse(raw)
|
|
12
12
|
payload.acent_hook = process.argv[2]
|
|
13
|
-
console.error("Acent capture timing: " + JSON.stringify({at:new Date().toISOString(),stage:"hook",event:payload.acent_hook,fullyIdle:payload.fullyIdle === true,terminationReason:payload.terminationReason,hasError:!!payload.error}))
|
|
14
13
|
if (!["PreInvocation", "PostInvocation", "Stop", "PreToolUse", "PostToolUse"].includes(payload.acent_hook)) throw new Error("Unknown Antigravity hook.")
|
|
15
14
|
await new Promise((resolve, reject) => {
|
|
16
15
|
const child = spawn(process.execPath, [fileURLToPath(new URL("./hook.mjs", import.meta.url)), "--tool", "Antigravity"],
|
|
@@ -21,6 +20,6 @@ try {
|
|
|
21
20
|
child.stdin.end(JSON.stringify(payload))
|
|
22
21
|
})
|
|
23
22
|
console.error("Acent capture timing: " + JSON.stringify({at:new Date().toISOString(),stage:"finished",durationMs:Date.now()-started}))
|
|
24
|
-
} catch (error) { console.error(
|
|
23
|
+
} catch (error) { console.error("Acent could not save this event.") }
|
|
25
24
|
// Hooks must emit a JSON object and must never force the agent to continue.
|
|
26
25
|
process.stdout.write("{}\n")
|
|
@@ -31,7 +31,7 @@ export function redactActivity(value) {
|
|
|
31
31
|
const text = typeof clean === "string" ? clean : JSON.stringify(clean, null, 2)
|
|
32
32
|
return { text: text.slice(0, 16000), truncated: clipped || text.length > 16000 || JSON.stringify(value).length > 16000 }
|
|
33
33
|
}
|
|
34
|
-
export async function captureActivity(p, config, directory) {
|
|
34
|
+
export async function captureActivity(p, config, directory, includeContent = true) {
|
|
35
35
|
const event = p.acent_hook || p.hook_event_name
|
|
36
36
|
const pre = ["PreToolUse", "preToolUse"].includes(event)
|
|
37
37
|
const post = ["PostToolUse", "PostToolUseFailure", "postToolUse", "postToolUseFailure"].includes(event)
|
|
@@ -50,10 +50,12 @@ export async function captureActivity(p, config, directory) {
|
|
|
50
50
|
const state = await read(path)
|
|
51
51
|
if (state?.completed) { if (post) p.acent_activity = [state.completed]; return true }
|
|
52
52
|
const hostTurn = config.tool === "Codex" ? p.turn_id : config.tool === "Cursor" ? p.generation_id : p.acent_turn_id || p.prompt_id
|
|
53
|
-
let request =
|
|
53
|
+
let request = includeContent
|
|
54
|
+
? config.tool === "Antigravity" ? p.acent_request : await read(join(directory, "code-capture", hash(session) + ".request.json"))
|
|
55
|
+
: null
|
|
54
56
|
if (hostTurn && request?.turnId !== hostTurn) request = null
|
|
55
57
|
if (request) request = { ...request, content: redactActivity(request.content).text, truncated: request.content.length > 16000 }
|
|
56
|
-
const input = redactActivity(p.tool_input ?? p.toolCall?.args)
|
|
58
|
+
const input = redactActivity(includeContent ? p.tool_input ?? p.toolCall?.args : null)
|
|
57
59
|
const at = new Date().toISOString()
|
|
58
60
|
if (pre) {
|
|
59
61
|
if (!state) await save(path, { request, input, at })
|
|
@@ -82,9 +84,9 @@ export async function captureActivity(p, config, directory) {
|
|
|
82
84
|
const record = {
|
|
83
85
|
id, callId, name: name.slice(0, 300), kind, status, capturedAt: at,
|
|
84
86
|
startedAt: state?.at ?? null, durationMs: duration == null ? null : Math.min(Math.round(duration), 604800000),
|
|
85
|
-
request: state ? state.request : hostTurn || p.acent_request ? request : null,
|
|
86
|
-
input: input.text === null && state ? state.input : input,
|
|
87
|
-
output: redactActivity(raw),
|
|
87
|
+
request: includeContent ? (state ? state.request : hostTurn || p.acent_request ? request : null) : null,
|
|
88
|
+
input: includeContent && input.text === null && state ? state.input : input,
|
|
89
|
+
output: redactActivity(includeContent ? raw : null),
|
|
88
90
|
changeIds: (p.acent_code_changes ?? []).map(change => change.id).slice(0, 32),
|
|
89
91
|
}
|
|
90
92
|
await save(path, { completed: record })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { constants } from "node:fs"
|
|
2
2
|
import { open } from "node:fs/promises"
|
|
3
3
|
import { basename, isAbsolute } from "node:path"
|
|
4
|
-
import { createHash } from "node:crypto"
|
|
4
|
+
import { createCipheriv, createHash, randomBytes } from "node:crypto"
|
|
5
5
|
|
|
6
6
|
export const attachmentTool = {
|
|
7
7
|
name: "acent_save_attachments",
|
|
@@ -33,9 +33,9 @@ export async function saveAttachments(paths, config, access, request, upload = f
|
|
|
33
33
|
if (!Array.isArray(paths) || !paths.length || paths.length > 20 ||
|
|
34
34
|
paths.some(path => typeof path !== "string" || !isAbsolute(path)))
|
|
35
35
|
throw new Error("Supply 1–20 absolute paths of user-attached files.")
|
|
36
|
-
const headers = { Authorization: "Bearer " + access }
|
|
36
|
+
const headers = { Authorization: "Bearer " + access, "X-Acent-Attachment-Encryption": "1" }
|
|
37
37
|
const settings = await request(config, "/api/external/attachments", { headers })
|
|
38
|
-
if (!settings.enabled) return { enabled: false, files: [] }
|
|
38
|
+
if (!settings.enabled || settings.encrypted !== true) return { enabled: false, files: [] }
|
|
39
39
|
const maxBytes = Math.min(50 * 1024 ** 2, settings.maxBytes)
|
|
40
40
|
if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) throw new Error("Attachment limit unavailable.")
|
|
41
41
|
const files = []
|
|
@@ -72,14 +72,23 @@ export async function saveAttachments(paths, config, access, request, upload = f
|
|
|
72
72
|
body: JSON.stringify({ ...metadata, ...(complete ? { complete: true } : {}) }),
|
|
73
73
|
})
|
|
74
74
|
let result = await post(false)
|
|
75
|
+
let savedId = result.id ?? id
|
|
75
76
|
if (result.uploadUrl) {
|
|
76
77
|
const url = new URL(result.uploadUrl)
|
|
77
78
|
if (url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname)))
|
|
78
79
|
throw new Error("Invalid upload URL")
|
|
79
80
|
// Never forward the Acent bearer token to Storage. Signed URL is path-scoped.
|
|
81
|
+
if (!/^[a-f0-9]{64}$/.test(result.id) || typeof result.uploadKey !== "string")
|
|
82
|
+
throw new Error("Encrypted upload unavailable")
|
|
83
|
+
const key = Buffer.from(result.uploadKey, "base64")
|
|
84
|
+
const iv = randomBytes(12)
|
|
85
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv)
|
|
86
|
+
cipher.setAAD(Buffer.from(`acent:attachment:v1:${result.id}:original`))
|
|
87
|
+
const body = Buffer.concat([iv, cipher.update(bytes), cipher.final(), cipher.getAuthTag()])
|
|
88
|
+
savedId = result.id
|
|
80
89
|
const response = await upload(url, {
|
|
81
90
|
method: "PUT", headers: { "Content-Type": "application/octet-stream", "x-upsert": "false" },
|
|
82
|
-
body
|
|
91
|
+
body, signal: AbortSignal.timeout(120_000),
|
|
83
92
|
})
|
|
84
93
|
if (!response.ok && response.status !== 409) {
|
|
85
94
|
const error = await response.json().catch(() => ({}))
|
|
@@ -87,18 +96,24 @@ export async function saveAttachments(paths, config, access, request, upload = f
|
|
|
87
96
|
}
|
|
88
97
|
result = await post(true)
|
|
89
98
|
}
|
|
90
|
-
if (result.id !==
|
|
91
|
-
|
|
99
|
+
if (result.id !== savedId || result.status !== "saved")
|
|
100
|
+
throw new Error("Upload not confirmed")
|
|
101
|
+
files.push({ ...metadata, id: savedId, status: "saved" })
|
|
92
102
|
} catch { files.push({ name, size, status: "failed" }) }
|
|
93
103
|
}
|
|
94
104
|
return { enabled: true, files }
|
|
95
105
|
}
|
|
96
106
|
|
|
97
|
-
export async function attachFiles(payload, config, access, request) {
|
|
107
|
+
export async function attachFiles(payload, config, access, request, destination) {
|
|
98
108
|
const paths = attachedPaths(payload, config.tool)
|
|
99
109
|
if (!paths.length) return { payload, enabled: false }
|
|
100
110
|
let result
|
|
101
|
-
|
|
111
|
+
const scopedRequest = destination
|
|
112
|
+
? (config, path, options) => request(config, path, {
|
|
113
|
+
...options, headers: { ...options.headers, "X-Acent-Capture-Destination": destination },
|
|
114
|
+
})
|
|
115
|
+
: request
|
|
116
|
+
try { result = await saveAttachments(paths.slice(0, 20), config, access, scopedRequest) }
|
|
102
117
|
catch (error) {
|
|
103
118
|
// Retry service/auth failures through the normal queue; never silently claim success.
|
|
104
119
|
if ([400, 404].includes(error.status)) return { payload, enabled: false }
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export function isToolActivityHook(hook) {
|
|
2
|
+
return ["PreToolUse", "PostToolUse", "PostToolUseFailure",
|
|
3
|
+
"preToolUse", "postToolUse", "postToolUseFailure"].includes(hook)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Only conversation fields understood by the host adapters cross the capture boundary.
|
|
7
|
+
export function capturePayload(event, code, activity) {
|
|
8
|
+
/** @type {Record<string, any>} */
|
|
9
|
+
const result = {}
|
|
10
|
+
for (const field of [
|
|
11
|
+
"session_id",
|
|
12
|
+
"conversation_id",
|
|
13
|
+
"conversationId",
|
|
14
|
+
"turn_id",
|
|
15
|
+
"prompt_id",
|
|
16
|
+
"generation_id",
|
|
17
|
+
"acent_turn_id",
|
|
18
|
+
"model",
|
|
19
|
+
"modelName",
|
|
20
|
+
"hook_event_name",
|
|
21
|
+
"event",
|
|
22
|
+
"prompt",
|
|
23
|
+
"last_assistant_message",
|
|
24
|
+
"text",
|
|
25
|
+
"response",
|
|
26
|
+
]) {
|
|
27
|
+
if (typeof event[field] === "string") result[field] = event[field]
|
|
28
|
+
}
|
|
29
|
+
function message(item) {
|
|
30
|
+
if (!item || !["user", "assistant"].includes(item.role)) return null
|
|
31
|
+
const content =
|
|
32
|
+
typeof item.content === "string"
|
|
33
|
+
? item.content
|
|
34
|
+
: Array.isArray(item.content)
|
|
35
|
+
? item.content
|
|
36
|
+
.filter(
|
|
37
|
+
(part) => part?.type === "text" && typeof part.text === "string"
|
|
38
|
+
)
|
|
39
|
+
.map((part) => part.text)
|
|
40
|
+
.join("")
|
|
41
|
+
: ""
|
|
42
|
+
return {
|
|
43
|
+
role: item.role,
|
|
44
|
+
content,
|
|
45
|
+
...(typeof item.model === "string" && { model: item.model }),
|
|
46
|
+
...(typeof item.turnId === "string" && { turnId: item.turnId }),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(event.messages))
|
|
50
|
+
result.messages = event.messages.map(message).filter(Boolean)
|
|
51
|
+
if (event.message)
|
|
52
|
+
result.message = message({
|
|
53
|
+
...event.message,
|
|
54
|
+
role: event.message.role ?? "user",
|
|
55
|
+
})
|
|
56
|
+
if (event.result)
|
|
57
|
+
result.result = Object.fromEntries(
|
|
58
|
+
["response", "conversation_id"]
|
|
59
|
+
.filter((field) => typeof event.result[field] === "string")
|
|
60
|
+
.map((field) => [field, event.result[field]])
|
|
61
|
+
)
|
|
62
|
+
if (Number.isSafeInteger(event.num_turns)) result.num_turns = event.num_turns
|
|
63
|
+
if (result.result && Number.isSafeInteger(event.result?.num_turns))
|
|
64
|
+
result.result.num_turns = event.result.num_turns
|
|
65
|
+
if (activity && Array.isArray(event.acent_activity))
|
|
66
|
+
result.acent_activity = event.acent_activity.map((item) =>
|
|
67
|
+
code
|
|
68
|
+
? item
|
|
69
|
+
: {
|
|
70
|
+
id: item.id,
|
|
71
|
+
callId: item.callId,
|
|
72
|
+
name: item.name,
|
|
73
|
+
kind: item.kind,
|
|
74
|
+
status: item.status,
|
|
75
|
+
capturedAt: item.capturedAt,
|
|
76
|
+
startedAt: item.startedAt,
|
|
77
|
+
durationMs: item.durationMs,
|
|
78
|
+
request: null,
|
|
79
|
+
input: { text: null, truncated: false },
|
|
80
|
+
output: { text: null, truncated: false },
|
|
81
|
+
changeIds: [],
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
if (code && Array.isArray(event.acent_code_changes))
|
|
85
|
+
result.acent_code_changes = event.acent_code_changes
|
|
86
|
+
if (code && Array.isArray(event.acent_activities))
|
|
87
|
+
result.acent_activities = event.acent_activities
|
|
88
|
+
return result
|
|
89
|
+
}
|
|
@@ -1,109 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createCipheriv,
|
|
3
|
-
createHash,
|
|
4
|
-
createHmac,
|
|
5
|
-
generateKeyPair,
|
|
6
|
-
privateDecrypt,
|
|
7
|
-
randomBytes,
|
|
8
|
-
timingSafeEqual,
|
|
9
|
-
} from "node:crypto"
|
|
10
|
-
import { listFields } from "./list-descriptor.mjs"
|
|
11
|
-
import { promisify } from "node:util"
|
|
12
|
-
|
|
13
|
-
export async function createPairing() {
|
|
14
|
-
const pair = await promisify(generateKeyPair)("rsa", { modulusLength: 3072 })
|
|
15
|
-
const challenge = randomBytes(32)
|
|
16
|
-
return {
|
|
17
|
-
proof: challenge.toString("base64url"),
|
|
18
|
-
publicKey: pair.publicKey
|
|
19
|
-
.export({ type: "spki", format: "der" })
|
|
20
|
-
.toString("base64url"),
|
|
21
|
-
unwrap(ciphertext) {
|
|
22
|
-
const key = privateDecrypt(
|
|
23
|
-
{ key: pair.privateKey, oaepHash: "sha256" },
|
|
24
|
-
Buffer.from(ciphertext, "base64")
|
|
25
|
-
)
|
|
26
|
-
if (key.length !== 64 || !timingSafeEqual(key.subarray(0, 32), challenge))
|
|
27
|
-
throw new Error("Device pairing failed verification.")
|
|
28
|
-
return key.subarray(32).toString("base64")
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Encode only host fields consumed by the conversation and activity readers.
|
|
34
|
-
const captureFields = [
|
|
35
|
-
"session_id",
|
|
36
|
-
"conversation_id",
|
|
37
|
-
"conversationId",
|
|
38
|
-
"turn_id",
|
|
39
|
-
"prompt_id",
|
|
40
|
-
"generation_id",
|
|
41
|
-
"acent_turn_id",
|
|
42
|
-
"model",
|
|
43
|
-
"modelName",
|
|
44
|
-
"hook_event_name",
|
|
45
|
-
"event",
|
|
46
|
-
"messages",
|
|
47
|
-
"prompt",
|
|
48
|
-
"last_assistant_message",
|
|
49
|
-
"text",
|
|
50
|
-
"message",
|
|
51
|
-
"response",
|
|
52
|
-
"num_turns",
|
|
53
|
-
"result",
|
|
54
|
-
"acent_activity",
|
|
55
|
-
"acent_code_changes",
|
|
56
|
-
"acent_activities",
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
export function encryptCapture(event, credentials, source) {
|
|
60
|
-
const key = Buffer.from(credentials.captureKey ?? "", "base64")
|
|
61
|
-
if (key.length !== 32)
|
|
62
|
-
throw new Error("Encrypted capture requires a paired key.")
|
|
63
|
-
const payload = Object.fromEntries(
|
|
64
|
-
captureFields
|
|
65
|
-
.filter((field) => field in event)
|
|
66
|
-
.map((field) => [field, event[field]])
|
|
67
|
-
)
|
|
68
|
-
const grant = credentials.client_id
|
|
69
|
-
const at = Date.now()
|
|
70
|
-
const record = { source, project: credentials.project, at, payload }
|
|
71
|
-
function seal(scope, value) {
|
|
72
|
-
const iv = randomBytes(12)
|
|
73
|
-
const cipher = createCipheriv("aes-256-gcm", key, iv)
|
|
74
|
-
cipher.setAAD(Buffer.from("acent:external:v1:" + scope))
|
|
75
|
-
return Buffer.concat([
|
|
76
|
-
iv,
|
|
77
|
-
cipher.update(JSON.stringify(value)),
|
|
78
|
-
cipher.final(),
|
|
79
|
-
cipher.getAuthTag(),
|
|
80
|
-
])
|
|
81
|
-
}
|
|
82
|
-
const sealed = seal(grant, record)
|
|
83
|
-
const { sessionId, preview, ...fields } = listFields(record)
|
|
84
|
-
const id = createHash("sha256")
|
|
85
|
-
.update(JSON.stringify([grant, sessionId]))
|
|
86
|
-
.digest("hex")
|
|
87
|
-
const token = (value) => createHmac("sha256", key).update(value).digest("hex")
|
|
88
|
-
const session = token("session:" + id)
|
|
89
|
-
const descriptor = sessionId
|
|
90
|
-
? {
|
|
91
|
-
...fields,
|
|
92
|
-
at,
|
|
93
|
-
session,
|
|
94
|
-
project: token("project:" + preview.project),
|
|
95
|
-
preview: seal("list:v1:" + grant + ":" + session, {
|
|
96
|
-
...preview,
|
|
97
|
-
id: "encrypted:" + id,
|
|
98
|
-
}).toString("base64"),
|
|
99
|
-
}
|
|
100
|
-
: { skip: true }
|
|
101
|
-
return {
|
|
102
|
-
id: createHash("sha256").update(sealed).digest("hex"),
|
|
103
|
-
ciphertext: sealed.toString("base64"),
|
|
104
|
-
descriptor,
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
107
2
|
|
|
108
3
|
export const privateGrant = (id) =>
|
|
109
4
|
typeof id === "string" && id.startsWith("ac_private_client_")
|
|
@@ -146,9 +41,10 @@ export async function readEncryptedRecords(
|
|
|
146
41
|
)
|
|
147
42
|
throw new Error("Invalid search.")
|
|
148
43
|
const init = { headers: { Authorization: "Bearer " + access } }
|
|
44
|
+
const endpoint = "/api/external/encrypted"
|
|
149
45
|
const page = args.id
|
|
150
46
|
? { records: [args.id], nextOffset: null }
|
|
151
|
-
: await request(config, "
|
|
47
|
+
: await request(config, endpoint + "?" + params, init)
|
|
152
48
|
const key = await crypto.subtle.importKey(
|
|
153
49
|
"raw",
|
|
154
50
|
Buffer.from(grant.captureKey, "base64"),
|
|
@@ -161,7 +57,7 @@ export async function readEncryptedRecords(
|
|
|
161
57
|
if (!/^[a-f0-9]{64}$/.test(id)) throw new Error("Invalid record ID.")
|
|
162
58
|
const record = await request(
|
|
163
59
|
config,
|
|
164
|
-
"
|
|
60
|
+
endpoint + "?records=1&id=" + id,
|
|
165
61
|
init
|
|
166
62
|
)
|
|
167
63
|
const bytes = Buffer.from(record.ciphertext, "base64")
|
package/acent/scripts/hook.mjs
CHANGED
|
@@ -99,7 +99,7 @@ async function startConnection(config) {
|
|
|
99
99
|
})
|
|
100
100
|
.catch((error) => {
|
|
101
101
|
ready.reject(error)
|
|
102
|
-
console.error(
|
|
102
|
+
console.error("Acent request failed.")
|
|
103
103
|
})
|
|
104
104
|
.finally(() => {
|
|
105
105
|
pendingConnection = undefined
|
|
@@ -234,7 +234,7 @@ async function handleLine(line) {
|
|
|
234
234
|
}
|
|
235
235
|
if (message.method === "tools/call" && message.params?.name === encryptedReadTool.name) {
|
|
236
236
|
const grant = JSON.parse(await readFile(directory + "/credentials.json", "utf8"))
|
|
237
|
-
if (!privateGrant(grant.client_id)) throw new Error("
|
|
237
|
+
if (!privateGrant(grant.client_id)) throw new Error("Session access unavailable.")
|
|
238
238
|
const value = await readEncryptedRecords(config, grant, access, message.params.arguments ?? {}, request)
|
|
239
239
|
reply(content(JSON.stringify(value)))
|
|
240
240
|
return
|
|
@@ -260,12 +260,12 @@ async function handleLine(line) {
|
|
|
260
260
|
const grant = JSON.parse(await readFile(directory + "/credentials.json", "utf8"))
|
|
261
261
|
const localTools = privateGrant(grant.client_id)
|
|
262
262
|
? (grant.captureKey && grant.scope?.split(" ").includes("original:read") ? [encryptedReadTool] : [])
|
|
263
|
-
: [attachmentTool]
|
|
263
|
+
: grant.scope?.split(" ").includes("conversation:write") ? [attachmentTool] : []
|
|
264
264
|
result.result.tools = [...result.result.tools.filter((tool) => tool.name !== clarificationTool.name), setupTool, clarificationTool, ...localTools]
|
|
265
265
|
}
|
|
266
266
|
write(result)
|
|
267
267
|
} catch (error) {
|
|
268
|
-
console.error(
|
|
268
|
+
console.error("Acent request failed.")
|
|
269
269
|
if (message?.id !== undefined)
|
|
270
270
|
write({
|
|
271
271
|
jsonrpc: "2.0",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
export const memoryInstructions = [
|
|
4
4
|
"Acent has five named skills: Acent Recall finds past context; Acent Trace explains saved code edits; Acent Decisions retrieves choices and reasons; Acent Resume continues saved work; Acent Connect manages connection setup. Recognize these names in user requests and use the relevant exposed tools. These are workflows within the Acent plugin, not separate connections. Automatic capture remains controlled by saving consent.",
|
|
5
5
|
"Use connected Acent as the first source for missing project history when it could change the answer or next action, including within the same conversation or after context compaction. Search before asking the user to restate that history, even without an explicit mention of Acent. For example, if the user says 'do it like last time' or '저번처럼 해줘' and the earlier approach is unclear, search using the task, feature, or error they mention. Also retrieve for resumed work, unexplained past decisions or constraints, conflicting records, and recurring failures where earlier attempts could affect the next step. Skip retrieval when the current context and files already answer the question. Reuse evidence already read and search again when the task changes, a reference is stale, or later corrections may matter.",
|
|
6
|
+
"When looking for conversations saved by this plugin connection, use read_saved_sessions when available. For an earlier device-encrypted connection use read_encrypted_sessions when available. Follow the returned pagination to continue a search.",
|
|
6
7
|
"Choose one focused entry point rather than calling every search tool. For recent work without a named task use get_recent_work first (just now, earlier, recently, 방금, 방금 전, 좀 전, 아까, 최근). An agent name identifies the source, so for '방금 Codex에서 어디까지 했지?' call get_recent_work with provider=codex when supported. For a named task use get_handoff with the task topic; for a specific choice, rejection, change or reported outcome use get_decision_context with 1–8 distinctive keywords. Use search_evidence for missing details, failed attempts, conflicts or later unsummarized corrections; use keyword mode for exact code or errors and hybrid for meaning. Use read_evidence for selected passages that need more context. To open the exact archived decision message, use read_original with the originalReference id and messageIndex when available. For saved files or images use search_attachments with a known sourceId, filename, extracted text or distinctive surrounding words. Use read_saved_file for extracted document text and follow nextOffset only as needed. Check analysis_status: partial is not the whole file and saved does not mean analyzed. Image links are not visual inspection.",
|
|
7
8
|
"Read the smallest relevant scope. Follow nextOffset only while the question remains unresolved; do not dump the whole project or send entire conversations as search queries. If a focused search misses, try a distinct term or permitted source before declaring the evidence unavailable; avoid repeated equivalent searches. No result does not prove no decision exists. Only use exposed tools within the approved project and account-wide scope. If original access is unavailable, use search_memories and read_memory when available, state the coverage limit, and never bypass it. If retrieval fails, report the limitation and continue independent work; ask for missing information only when needed for the dependent task.",
|
|
8
9
|
"For questions about past events, success, or decision reasons, use the evidence already available when it clearly supports the answer. Search original evidence and open the relevant passage with surrounding turns when summaries or excerpts are ambiguous, conflicting, incomplete, or fail to establish the requested fact. Also read the original when the user explicitly requests it or exact wording matters. Do not open originals routinely merely because a question concerns the past. Use read_evidence with the returned ID and revision, read_original with the originalReference ID and messageIndex, or read_context for legacy row hits. Reuse an original passage already read when it contains enough context. Continue adjacent passages or pagination only until the claimed action, its reported result, and relevant later corrections are clear. These read-only steps within approved access do not require another confirmation.",
|
|
@@ -195,6 +195,6 @@ if (
|
|
|
195
195
|
import.meta.url === pathToFileURL(resolve(process.argv[1])).href
|
|
196
196
|
)
|
|
197
197
|
provideDiff(process.argv.slice(2)).catch((error) => {
|
|
198
|
-
console.error(
|
|
198
|
+
console.error("Acent could not prepare the diff.")
|
|
199
199
|
process.exitCode = 1
|
|
200
200
|
})
|
package/antigravity/plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://antigravity.google/schemas/v1/plugin.json",
|
|
3
3
|
"name": "acent",
|
|
4
4
|
"displayName": "Acent",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "1.0.1",
|
|
6
6
|
"description": "Recall past work, trace code changes, revisit decisions, and resume tasks with Acent.",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Cirtium"
|