@codelia/storage 0.1.84 → 0.1.86

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/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _codelia_core from '@codelia/core';
2
- import { StoragePaths, ResolveStorageOptions, RunEventStoreFactory, RunEventStoreInit, SessionStore, ConversationSearchResult, ConversationMessage, SessionStateStore, SessionState, SessionStateSummary, StoragePathService, SessionRecord, ToolOutputCacheStore, ToolOutputCacheRecord, ToolOutputRef, ToolOutputCacheReadOptions, ToolOutputCacheSearchOptions } from '@codelia/core';
2
+ import { StoragePaths, ResolveStorageOptions, RunEventStoreFactory, RunEventStoreInit, SessionStore, BaseMessage, ConversationApprovalProvenance, ConversationSearchResult, ConversationMessage, ConversationApprovalScope, ConversationApprovalContext, SessionStateStore, SessionState, SessionStateSummary, StoragePathService, SessionRecord, ToolOutputCacheStore, ToolOutputCacheRecord, ToolOutputRef, ToolOutputCacheReadOptions, ToolOutputCacheSearchOptions } from '@codelia/core';
3
3
  export { ResolveStorageOptions, StorageLayout, StoragePathService, StoragePaths } from '@codelia/core';
4
- import { GeneratedImageMetadata, ImageArtifactRef, ImageMediaType, AttachedImageMetadata, ImageArtifactMetadata, AttachmentRef, ApprovalMode, SubagentLineage, AgentMessage, TaskTerminationReason, TaskUsage } from '@codelia/shared-types';
4
+ import { GeneratedImageMetadata, ImageArtifactRef, ImageMediaType, AttachedImageMetadata, ImageArtifactMetadata, AttachmentRef, ApprovalMode, SandboxMode, GoalRecord, SubagentLineage, AgentMessage, TaskTerminationReason, TaskUsage } from '@codelia/shared-types';
5
5
 
