@company-semantics/contracts 0.44.0 → 0.45.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.44.0",
3
+ "version": "0.45.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,6 +36,10 @@
36
36
  "types": "./src/email/index.ts",
37
37
  "default": "./src/email/index.ts"
38
38
  },
39
+ "./ralph": {
40
+ "types": "./src/ralph/index.ts",
41
+ "default": "./src/ralph/index.ts"
42
+ },
39
43
  "./schemas/guard-result.schema.json": "./schemas/guard-result.schema.json"
40
44
  },
41
45
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -307,3 +307,27 @@ export type {
307
307
  } from './ci-envelope/index'
308
308
 
309
309
  export { ENVELOPE_TRANSITIONS } from './ci-envelope/index'
310
+
311
+ // Ralph autonomous coding loop types
312
+ // @see company-semantics-control/docs/ralph.md for usage
313
+ export type {
314
+ // PRD types
315
+ RalphPRDCategory,
316
+ RalphPRDPriority,
317
+ RalphPRDItem,
318
+ RalphPRD,
319
+ // Progress types
320
+ RalphIteration,
321
+ RalphMode,
322
+ RalphProgress,
323
+ // Trust types
324
+ RalphTrustLevel,
325
+ RalphRunResult,
326
+ RalphCIStatus,
327
+ RalphTrustLog,
328
+ RalphTL1Policy,
329
+ RalphTL2Policy,
330
+ RalphTL3Policy,
331
+ RalphTrustPolicy,
332
+ RalphDemotionReason,
333
+ } from './ralph/index'
@@ -0,0 +1,42 @@
1
+ # ralph/
2
+
3
+ ## Purpose
4
+
5
+ TypeScript types for Ralph, an autonomous AI coding loop with graduated trust levels.
6
+
7
+ ## Invariants
8
+
9
+ - Types only; no runtime code (contracts policy)
10
+ - No external dependencies (contracts policy)
11
+ - `RalphTrustLevel` is limited to values 0-3
12
+ - PRD `passes` field is the only field Ralph should modify during execution
13
+ - Orchestration, prompts, and trust logic live in company-semantics-control, not here
14
+
15
+ ## Public API
16
+
17
+ ### PRD Types
18
+
19
+ - `RalphPRDCategory` — Category of feature item (`functional`, `architectural`, `integration`, `polish`)
20
+ - `RalphPRDPriority` — Priority level (`high`, `medium`, `low`)
21
+ - `RalphPRDItem` — Single feature item in a PRD
22
+ - `RalphPRD` — Complete PRD document
23
+
24
+ ### Progress Types
25
+
26
+ - `RalphIteration` — Record of a single iteration
27
+ - `RalphMode` — Operation mode (`hitl`, `afk`)
28
+ - `RalphProgress` — Complete session progress state
29
+
30
+ ### Trust Types
31
+
32
+ - `RalphTrustLevel` — Trust level (0-3)
33
+ - `RalphRunResult` — Run outcome (`success`, `failure`)
34
+ - `RalphCIStatus` — CI status (`green`, `red`, `skipped`)
35
+ - `RalphTrustLog` — Run outcome record for audit
36
+ - `RalphTrustPolicy` — Trust policy configuration
37
+ - `RalphDemotionReason` — Reasons for automatic demotion
38
+
39
+ ## Dependencies
40
+
41
+ **Imports from:** (none — leaf module)
42
+ **Imported by:** company-semantics-control
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Ralph Types Barrel
3
+ *
4
+ * Re-exports all Ralph autonomous coding loop vocabulary types.
5
+ * Import from '@company-semantics/contracts/ralph' or '@company-semantics/contracts'.
6
+ *
7
+ * Note: This module exports types only (no runtime code per contracts policy).
8
+ * Orchestration, prompts, and trust logic live in company-semantics-control.
9
+ *
10
+ * @see company-semantics-control/docs/ralph.md for usage
11
+ */
12
+
13
+ // PRD types
14
+ export type {
15
+ RalphPRDCategory,
16
+ RalphPRDPriority,
17
+ RalphPRDItem,
18
+ RalphPRD,
19
+ } from './prd';
20
+
21
+ // Progress types
22
+ export type {
23
+ RalphIteration,
24
+ RalphMode,
25
+ RalphProgress,
26
+ } from './progress';
27
+
28
+ // Trust types
29
+ export type {
30
+ RalphTrustLevel,
31
+ RalphRunResult,
32
+ RalphCIStatus,
33
+ RalphTrustLog,
34
+ RalphTL1Policy,
35
+ RalphTL2Policy,
36
+ RalphTL3Policy,
37
+ RalphTrustPolicy,
38
+ RalphDemotionReason,
39
+ } from './trust';
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Ralph PRD (Product Requirements Document) Types
3
+ *
4
+ * Defines the structure for Ralph's feature tracking, aligned with
5
+ * Anthropic's feature list pattern for autonomous coding loops.
6
+ *
7
+ * Key invariant: The `passes` field is the only field Ralph should modify
8
+ * during execution — it flips from false to true when verified.
9
+ *
10
+ * @see company-semantics-control/docs/ralph.md for usage
11
+ */
12
+
13
+ // =============================================================================
14
+ // PRD Item Types
15
+ // =============================================================================
16
+
17
+ /**
18
+ * Category of PRD feature item.
19
+ * Used for prioritization and verification strategy selection.
20
+ */
21
+ export type RalphPRDCategory =
22
+ | 'functional'
23
+ | 'architectural'
24
+ | 'integration'
25
+ | 'polish';
26
+
27
+ /**
28
+ * Priority level for feature ordering.
29
+ */
30
+ export type RalphPRDPriority = 'high' | 'medium' | 'low';
31
+
32
+ /**
33
+ * A single feature item in a Ralph PRD.
34
+ *
35
+ * Design invariants:
36
+ * - `id` is unique within the PRD (typically "repo/feature-name")
37
+ * - `passes` starts false and flips to true when verified
38
+ * - `blockedBy` references other item IDs (dependency ordering)
39
+ * - `steps` describe verification from user perspective
40
+ */
41
+ export type RalphPRDItem = {
42
+ /** Unique identifier, e.g., "contracts/add-ralph-types" */
43
+ id: string;
44
+ /** Category for prioritization */
45
+ category: RalphPRDCategory;
46
+ /** Human-readable goal description */
47
+ description: string;
48
+ /** Verification steps (as a user would test) */
49
+ steps: string[];
50
+ /** Whether this feature has been completed and verified */
51
+ passes: boolean;
52
+ /** Priority level */
53
+ priority: RalphPRDPriority;
54
+ /** IDs of features that must complete before this one */
55
+ blockedBy?: string[];
56
+ };
57
+
58
+ // =============================================================================
59
+ // PRD Document Types
60
+ // =============================================================================
61
+
62
+ /**
63
+ * A complete Ralph PRD document.
64
+ *
65
+ * Contains all features for a Ralph session and defines
66
+ * the explicit stop condition for completion.
67
+ */
68
+ export type RalphPRD = {
69
+ /** Schema version for migration */
70
+ version: string;
71
+ /** Target repository name */
72
+ repo: string;
73
+ /** Feature items to implement */
74
+ features: RalphPRDItem[];
75
+ /** Explicit "done" definition (e.g., "All features pass") */
76
+ stopCondition: string;
77
+ };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Ralph Progress Tracking Types
3
+ *
4
+ * Types for tracking Ralph session progress. Progress files are
5
+ * committed to repos after each iteration to enable state rehydration
6
+ * across context windows.
7
+ *
8
+ * Key insight: Each `claude -p` invocation is a FRESH context window.
9
+ * Progress persists via git-committed state files, not memory.
10
+ *
11
+ * @see company-semantics-control/docs/ralph.md for usage
12
+ */
13
+
14
+ import type { RalphTrustLevel } from './trust';
15
+
16
+ // =============================================================================
17
+ // Iteration Types
18
+ // =============================================================================
19
+
20
+ /**
21
+ * Record of a single Ralph iteration.
22
+ *
23
+ * Written to progress file after each feature completion.
24
+ * Enables next iteration to understand prior work.
25
+ */
26
+ export type RalphIteration = {
27
+ /** Iteration number (1-indexed) */
28
+ iteration: number;
29
+ /** ISO 8601 timestamp of iteration completion */
30
+ timestamp: string;
31
+ /** PRD feature ID that was worked on */
32
+ featureId: string;
33
+ /** Relative paths of files changed */
34
+ filesChanged: string[];
35
+ /** Git commit SHA for this iteration */
36
+ commitSha: string;
37
+ /** Whether all guards passed */
38
+ guardsPassed: boolean;
39
+ /** Concise notes (sacrifice grammar for brevity) */
40
+ notes: string;
41
+ };
42
+
43
+ // =============================================================================
44
+ // Session Progress Types
45
+ // =============================================================================
46
+
47
+ /**
48
+ * Ralph operation mode.
49
+ */
50
+ export type RalphMode = 'hitl' | 'afk';
51
+
52
+ /**
53
+ * Complete progress state for a Ralph session.
54
+ *
55
+ * Stored in `.ralph/progress.txt` (human-readable) or
56
+ * `.ralph/progress.json` (machine-readable).
57
+ */
58
+ export type RalphProgress = {
59
+ /** Unique session identifier (ISO timestamp or UUID) */
60
+ sessionId: string;
61
+ /** Target repository name */
62
+ repo: string;
63
+ /** Current trust level (0-3) */
64
+ trustLevel: RalphTrustLevel;
65
+ /** Operation mode (HITL or AFK) */
66
+ mode: RalphMode;
67
+ /** Completed iterations */
68
+ iterations: RalphIteration[];
69
+ /** PRD feature IDs that have been completed */
70
+ completedFeatureIds: string[];
71
+ /** PRD feature IDs that are blocked (dependencies not met) */
72
+ blockedFeatureIds: string[];
73
+ };
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Ralph Trust Level Types
3
+ *
4
+ * Defines the Trust Promotion framework for graduated AI autonomy.
5
+ * Ralph earns trust through repeated, measurable compliance — not intent.
6
+ *
7
+ * Trust Level Summary:
8
+ * - TL0 (Sandbox): Default, no network, single repo
9
+ * - TL1 (Verified): Earned after 8+ consecutive clean runs
10
+ * - TL2 (Limited Network): Requires human approval, npm/GitHub access
11
+ * - TL3 (Full AFK): Rare, mechanical tasks only, full network
12
+ *
13
+ * @see company-semantics-control/docs/ralph.md for usage
14
+ */
15
+
16
+ // =============================================================================
17
+ // Trust Level Types
18
+ // =============================================================================
19
+
20
+ /**
21
+ * Trust level numeric value.
22
+ *
23
+ * - 0: Sandbox (default)
24
+ * - 1: Verified AFK
25
+ * - 2: Limited Network
26
+ * - 3: Full AFK
27
+ */
28
+ export type RalphTrustLevel = 0 | 1 | 2 | 3;
29
+
30
+ /**
31
+ * Result of a Ralph run.
32
+ */
33
+ export type RalphRunResult = 'success' | 'failure';
34
+
35
+ /**
36
+ * CI status after a Ralph run.
37
+ */
38
+ export type RalphCIStatus = 'green' | 'red' | 'skipped';
39
+
40
+ // =============================================================================
41
+ // Trust Log Types
42
+ // =============================================================================
43
+
44
+ /**
45
+ * Record of a single Ralph run outcome.
46
+ *
47
+ * Stored in `.ralph/trust-log.json` for audit and promotion decisions.
48
+ */
49
+ export type RalphTrustLog = {
50
+ /** Run identifier (ISO timestamp) */
51
+ runId: string;
52
+ /** Repository where run occurred */
53
+ repo: string;
54
+ /** Trust level at time of run */
55
+ trustLevel: RalphTrustLevel;
56
+ /** Overall run result */
57
+ result: RalphRunResult;
58
+ /** CI status after run */
59
+ ciStatus: RalphCIStatus;
60
+ /** Whether human fixes were required post-run */
61
+ humanFixesRequired: boolean;
62
+ /** Reason for demotion if applicable */
63
+ demotionReason?: string;
64
+ /** Number of iterations completed */
65
+ iterationsCompleted?: number;
66
+ /** Number of features completed */
67
+ featuresCompleted?: number;
68
+ };
69
+
70
+ // =============================================================================
71
+ // Trust Policy Types
72
+ // =============================================================================
73
+
74
+ /**
75
+ * Promotion criteria for TL1 (Verified AFK).
76
+ */
77
+ export type RalphTL1Policy = {
78
+ requiredConsecutiveRuns: number;
79
+ allowNetwork: false;
80
+ };
81
+
82
+ /**
83
+ * Promotion criteria for TL2 (Limited Network).
84
+ */
85
+ export type RalphTL2Policy = {
86
+ requiresHumanApproval: true;
87
+ /** Domains allowed for network access */
88
+ networkAllowlist: string[];
89
+ };
90
+
91
+ /**
92
+ * Promotion criteria for TL3 (Full AFK).
93
+ */
94
+ export type RalphTL3Policy = {
95
+ requiresExplicitPromotion: true;
96
+ /** Glob patterns for allowed repos */
97
+ allowedRepoPatterns: string[];
98
+ };
99
+
100
+ /**
101
+ * Complete trust policy configuration.
102
+ *
103
+ * Note: Policy logic lives in control repo, not here.
104
+ * This type defines vocabulary only.
105
+ */
106
+ export type RalphTrustPolicy = {
107
+ trustLevel1: RalphTL1Policy;
108
+ trustLevel2: RalphTL2Policy;
109
+ trustLevel3: RalphTL3Policy;
110
+ };
111
+
112
+ // =============================================================================
113
+ // Demotion Types
114
+ // =============================================================================
115
+
116
+ /**
117
+ * Reasons for automatic demotion to TL0.
118
+ */
119
+ export type RalphDemotionReason =
120
+ | 'ci_failed'
121
+ | 'guard_violation'
122
+ | 'manual_patch_required'
123
+ | 'scope_violation'
124
+ | 'network_abuse'
125
+ | 'prd_marked_complete_incorrectly';