@company-semantics/contracts 0.46.0 → 0.47.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-semantics/contracts",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,6 +17,17 @@ export type {
17
17
  RalphPRDPriority,
18
18
  RalphPRDItem,
19
19
  RalphPRD,
20
+ // PRD v2.0 schema extensions
21
+ RalphAgentContract,
22
+ RalphFailurePolicy,
23
+ RalphScope,
24
+ RalphMeta,
25
+ RalphAcceptanceCriteria,
26
+ RalphReferenceImplementation,
27
+ RalphInteractionFlow,
28
+ RalphCapabilities,
29
+ RalphSuccessCriteria,
30
+ RalphCommitPolicy,
20
31
  } from './prd';
21
32
 
22
33
  // PRD constants (cross-repo support)
package/src/ralph/prd.ts CHANGED
@@ -29,8 +29,8 @@ export const REPO_PRECEDENCE = [
29
29
  'company-semantics-ci',
30
30
  'company-semantics-backend',
31
31
  'company-semantics-edge',
32
- 'company-semantics-site',
33
32
  'company-semantics-app',
33
+ 'company-semantics-site',
34
34
  ] as const;
35
35
 
36
36
  /**
@@ -84,12 +84,209 @@ export type RalphPRDItem = {
84
84
  blockedBy?: string[];
85
85
  /** Target repository for this feature (inherits from PRD if omitted) */
86
86
  repo?: AllowedRepo;
87
+ /** Machine-verifiable acceptance criteria (preferred over steps) */
88
+ acceptance?: RalphAcceptanceCriteria[];
89
+ /** Code shape guidance for implementation */
90
+ referenceImplementation?: RalphReferenceImplementation;
87
91
  };
88
92
 
89
93
  // =============================================================================
90
94
  // PRD Document Types
91
95
  // =============================================================================
92
96
 