6
6
  type AttachmentWriteOptions = {
7
7
  artifactId?: string;
@@ -108,20 +108,42 @@ declare const getProcessIdentity: (pid: number, options?: {
108
108
  canonicalEnvironment?: boolean;
109
109
  }) => Promise<string | null>;
110
110
 
111
+ type ProjectSandboxPolicy = {
112
+ remembered_tool_allows?: Array<{
113
+ tool: string;
114
+ }>;
115
+ trust_project_allows?: boolean;
116
+ approval_mode?: ApprovalMode;
117
+ sandbox_mode?: SandboxMode;
118
+ protected_paths?: string[];
119
+ };
111
120
  type ProjectsPolicyFile = {
112
121
  version: 1;
113
- default?: {
114
- approval_mode?: ApprovalMode;
115
- };
116
- projects?: Record<string, {
117
- approval_mode?: ApprovalMode;
118
- }>;
122
+ default?: ProjectSandboxPolicy;
123
+ projects?: Record<string, ProjectSandboxPolicy>;
119
124
  };
120
125
  declare class ProjectsPolicyStore {
121
126
  private readonly paths;
122
127
  constructor(paths?: StoragePaths);
123
128
  getFilePath(): string;
124
- load(): Promise<ProjectsPolicyFile | null>;
129
+ private verifyWorkspaceLocation;
130
+ private trustedPath;
131
+ private readUserFile;
132
+ /** Read user-authored permission settings through the same private-file boundary as project trust. */
133
+ readUserConfig(workspace: string, configured: string): Promise<string | undefined>;
134
+ private readPolicyFile;
135
+ private readTrusted;
136
+ private hasUnverifiableProtectedPaths;
137
+ loadUserOwned(workspace: string, { strict }?: {
138
+ strict?: boolean;
139
+ }): Promise<ProjectsPolicyFile | null>;
140
+ verifyProjectModeWritable(workspace: string): Promise<void>;
141
+ /** Merge into a private user policy while other runtimes are excluded. */
142
+ writeProjectMode(workspace: string, mode: SandboxMode): Promise<void>;
143
+ writeProjectAllowTrust(workspace: string, trusted: boolean, verify: () => void): Promise<void>;
144
+ updateRememberedTool(workspace: string, tool: string, allow: boolean, verify?: () => void): Promise<boolean>;
145
+ private updateProject;
146
+ load(canonicalPath?: string): Promise<ProjectsPolicyFile | null>;
125
147
  save(data: ProjectsPolicyFile): Promise<void>;
126
148
  }
127
149
 
@@ -169,6 +191,11 @@ declare class RunEventStoreFactoryImpl implements RunEventStoreFactory {
169
191
  declare const resolveRunLogPath: (file: string) => string;
170
192
  declare function readRunLogLines(file: string): AsyncGenerator<string>;
171
193
 
194
+ declare function appendOriginalMessages(file: string, messages: BaseMessage[], provenance?: readonly (ConversationApprovalProvenance | undefined)[]): void;
195
+ declare function readOriginalApprovalContext(file: string, { userMessageId, proposalMessageId, workspace, cwd, workspaceIdentity, cwdIdentity, }: ConversationApprovalScope & {
196
+ userMessageId: string;
197
+ proposalMessageId?: string;
198
+ }, isAppliedSteer: (runId: string, steerId: string) => boolean): Promise<ConversationApprovalContext | null>;
172
199
  declare function searchOriginalMessages(file: string, options: {
173
200
  query: string;
174
201
  cursor?: string;
@@ -180,6 +207,51 @@ declare function readOriginalMessage(file: string, options: {
180
207
  limit?: number;
181
208
  }): Promise<ConversationMessage | null>;
182
209
 
210
+ type GoalRunClaim = {
211
+ run_id: string;
212
+ revision: number;
213
+ activation_id: string;
214
+ continuation_id?: string;
215
+ owner_pid: number;
216
+ owner_identity: string | null;
217
+ pending_seq?: number;
218
+ accounted_seq?: number;
219
+ };
220
+ type StoredSessionGoal = {
221
+ goal: GoalRecord;
222
+ claim?: GoalRunClaim;
223
+ blocker?: {
224
+ key: string;
225
+ runs: number;
226
+ };
227
+ /** Applied user Steers for this goal. Null means the evidence is incomplete. */
228
+ approvalSteers?: Array<string | Readonly<{
229
+ text: string;
230
+ attachmentsOmitted: true;
231
+ }>> | null;
232
+ /** Steers before this index predate the latest objective edit. */
233
+ approvalObjectiveAfterSteers?: number;
234
+ };
235
+ type Sqlite = {
236
+ exec(sql: string): void;
237
+ run(sql: string, params?: unknown[]): void;
238
+ get<T>(sql: string, params?: unknown[]): T | undefined;
239
+ };
240
+ type GoalTransaction = {
241
+ entry: StoredSessionGoal | null;
242
+ consume(continuationId: string, goalId: string, runId: string): void;
243
+ };
244
+ declare class SessionGoalStore {
245
+ private readonly getDb;
246
+ constructor(getDb: () => Promise<Sqlite>);
247
+ private load;
248
+ read(sessionId: string, continuationId?: string): Promise<{
249
+ entry: StoredSessionGoal | null;
250
+ acceptedRunId?: string;
251
+ }>;
252
+ update<T>(sessionId: string, update: (tx: GoalTransaction) => T): Promise<T>;
253
+ }
254
+
183
255
  type SessionStateStoreOptions = {
184
256
  paths?: StoragePaths;
185
257
  onError?: (error: unknown, context: {
@@ -190,6 +262,7 @@ type SessionStateStoreOptions = {
190
262
  declare class SessionStateStoreImpl implements SessionStateStore, SessionRunRecorder {
191
263
  /** Root that `session_runs.rel_path` values are relative to. */
192
264
  readonly sessionsDir: string;
265
+ readonly goals: SessionGoalStore;
193
266
  private readonly legacyStateDir;
194
267
  private readonly messagesDir;
195
268
  private readonly contextsDir;
@@ -214,9 +287,11 @@ declare class SessionStateStoreImpl implements SessionStateStore, SessionRunReco
214
287
  private loadLegacy;
215
288
  private loadFromIndex;
216
289
  private saveToIndex;
217
- appendMessages(sessionId: string, messages: SessionState["messages"]): Promise<void>;
290
+ appendMessages(sessionId: string, messages: SessionState["messages"], origins?: Parameters<typeof appendOriginalMessages>[2]): Promise<void>;
218
291
  searchMessages(sessionId: string, options: Parameters<typeof searchOriginalMessages>[1]): Promise<_codelia_core.ConversationSearchResult>;
219
292
  readMessage(sessionId: string, options: Parameters<typeof readOriginalMessage>[1]): Promise<_codelia_core.ConversationMessage | null>;
293
+ readApprovalContext(sessionId: string, references: Parameters<typeof readOriginalApprovalContext>[1]): Promise<_codelia_core.ConversationApprovalContext | null>;
294
+ confirmApprovalSteer(sessionId: string, runId: string, steerId: string): Promise<void>;
220
295
  load(sessionId: string): Promise<SessionState | null>;
221
296
  save(state: SessionState): Promise<void>;
222
297
  getSummary(sessionId: string): Promise<SessionStateSummary | null>;
@@ -400,4 +475,4 @@ declare class ToolOutputCacheStoreImpl implements ToolOutputCacheStore {
400
475
  private resolvePath;
401
476
  }
402
477
 
403
- export { type AttachmentStore, FileAttachmentStore, IMAGE_MAX_BYTES, ImageArtifactStore, type McpAuthFile, McpAuthStore, type McpOAuthTokens, type ProjectsPolicyFile, ProjectsPolicyStore, RUN_LOG_RETENTION_MS, RunEventStoreFactoryImpl, type RunLogCleanupResult, type SessionRunEntry, type SessionRunRecorder, SessionStateStoreImpl, SessionStoreWriterImpl, StoragePathServiceImpl, type StoredAttachment, type TaskArtifact, type TaskKind, type TaskRecord, TaskRegistryStore, type TaskResult, type TaskState, type TaskTruncatedOutput, type TaskWorkspaceMode, ToolOutputCacheStoreImpl, cleanupRunLogs, createAttachmentId, detectImageAttachmentType, ensureStorageDirs, getProcessIdentity, isAttachmentId, readRunLogLines, resolveIndexedRunLog, resolveRunLogPath, resolveStoragePaths, scanSessionRunLogs, validateImageAttachment, validateImagePng };
478
+ export { type AttachmentStore, FileAttachmentStore, type GoalRunClaim, IMAGE_MAX_BYTES, ImageArtifactStore, type McpAuthFile, McpAuthStore, type McpOAuthTokens, type ProjectsPolicyFile, ProjectsPolicyStore, RUN_LOG_RETENTION_MS, RunEventStoreFactoryImpl, type RunLogCleanupResult, SessionGoalStore, type SessionRunEntry, type SessionRunRecorder, SessionStateStoreImpl, SessionStoreWriterImpl, StoragePathServiceImpl, type StoredAttachment, type StoredSessionGoal, type TaskArtifact, type TaskKind, type TaskRecord, TaskRegistryStore, type TaskResult, type TaskState, type TaskTruncatedOutput, type TaskWorkspaceMode, ToolOutputCacheStoreImpl, cleanupRunLogs, createAttachmentId, detectImageAttachmentType, ensureStorageDirs, getProcessIdentity, isAttachmentId, readRunLogLines, resolveIndexedRunLog, resolveRunLogPath, resolveStoragePaths, scanSessionRunLogs, validateImageAttachment, validateImagePng };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _codelia_core from '@codelia/core';
2
- import { StoragePaths, ResolveStorageOptions, RunEventStoreFactory, RunEventStoreInit, SessionStore, ConversationSearchResult, ConversationMessage, SessionStateStore, SessionState, SessionStateSummary, StoragePathService, SessionRecord, ToolOutputCacheStore, ToolOutputCacheRecord, ToolOutputRef, ToolOutputCacheReadOptions, ToolOutputCacheSearchOptions } from '@codelia/core';
2
+ import { StoragePaths, ResolveStorageOptions, RunEventStoreFactory, RunEventStoreInit, SessionStore, BaseMessage, ConversationApprovalProvenance, ConversationSearchResult, ConversationMessage, ConversationApprovalScope, ConversationApprovalContext, SessionStateStore, SessionState, SessionStateSummary, StoragePathService, SessionRecord, ToolOutputCacheStore, ToolOutputCacheRecord, ToolOutputRef, ToolOutputCacheReadOptions, ToolOutputCacheSearchOptions } from '@codelia/core';
3
3
  export { ResolveStorageOptions, StorageLayout, StoragePathService, StoragePaths } from '@codelia/core';
4
- import { GeneratedImageMetadata, ImageArtifactRef, ImageMediaType, AttachedImageMetadata, ImageArtifactMetadata, AttachmentRef, ApprovalMode, SubagentLineage, AgentMessage, TaskTerminationReason, TaskUsage } from '@codelia/shared-types';
4
+ import { GeneratedImageMetadata, ImageArtifactRef, ImageMediaType, AttachedImageMetadata, ImageArtifactMetadata, AttachmentRef, ApprovalMode, SandboxMode, GoalRecord, SubagentLineage, AgentMessage, TaskTerminationReason, TaskUsage } from '@codelia/shared-types';
5
5
 
6
6
  type AttachmentWriteOptions = {
7
7
  artifactId?: string;
@@ -108,20 +108,42 @@ declare const getProcessIdentity: (pid: number, options?: {
108
108
  canonicalEnvironment?: boolean;
109
109
  }) => Promise<string | null>;
110
110
 
111
+ type ProjectSandboxPolicy = {
112
+ remembered_tool_allows?: Array<{
113
+ tool: string;
114
+ }>;
115
+ trust_project_allows?: boolean;
116
+ approval_mode?: ApprovalMode;
117
+ sandbox_mode?: SandboxMode;
118
+ protected_paths?: string[];
119
+ };
111
120
  type ProjectsPolicyFile = {
112
121
  version: 1;
113
- default?: {
114
- approval_mode?: ApprovalMode;
115
- };
116
- projects?: Record<string, {
117
- approval_mode?: ApprovalMode;
118
- }>;
122
+ default?: ProjectSandboxPolicy;
123
+ projects?: Record<string, ProjectSandboxPolicy>;
119
124
  };
120
125
  declare class ProjectsPolicyStore {
121
126
  private readonly paths;
122
127
  constructor(paths?: StoragePaths);
123
128
  getFilePath(): string;
124
- load(): Promise<ProjectsPolicyFile | null>;
129
+ private verifyWorkspaceLocation;
130
+ private trustedPath;
131
+ private readUserFile;
132
+ /** Read user-authored permission settings through the same private-file boundary as project trust. */
133
+ readUserConfig(workspace: string, configured: string): Promise<string | undefined>;
134
+ private readPolicyFile;
135
+ private readTrusted;
136
+ private hasUnverifiableProtectedPaths;
137
+ loadUserOwned(workspace: string, { strict }?: {
138
+ strict?: boolean;
139
+ }): Promise<ProjectsPolicyFile | null>;
140
+ verifyProjectModeWritable(workspace: string): Promise<void>;
141
+ /** Merge into a private user policy while other runtimes are excluded. */
142
+ writeProjectMode(workspace: string, mode: SandboxMode): Promise<void>;
143
+ writeProjectAllowTrust(workspace: string, trusted: boolean, verify: () => void): Promise<void>;
144
+ updateRememberedTool(workspace: string, tool: string, allow: boolean, verify?: () => void): Promise<boolean>;
145
+ private updateProject;
146
+ load(canonicalPath?: string): Promise<ProjectsPolicyFile | null>;
125
147
  save(data: ProjectsPolicyFile): Promise<void>;
126
148
  }
127
149
 
@@ -169,6 +191,11 @@ declare class RunEventStoreFactoryImpl implements RunEventStoreFactory {
169
191
  declare const resolveRunLogPath: (file: string) => string;
170
192
  declare function readRunLogLines(file: string): AsyncGenerator<string>;
171
193
 
194
+ declare function appendOriginalMessages(file: string, messages: BaseMessage[], provenance?: readonly (ConversationApprovalProvenance | undefined)[]): void;
195
+ declare function readOriginalApprovalContext(file: string, { userMessageId, proposalMessageId, workspace, cwd, workspaceIdentity, cwdIdentity, }: ConversationApprovalScope & {
196
+ userMessageId: string;
197
+ proposalMessageId?: string;
198
+ }, isAppliedSteer: (runId: string, steerId: string) => boolean): Promise<ConversationApprovalContext | null>;
172
199
  declare function searchOriginalMessages(file: string, options: {
173
200
  query: string;
174
201
  cursor?: string;
@@ -180,6 +207,51 @@ declare function readOriginalMessage(file: string, options: {
180
207
  limit?: number;
181
208
  }): Promise<ConversationMessage | null>;
182
209
 
210
+ type GoalRunClaim = {
211
+ run_id: string;
212
+ revision: number;
213
+ activation_id: string;
214
+ continuation_id?: string;
215
+ owner_pid: number;
216
+ owner_identity: string | null;
217
+ pending_seq?: number;
218
+ accounted_seq?: number;
219
+ };
220
+ type StoredSessionGoal = {
221
+ goal: GoalRecord;
222
+ claim?: GoalRunClaim;
223
+ blocker?: {
224
+ key: string;
225
+ runs: number;
226
+ };
227
+ /** Applied user Steers for this goal. Null means the evidence is incomplete. */
228
+ approvalSteers?: Array<string | Readonly<{
229
+ text: string;
230
+ attachmentsOmitted: true;
231
+ }>> | null;
232
+ /** Steers before this index predate the latest objective edit. */
233
+ approvalObjectiveAfterSteers?: number;
234
+ };
235
+ type Sqlite = {
236
+ exec(sql: string): void;
237
+ run(sql: string, params?: unknown[]): void;
238
+ get<T>(sql: string, params?: unknown[]): T | undefined;
239
+ };
240
+ type GoalTransaction = {
241
+ entry: StoredSessionGoal | null;
242
+ consume(continuationId: string, goalId: string, runId: string): void;
243
+ };
244
+ declare class SessionGoalStore {
245
+ private readonly getDb;
246
+ constructor(getDb: () => Promise<Sqlite>);
247
+ private load;
248
+ read(sessionId: string, continuationId?: string): Promise<{
249
+ entry: StoredSessionGoal | null;
250
+ acceptedRunId?: string;
251
+ }>;
252
+ update<T>(sessionId: string, update: (tx: GoalTransaction) => T): Promise<T>;
253
+ }
254
+
183
255
  type SessionStateStoreOptions = {
184
256
  paths?: StoragePaths;
185
257
  onError?: (error: unknown, context: {
@@ -190,6 +262,7 @@ type SessionStateStoreOptions = {
190
262
  declare class SessionStateStoreImpl implements SessionStateStore, SessionRunRecorder {
191
263
  /** Root that `session_runs.rel_path` values are relative to. */
192
264
  readonly sessionsDir: string;
265
+ readonly goals: SessionGoalStore;
193
266
  private readonly legacyStateDir;
194
267
  private readonly messagesDir;
195
268
  private readonly contextsDir;
@@ -214,9 +287,11 @@ declare class SessionStateStoreImpl implements SessionStateStore, SessionRunReco
214
287
  private loadLegacy;
215
288
  private loadFromIndex;
216
289
  private saveToIndex;
217
- appendMessages(sessionId: string, messages: SessionState["messages"]): Promise<void>;
290
+ appendMessages(sessionId: string, messages: SessionState["messages"], origins?: Parameters<typeof appendOriginalMessages>[2]): Promise<void>;
218
291
  searchMessages(sessionId: string, options: Parameters<typeof searchOriginalMessages>[1]): Promise<_codelia_core.ConversationSearchResult>;
219
292
  readMessage(sessionId: string, options: Parameters<typeof readOriginalMessage>[1]): Promise<_codelia_core.ConversationMessage | null>;
293
+ readApprovalContext(sessionId: string, references: Parameters<typeof readOriginalApprovalContext>[1]): Promise<_codelia_core.ConversationApprovalContext | null>;
294
+ confirmApprovalSteer(sessionId: string, runId: string, steerId: string): Promise<void>;
220
295
  load(sessionId: string): Promise<SessionState | null>;
221
296
  save(state: SessionState): Promise<void>;
222
297
  getSummary(sessionId: string): Promise<SessionStateSummary | null>;
@@ -400,4 +475,4 @@ declare class ToolOutputCacheStoreImpl implements ToolOutputCacheStore {
400
475
  private resolvePath;
401
476
  }
402
477
 
403
- export { type AttachmentStore, FileAttachmentStore, IMAGE_MAX_BYTES, ImageArtifactStore, type McpAuthFile, McpAuthStore, type McpOAuthTokens, type ProjectsPolicyFile, ProjectsPolicyStore, RUN_LOG_RETENTION_MS, RunEventStoreFactoryImpl, type RunLogCleanupResult, type SessionRunEntry, type SessionRunRecorder, SessionStateStoreImpl, SessionStoreWriterImpl, StoragePathServiceImpl, type StoredAttachment, type TaskArtifact, type TaskKind, type TaskRecord, TaskRegistryStore, type TaskResult, type TaskState, type TaskTruncatedOutput, type TaskWorkspaceMode, ToolOutputCacheStoreImpl, cleanupRunLogs, createAttachmentId, detectImageAttachmentType, ensureStorageDirs, getProcessIdentity, isAttachmentId, readRunLogLines, resolveIndexedRunLog, resolveRunLogPath, resolveStoragePaths, scanSessionRunLogs, validateImageAttachment, validateImagePng };
478
+ export { type AttachmentStore, FileAttachmentStore, type GoalRunClaim, IMAGE_MAX_BYTES, ImageArtifactStore, type McpAuthFile, McpAuthStore, type McpOAuthTokens, type ProjectsPolicyFile, ProjectsPolicyStore, RUN_LOG_RETENTION_MS, RunEventStoreFactoryImpl, type RunLogCleanupResult, SessionGoalStore, type SessionRunEntry, type SessionRunRecorder, SessionStateStoreImpl, SessionStoreWriterImpl, StoragePathServiceImpl, type StoredAttachment, type StoredSessionGoal, type TaskArtifact, type TaskKind, type TaskRecord, TaskRegistryStore, type TaskResult, type TaskState, type TaskTruncatedOutput, type TaskWorkspaceMode, ToolOutputCacheStoreImpl, cleanupRunLogs, createAttachmentId, detectImageAttachmentType, ensureStorageDirs, getProcessIdentity, isAttachmentId, readRunLogLines, resolveIndexedRunLog, resolveRunLogPath, resolveStoragePaths, scanSessionRunLogs, validateImageAttachment, validateImagePng };