@pugi/sdk 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { permissionDecisionSchema } from './permission-rules.js';
3
+ import { subagentIsolationSchema, subagentRoleSchema } from './subagent-contracts.js';
3
4
  export const auditEventBaseSchema = z.object({
4
5
  id: z.string().min(1),
5
6
  sessionId: z.string().min(1),
@@ -35,10 +36,150 @@ export const sessionEventSchema = auditEventBaseSchema.extend({
35
36
  command: z.string().min(1).optional(),
36
37
  status: z.enum(['success', 'error']).optional(),
37
38
  });
39
+ const hookEventName = z.enum([
40
+ 'SessionStart',
41
+ 'UserPromptSubmit',
42
+ 'PreToolUse',
43
+ 'PermissionRequest',
44
+ 'PostToolUse',
45
+ 'PostToolUseFailure',
46
+ 'Stop',
47
+ 'SessionEnd',
48
+ ]);
49
+ export const hookInvokedEventSchema = auditEventBaseSchema.extend({
50
+ type: z.literal('hook.invoked'),
51
+ event: hookEventName,
52
+ matchSummary: z.string().min(1),
53
+ runSummary: z.string().min(1),
54
+ });
55
+ export const hookResultEventSchema = auditEventBaseSchema.extend({
56
+ type: z.literal('hook.result'),
57
+ event: hookEventName,
58
+ ok: z.boolean(),
59
+ exitCode: z.number().int(),
60
+ elapsedMs: z.number().int().nonnegative(),
61
+ stdoutLen: z.number().int().nonnegative(),
62
+ stderrLen: z.number().int().nonnegative(),
63
+ });
64
+ export const hookSkippedEventSchema = auditEventBaseSchema.extend({
65
+ type: z.literal('hook.skipped'),
66
+ event: hookEventName,
67
+ reason: z.enum(['dedup', 'no-match', 'untrusted-project']),
68
+ });
69
+ export const compactionTierSchema = z.enum([
70
+ 'microcompact',
71
+ 'cached_microcompact',
72
+ 'reactive_summary',
73
+ 'session_memory',
74
+ 'full_compaction',
75
+ 'reset',
76
+ ]);
77
+ export const compactionStartedEventSchema = auditEventBaseSchema.extend({
78
+ type: z.literal('compaction.started'),
79
+ tier: compactionTierSchema,
80
+ trigger: z.object({
81
+ budgetUsed: z.number().nonnegative(),
82
+ budgetMax: z.number().positive(),
83
+ }),
84
+ });
85
+ export const compactionCompletedEventSchema = auditEventBaseSchema.extend({
86
+ type: z.literal('compaction.completed'),
87
+ tier: compactionTierSchema,
88
+ bytesReclaimed: z.number().nonnegative(),
89
+ newContextSize: z.number().nonnegative(),
90
+ artifactsCreated: z.array(z.object({
91
+ sha256: z.string().min(1),
92
+ size: z.number().nonnegative(),
93
+ producedBy: z.string().min(1),
94
+ })),
95
+ });
96
+ export const compactionSkippedEventSchema = auditEventBaseSchema.extend({
97
+ type: z.literal('compaction.skipped'),
98
+ tier: compactionTierSchema,
99
+ reason: z.string(),
100
+ });
101
+ export const compactionInvariantViolatedEventSchema = auditEventBaseSchema.extend({
102
+ type: z.literal('compaction.invariant_violated'),
103
+ invariant: z.enum([
104
+ 'secrets-never-summarize',
105
+ 'open-decisions-preserved',
106
+ 'artifact-refs-resolvable',
107
+ 'static-hash-unchanged',
108
+ ]),
109
+ evidence: z.string(),
110
+ artifactRef: z.string().min(1).optional(),
111
+ });
112
+ /**
113
+ * Subagent lifecycle events. Extended in Sprint a5.4 (M1 gap remediation D)
114
+ * so dispatcher activity surfaces in the same `.pugi/events.jsonl` audit
115
+ * stream as tool calls, hooks, and compactions. The dispatcher
116
+ * implementation lives in `apps/pugi-cli/src/core/subagents/dispatcher.ts`;
117
+ * the wire-level shape and role/isolation enums are defined in
118
+ * `subagent-contracts.ts` and re-used here so a single source of truth
119
+ * governs validation on both sides of the boundary.
120
+ */
121
+ export const subagentSpawnedAuditEventSchema = auditEventBaseSchema.extend({
122
+ type: z.literal('subagent.spawned'),
123
+ taskId: z.string().min(1),
124
+ role: subagentRoleSchema,
125
+ personaSlug: z.string().min(1),
126
+ parentSessionId: z.string().min(1),
127
+ isolation: subagentIsolationSchema,
128
+ });
129
+ export const subagentToolCallAuditEventSchema = auditEventBaseSchema.extend({
130
+ type: z.literal('subagent.tool_call'),
131
+ taskId: z.string().min(1),
132
+ role: subagentRoleSchema,
133
+ personaSlug: z.string().min(1),
134
+ toolName: z.string().min(1),
135
+ toolCallId: z.string().min(1),
136
+ });
137
+ export const subagentCompletedAuditEventSchema = auditEventBaseSchema.extend({
138
+ type: z.literal('subagent.completed'),
139
+ taskId: z.string().min(1),
140
+ role: subagentRoleSchema,
141
+ personaSlug: z.string().min(1),
142
+ toolCallCount: z.number().int().nonnegative(),
143
+ tokensIn: z.number().int().nonnegative(),
144
+ tokensOut: z.number().int().nonnegative(),
145
+ durationMs: z.number().int().nonnegative(),
146
+ });
147
+ export const subagentBlockedAuditEventSchema = auditEventBaseSchema.extend({
148
+ type: z.literal('subagent.blocked'),
149
+ taskId: z.string().min(1),
150
+ role: subagentRoleSchema,
151
+ personaSlug: z.string().min(1),
152
+ reason: z.enum([
153
+ 'budget_exhausted',
154
+ 'plan_mode_refused',
155
+ 'permission_denied',
156
+ 'tool_unavailable',
157
+ ]),
158
+ detail: z.string().min(1),
159
+ });
160
+ export const subagentFailedAuditEventSchema = auditEventBaseSchema.extend({
161
+ type: z.literal('subagent.failed'),
162
+ taskId: z.string().min(1),
163
+ role: subagentRoleSchema,
164
+ personaSlug: z.string().min(1),
165
+ error: z.string().min(1),
166
+ });
38
167
  export const auditEventSchema = z.discriminatedUnion('type', [
39
168
  sessionEventSchema,
40
169
  toolCallEventSchema,
41
170
  toolResultEventSchema,
42
171
  fileMutationEventSchema,
172
+ hookInvokedEventSchema,
173
+ hookResultEventSchema,
174
+ hookSkippedEventSchema,
175
+ compactionStartedEventSchema,
176
+ compactionCompletedEventSchema,
177
+ compactionSkippedEventSchema,
178
+ compactionInvariantViolatedEventSchema,
179
+ subagentSpawnedAuditEventSchema,
180
+ subagentToolCallAuditEventSchema,
181
+ subagentCompletedAuditEventSchema,
182
+ subagentBlockedAuditEventSchema,
183
+ subagentFailedAuditEventSchema,
43
184
  ]);
44
185
  //# sourceMappingURL=audit-trace.js.map
package/dist/index.d.ts CHANGED
@@ -6,5 +6,6 @@ export * from './engine-loop.js';
6
6
  export * from './handoff.js';
7
7
  export * from './mcp-schemas.js';
8
8
  export * from './permission-rules.js';
9
+ export * from './subagent-contracts.js';
9
10
  export * from './transport.js';
10
11
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -6,5 +6,6 @@ export * from './engine-loop.js';
6
6
  export * from './handoff.js';
7
7
  export * from './mcp-schemas.js';
8
8
  export * from './permission-rules.js';
9
+ export * from './subagent-contracts.js';
9
10
  export * from './transport.js';
10
11
  //# sourceMappingURL=index.js.map