@granular-software/sdk 0.4.41 → 0.4.43

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.
@@ -100,6 +100,55 @@ interface BuildGranularAgentSystemPromptInput {
100
100
  checkpoint?: GranularAgentExecutionCheckpoint | null;
101
101
  outputMode?: "agentMessages" | "returnValue";
102
102
  }
103
+ type HarnessTemplateStatus = "draft" | "candidate" | "release-candidate" | "stable" | "deprecated";
104
+ interface HarnessTemplateManifest {
105
+ id: string;
106
+ version: string;
107
+ status: HarnessTemplateStatus;
108
+ owner: string;
109
+ createdAt: string;
110
+ changelog: string;
111
+ promptBuilder: string;
112
+ continuationBuilder: string;
113
+ modelOutputInstruction: string;
114
+ codeReviewPolicy: string;
115
+ defaultModel: string;
116
+ modelMatrix: string[];
117
+ temperature: number;
118
+ compatibility: {
119
+ minSdkVersion: string;
120
+ capabilities: string[];
121
+ };
122
+ evalGates: {
123
+ requiredSuites: string[];
124
+ criticalBuckets: string[];
125
+ maxRegressionPct: number;
126
+ minPassK: Record<string, number>;
127
+ };
128
+ }
129
+ interface HarnessRenderedPrompt {
130
+ templateId: string;
131
+ templateVersion: string;
132
+ templateHash: string;
133
+ promptInstanceHash: string;
134
+ prompt: string;
135
+ }
136
+ interface HarnessRenderedContinuation {
137
+ templateId: string;
138
+ templateVersion: string;
139
+ templateHash: string;
140
+ instruction: string;
141
+ }
142
+ interface HarnessTemplate {
143
+ manifest: HarnessTemplateManifest;
144
+ renderPrompt: (input: BuildGranularAgentSystemPromptInput) => HarnessRenderedPrompt;
145
+ renderContinuation: (resultPreview?: string) => HarnessRenderedContinuation;
146
+ }
147
+ declare function validateHarnessTemplateManifest(value: unknown, context?: string): HarnessTemplateManifest;
148
+ interface HarnessTemplateSelectionOptions {
149
+ templateId?: string;
150
+ strict?: boolean;
151
+ }
103
152
  interface GeneratedJobCodeIssue {
104
153
  code: "commonjs_require" | "process_exit" | "dynamic_import_in_job" | "syntax_error_in_job" | "nested_template_literal_in_job" | "undefined_template_identifier" | "object_spread_in_job" | "runtime_import_contract" | "runtime_api_contract" | "missing_runtime_import" | "missing_loop_import" | "bare_loop_helper_import" | "loop_helper_contract" | "stdout_json_reply" | "return_chat_payload";
105
154
  severity: "error";
@@ -168,5 +217,15 @@ declare function buildGranularAgentWorkflowBlock(workflowSummary?: string): stri
168
217
  declare function buildGranularAgentToolBlock(tools?: GranularAgentToolInfo[], capabilityOverrides?: GranularAgentPromptCapabilities | null): string;
169
218
  declare function buildGranularAgentCheckpointBlock(checkpoint?: GranularAgentExecutionCheckpoint | null): string;
170
219
  declare function buildGranularAgentSystemPrompt(input: BuildGranularAgentSystemPromptInput): string;
220
+ declare function hashHarnessTemplateValue(value: unknown): string;
221
+ declare function listHarnessTemplates(): HarnessTemplateManifest[];
222
+ declare function resolveHarnessTemplate(templateId?: string, options?: {
223
+ strict?: boolean;
224
+ }): HarnessTemplate;
225
+ declare function getDefaultHarnessTemplateId(): string;
226
+ declare function renderGranularAgentSystemPromptFromTemplate(input: BuildGranularAgentSystemPromptInput, options?: HarnessTemplateSelectionOptions): HarnessRenderedPrompt;
227
+ declare function buildGranularAgentSystemPromptFromTemplate(input: BuildGranularAgentSystemPromptInput, options?: HarnessTemplateSelectionOptions): string;
228
+ declare function renderContinuationInstructionFromTemplate(resultPreview?: string, options?: HarnessTemplateSelectionOptions): HarnessRenderedContinuation;
229
+ declare function buildContinuationInstructionFromTemplate(resultPreview?: string, options?: HarnessTemplateSelectionOptions): string;
171
230
 
172
- export { type BuildGranularAgentSystemPromptInput, type GeneratedJobCodeIssue, type GranularAgentExecutionCheckpoint, type GranularAgentHeapSummaryOptions, type GranularAgentPromptCapabilities, type GranularAgentReferentFocus, type GranularAgentSessionContext, type GranularAgentToolInfo, type GranularAgentWorkflowFocus, type GranularReasoningTraceChunkResult, type GranularReasoningTraceOptions, type HarnessContinuationDecision, type HarnessControllerBudgets, type HarnessProjectionOptions, type HarnessPromptLike, type HarnessVerifierSnapshot, type HarnessVerifierSnapshotInput, type ReviewGeneratedJobCodeOptions, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentFileBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentReferentBlock, buildGranularAgentRuntimeImportsBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, consumeGranularReasoningOnlyChunk, consumeGranularReasoningTraceChunk, createHarnessVerifierSnapshot, evaluateContinuation, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, projectConversationReferentFocus, projectConversationReferentSummary, projectHeapSummary, projectLoopSummary, projectSessionFileSummary, projectWorkflowFocus, projectWorkflowSummary, reviewGeneratedJobCode, stripGranularReasoningTrace };
231
+ export { type BuildGranularAgentSystemPromptInput, type GeneratedJobCodeIssue, type GranularAgentExecutionCheckpoint, type GranularAgentHeapSummaryOptions, type GranularAgentPromptCapabilities, type GranularAgentReferentFocus, type GranularAgentSessionContext, type GranularAgentToolInfo, type GranularAgentWorkflowFocus, type GranularReasoningTraceChunkResult, type GranularReasoningTraceOptions, type HarnessContinuationDecision, type HarnessControllerBudgets, type HarnessProjectionOptions, type HarnessPromptLike, type HarnessRenderedContinuation, type HarnessRenderedPrompt, type HarnessTemplate, type HarnessTemplateManifest, type HarnessTemplateSelectionOptions, type HarnessTemplateStatus, type HarnessVerifierSnapshot, type HarnessVerifierSnapshotInput, type ReviewGeneratedJobCodeOptions, buildContinuationInstruction, buildContinuationInstructionFromTemplate, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentFileBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentReferentBlock, buildGranularAgentRuntimeImportsBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentSystemPromptFromTemplate, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, consumeGranularReasoningOnlyChunk, consumeGranularReasoningTraceChunk, createHarnessVerifierSnapshot, evaluateContinuation, getCurrentClosureId, getDefaultHarnessTemplateId, getExclusivePromptTarget, hasOpenPrompt, hashHarnessTemplateValue, listHarnessTemplates, projectConversationReferentFocus, projectConversationReferentSummary, projectHeapSummary, projectLoopSummary, projectSessionFileSummary, projectWorkflowFocus, projectWorkflowSummary, renderContinuationInstructionFromTemplate, renderGranularAgentSystemPromptFromTemplate, resolveHarnessTemplate, reviewGeneratedJobCode, stripGranularReasoningTrace, validateHarnessTemplateManifest };
@@ -100,6 +100,55 @@ interface BuildGranularAgentSystemPromptInput {
100
100
  checkpoint?: GranularAgentExecutionCheckpoint | null;
101
101
  outputMode?: "agentMessages" | "returnValue";
102
102
  }
103
+ type HarnessTemplateStatus = "draft" | "candidate" | "release-candidate" | "stable" | "deprecated";
104
+ interface HarnessTemplateManifest {
105
+ id: string;
106
+ version: string;
107
+ status: HarnessTemplateStatus;
108
+ owner: string;
109
+ createdAt: string;
110
+ changelog: string;
111
+ promptBuilder: string;
112
+ continuationBuilder: string;
113
+ modelOutputInstruction: string;
114
+ codeReviewPolicy: string;
115
+ defaultModel: string;
116
+ modelMatrix: string[];
117
+ temperature: number;
118
+ compatibility: {
119
+ minSdkVersion: string;
120
+ capabilities: string[];
121
+ };
122
+ evalGates: {
123
+ requiredSuites: string[];
124
+ criticalBuckets: string[];
125
+ maxRegressionPct: number;
126
+ minPassK: Record<string, number>;
127
+ };
128
+ }
129
+ interface HarnessRenderedPrompt {
130
+ templateId: string;
131
+ templateVersion: string;
132
+ templateHash: string;
133
+ promptInstanceHash: string;
134
+ prompt: string;
135
+ }
136
+ interface HarnessRenderedContinuation {
137
+ templateId: string;
138
+ templateVersion: string;
139
+ templateHash: string;
140
+ instruction: string;
141
+ }
142
+ interface HarnessTemplate {
143
+ manifest: HarnessTemplateManifest;
144
+ renderPrompt: (input: BuildGranularAgentSystemPromptInput) => HarnessRenderedPrompt;
145
+ renderContinuation: (resultPreview?: string) => HarnessRenderedContinuation;
146
+ }
147
+ declare function validateHarnessTemplateManifest(value: unknown, context?: string): HarnessTemplateManifest;
148
+ interface HarnessTemplateSelectionOptions {
149
+ templateId?: string;
150
+ strict?: boolean;
151
+ }
103
152
  interface GeneratedJobCodeIssue {
104
153
  code: "commonjs_require" | "process_exit" | "dynamic_import_in_job" | "syntax_error_in_job" | "nested_template_literal_in_job" | "undefined_template_identifier" | "object_spread_in_job" | "runtime_import_contract" | "runtime_api_contract" | "missing_runtime_import" | "missing_loop_import" | "bare_loop_helper_import" | "loop_helper_contract" | "stdout_json_reply" | "return_chat_payload";
105
154
  severity: "error";
@@ -168,5 +217,15 @@ declare function buildGranularAgentWorkflowBlock(workflowSummary?: string): stri
168
217
  declare function buildGranularAgentToolBlock(tools?: GranularAgentToolInfo[], capabilityOverrides?: GranularAgentPromptCapabilities | null): string;
169
218
  declare function buildGranularAgentCheckpointBlock(checkpoint?: GranularAgentExecutionCheckpoint | null): string;
170
219
  declare function buildGranularAgentSystemPrompt(input: BuildGranularAgentSystemPromptInput): string;
220
+ declare function hashHarnessTemplateValue(value: unknown): string;
221
+ declare function listHarnessTemplates(): HarnessTemplateManifest[];
222
+ declare function resolveHarnessTemplate(templateId?: string, options?: {
223
+ strict?: boolean;
224
+ }): HarnessTemplate;
225
+ declare function getDefaultHarnessTemplateId(): string;
226
+ declare function renderGranularAgentSystemPromptFromTemplate(input: BuildGranularAgentSystemPromptInput, options?: HarnessTemplateSelectionOptions): HarnessRenderedPrompt;
227
+ declare function buildGranularAgentSystemPromptFromTemplate(input: BuildGranularAgentSystemPromptInput, options?: HarnessTemplateSelectionOptions): string;
228
+ declare function renderContinuationInstructionFromTemplate(resultPreview?: string, options?: HarnessTemplateSelectionOptions): HarnessRenderedContinuation;
229
+ declare function buildContinuationInstructionFromTemplate(resultPreview?: string, options?: HarnessTemplateSelectionOptions): string;
171
230
 
172
- export { type BuildGranularAgentSystemPromptInput, type GeneratedJobCodeIssue, type GranularAgentExecutionCheckpoint, type GranularAgentHeapSummaryOptions, type GranularAgentPromptCapabilities, type GranularAgentReferentFocus, type GranularAgentSessionContext, type GranularAgentToolInfo, type GranularAgentWorkflowFocus, type GranularReasoningTraceChunkResult, type GranularReasoningTraceOptions, type HarnessContinuationDecision, type HarnessControllerBudgets, type HarnessProjectionOptions, type HarnessPromptLike, type HarnessVerifierSnapshot, type HarnessVerifierSnapshotInput, type ReviewGeneratedJobCodeOptions, buildContinuationInstruction, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentFileBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentReferentBlock, buildGranularAgentRuntimeImportsBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, consumeGranularReasoningOnlyChunk, consumeGranularReasoningTraceChunk, createHarnessVerifierSnapshot, evaluateContinuation, getCurrentClosureId, getExclusivePromptTarget, hasOpenPrompt, projectConversationReferentFocus, projectConversationReferentSummary, projectHeapSummary, projectLoopSummary, projectSessionFileSummary, projectWorkflowFocus, projectWorkflowSummary, reviewGeneratedJobCode, stripGranularReasoningTrace };
231
+ export { type BuildGranularAgentSystemPromptInput, type GeneratedJobCodeIssue, type GranularAgentExecutionCheckpoint, type GranularAgentHeapSummaryOptions, type GranularAgentPromptCapabilities, type GranularAgentReferentFocus, type GranularAgentSessionContext, type GranularAgentToolInfo, type GranularAgentWorkflowFocus, type GranularReasoningTraceChunkResult, type GranularReasoningTraceOptions, type HarnessContinuationDecision, type HarnessControllerBudgets, type HarnessProjectionOptions, type HarnessPromptLike, type HarnessRenderedContinuation, type HarnessRenderedPrompt, type HarnessTemplate, type HarnessTemplateManifest, type HarnessTemplateSelectionOptions, type HarnessTemplateStatus, type HarnessVerifierSnapshot, type HarnessVerifierSnapshotInput, type ReviewGeneratedJobCodeOptions, buildContinuationInstruction, buildContinuationInstructionFromTemplate, buildGranularAgentCheckpointBlock, buildGranularAgentDomainBlock, buildGranularAgentFileBlock, buildGranularAgentHeapBlock, buildGranularAgentLoopBlock, buildGranularAgentReferentBlock, buildGranularAgentRuntimeImportsBlock, buildGranularAgentSessionBlock, buildGranularAgentSystemPrompt, buildGranularAgentSystemPromptFromTemplate, buildGranularAgentToolBlock, buildGranularAgentWorkflowBlock, consumeGranularReasoningOnlyChunk, consumeGranularReasoningTraceChunk, createHarnessVerifierSnapshot, evaluateContinuation, getCurrentClosureId, getDefaultHarnessTemplateId, getExclusivePromptTarget, hasOpenPrompt, hashHarnessTemplateValue, listHarnessTemplates, projectConversationReferentFocus, projectConversationReferentSummary, projectHeapSummary, projectLoopSummary, projectSessionFileSummary, projectWorkflowFocus, projectWorkflowSummary, renderContinuationInstructionFromTemplate, renderGranularAgentSystemPromptFromTemplate, resolveHarnessTemplate, reviewGeneratedJobCode, stripGranularReasoningTrace, validateHarnessTemplateManifest };
@@ -1,6 +1,274 @@
1
1
  'use strict';
2
2
 
3
+ // src/agent-harness-templates/action-presentation/0.1.0/manifest.json
4
+ var manifest_default = {
5
+ id: "action-presentation",
6
+ version: "0.1.0",
7
+ status: "candidate",
8
+ owner: "granular",
9
+ createdAt: "2026-05-25T00:00:00.000Z",
10
+ changelog: "Candidate harness template focused on action-request detection and mutation result presentation. It exists to harden cases where the model answers with a terse completion such as Done instead of using tools and reporting the target/action/result.",
11
+ promptBuilder: "buildGranularAgentSystemPrompt:action-presentation",
12
+ continuationBuilder: "buildContinuationInstruction:action-presentation",
13
+ modelOutputInstruction: "agent-evals:modelOutputInstruction",
14
+ codeReviewPolicy: "reviewGeneratedJobCode",
15
+ defaultModel: "gpt-5.4",
16
+ modelMatrix: ["gpt-5.4"],
17
+ temperature: 0,
18
+ compatibility: {
19
+ minSdkVersion: "0.4.40",
20
+ capabilities: [
21
+ "executeCode",
22
+ "readEntities",
23
+ "workflowHelpers",
24
+ "savedData",
25
+ "showRecords"
26
+ ]
27
+ },
28
+ evalGates: {
29
+ requiredSuites: [
30
+ "agent-harness-hardening",
31
+ "agent-harness-runtime-e2e",
32
+ "agent-production-readiness-e2e"
33
+ ],
34
+ criticalBuckets: [
35
+ "relationship-traversal",
36
+ "cross-turn-reference",
37
+ "ambiguous-target-choice",
38
+ "confirmation-gated-mutation",
39
+ "denied-action-refusal",
40
+ "mutation-presentation"
41
+ ],
42
+ maxRegressionPct: 0,
43
+ minPassK: {
44
+ "critical-mutation": 0.9,
45
+ "permission-boundary": 1
46
+ }
47
+ }
48
+ };
49
+
50
+ // src/agent-harness-templates/experimental-compact/0.1.0/manifest.json
51
+ var manifest_default2 = {
52
+ id: "experimental-compact",
53
+ version: "0.1.0",
54
+ status: "candidate",
55
+ owner: "granular",
56
+ createdAt: "2026-05-24T00:00:00.000Z",
57
+ changelog: "Candidate harness template used for champion/challenger testing. It adds a compact decision discipline section on top of the stable renderer.",
58
+ promptBuilder: "buildGranularAgentSystemPrompt:experimental-compact",
59
+ continuationBuilder: "buildContinuationInstruction:experimental-compact",
60
+ modelOutputInstruction: "agent-evals:modelOutputInstruction",
61
+ codeReviewPolicy: "reviewGeneratedJobCode",
62
+ defaultModel: "gpt-5.4",
63
+ modelMatrix: ["gpt-5.4"],
64
+ temperature: 0,
65
+ compatibility: {
66
+ minSdkVersion: "0.4.40",
67
+ capabilities: [
68
+ "executeCode",
69
+ "readEntities",
70
+ "workflowHelpers",
71
+ "savedData",
72
+ "showRecords"
73
+ ]
74
+ },
75
+ evalGates: {
76
+ requiredSuites: [
77
+ "agent-harness-hardening",
78
+ "agent-harness-runtime-e2e",
79
+ "agent-production-readiness-e2e"
80
+ ],
81
+ criticalBuckets: [
82
+ "relationship-traversal",
83
+ "cross-turn-reference",
84
+ "ambiguous-target-choice",
85
+ "confirmation-gated-mutation",
86
+ "denied-action-refusal",
87
+ "mutation-presentation"
88
+ ],
89
+ maxRegressionPct: 0,
90
+ minPassK: {
91
+ "critical-mutation": 0.9,
92
+ "permission-boundary": 1
93
+ }
94
+ }
95
+ };
96
+
97
+ // src/agent-harness-templates/stable/1.0.0/manifest.json
98
+ var manifest_default3 = {
99
+ id: "stable",
100
+ version: "1.0.0",
101
+ status: "stable",
102
+ owner: "granular",
103
+ createdAt: "2026-05-24T00:00:00.000Z",
104
+ changelog: "Baseline template wrapping the existing Granular agent harness prompt, continuation instruction, output contract, and generated-job review policy.",
105
+ promptBuilder: "buildGranularAgentSystemPrompt",
106
+ continuationBuilder: "buildContinuationInstruction",
107
+ modelOutputInstruction: "agent-evals:modelOutputInstruction",
108
+ codeReviewPolicy: "reviewGeneratedJobCode",
109
+ defaultModel: "gpt-5.4",
110
+ modelMatrix: ["gpt-5.4"],
111
+ temperature: 0,
112
+ compatibility: {
113
+ minSdkVersion: "0.4.40",
114
+ capabilities: [
115
+ "executeCode",
116
+ "readEntities",
117
+ "workflowHelpers",
118
+ "savedData",
119
+ "showRecords"
120
+ ]
121
+ },
122
+ evalGates: {
123
+ requiredSuites: [
124
+ "agent-harness-hardening",
125
+ "agent-harness-runtime-e2e",
126
+ "agent-production-readiness-e2e"
127
+ ],
128
+ criticalBuckets: [
129
+ "relationship-traversal",
130
+ "cross-turn-reference",
131
+ "ambiguous-target-choice",
132
+ "confirmation-gated-mutation",
133
+ "denied-action-refusal",
134
+ "mutation-presentation"
135
+ ],
136
+ maxRegressionPct: 0,
137
+ minPassK: {
138
+ "critical-mutation": 0.9,
139
+ "permission-boundary": 1
140
+ }
141
+ }
142
+ };
143
+
3
144
  // src/agent-harness.ts
145
+ var HARNESS_TEMPLATE_STATUSES = [
146
+ "draft",
147
+ "candidate",
148
+ "release-candidate",
149
+ "stable",
150
+ "deprecated"
151
+ ];
152
+ function requireRecord(value, context) {
153
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
154
+ throw new Error(`${context} must be an object.`);
155
+ }
156
+ return value;
157
+ }
158
+ function requiredString(record, key, context) {
159
+ const value = record[key];
160
+ if (typeof value !== "string" || !value.trim()) {
161
+ throw new Error(`${context}.${key} must be a non-empty string.`);
162
+ }
163
+ return value;
164
+ }
165
+ function requiredNumber(record, key, context) {
166
+ const value = record[key];
167
+ if (typeof value !== "number" || !Number.isFinite(value)) {
168
+ throw new Error(`${context}.${key} must be a finite number.`);
169
+ }
170
+ return value;
171
+ }
172
+ function requiredStringArray(record, key, context) {
173
+ const value = record[key];
174
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !item.trim())) {
175
+ throw new Error(`${context}.${key} must be an array of non-empty strings.`);
176
+ }
177
+ return [...value];
178
+ }
179
+ function requiredNumberRecord(record, key, context) {
180
+ const value = requireRecord(record[key], `${context}.${key}`);
181
+ const output = {};
182
+ for (const [entryKey, entryValue] of Object.entries(value)) {
183
+ if (typeof entryValue !== "number" || !Number.isFinite(entryValue) || entryValue < 0 || entryValue > 1) {
184
+ throw new Error(
185
+ `${context}.${key}.${entryKey} must be a number between 0 and 1.`
186
+ );
187
+ }
188
+ output[entryKey] = entryValue;
189
+ }
190
+ return output;
191
+ }
192
+ function validateHarnessTemplateManifest(value, context = "HarnessTemplateManifest") {
193
+ const record = requireRecord(value, context);
194
+ const status = requiredString(record, "status", context);
195
+ if (!HARNESS_TEMPLATE_STATUSES.includes(status)) {
196
+ throw new Error(
197
+ `${context}.status must be one of ${HARNESS_TEMPLATE_STATUSES.join(", ")}.`
198
+ );
199
+ }
200
+ const createdAt = requiredString(record, "createdAt", context);
201
+ if (Number.isNaN(Date.parse(createdAt))) {
202
+ throw new Error(`${context}.createdAt must be an ISO timestamp.`);
203
+ }
204
+ const compatibility = requireRecord(
205
+ record.compatibility,
206
+ `${context}.compatibility`
207
+ );
208
+ const evalGates = requireRecord(record.evalGates, `${context}.evalGates`);
209
+ const maxRegressionPct = requiredNumber(
210
+ evalGates,
211
+ "maxRegressionPct",
212
+ `${context}.evalGates`
213
+ );
214
+ if (maxRegressionPct < 0 || maxRegressionPct > 1) {
215
+ throw new Error(
216
+ `${context}.evalGates.maxRegressionPct must be between 0 and 1.`
217
+ );
218
+ }
219
+ return {
220
+ id: requiredString(record, "id", context),
221
+ version: requiredString(record, "version", context),
222
+ status,
223
+ owner: requiredString(record, "owner", context),
224
+ createdAt,
225
+ changelog: requiredString(record, "changelog", context),
226
+ promptBuilder: requiredString(record, "promptBuilder", context),
227
+ continuationBuilder: requiredString(record, "continuationBuilder", context),
228
+ modelOutputInstruction: requiredString(
229
+ record,
230
+ "modelOutputInstruction",
231
+ context
232
+ ),
233
+ codeReviewPolicy: requiredString(record, "codeReviewPolicy", context),
234
+ defaultModel: requiredString(record, "defaultModel", context),
235
+ modelMatrix: requiredStringArray(record, "modelMatrix", context),
236
+ temperature: requiredNumber(record, "temperature", context),
237
+ compatibility: {
238
+ minSdkVersion: requiredString(
239
+ compatibility,
240
+ "minSdkVersion",
241
+ `${context}.compatibility`
242
+ ),
243
+ capabilities: requiredStringArray(
244
+ compatibility,
245
+ "capabilities",
246
+ `${context}.compatibility`
247
+ )
248
+ },
249
+ evalGates: {
250
+ requiredSuites: requiredStringArray(
251
+ evalGates,
252
+ "requiredSuites",
253
+ `${context}.evalGates`
254
+ ),
255
+ criticalBuckets: requiredStringArray(
256
+ evalGates,
257
+ "criticalBuckets",
258
+ `${context}.evalGates`
259
+ ),
260
+ maxRegressionPct,
261
+ minPassK: requiredNumberRecord(
262
+ evalGates,
263
+ "minPassK",
264
+ `${context}.evalGates`
265
+ )
266
+ }
267
+ };
268
+ }
269
+ function defineHarnessTemplateManifest(value, context) {
270
+ return validateHarnessTemplateManifest(value, context);
271
+ }
4
272
  var DEFAULT_IGNORED_REASONING_COMMENT_DIRECTIVES = [
5
273
  /^@ts-ignore\b/i,
6
274
  /^@ts-expect-error\b/i,
@@ -103,6 +371,16 @@ function uniqueStrings(values, maxCount) {
103
371
  }
104
372
  return output;
105
373
  }
