snipara-companion 2.0.0 → 2.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
@@ -31,10 +31,58 @@ Local continuity commands work without a Snipara account; commands that read
31
31
  hosted context or memory need `init`/`login` first. Run
32
32
  `snipara-companion --help` for the full command list.
33
33
 
34
+ ## Local Context Pack
35
+
36
+ `context-pack` is a free, local-only reversible pack for long tool outputs,
37
+ logs, diffs, and notes. It stores exact content under
38
+ `.snipara/context-pack` and never uploads raw output to hosted Snipara.
39
+
40
+ ```bash
41
+ # Pack piped tool output
42
+ pnpm test 2>&1 | snipara-companion context-pack pack \
43
+ --label "package test output" \
44
+ --source "pnpm test"
45
+
46
+ # Pack a local file
47
+ snipara-companion context-pack pack --file ./debug.log --kind log --json
48
+
49
+ # Retrieve exact content later
50
+ snipara-companion context-pack retrieve latest
51
+ snipara-companion context-pack retrieve cpack_abcd1234 --output ./restored.log
52
+ snipara-companion context-pack retrieve cpack_abcd1234 --json --metadata-only
53
+
54
+ # Inspect and clean local storage
55
+ snipara-companion context-pack stats
56
+ snipara-companion context-pack clean --older-than-days 14
57
+
58
+ # Attach metadata-only receipts to events/checkpoints
59
+ snipara-companion post-tool --tool Bash --result "$(cat ./debug.log)" --pack-result
60
+ snipara-companion emit-event -e tool_result --context-pack cpack_abcd1234
61
+ snipara-companion workflow runtime-checkpoint verify \
62
+ --summary "Captured verifier output" \
63
+ --context-pack cpack_abcd1234
64
+ ```
65
+
66
+ The pack ID is derived from the content hash, so packing identical content is
67
+ idempotent. Use `--ttl-days` when temporary output should be cleaned by the
68
+ default `context-pack clean` path. The storage directory writes its own
69
+ `.gitignore` so raw pack blobs do not appear in normal Git staging. Pack blobs
70
+ are plaintext local files with restrictive permissions. Secret-like input is
71
+ blocked by default; use `--allow-sensitive` only when you intentionally need an
72
+ exact local recovery artifact, and prefer the exact pack ID over `latest` in
73
+ handoffs.
74
+
75
+ Metadata-only context-pack receipts include token economy fields:
76
+ `baseline_tokens`, `packed_tokens`, `retrieved_tokens`, and `saved_tokens`.
77
+ Pack/reference receipts can claim saved tokens because only receipt metadata is
78
+ uploaded; retrieve receipts set retrieved tokens to the local baseline so they
79
+ do not overstate savings.
80
+
34
81
  ```mermaid
35
82
  flowchart LR
36
83
  Project["Local project"] --> Companion["snipara-companion"]
37
84
  Companion --> Diagnostics["status, brief, timeline, phase commits, handoff"]
85
+ Companion --> Packs["context-pack (local output packs)"]
38
86
  Companion --> Memory["snipara-memory (optional local memory)"]
39
87
  Companion --> Evals["snipara-evals (optional local evals)"]
40
88
  Companion --> Hosted["Snipara Hosted MCP / API"]
@@ -202,6 +250,15 @@ Project owners can configure Adaptive Work Routing in Project > Automation:
202
250
  `off`, `recommend`, or `catalog`; approval; planner-retained reasoning; allowed
203
251
  endpoint types (`cloud`, `local`, `self_hosted`); worker classes; and budget
204
252
  hints. `workflow run` reads that hosted policy and CLI flags cannot broaden it.
253
+ Companion passes policy budgets into provider-neutral model requirements; the
254
+ hosted gateway enforces project and provider daily/monthly budgets when receipt
255
+ history is available.
256
+
257
+ Approval is an MCP contract, not a dashboard-only UX path. When project policy
258
+ requires approval, a coding agent calls `snipara_adaptive_routing_approve` with
259
+ the routing card or handoff subject, approved write scopes, endpoint types, a
260
+ stable `idempotency_key`, and optional cost/expiry bounds. Companion dry-runs
261
+ surface the approval requirement but do not auto-approve or spawn workers.
205
262
  Project credentials stay server-side behind the hosted gateway; local endpoints
206
263
  such as Ollama, LM Studio, AnythingLLM, or other OpenAI-compatible servers must
207
264
  be reachable from the worker execution environment.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,136 @@ declare function resolveQueryFromToolInput(toolInput?: string, tool?: string): s
3
3
 
4
4
  declare function extractFilesFromToolInput(toolInput?: string): string[];
5
5
 
6
+ type ContextPackKind = "tool_output" | "log" | "diff" | "file" | "text" | "note";
7
+ interface ContextPackRecord {
8
+ version: "snipara.context_pack.v1";
9
+ id: string;
10
+ createdAt: string;
11
+ updatedAt: string;
12
+ kind: ContextPackKind;
13
+ label: string | null;
14
+ source: string | null;
15
+ tags: string[];
16
+ repoRoot: string;
17
+ sha256: string;
18
+ bytes: number;
19
+ lineCount: number;
20
+ contentType: "text/plain";
21
+ contentEncoding: "utf8";
22
+ preview: string;
23
+ expiresAt: string | null;
24
+ sensitive: boolean;
25
+ warnings: Array<{
26
+ code: string;
27
+ message: string;
28
+ }>;
29
+ storage: {
30
+ baseRelativePath: string;
31
+ manifestRelativePath: string;
32
+ blobRelativePath: string;
33
+ };
34
+ }
35
+ interface PackContextOptions {
36
+ cwd?: string;
37
+ content: string;
38
+ label?: string;
39
+ source?: string;
40
+ kind?: string;
41
+ tags?: string[];
42
+ ttlDays?: number;
43
+ maxBytes?: number;
44
+ allowSensitive?: boolean;
45
+ now?: Date;
46
+ }
47
+ interface ContextPackPackCommandOptions {
48
+ cwd?: string;
49
+ text?: string;
50
+ file?: string;
51
+ input?: string;
52
+ label?: string;
53
+ source?: string;
54
+ kind?: string;
55
+ tags?: string[];
56
+ ttlDays?: number;
57
+ maxBytes?: number;
58
+ allowSensitive?: boolean;
59
+ json?: boolean;
60
+ }
61
+ interface ContextPackRetrieveCommandOptions {
62
+ cwd?: string;
63
+ output?: string;
64
+ metadataOnly?: boolean;
65
+ json?: boolean;
66
+ }
67
+ interface ContextPackStatsCommandOptions {
68
+ cwd?: string;
69
+ json?: boolean;
70
+ }
71
+ interface ContextPackCleanCommandOptions {
72
+ cwd?: string;
73
+ all?: boolean;
74
+ expired?: boolean;
75
+ olderThanDays?: number;
76
+ dryRun?: boolean;
77
+ json?: boolean;
78
+ now?: Date;
79
+ }
80
+ interface ContextPackStoragePaths {
81
+ repoRoot: string;
82
+ baseDir: string;
83
+ blobsDir: string;
84
+ manifestsDir: string;
85
+ latestPath: string;
86
+ }
87
+ interface PackContextResult {
88
+ record: ContextPackRecord;
89
+ created: boolean;
90
+ baseDir: string;
91
+ manifestPath: string;
92
+ blobPath: string;
93
+ }
94
+ interface RetrieveContextPackResult {
95
+ record: ContextPackRecord;
96
+ content: string;
97
+ baseDir: string;
98
+ manifestPath: string;
99
+ blobPath: string;
100
+ }
101
+ interface ContextPackStats {
102
+ version: "snipara.context_pack.stats.v1";
103
+ baseDir: string;
104
+ totalPacks: number;
105
+ totalBytes: number;
106
+ sensitivePacks: number;
107
+ expiredPacks: number;
108
+ kinds: Record<string, number>;
109
+ oldestCreatedAt: string | null;
110
+ newestCreatedAt: string | null;
111
+ latestId: string | null;
112
+ }
113
+ interface ContextPackCleanResult {
114
+ version: "snipara.context_pack.clean.v1";
115
+ baseDir: string;
116
+ dryRun: boolean;
117
+ selected: number;
118
+ deleted: number;
119
+ deletedIds: string[];
120
+ }
121
+ declare function getContextPackStoragePaths(cwd?: string): ContextPackStoragePaths;
122
+ declare function packContext(options: PackContextOptions): PackContextResult;
123
+ declare function resolveContextPackRecord(idOrRef: string, cwd?: string): {
124
+ paths: ContextPackStoragePaths;
125
+ record: ContextPackRecord;
126
+ manifestPath: string;
127
+ };
128
+ declare function retrieveContextPack(idOrRef: string, cwd?: string): RetrieveContextPackResult;
129
+ declare function buildContextPackStats(options?: ContextPackStatsCommandOptions): ContextPackStats;
130
+ declare function cleanContextPacks(options?: ContextPackCleanCommandOptions): ContextPackCleanResult;
131
+ declare function contextPackPackCommand(options: ContextPackPackCommandOptions): Promise<void>;
132
+ declare function contextPackRetrieveCommand(idOrRef: string, options?: ContextPackRetrieveCommandOptions): Promise<void>;
133
+ declare function contextPackStatsCommand(options?: ContextPackStatsCommandOptions): Promise<void>;
134
+ declare function contextPackCleanCommand(options?: ContextPackCleanCommandOptions): Promise<void>;
135
+
6
136
  type PrivacyLevel = "standard" | "sensitive" | "restricted";
7
137
  type CanonicalEventType = "session_start" | "session_end" | "compact" | "message_user" | "message_assistant" | "tool_call" | "tool_result" | "file_changed" | "error_observed";
8
138
  interface CanonicalEventOptions {
@@ -13,7 +143,48 @@ interface CanonicalEventOptions {
13
143
  agentId?: string;
14
144
  privacyLevel?: PrivacyLevel;
15
145
  payload?: Record<string, unknown>;
146
+ contextPackReceipts?: LocalContextPackReceiptPayload[];
147
+ }
148
+ type LocalContextPackReceiptOperation = "pack" | "retrieve" | "reference";
149
+ interface LocalContextPackReceiptPayload {
150
+ version: "snipara.context_pack.receipt.v1";
151
+ receipt_id: string;
152
+ pack_id: string;
153
+ operation: LocalContextPackReceiptOperation;
154
+ content_uploaded: false;
155
+ policy_decision: "local_only" | "blocked" | "metadata_only";
156
+ privacy_level: PrivacyLevel;
157
+ kind: ContextPackRecord["kind"];
158
+ label?: string | null;
159
+ source?: string | null;
160
+ tags: string[];
161
+ bytes: number;
162
+ line_count: number;
163
+ baseline_tokens?: number;
164
+ packed_tokens?: number;
165
+ retrieved_tokens?: number;
166
+ saved_tokens?: number;
167
+ payload_digest?: string;
168
+ sensitive: boolean;
169
+ created_at: string;
170
+ expires_at?: string | null;
171
+ local_ref: {
172
+ base_relative_path: string;
173
+ manifest_relative_path: string;
174
+ };
16
175
  }
176
+ declare function buildLocalContextPackReceipt(record: ContextPackRecord, options?: {
177
+ operation?: LocalContextPackReceiptOperation;
178
+ privacyLevel?: PrivacyLevel;
179
+ policyDecision?: LocalContextPackReceiptPayload["policy_decision"];
180
+ }): LocalContextPackReceiptPayload;
181
+ declare function buildLocalContextPackReceipts(options: {
182
+ ids: string[];
183
+ cwd?: string;
184
+ operation?: LocalContextPackReceiptOperation;
185
+ privacyLevel?: PrivacyLevel;
186
+ }): LocalContextPackReceiptPayload[];
187
+ declare function attachLocalContextPackReceipts(payload: Record<string, unknown>, receipts: LocalContextPackReceiptPayload[]): Record<string, unknown>;
17
188
  declare function buildCanonicalEvent(options: CanonicalEventOptions): {
18
189
  type: CanonicalEventType;
19
190
  client: string;
@@ -2820,6 +2991,7 @@ interface OrchestratorHandoffRuntimeSandboxPhase {
2820
2991
  bootstrapQuery: string;
2821
2992
  files: string[];
2822
2993
  artifacts: string[];
2994
+ contextPacks: string[];
2823
2995
  sessionId: string | null;
2824
2996
  environment: string | null;
2825
2997
  profile: string | null;
@@ -2849,6 +3021,8 @@ interface AdaptiveModelRequirements {
2849
3021
  preferredEndpointTypes?: string[];
2850
3022
  allowedEndpointTypes?: string[];
2851
3023
  catalogLimit?: number;
3024
+ dailyBudgetCents?: number;
3025
+ monthlyBudgetCents?: number;
2852
3026
  fallback: "main_agent";
2853
3027
  }
2854
3028
  interface AdaptiveRoutingCostEstimate {
@@ -2894,6 +3068,8 @@ interface AdaptiveWorkRoutingOptions {
2894
3068
  workerRole?: string;
2895
3069
  plannerRetainsReasoning?: boolean;
2896
3070
  catalogLimit?: number;
3071
+ dailyBudgetCents?: number;
3072
+ monthlyBudgetCents?: number;
2897
3073
  }
2898
3074
  interface OrchestratorHandoffArtifact {
2899
3075
  schemaVersion: "snipara.orchestrator.handoff.v1";
@@ -2986,4 +3162,4 @@ declare function buildOrchestratorHandoff(options: OrchestratorHandoffOptions):
2986
3162
  declare function buildAdaptiveWorkRoutingRecommendation(options: AdaptiveWorkRoutingOptions): AdaptiveWorkRoutingRecommendation;
2987
3163
  declare function writeOrchestratorHandoff(options: OrchestratorHandoffOptions): WrittenOrchestratorHandoff;
2988
3164
 
2989
- export { AUTOMATION_MANIFEST_RELATIVE_PATH, AutomationInstallConflictError, AutomationUnsupportedHookBundleError, COLLABORATION_STATE_RELATIVE_PATH, ORCHESTRATOR_HANDOFF_RELATIVE_PATH, TEAM_SYNC_STATE_RELATIVE_PATH, WORKFLOW_PLANS_RELATIVE_DIR, WORKFLOW_STATE_RELATIVE_PATH, archiveInactiveTeamSyncWork, autoArchiveTeamSyncState, buildAdaptiveWorkRoutingRecommendation, buildAgenticHandoffMarkdown, buildAgenticTimeline, buildAgenticWorkStatus, buildAutomationInstallPlan, buildCanonicalEvent, buildCodeHooksInstallPlan, buildCodePromotionResult, buildCodeStatusResult, buildCodeSyncResult, buildCollaborationActor, buildCollaborationGuardActionCards, buildCollaborationHooksInstallPlan, buildEvalCaseArtifact, buildGeneratedWorkflowPlanDocument, buildHostedCodeOverlayUploadPayload, buildHostedGuardPayload, buildJournalCheckpointEntry, buildLocalCallersResult, buildLocalCodeOverlay, buildLocalImpactResult, buildLocalImportsResult, buildLocalNeighborsResult, buildLocalShortestPathResult, buildMemoryAudit, buildOnboardFolderManifest, buildOrchestratorHandoff, buildProjectIntelligenceBrief, buildProjectIntelligenceRun, buildProjectJudgmentCard, buildSessionBootstrapQuality, buildSyncDocumentsDryRun, buildTeamSyncHandoffRecord, buildTeamSyncStartWorkRecord, buildTeamSyncSummary, buildToolCallPayload, buildToolResultPayload, buildVerificationPlan, buildWorkflowImpactGate, buildWorkflowPhaseCommitSummary, buildWorkflowPlanScaffold, categoryFromGuardTag, classifyToolResult, collaborationIdeStatusCommand, collectSyncDocuments, collectSyncDocumentsInput, compactHostedGuardResources, completeTeamSyncStateFromEvidence, completeTeamSyncWorkFromEvidence, createClient, createEmptyCollaborationState, createEmptyTeamSyncState, createLocalQueryCache, deriveLocalCollaborationResourcesFromFiles, detectReleaseSurfacesFromFiles, detectRuntimeEnvironment, evalExportCommand, evalRunCommand, extractCommandFromToolInput, extractFilesFromToolInput, formatOrchestratorRecommendationReason, formatProjectJudgmentCard, formatStuckGuardDecision, getAutomationManifestPath, getAutomationStatus, getCollaborationStatePath, getConfigPath, getLocalCodeOverlayCachePath, getLocalCodePromotionStatePath, getOrchestratorRecommendation, getPlanStepDisplayTitle, getStagedFiles, getStuckGuardInjection, getTeamSyncStatePath, ingestReferences, installAutomationBundle, listProjectsForApiKey, loadAutomationManifest, loadCollaborationState, loadConfig, loadTeamSyncState, memoryAuditCommand, memoryCleanCandidatesCommand, memoryCompactCommand, memoryHealthCommand, memoryLocalCommand, normalizeCollaborationFiles, normalizeGuardTag, normalizeWorkflowPlanInput, parseCollaborationResources, projectIntelligenceBriefCommand, projectIntelligenceRunCommand, readLocalCodeOverlayCache, readLocalCodePromotionState, referencesIngestCommand, referencesScanCommand, resolveFullWorkflowTokenBudget, resolveQueryFromToolInput, runMemoryGuardCheck, saveCollaborationState, saveConfig, saveTeamSyncState, scanReferences, shouldSuggestOrchestratorForWorkflow, shouldSuggestRuntimeForWorkflow, summarizeLocalCodeOverlay, teamSyncSweepCommand, validatePlanResult, verifyCommand, writeLocalCodeOverlayCache, writeLocalCodePromotionState, writeOrchestratorHandoff };
3165
+ export { AUTOMATION_MANIFEST_RELATIVE_PATH, AutomationInstallConflictError, AutomationUnsupportedHookBundleError, COLLABORATION_STATE_RELATIVE_PATH, ORCHESTRATOR_HANDOFF_RELATIVE_PATH, TEAM_SYNC_STATE_RELATIVE_PATH, WORKFLOW_PLANS_RELATIVE_DIR, WORKFLOW_STATE_RELATIVE_PATH, archiveInactiveTeamSyncWork, attachLocalContextPackReceipts, autoArchiveTeamSyncState, buildAdaptiveWorkRoutingRecommendation, buildAgenticHandoffMarkdown, buildAgenticTimeline, buildAgenticWorkStatus, buildAutomationInstallPlan, buildCanonicalEvent, buildCodeHooksInstallPlan, buildCodePromotionResult, buildCodeStatusResult, buildCodeSyncResult, buildCollaborationActor, buildCollaborationGuardActionCards, buildCollaborationHooksInstallPlan, buildContextPackStats, buildEvalCaseArtifact, buildGeneratedWorkflowPlanDocument, buildHostedCodeOverlayUploadPayload, buildHostedGuardPayload, buildJournalCheckpointEntry, buildLocalCallersResult, buildLocalCodeOverlay, buildLocalContextPackReceipt, buildLocalContextPackReceipts, buildLocalImpactResult, buildLocalImportsResult, buildLocalNeighborsResult, buildLocalShortestPathResult, buildMemoryAudit, buildOnboardFolderManifest, buildOrchestratorHandoff, buildProjectIntelligenceBrief, buildProjectIntelligenceRun, buildProjectJudgmentCard, buildSessionBootstrapQuality, buildSyncDocumentsDryRun, buildTeamSyncHandoffRecord, buildTeamSyncStartWorkRecord, buildTeamSyncSummary, buildToolCallPayload, buildToolResultPayload, buildVerificationPlan, buildWorkflowImpactGate, buildWorkflowPhaseCommitSummary, buildWorkflowPlanScaffold, categoryFromGuardTag, classifyToolResult, cleanContextPacks, collaborationIdeStatusCommand, collectSyncDocuments, collectSyncDocumentsInput, compactHostedGuardResources, completeTeamSyncStateFromEvidence, completeTeamSyncWorkFromEvidence, contextPackCleanCommand, contextPackPackCommand, contextPackRetrieveCommand, contextPackStatsCommand, createClient, createEmptyCollaborationState, createEmptyTeamSyncState, createLocalQueryCache, deriveLocalCollaborationResourcesFromFiles, detectReleaseSurfacesFromFiles, detectRuntimeEnvironment, evalExportCommand, evalRunCommand, extractCommandFromToolInput, extractFilesFromToolInput, formatOrchestratorRecommendationReason, formatProjectJudgmentCard, formatStuckGuardDecision, getAutomationManifestPath, getAutomationStatus, getCollaborationStatePath, getConfigPath, getContextPackStoragePaths, getLocalCodeOverlayCachePath, getLocalCodePromotionStatePath, getOrchestratorRecommendation, getPlanStepDisplayTitle, getStagedFiles, getStuckGuardInjection, getTeamSyncStatePath, ingestReferences, installAutomationBundle, listProjectsForApiKey, loadAutomationManifest, loadCollaborationState, loadConfig, loadTeamSyncState, memoryAuditCommand, memoryCleanCandidatesCommand, memoryCompactCommand, memoryHealthCommand, memoryLocalCommand, normalizeCollaborationFiles, normalizeGuardTag, normalizeWorkflowPlanInput, packContext, parseCollaborationResources, projectIntelligenceBriefCommand, projectIntelligenceRunCommand, readLocalCodeOverlayCache, readLocalCodePromotionState, referencesIngestCommand, referencesScanCommand, resolveContextPackRecord, resolveFullWorkflowTokenBudget, resolveQueryFromToolInput, retrieveContextPack, runMemoryGuardCheck, saveCollaborationState, saveConfig, saveTeamSyncState, scanReferences, shouldSuggestOrchestratorForWorkflow, shouldSuggestRuntimeForWorkflow, summarizeLocalCodeOverlay, teamSyncSweepCommand, validatePlanResult, verifyCommand, writeLocalCodeOverlayCache, writeLocalCodePromotionState, writeOrchestratorHandoff };