97
+ // =============================================================================
98
+ // PRD v2.0 Schema Extensions
99
+ // =============================================================================
100
+
101
+ /**
102
+ * Agent behavioral constraints for execution.
103
+ *
104
+ * Defines what the agent is allowed to do during execution.
105
+ * When omitted, agent uses trust-level defaults.
106
+ */
107
+ export type RalphAgentContract = {
108
+ /** Execution mode (inferred from invocation if omitted) */
109
+ mode: 'afk' | 'hitl';
110
+ /** Actions explicitly allowed (empty = all allowed per trust level) */
111
+ allowedActions: string[];
112
+ /** Actions explicitly forbidden */
113
+ forbiddenActions: string[];
114
+ /** Autonomy level: bounded = conservative, full = aggressive */
115
+ autonomyLevel: 'bounded' | 'full';
116
+ /** Enforcement: hard = block on violation, soft = warn + log */
117
+ enforcement?: 'hard' | 'soft';
118
+ };
119
+
120
+ /**
121
+ * Recovery semantics for failures.
122
+ *
123
+ * Determines how the agent handles repeated failures.
124
+ * Default: { maxRetries: 0, onRepeatedFailure: 'halt_and_report', retryScope: 'current_feature_only' }
125
+ */
126
+ export type RalphFailurePolicy = {
127
+ /** Number of retries before triggering onRepeatedFailure (0 = no retries) */
128
+ maxRetries: number;
129
+ /** Action on repeated failure */
130
+ onRepeatedFailure: 'halt_and_report' | 'continue_next_feature' | 'escalate';
131
+ /** Scope for retry attempts */
132
+ retryScope: 'current_feature_only' | 'full_prd';
133
+ /** Target for escalation (for future HITL workflows) */
134
+ escalationTarget?: 'human' | 'issue' | 'log_only';
135
+ };
136
+
137
+ /**
138
+ * Path boundaries for file operations.
139
+ *
140
+ * Constrains where the agent can read/write files.
141
+ * When omitted, entire repo is allowed with no restrictions.
142
+ */
143
+ export type RalphScope = {
144
+ /** Glob patterns for allowed paths */
145
+ allowedPaths: string[];
146
+ /** Glob patterns for forbidden paths */
147
+ forbiddenPaths: string[];
148
+ /** Whether refactoring (beyond feature scope) is allowed */
149
+ refactoringAllowed: boolean;
150
+ };
151
+
152
+ /**
153
+ * Normalized metadata for PRD tracking.
154
+ *
155
+ * Generated at runtime if omitted.
156
+ */
157
+ export type RalphMeta = {
158
+ /** Schema version (e.g., "2.0") */
159
+ schemaVersion: string;
160
+ /** ISO timestamp when PRD was created */
161
+ createdAt: string;
162
+ /** ISO timestamp when PRD was completed (required if status === "completed") */
163
+ completedAt?: string;
164
+ /** Owner identifier (user or system) */
165
+ owner: string;
166
+ };
167
+
168
+ /**
169
+ * Machine-verifiable acceptance criteria.
170
+ *
171
+ * Discriminated union of verification check types.
172
+ * All criteria must pass for feature to be marked passes: true.
173
+ */
174
+ export type RalphAcceptanceCriteria =
175
+ | { type: 'file_contains'; path: string; pattern: string }
176
+ | {
177
+ type: 'command_exit';
178
+ command: string;
179
+ expectedExitCode: number;
180
+ }
181
+ | {
182
+ type: 'ci_status';
183
+ workflow?: string;
184
+ status: 'success' | 'failure';
185
+ scope?: 'current_sha' | 'branch';
186
+ }
187
+ | { type: 'test_passes'; pattern?: string };
188
+
189
+ /**
190
+ * Code shape guidance for feature implementation.
191
+ *
192
+ * Provides structural hints without being prescriptive.
193
+ */
194
+ export type RalphReferenceImplementation = {
195
+ /** How authoritative is this reference */
196
+ status: 'authoritative' | 'guidance' | 'partial' | 'anti-pattern';
197
+ /** Programming language */
198
+ language: string;
199
+ /** Location: 'inline' for embedded code, or file path */
200
+ location: 'inline' | string;
201
+ /** Inline code (when location is 'inline') */
202
+ code?: string;
203
+ /** Policy for deviations from reference */
204
+ deviationPolicy?: 'must_log' | 'allowed';
205
+ /** Scoping for where this reference applies */
206
+ appliesTo?: {
207
+ /** File paths where this applies */
208
+ files?: string[];
209
+ /** Function names where this applies */
210
+ functions?: string[];
211
+ };
212
+ };
213
+
214
+ /**
215
+ * Temporal behavior expectations.
216
+ *
217
+ * Describes expected interaction patterns without UI coupling.
218
+ */
219
+ export type RalphInteractionFlow = {
220
+ /** Unique identifier within PRD */
221
+ id: string;
222
+ /** Human-readable description */
223
+ description: string;
224
+ /** Required behaviors (must be non-empty) */
225
+ must: string[];
226
+ /** Forbidden behaviors */
227
+ mustNot?: string[];
228
+ };
229
+
230
+ /**
231
+ * Feature-scoped capability declarations.
232
+ *
233
+ * Declares what capabilities the feature requires.
234
+ * When omitted, all standard capabilities assumed available.
235
+ */
236
+ export type RalphCapabilities = {
237
+ /** Whether streaming responses are needed */
238
+ streaming?: boolean;
239
+ /** Artifact types produced (e.g., ["code", "text", "diagram"]) */
240
+ artifacts?: string[];
241
+ /** Whether multi-modal input/output is needed */
242
+ multiModal?: boolean;
243
+ /** Whether regeneration of outputs is allowed */
244
+ regeneration?: boolean;
245
+ /** Extensible for future capabilities */
246
+ [key: string]: boolean | string[] | undefined;
247
+ };
248
+
249
+ /**
250
+ * PRD-level success criteria (multi-dimensional).
251
+ *
252
+ * Defines what "success" means across functional, operational, and quality dimensions.
253
+ */
254
+ export type RalphSuccessCriteria = {
255
+ /** What must work (at least one required) */
256
+ functional: string[];
257
+ /** Runtime/safety constraints */
258
+ operational: string[];
259
+ /** Code/artifact quality requirements */
260
+ quality: string[];
261
+ };
262
+
263
+ /**
264
+ * Rollback and commit semantics.
265
+ *
266
+ * Separate from failurePolicy: failure policy decides WHEN to stop,
267
+ * commit policy decides WHAT HAPPENS TO CODE.
268
+ *
269
+ * Default: {
270
+ * strategy: 'per_feature',
271
+ * commitOn: 'acceptance_pass',
272
+ * rollbackOnFailure: 'uncommitted_only',
273
+ * onHalt: 'leave_committed',
274
+ * logRollback: true
275
+ * }
276
+ */
277
+ export type RalphCommitPolicy = {
278
+ /** When commits are created */
279
+ strategy: 'per_feature' | 'manual';
280
+ /** Gate for allowing commits */
281
+ commitOn: 'acceptance_pass' | 'manual';
282
+ /** What to do with code on failure */
283
+ rollbackOnFailure: 'none' | 'uncommitted_only' | 'current_feature';
284
+ /** What to do with completed work on halt/escalation */
285
+ onHalt: 'leave_committed' | 'rollback_uncommitted';
286
+ /** Whether to log all rollback actions (must be true if rollbackOnFailure !== 'none') */
287
+ logRollback: boolean;
288
+ };
289
+
93
290
  /**
94
291
  * A complete Ralph PRD document.
95
292
  *
@@ -105,4 +302,22 @@ export type RalphPRD = {
105
302
  features: RalphPRDItem[];
106
303
  /** Explicit "done" definition (e.g., "All features pass") */
107
304
  stopCondition: string;
305
+ /** Agent behavioral constraints */
306
+ agentContract?: RalphAgentContract;
307
+ /** Recovery semantics for failures */
308
+ failurePolicy?: RalphFailurePolicy;
309
+ /** Path boundaries for file operations */
310
+ scope?: RalphScope;
311
+ /** Normalized metadata */
312
+ meta?: RalphMeta;
313
+ /** Temporal behavior expectations */
314
+ interactionFlows?: RalphInteractionFlow[];
315
+ /** Feature-scoped capability declarations */
316
+ capabilities?: RalphCapabilities;
317
+ /** PRD-level success criteria */
318
+ successCriteria?: RalphSuccessCriteria;
319
+ /** Explicit exclusions to prevent agent overreach */
320
+ nonGoals?: string[];
321
+ /** Rollback and commit semantics */
322
+ commitPolicy?: RalphCommitPolicy;
108
323
  };