374
+ function stableStringify(value) {
375
+ if (value === null || typeof value !== "object") {
376
+ return JSON.stringify(value);
377
+ }
378
+ if (Array.isArray(value)) {
379
+ return `[${value.map((entry) => stableStringify(entry)).join(",")}]`;
380
+ }
381
+ const record = value;
382
+ return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`).join(",")}}`;
383
+ }
106
384
  function renderConstBlock(name, value) {
107
385
  return `const ${name} = ${JSON.stringify(value, null, 2)} as const;`;
108
386
  }
@@ -2047,8 +2325,197 @@ ${knownFactsBlock}
2047
2325
  [Request]
2048
2326
  ${input.request?.trim() || "Use the latest user message in the conversation."}`;
2049
2327
  }
2328
+ var STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST = defineHarnessTemplateManifest(
2329
+ manifest_default3,
2330
+ "stable@1.0.0 manifest"
2331
+ );
2332
+ function hashHarnessTemplateValue(value) {
2333
+ return hashString(stableStringify(value)) || "00000000";
2334
+ }
2335
+ function renderStableHarnessPrompt(input) {
2336
+ const prompt = buildGranularAgentSystemPrompt(input);
2337
+ const templateHash = hashHarnessTemplateValue(
2338
+ STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST
2339
+ );
2340
+ return {
2341
+ templateId: STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST.id,
2342
+ templateVersion: STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST.version,
2343
+ templateHash,
2344
+ promptInstanceHash: hashHarnessTemplateValue({
2345
+ templateHash,
2346
+ input,
2347
+ prompt
2348
+ }),
2349
+ prompt
2350
+ };
2351
+ }
2352
+ function renderStableHarnessContinuation(resultPreview) {
2353
+ const instruction = buildContinuationInstruction(resultPreview);
2354
+ const templateHash = hashHarnessTemplateValue(
2355
+ STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST
2356
+ );
2357
+ return {
2358
+ templateId: STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST.id,
2359
+ templateVersion: STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST.version,
2360
+ templateHash,
2361
+ instruction
2362
+ };
2363
+ }
2364
+ var STABLE_AGENT_HARNESS_TEMPLATE = {
2365
+ manifest: STABLE_AGENT_HARNESS_TEMPLATE_MANIFEST,
2366
+ renderPrompt: renderStableHarnessPrompt,
2367
+ renderContinuation: renderStableHarnessContinuation
2368
+ };
2369
+ var EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST = defineHarnessTemplateManifest(
2370
+ manifest_default2,
2371
+ "experimental-compact@0.1.0 manifest"
2372
+ );
2373
+ function renderExperimentalCompactHarnessPrompt(input) {
2374
+ const prompt = `${buildGranularAgentSystemPrompt(input)}
2375
+
2376
+ [Candidate Harness Delta: Compact Decision Discipline]
2377
+ - Prefer the smallest action that satisfies the current request.
2378
+ - When several records could match, ask one structured choice question before mutating.
2379
+ - Before any irreversible or outbound mutation, obtain explicit confirmation unless the policy surface already requires it.
2380
+ - Do not compensate for missing tools with raw network calls, synthetic records, or hidden side channels.
2381
+ - Keep the final user-facing reply focused on what was done, what was not done, and any remaining blocker.`;
2382
+ const templateHash = hashHarnessTemplateValue(
2383
+ EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST
2384
+ );
2385
+ return {
2386
+ templateId: EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST.id,
2387
+ templateVersion: EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST.version,
2388
+ templateHash,
2389
+ promptInstanceHash: hashHarnessTemplateValue({
2390
+ templateHash,
2391
+ input,
2392
+ prompt
2393
+ }),
2394
+ prompt
2395
+ };
2396
+ }
2397
+ function renderExperimentalCompactHarnessContinuation(resultPreview) {
2398
+ const instruction = `${buildContinuationInstruction(resultPreview)}
2399
+
2400
+ Keep the continuation compact: either finish, ask the one blocking question, or run the next smallest safe action.`;
2401
+ const templateHash = hashHarnessTemplateValue(
2402
+ EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST
2403
+ );
2404
+ return {
2405
+ templateId: EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST.id,
2406
+ templateVersion: EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST.version,
2407
+ templateHash,
2408
+ instruction
2409
+ };
2410
+ }
2411
+ var EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE = {
2412
+ manifest: EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE_MANIFEST,
2413
+ renderPrompt: renderExperimentalCompactHarnessPrompt,
2414
+ renderContinuation: renderExperimentalCompactHarnessContinuation
2415
+ };
2416
+ var ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST = defineHarnessTemplateManifest(
2417
+ manifest_default,
2418
+ "action-presentation@0.1.0 manifest"
2419
+ );
2420
+ function renderActionPresentationHarnessPrompt(input) {
2421
+ const prompt = `${buildGranularAgentSystemPrompt(input)}
2422
+
2423
+ [Candidate Harness Delta: Action Request And Result Presentation]
2424
+ - Treat requests like "handle it", "take care of it", "send it", "update it", "fix it", "process it", or "do it" as action requests when the message names a business object, target, workflow, or mutation verb.
2425
+ - For action requests involving session data, generated files, records, effects, or workflows, do not use text-only completion. Generate and run code, ask the blocking human question, or clearly refuse if policy/tooling prevents the action.
2426
+ - Never answer only "Done", "OK", "Handled", or similar terse completion text for a mutation request. The final user-facing reply must name the action attempted, the grounded target or blocker, and the actual result.
2427
+ - After a mutation/effect call, base the reply on the returned action result and include a visible target label or identifier when one exists.
2428
+ - If no target can be grounded, say what was searched and what exact identifier or choice is needed; do not pretend the action completed.`;
2429
+ const templateHash = hashHarnessTemplateValue(
2430
+ ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST
2431
+ );
2432
+ return {
2433
+ templateId: ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST.id,
2434
+ templateVersion: ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST.version,
2435
+ templateHash,
2436
+ promptInstanceHash: hashHarnessTemplateValue({
2437
+ templateHash,
2438
+ input,
2439
+ prompt
2440
+ }),
2441
+ prompt
2442
+ };
2443
+ }
2444
+ function renderActionPresentationHarnessContinuation(resultPreview) {
2445
+ const instruction = `${buildContinuationInstruction(resultPreview)}
2446
+
2447
+ Before finishing, check whether the latest user request asked for an action. If it did, do not finish with a bare completion token; either continue with the needed tool/code step, ask the blocking question, refuse with the policy reason, or report the grounded action result with the target label.`;
2448
+ const templateHash = hashHarnessTemplateValue(
2449
+ ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST
2450
+ );
2451
+ return {
2452
+ templateId: ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST.id,
2453
+ templateVersion: ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST.version,
2454
+ templateHash,
2455
+ instruction
2456
+ };
2457
+ }
2458
+ var ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE = {
2459
+ manifest: ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE_MANIFEST,
2460
+ renderPrompt: renderActionPresentationHarnessPrompt,
2461
+ renderContinuation: renderActionPresentationHarnessContinuation
2462
+ };
2463
+ var AGENT_HARNESS_TEMPLATES = {
2464
+ [STABLE_AGENT_HARNESS_TEMPLATE.manifest.id]: STABLE_AGENT_HARNESS_TEMPLATE,
2465
+ [EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE.manifest.id]: EXPERIMENTAL_COMPACT_AGENT_HARNESS_TEMPLATE,
2466
+ [ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE.manifest.id]: ACTION_PRESENTATION_AGENT_HARNESS_TEMPLATE
2467
+ };
2468
+ function listHarnessTemplates() {
2469
+ return Object.values(AGENT_HARNESS_TEMPLATES).map((template) => ({
2470
+ ...template.manifest,
2471
+ compatibility: { ...template.manifest.compatibility },
2472
+ evalGates: {
2473
+ ...template.manifest.evalGates,
2474
+ minPassK: { ...template.manifest.evalGates.minPassK }
2475
+ }
2476
+ }));
2477
+ }
2478
+ function resolveHarnessTemplate(templateId = "stable", options) {
2479
+ const resolved = AGENT_HARNESS_TEMPLATES[templateId];
2480
+ if (resolved) return resolved;
2481
+ if (options?.strict) {
2482
+ const known = Object.keys(AGENT_HARNESS_TEMPLATES).join(", ");
2483
+ throw new Error(
2484
+ `Unknown harness template "${templateId}". Known templates: ${known}`
2485
+ );
2486
+ }
2487
+ return STABLE_AGENT_HARNESS_TEMPLATE;
2488
+ }
2489
+ function getDefaultHarnessTemplateId() {
2490
+ if (typeof process !== "undefined") {
2491
+ const configured = process.env.GRANULAR_AGENT_HARNESS_TEMPLATE || process.env.NEXT_PUBLIC_GRANULAR_AGENT_HARNESS_TEMPLATE;
2492
+ if (configured?.trim()) return configured.trim();
2493
+ }
2494
+ return "stable";
2495
+ }
2496
+ function renderGranularAgentSystemPromptFromTemplate(input, options) {
2497
+ const template = resolveHarnessTemplate(
2498
+ options?.templateId || getDefaultHarnessTemplateId(),
2499
+ { strict: options?.strict ?? true }
2500
+ );
2501
+ return template.renderPrompt(input);
2502
+ }
2503
+ function buildGranularAgentSystemPromptFromTemplate(input, options) {
2504
+ return renderGranularAgentSystemPromptFromTemplate(input, options).prompt;
2505
+ }
2506
+ function renderContinuationInstructionFromTemplate(resultPreview, options) {
2507
+ const template = resolveHarnessTemplate(
2508
+ options?.templateId || getDefaultHarnessTemplateId(),
2509
+ { strict: options?.strict ?? true }
2510
+ );
2511
+ return template.renderContinuation(resultPreview);
2512
+ }
2513
+ function buildContinuationInstructionFromTemplate(resultPreview, options) {
2514
+ return renderContinuationInstructionFromTemplate(resultPreview, options).instruction;
2515
+ }
2050
2516
 
2051
2517
  exports.buildContinuationInstruction = buildContinuationInstruction;
2518
+ exports.buildContinuationInstructionFromTemplate = buildContinuationInstructionFromTemplate;
2052
2519
  exports.buildGranularAgentCheckpointBlock = buildGranularAgentCheckpointBlock;
2053
2520
  exports.buildGranularAgentDomainBlock = buildGranularAgentDomainBlock;
2054
2521
  exports.buildGranularAgentFileBlock = buildGranularAgentFileBlock;
@@ -2058,6 +2525,7 @@ exports.buildGranularAgentReferentBlock = buildGranularAgentReferentBlock;
2058
2525
  exports.buildGranularAgentRuntimeImportsBlock = buildGranularAgentRuntimeImportsBlock;
2059
2526
  exports.buildGranularAgentSessionBlock = buildGranularAgentSessionBlock;
2060
2527
  exports.buildGranularAgentSystemPrompt = buildGranularAgentSystemPrompt;
2528
+ exports.buildGranularAgentSystemPromptFromTemplate = buildGranularAgentSystemPromptFromTemplate;
2061
2529
  exports.buildGranularAgentToolBlock = buildGranularAgentToolBlock;
2062
2530
  exports.buildGranularAgentWorkflowBlock = buildGranularAgentWorkflowBlock;
2063
2531
  exports.consumeGranularReasoningOnlyChunk = consumeGranularReasoningOnlyChunk;
@@ -2065,8 +2533,11 @@ exports.consumeGranularReasoningTraceChunk = consumeGranularReasoningTraceChunk;
2065
2533
  exports.createHarnessVerifierSnapshot = createHarnessVerifierSnapshot;
2066
2534
  exports.evaluateContinuation = evaluateContinuation;
2067
2535
  exports.getCurrentClosureId = getCurrentClosureId;
2536
+ exports.getDefaultHarnessTemplateId = getDefaultHarnessTemplateId;
2068
2537
  exports.getExclusivePromptTarget = getExclusivePromptTarget;
2069
2538
  exports.hasOpenPrompt = hasOpenPrompt;
2539
+ exports.hashHarnessTemplateValue = hashHarnessTemplateValue;
2540
+ exports.listHarnessTemplates = listHarnessTemplates;
2070
2541
  exports.projectConversationReferentFocus = projectConversationReferentFocus;
2071
2542
  exports.projectConversationReferentSummary = projectConversationReferentSummary;
2072
2543
  exports.projectHeapSummary = projectHeapSummary;
@@ -2074,7 +2545,11 @@ exports.projectLoopSummary = projectLoopSummary;
2074
2545
  exports.projectSessionFileSummary = projectSessionFileSummary;
2075
2546
  exports.projectWorkflowFocus = projectWorkflowFocus;
2076
2547
  exports.projectWorkflowSummary = projectWorkflowSummary;
2548
+ exports.renderContinuationInstructionFromTemplate = renderContinuationInstructionFromTemplate;
2549
+ exports.renderGranularAgentSystemPromptFromTemplate = renderGranularAgentSystemPromptFromTemplate;
2550
+ exports.resolveHarnessTemplate = resolveHarnessTemplate;
2077
2551
  exports.reviewGeneratedJobCode = reviewGeneratedJobCode;
2078
2552
  exports.stripGranularReasoningTrace = stripGranularReasoningTrace;
2553
+ exports.validateHarnessTemplateManifest = validateHarnessTemplateManifest;
2079
2554
  //# sourceMappingURL=agent-harness.js.map
2080
2555
  //# sourceMappingURL=agent-harness.js.map