typevault 0.6.0 → 0.7.0

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.
@@ -10,7 +10,7 @@ import { claimDaemon, type DaemonClaim, refuseForeignDaemon } from '../core/hold
10
10
  import { type Layout, localLayout } from '../core/layout'
11
11
  import { holdLock, isLockHeld } from '../core/lock'
12
12
  import { loadState, readOwner } from '../core/state'
13
- import { Vault } from '../core/vault'
13
+ import { readSnapshot, Vault } from '../core/vault'
14
14
  import { worktreeVaults } from '../core/worktrees'
15
15
  import { adminRoutes, type Ceiling } from './admin-routes'
16
16
  import { agentRoutes, type DaemonContext } from './agent-routes'
@@ -56,7 +56,11 @@ async function openSession(context: DaemonContext, ttlMs: number): Promise<strin
56
56
  const tiers = [...(await vault.keyring.reachableTiers())].sort()
57
57
  const { token, record } = grants.issue({ tiers, only: [], ttlMs, label: 'session', ceiling: SESSION_CEILING })
58
58
  atomicWrite(vault.layout.sessionFile, token, 0o600)
59
- await appendAudit(vault.layout, { action: 'grant.issue', mode: 'live', grant: record.id, label: 'session', tiers })
59
+ await appendAudit(
60
+ vault.layout,
61
+ { action: 'grant.issue', mode: 'live', grant: record.id, label: 'session', tiers },
62
+ vault.anchorsFile,
63
+ )
60
64
  return record.id
61
65
  }
62
66
 
@@ -145,10 +149,19 @@ async function serve(options: DaemonOptions, claim: DaemonClaim, releaseLock: ()
145
149
  // A shared session whose source is gone answers nothing but ping (how `stopDaemon` finds it) until it stops.
146
150
  const bound =
147
151
  (fetch: (request: Request) => Promise<Response>) =>
148
- async (request: Request): Promise<Response> =>
149
- sourceAlive() || new URL(request.url).pathname === '/v1/ping'
150
- ? fetch(request)
151
- : errorResponse(new TypeVaultError('locked', LOCKED_MESSAGE))
152
+ async (request: Request): Promise<Response> => {
153
+ if (new URL(request.url).pathname === '/v1/ping') return fetch(request)
154
+ if (!sourceAlive()) return errorResponse(new TypeVaultError('locked', LOCKED_MESSAGE))
155
+ try {
156
+ // Includes cached redaction values and worktree attachment: neither necessarily scans the vault. The snapshot
157
+ // finishes an interrupted rotation and keeps a running one's half-written files out of view; it's released
158
+ // before dispatch so writes can take the lock.
159
+ await readSnapshot(layout, options.env, async () => vault.refresh())
160
+ } catch (error) {
161
+ return errorResponse(error)
162
+ }
163
+ return fetch(request)
164
+ }
152
165
  const listen = (path: string, fetch: (request: Request) => Promise<Response>) => {
153
166
  const server = Bun.serve({ unix: path, fetch, maxRequestBodySize: 1 << 20 })
154
167
  // Windows sockets take the run directory's ACL; chmod there only toggles read-only.
@@ -96,13 +96,17 @@ export class PromptRequests {
96
96
  }
97
97
  if (!session.isLive()) throw new TypeVaultError('denied', 'the requesting grant is no longer live')
98
98
  await session.access.set({ name: input.name, fields: payload.fields, tier })
99
- await appendAudit(this.#vault.layout, {
100
- action: 'request.stored',
101
- mode: 'live',
102
- grant: grant.id,
103
- label: grant.label,
104
- entries: [input.name],
105
- })
99
+ await appendAudit(
100
+ this.#vault.layout,
101
+ {
102
+ action: 'request.stored',
103
+ mode: 'live',
104
+ grant: grant.id,
105
+ label: grant.label,
106
+ entries: [input.name],
107
+ },
108
+ this.#vault.anchorsFile,
109
+ )
106
110
  await handle.accept()
107
111
  return input.name
108
112
  } catch (error) {
@@ -111,13 +115,17 @@ export class PromptRequests {
111
115
  ? error
112
116
  : new TypeVaultError('unavailable', 'the submitted secret could not be stored')
113
117
  try {
114
- await appendAudit(this.#vault.layout, {
115
- action: 'request.rejected',
116
- mode: 'live',
117
- grant: grant.id,
118
- label: grant.label,
119
- entries: [input.name],
120
- })
118
+ await appendAudit(
119
+ this.#vault.layout,
120
+ {
121
+ action: 'request.rejected',
122
+ mode: 'live',
123
+ grant: grant.id,
124
+ label: grant.label,
125
+ entries: [input.name],
126
+ },
127
+ this.#vault.anchorsFile,
128
+ )
121
129
  } finally {
122
130
  await handle.reject(rejected)
123
131
  }
@@ -134,15 +142,19 @@ export class PromptRequests {
134
142
  if (!(error instanceof TypeVaultError)) console.error('typevault daemon: storing a prompted secret failed', error)
135
143
  })
136
144
  this.#pending.set(handle.id, { owner: grant.id, stored })
137
- await appendAudit(this.#vault.layout, {
138
- action: 'request.open',
139
- mode: 'live',
140
- grant: grant.id,
141
- label: grant.label,
142
- entries: [input.name],
143
- tiers: [tier],
144
- reason: input.reason,
145
- })
145
+ await appendAudit(
146
+ this.#vault.layout,
147
+ {
148
+ action: 'request.open',
149
+ mode: 'live',
150
+ grant: grant.id,
151
+ label: grant.label,
152
+ entries: [input.name],
153
+ tiers: [tier],
154
+ reason: input.reason,
155
+ },
156
+ this.#vault.anchorsFile,
157
+ )
146
158
  return { id: handle.id, url: handle.url, code, expiresAt }
147
159
  }
148
160