pi-agy-acp 0.1.0 → 0.1.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/src/preflight.ts CHANGED
@@ -16,6 +16,9 @@ import {
16
16
  writeFileSync,
17
17
  readFileSync,
18
18
  statSync,
19
+ lstatSync,
20
+ readdirSync,
21
+ rmSync,
19
22
  } from 'node:fs'
20
23
  import { homedir } from 'node:os'
21
24
  import { delimiter, isAbsolute, join } from 'node:path'
@@ -208,6 +211,46 @@ export function syncOAuthToken(
208
211
  }
209
212
  }
210
213
 
214
+ /** Remove only one closed ACP session's files; session ids come from the agent. */
215
+ export function removeSessionArtifacts(home: string, sessionId: string): void {
216
+ if (
217
+ typeof sessionId !== 'string' ||
218
+ sessionId.length === 0 ||
219
+ /[^A-Za-z0-9._-]/.test(sessionId) ||
220
+ sessionId === '.' ||
221
+ sessionId.includes('..')
222
+ )
223
+ return
224
+ const appData = join(home, 'agy')
225
+ if (!isRealDirectory(appData)) return
226
+ removeArtifacts(join(appData, 'conversations'), [
227
+ `${sessionId}.db`,
228
+ `${sessionId}.db-wal`,
229
+ `${sessionId}.db-shm`,
230
+ ])
231
+ removeArtifacts(join(appData, 'brain'), [sessionId])
232
+ }
233
+
234
+ function isRealDirectory(path: string): boolean {
235
+ try {
236
+ return lstatSync(path).isDirectory()
237
+ } catch {
238
+ return false
239
+ }
240
+ }
241
+
242
+ function removeArtifacts(directory: string, names: readonly string[]): void {
243
+ // Never follow a replaced parent directory into data outside the isolated home.
244
+ if (!isRealDirectory(directory)) return
245
+ for (const name of names) {
246
+ try {
247
+ rmSync(join(directory, name), { recursive: true, force: true })
248
+ } catch {
249
+ // Locked or unreadable leftovers can be retried on the next startup.
250
+ }
251
+ }
252
+ }
253
+
211
254
  /**
212
255
  * Write the isolated Antigravity home: bridge agent and ACP settings.
213
256
  * @param home - absolute home directory used as `--gemini-dir`.
@@ -240,6 +283,24 @@ export function prepareHome(
240
283
  )
241
284
  const appData = join(home, 'agy')
242
285
  mkdirSync(appData, { recursive: true })
286
+ // Pi owns conversation history; no ACP session is restored across processes.
287
+ // shortcut: cleanup requires an exclusive home; add locking before supporting shared homes.
288
+ removeArtifacts(appData, [
289
+ 'conversations',
290
+ 'brain',
291
+ 'conversation_summaries.db',
292
+ 'conversation_summaries.db-wal',
293
+ 'conversation_summaries.db-shm',
294
+ 'jetbox_summaries_proto.pb',
295
+ ])
296
+ try {
297
+ removeArtifacts(
298
+ home,
299
+ readdirSync(home).filter((name) => /^acp\.log\.\d+$/.test(name)),
300
+ )
301
+ } catch {
302
+ // Log cleanup is best-effort when the home cannot be listed.
303
+ }
243
304
  syncOAuthToken(home, userHome)
244
305
  const settingsPath = join(appData, 'settings.json')
245
306
  const settings = readJson(settingsPath)
package/src/quota.ts CHANGED
@@ -123,6 +123,18 @@ export class QuotaReader {
123
123
  this.ttlMs = ttlMs
124
124
  }
125
125
 
126
+ /** Fresh successful data only; never starts a command. */
127
+ peek(): QuotaSnapshot | undefined {
128
+ return this.cached?.status === 'ok' &&
129
+ Date.now() - this.cachedAt < this.ttlMs
130
+ ? this.cached
131
+ : undefined
132
+ }
133
+
134
+ get pending(): boolean {
135
+ return this.inflight !== undefined
136
+ }
137
+
126
138
  /**
127
139
  * Read the quota snapshot.
128
140
  * @param force - bypass the cache.
@@ -167,6 +179,9 @@ export class QuotaReader {
167
179
  groups: this.cached?.groups ?? [],
168
180
  error: error instanceof Error ? error.message : String(error),
169
181
  }
182
+ // Apply the same TTL to failures so settled events cannot hammer an unavailable CLI.
183
+ this.cached = snapshot
184
+ this.cachedAt = Date.now()
170
185
  return snapshot
171
186
  }
172
187
  }