@lucern/events 0.3.0-alpha.0 → 0.3.0-alpha.1

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/dist/webhooks.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { v } from 'convex/values';
2
3
 
3
4
  // ../contracts/src/events.contract.ts
4
5
  var WEBHOOK_MAX_ATTEMPTS = 5;
@@ -404,6 +405,28 @@ defineTable({
404
405
  { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
405
406
  ]
406
407
  });
408
+ defineTable({
409
+ name: "neo4jSyncQueue",
410
+ component: "kernel",
411
+ category: "infra",
412
+ shape: z.object({
413
+ "entityType": z.enum(["node", "edge"]),
414
+ "entityId": z.string(),
415
+ "operation": z.enum(["upsert", "delete"]),
416
+ "attempts": z.number(),
417
+ "maxAttempts": z.number(),
418
+ "lastAttemptAt": z.number().optional(),
419
+ "lastError": z.string().optional(),
420
+ "status": z.enum(["pending", "in_progress", "failed", "succeeded"]),
421
+ "createdAt": z.number(),
422
+ "updatedAt": z.number()
423
+ }),
424
+ indices: [
425
+ { kind: "index", name: "by_status", columns: ["status"] },
426
+ { kind: "index", name: "by_entity", columns: ["entityType", "entityId"] },
427
+ { kind: "index", name: "by_status_attempts", columns: ["status", "attempts"] }
428
+ ]
429
+ });
407
430
  defineTable({
408
431
  name: "backgroundJobRuns",
409
432
  component: "kernel",
@@ -473,9 +496,9 @@ defineTable({
473
496
  category: "epistemic",
474
497
  shape: z.object({
475
498
  "beliefId": z.string(),
476
- "belief": z.number().optional(),
477
- "disbelief": z.number().optional(),
478
- "uncertainty": z.number().optional(),
499
+ "belief": z.number(),
500
+ "disbelief": z.number(),
501
+ "uncertainty": z.number(),
479
502
  "baseRate": z.number(),
480
503
  "slOperator": z.string().optional(),
481
504
  "confidence": z.number(),
@@ -484,10 +507,12 @@ defineTable({
484
507
  "certainty": z.number().optional(),
485
508
  "assessedAt": z.number(),
486
509
  "assessedBy": z.string(),
487
- "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "manual", "decay", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
510
+ "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
488
511
  "rationale": z.string().optional(),
489
512
  "triggeringEvidenceId": z.string().optional(),
490
513
  "triggeringEvidenceIds": z.array(z.string()).optional(),
514
+ "triggeringQuestionId": z.string().optional(),
515
+ "triggeringAnswerId": z.string().optional(),
491
516
  "triggeringContradictionId": idOf("contradictions").optional(),
492
517
  "triggeringWorktreeId": z.string().optional(),
493
518
  "triggeringAgentId": z.string().optional(),
@@ -1170,7 +1195,7 @@ defineTable({
1170
1195
  "credentialRef": z.string(),
1171
1196
  "tenantId": idOf("tenants"),
1172
1197
  "target": z.enum(["kernelDeployment", "appDeployment"]),
1173
- "environment": z.enum(["dev", "prod"]),
1198
+ "environment": z.enum(["dev", "staging", "prod"]),
1174
1199
  "encryptedDeployKey": z.string(),
1175
1200
  "encryptionVersion": z.string(),
1176
1201
  "keyFingerprint": z.string(),
@@ -3839,13 +3864,13 @@ defineTable({
3839
3864
  "rationale": z.string().optional(),
3840
3865
  "confidenceImpact": z.enum(["high", "medium", "low"]).optional(),
3841
3866
  "hypothesis": z.string().optional(),
3842
- "executionOrder": z.number().optional(),
3843
3867
  "dependsOn": z.array(idOf("worktrees")).optional(),
3844
3868
  "blocks": z.array(idOf("worktrees")).optional(),
3845
3869
  "gate": z.string().optional(),
3846
- "track": z.string().optional(),
3847
- "trackPosition": z.number().optional(),
3848
- "executionBand": z.number().optional(),
3870
+ "campaign": z.number().optional(),
3871
+ "lane": z.string().optional(),
3872
+ "laneOrderInCampaign": z.number().optional(),
3873
+ "orderInLane": z.number().optional(),
3849
3874
  "startDate": z.number(),
3850
3875
  "endDate": z.number(),
3851
3876
  "durationWeeks": z.number(),
@@ -4093,10 +4118,469 @@ defineTable({
4093
4118
  { kind: "index", name: "by_topicId_index", columns: ["topicId", "index"] },
4094
4119
  { kind: "index", name: "by_worktreeType", columns: ["topicId", "worktreeType"] },
4095
4120
  { kind: "index", name: "by_topicId_priority", columns: ["topicId", "priority"] },
4121
+ { kind: "index", name: "by_topicId_campaign_lane_order", columns: ["topicId", "campaign", "laneOrderInCampaign", "orderInLane"] },
4122
+ { kind: "index", name: "by_topicId_lane_order", columns: ["topicId", "lane", "orderInLane"] },
4096
4123
  { kind: "index", name: "by_topicId_branch", columns: ["topicId", "targetBranch"] },
4097
4124
  { kind: "index", name: "by_topicId_scope", columns: ["topicId", "worktreeScope"] }
4098
4125
  ]
4099
4126
  });
4127
+ z.object({
4128
+ manifestVersion: z.string(),
4129
+ componentName: z.enum(["kernel", "identity"]),
4130
+ tier: z.enum(["K", "I"]),
4131
+ packageVersion: z.string(),
4132
+ tables: z.array(
4133
+ z.object({
4134
+ name: z.string(),
4135
+ fields: z.array(
4136
+ z.object({
4137
+ name: z.string(),
4138
+ type: z.string(),
4139
+ optional: z.boolean(),
4140
+ validator: z.string().optional()
4141
+ })
4142
+ )
4143
+ })
4144
+ )
4145
+ });
4146
+ var SL_EPSILON = 1e-9;
4147
+ z.object({
4148
+ belief: z.number(),
4149
+ disbelief: z.number(),
4150
+ uncertainty: z.number(),
4151
+ baseRate: z.number()
4152
+ }).refine(
4153
+ (o) => Math.abs(o.belief + o.disbelief + o.uncertainty - 1) < SL_EPSILON,
4154
+ {
4155
+ message: "SL invariant b+d+u=1 violated at API boundary"
4156
+ }
4157
+ );
4158
+ var EpistemicNodeTypeSchema = z.enum([
4159
+ "belief",
4160
+ "evidence",
4161
+ "question",
4162
+ "answer",
4163
+ "topic",
4164
+ "edge",
4165
+ "ontology",
4166
+ "lens",
4167
+ "contradiction"
4168
+ ]);
4169
+ var GraphRefSchema = z.discriminatedUnion("kind", [
4170
+ z.object({
4171
+ kind: z.literal("epistemic_node"),
4172
+ nodeId: z.string(),
4173
+ nodeType: EpistemicNodeTypeSchema
4174
+ }),
4175
+ z.object({
4176
+ kind: z.literal("external_belief"),
4177
+ ref: z.object({
4178
+ tenantId: z.string(),
4179
+ beliefId: z.string()
4180
+ })
4181
+ })
4182
+ ]);
4183
+ var graphRefKind = z.enum(["epistemic_node", "external_belief"]);
4184
+ var EdgePolicyEntrySchema = z.object({
4185
+ edgeType: z.string(),
4186
+ fromKinds: z.array(graphRefKind),
4187
+ fromNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4188
+ toKinds: z.array(graphRefKind),
4189
+ toNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4190
+ description: z.string()
4191
+ });
4192
+ z.object({
4193
+ manifestVersion: z.literal("1.0.0"),
4194
+ policies: z.array(EdgePolicyEntrySchema)
4195
+ });
4196
+ function findEdgePolicy(manifest, edgeType) {
4197
+ return manifest.policies.find((policy) => policy.edgeType === edgeType);
4198
+ }
4199
+ function nodeTypeAllowed(allowed, ref) {
4200
+ return ref.kind !== "epistemic_node" || !allowed || allowed.includes(ref.nodeType);
4201
+ }
4202
+ function assertEdgePolicyAllowed(manifest, edgeType, from, to) {
4203
+ const policy = findEdgePolicy(manifest, edgeType);
4204
+ const allowed = Boolean(policy) && policy.fromKinds.includes(from.kind) && policy.toKinds.includes(to.kind) && nodeTypeAllowed(policy.fromNodeTypes, from) && nodeTypeAllowed(policy.toNodeTypes, to);
4205
+ if (!allowed) {
4206
+ const error = new Error(
4207
+ `Edge policy violation for ${edgeType}: ${from.kind} -> ${to.kind}`
4208
+ );
4209
+ error.code = "POLICY_VIOLATION";
4210
+ error.details = { code: "POLICY_VIOLATION", edgeType, from, to };
4211
+ throw error;
4212
+ }
4213
+ }
4214
+
4215
+ // ../contracts/src/manifests/edge-policy-manifest.data.ts
4216
+ var edgePolicyManifest = {
4217
+ policies: [
4218
+ {
4219
+ edgeType: "evidence_derived_from_evidence",
4220
+ fromKinds: ["epistemic_node"],
4221
+ fromNodeTypes: ["evidence"],
4222
+ toKinds: ["epistemic_node"],
4223
+ toNodeTypes: ["evidence"],
4224
+ description: "Evidence E2 was synthesized from evidence E1 by a transformation. Provides chain-of-evidence lineage."
4225
+ },
4226
+ {
4227
+ edgeType: "evidence_supports_belief",
4228
+ fromKinds: ["epistemic_node"],
4229
+ fromNodeTypes: ["evidence"],
4230
+ toKinds: ["epistemic_node"],
4231
+ toNodeTypes: ["belief"],
4232
+ description: "Existing link_evidence_to_belief semantics promoted to the create_edge policy source."
4233
+ },
4234
+ {
4235
+ edgeType: "evidence_supports_question",
4236
+ fromKinds: ["epistemic_node"],
4237
+ fromNodeTypes: ["evidence"],
4238
+ toKinds: ["epistemic_node"],
4239
+ toNodeTypes: ["question"],
4240
+ description: "Existing link_evidence_to_question semantics promoted to the create_edge policy source."
4241
+ }
4242
+ ]
4243
+ };
4244
+ z.object({
4245
+ manifestVersion: z.literal("1.0.0"),
4246
+ rules: z.array(
4247
+ z.object({
4248
+ invariant: z.string(),
4249
+ description: z.string(),
4250
+ checker: z.enum(["ast", "manifest", "runtime"]),
4251
+ severity: z.enum(["block_publish", "block_pr", "warn"])
4252
+ })
4253
+ )
4254
+ });
4255
+
4256
+ // ../contracts/src/projections/projection-dsl.ts
4257
+ function defineProjection(def) {
4258
+ return def;
4259
+ }
4260
+
4261
+ // ../contracts/src/projections/create-evidence.projection.ts
4262
+ var jsonRecordSchema = z.record(z.unknown());
4263
+ var createEvidenceInputSchemaBase = z.object({
4264
+ projectId: z.string().optional(),
4265
+ topicId: z.string().optional(),
4266
+ text: z.string().optional(),
4267
+ canonicalText: z.string().optional(),
4268
+ title: z.string().optional(),
4269
+ content: z.string().optional(),
4270
+ contentType: z.string().optional(),
4271
+ kind: z.string().optional(),
4272
+ tags: z.array(z.string()).optional(),
4273
+ source: z.string().optional(),
4274
+ sourceUrl: z.string().optional(),
4275
+ sourceType: z.string().optional(),
4276
+ externalSourceType: z.string().optional(),
4277
+ sourceQuestionId: z.string().optional(),
4278
+ methodology: z.string().optional(),
4279
+ informationAsymmetry: z.string().optional(),
4280
+ sourceDescription: z.string().optional(),
4281
+ targetId: z.string().optional(),
4282
+ targetNodeId: z.string().optional(),
4283
+ linkedBeliefNodeId: z.string().optional(),
4284
+ evidenceRelation: z.enum(["supports", "contradicts", "neutral"]).optional(),
4285
+ confidence: z.number().optional(),
4286
+ weight: z.number().optional(),
4287
+ reasoning: z.string().optional(),
4288
+ rationale: z.string(),
4289
+ metadata: jsonRecordSchema.optional(),
4290
+ trustedBypassAccessCheck: z.boolean().optional()
4291
+ }).passthrough();
4292
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
4293
+ (input) => Boolean(input.text ?? input.canonicalText),
4294
+ {
4295
+ message: "create_evidence requires text",
4296
+ path: ["text"]
4297
+ }
4298
+ );
4299
+ function compactRecord(input) {
4300
+ return Object.fromEntries(
4301
+ Object.entries(input).filter(([, value]) => value !== void 0)
4302
+ );
4303
+ }
4304
+ function recordValue(value) {
4305
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4306
+ }
4307
+ var createEvidenceProjection = defineProjection({
4308
+ contractName: "create_evidence",
4309
+ inputSchema: createEvidenceInputSchema,
4310
+ project: (input) => {
4311
+ const text = input.text ?? input.canonicalText;
4312
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
4313
+ return compactRecord({
4314
+ projectId: input.projectId,
4315
+ topicId: input.topicId,
4316
+ text,
4317
+ title: input.title ?? text,
4318
+ content: input.content ?? text,
4319
+ contentType: input.contentType,
4320
+ kind: input.kind,
4321
+ tags: input.tags,
4322
+ sourceType: input.sourceType,
4323
+ externalSourceType: input.externalSourceType,
4324
+ sourceUrl: input.sourceUrl ?? input.source,
4325
+ sourceQuestionId: input.sourceQuestionId,
4326
+ methodology: input.methodology,
4327
+ informationAsymmetry: input.informationAsymmetry,
4328
+ sourceDescription: input.sourceDescription,
4329
+ metadata: compactRecord({
4330
+ ...recordValue(input.metadata),
4331
+ source: input.source,
4332
+ targetId: input.targetId,
4333
+ targetNodeId: input.targetNodeId,
4334
+ weight,
4335
+ reasoning: input.reasoning,
4336
+ rationale: input.rationale
4337
+ }),
4338
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
4339
+ evidenceRelation: input.evidenceRelation ?? (weight === void 0 ? void 0 : weight < 0 ? "contradicts" : "supports"),
4340
+ confidence: input.confidence ?? (weight === void 0 ? void 0 : Math.min(1, Math.max(0, Math.abs(weight)))),
4341
+ rationale: input.rationale,
4342
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4343
+ });
4344
+ },
4345
+ convexArgsValidator: v.object({
4346
+ projectId: v.optional(v.string()),
4347
+ topicId: v.optional(v.string()),
4348
+ text: v.string(),
4349
+ title: v.optional(v.string()),
4350
+ content: v.optional(v.string()),
4351
+ contentType: v.optional(v.string()),
4352
+ kind: v.optional(v.string()),
4353
+ tags: v.optional(v.array(v.string())),
4354
+ sourceType: v.optional(v.string()),
4355
+ externalSourceType: v.optional(v.string()),
4356
+ sourceUrl: v.optional(v.string()),
4357
+ sourceQuestionId: v.optional(v.string()),
4358
+ methodology: v.optional(v.string()),
4359
+ informationAsymmetry: v.optional(v.string()),
4360
+ sourceDescription: v.optional(v.string()),
4361
+ metadata: v.optional(v.record(v.string(), v.any())),
4362
+ linkedBeliefNodeId: v.optional(v.string()),
4363
+ evidenceRelation: v.optional(
4364
+ v.union(
4365
+ v.literal("supports"),
4366
+ v.literal("contradicts"),
4367
+ v.literal("neutral")
4368
+ )
4369
+ ),
4370
+ confidence: v.optional(v.number()),
4371
+ rationale: v.string(),
4372
+ trustedBypassAccessCheck: v.optional(v.boolean())
4373
+ })
4374
+ });
4375
+ var beliefStatusSchema = z.enum(["active", "superseded", "archived", "unscored", "scored"]).optional().describe("Filter by belief lifecycle or scoring status");
4376
+ var listBeliefsInputSchema = z.object({
4377
+ topicId: z.string().describe("Topic scope"),
4378
+ worktreeId: z.string().optional().describe("Filter to worktree scope"),
4379
+ status: beliefStatusSchema,
4380
+ minConfidence: z.number().optional().describe("Minimum confidence threshold"),
4381
+ limit: z.number().optional().describe("Maximum results"),
4382
+ includeEdgeAssociated: z.boolean().optional().describe("Include beliefs associated to the topic through edges")
4383
+ });
4384
+ function kernelStatus(status) {
4385
+ return status === "active" || status === "superseded" || status === "archived" ? status : void 0;
4386
+ }
4387
+ function compactRecord2(input) {
4388
+ return Object.fromEntries(
4389
+ Object.entries(input).filter(([, value]) => value !== void 0)
4390
+ );
4391
+ }
4392
+ var listBeliefsProjection = defineProjection({
4393
+ contractName: "list_beliefs",
4394
+ inputSchema: listBeliefsInputSchema,
4395
+ project: (input) => compactRecord2({
4396
+ topicId: input.topicId,
4397
+ status: kernelStatus(input.status),
4398
+ limit: input.limit,
4399
+ includeEdgeAssociated: input.includeEdgeAssociated
4400
+ }),
4401
+ convexArgsValidator: v.object({
4402
+ topicId: v.string(),
4403
+ status: v.optional(
4404
+ v.union(
4405
+ v.literal("active"),
4406
+ v.literal("superseded"),
4407
+ v.literal("archived")
4408
+ )
4409
+ ),
4410
+ limit: v.optional(v.number()),
4411
+ includeEdgeAssociated: v.optional(v.boolean())
4412
+ })
4413
+ });
4414
+ var taskStatusSchema = z.enum(["todo", "in_progress", "blocked", "done"]).optional().describe("Filter by task status");
4415
+ var listTasksInputSchema = z.object({
4416
+ topicId: z.string().describe("Topic scope"),
4417
+ worktreeId: z.string().optional().describe("Alias for linkedWorktreeId"),
4418
+ linkedWorktreeId: z.string().optional().describe("Filter to tasks linked to this worktree"),
4419
+ status: taskStatusSchema,
4420
+ limit: z.number().optional().describe("Maximum results")
4421
+ });
4422
+ function compactRecord3(input) {
4423
+ return Object.fromEntries(
4424
+ Object.entries(input).filter(([, value]) => value !== void 0)
4425
+ );
4426
+ }
4427
+ var listTasksProjection = defineProjection({
4428
+ contractName: "list_tasks",
4429
+ inputSchema: listTasksInputSchema,
4430
+ project: (input) => compactRecord3({
4431
+ topicId: input.topicId,
4432
+ status: input.status,
4433
+ userId: void 0,
4434
+ limit: input.limit,
4435
+ linkedWorktreeId: input.linkedWorktreeId ?? input.worktreeId
4436
+ }),
4437
+ convexArgsValidator: v.object({
4438
+ topicId: v.string(),
4439
+ status: v.optional(
4440
+ v.union(
4441
+ v.literal("todo"),
4442
+ v.literal("in_progress"),
4443
+ v.literal("blocked"),
4444
+ v.literal("done")
4445
+ )
4446
+ ),
4447
+ limit: v.optional(v.number()),
4448
+ linkedWorktreeId: v.optional(v.string())
4449
+ })
4450
+ });
4451
+ var confidenceTriggerSchema = z.enum([
4452
+ "evidence_added",
4453
+ "evidence_removed",
4454
+ "contradiction_resolved",
4455
+ "agent_assessment",
4456
+ "worktree_outcome",
4457
+ "worktree_completed",
4458
+ "contradiction_detected",
4459
+ "answer_recorded",
4460
+ "fusion",
4461
+ "discount",
4462
+ "deduction",
4463
+ "backfill_synthetic"
4464
+ ]);
4465
+ var provenanceSchema = z.object({
4466
+ evidence: z.string().optional(),
4467
+ question: z.string().optional(),
4468
+ answer: z.string().optional(),
4469
+ contradiction: z.string().optional(),
4470
+ worktree: z.string().optional()
4471
+ });
4472
+ var slOpinionProjectionSchema = z.object({
4473
+ belief: z.number(),
4474
+ disbelief: z.number(),
4475
+ uncertainty: z.number(),
4476
+ baseRate: z.number()
4477
+ });
4478
+ var modulateConfidenceInputObjectSchema = z.object({
4479
+ nodeId: z.string().optional(),
4480
+ beliefNodeId: z.string().optional(),
4481
+ worktreeId: z.string().optional(),
4482
+ opinion: slOpinionProjectionSchema.optional(),
4483
+ belief: z.number().optional(),
4484
+ disbelief: z.number().optional(),
4485
+ uncertainty: z.number().optional(),
4486
+ baseRate: z.number().optional(),
4487
+ trigger: confidenceTriggerSchema,
4488
+ provenance: provenanceSchema.optional(),
4489
+ triggeringEvidenceId: z.string().optional(),
4490
+ triggeringQuestionId: z.string().optional(),
4491
+ triggeringAnswerId: z.string().optional(),
4492
+ triggeringContradictionId: z.string().optional(),
4493
+ triggeringWorktreeId: z.string().optional(),
4494
+ rationale: z.string(),
4495
+ trustedBypassAccessCheck: z.boolean().optional()
4496
+ });
4497
+ var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
4498
+ if (hasProvenance(input)) {
4499
+ return;
4500
+ }
4501
+ ctx.addIssue({
4502
+ code: z.ZodIssueCode.custom,
4503
+ message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
4504
+ path: ["provenance"]
4505
+ });
4506
+ });
4507
+ var modulateConfidenceProjection = defineProjection({
4508
+ contractName: "modulate_confidence",
4509
+ inputSchema: modulateConfidenceInputSchema,
4510
+ project: (input) => {
4511
+ const nodeId = input.beliefNodeId ?? input.nodeId;
4512
+ if (!nodeId) {
4513
+ throw new Error("modulate_confidence requires beliefNodeId or nodeId");
4514
+ }
4515
+ const opinion = input.opinion ?? {
4516
+ belief: requireNumber(input.belief, "belief"),
4517
+ disbelief: requireNumber(input.disbelief, "disbelief"),
4518
+ uncertainty: requireNumber(input.uncertainty, "uncertainty"),
4519
+ baseRate: requireNumber(input.baseRate, "baseRate")
4520
+ };
4521
+ assertProvenance(input);
4522
+ return {
4523
+ nodeId,
4524
+ worktreeId: input.worktreeId,
4525
+ belief: opinion.belief,
4526
+ disbelief: opinion.disbelief,
4527
+ uncertainty: opinion.uncertainty,
4528
+ baseRate: opinion.baseRate,
4529
+ trigger: input.trigger === "answer_recorded" ? "agent_assessment" : input.trigger,
4530
+ triggeringEvidenceId: input.provenance?.evidence ?? input.triggeringEvidenceId,
4531
+ triggeringQuestionId: input.provenance?.question ?? input.triggeringQuestionId,
4532
+ triggeringAnswerId: input.provenance?.answer ?? input.triggeringAnswerId,
4533
+ triggeringContradictionId: input.provenance?.contradiction ?? input.triggeringContradictionId,
4534
+ triggeringWorktreeId: input.provenance?.worktree ?? input.triggeringWorktreeId,
4535
+ rationale: input.rationale,
4536
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4537
+ };
4538
+ },
4539
+ convexArgsValidator: v.object({
4540
+ nodeId: v.string(),
4541
+ worktreeId: v.optional(v.string()),
4542
+ belief: v.number(),
4543
+ disbelief: v.number(),
4544
+ uncertainty: v.number(),
4545
+ baseRate: v.number(),
4546
+ trigger: v.union(
4547
+ v.literal("evidence_added"),
4548
+ v.literal("evidence_removed"),
4549
+ v.literal("worktree_completed"),
4550
+ v.literal("contradiction_detected"),
4551
+ v.literal("contradiction_resolved"),
4552
+ v.literal("agent_assessment"),
4553
+ v.literal("worktree_outcome"),
4554
+ v.literal("fusion"),
4555
+ v.literal("discount"),
4556
+ v.literal("deduction"),
4557
+ v.literal("backfill_synthetic")
4558
+ ),
4559
+ triggeringEvidenceId: v.optional(v.string()),
4560
+ triggeringQuestionId: v.optional(v.string()),
4561
+ triggeringAnswerId: v.optional(v.string()),
4562
+ triggeringContradictionId: v.optional(v.string()),
4563
+ triggeringWorktreeId: v.optional(v.string()),
4564
+ rationale: v.string(),
4565
+ trustedBypassAccessCheck: v.optional(v.boolean())
4566
+ })
4567
+ });
4568
+ function requireNumber(value, field) {
4569
+ if (value === void 0) {
4570
+ throw new Error(`modulate_confidence requires ${field}`);
4571
+ }
4572
+ return value;
4573
+ }
4574
+ function assertProvenance(input) {
4575
+ if (!hasProvenance(input)) {
4576
+ throw new Error(
4577
+ "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
4578
+ );
4579
+ }
4580
+ }
4581
+ function hasProvenance(input) {
4582
+ return input.trigger === "backfill_synthetic" || Boolean(input.provenance && Object.values(input.provenance).some(Boolean)) || Boolean(input.triggeringEvidenceId) || Boolean(input.triggeringQuestionId) || Boolean(input.triggeringAnswerId) || Boolean(input.triggeringContradictionId) || Boolean(input.triggeringWorktreeId);
4583
+ }
4100
4584
 
4101
4585
  // ../contracts/src/lens-workflow.contract.ts
4102
4586
  var LENS_PERSPECTIVE_TYPES = [
@@ -4110,7 +4594,7 @@ var LENS_PERSPECTIVE_TYPES = [
4110
4594
  // ../contracts/src/tool-contracts.ts
4111
4595
  var CREATE_BELIEF = {
4112
4596
  name: "create_belief",
4113
- description: "Commit a new belief (knowledge unit) to the reasoning graph. Like `git commit` \u2014 creates an atomic, traceable knowledge object with a mandatory prior. Creation stores the vacuous opinion `(0, 0, 1, a)`; use modulate_confidence to record the first evidential update.",
4597
+ description: "Commit a new belief (knowledge unit) to the reasoning graph. Like `git commit` \u2014 creates an atomic, traceable knowledge object with a prior. Creation stores the vacuous opinion `(0, 0, 1, a)`; use modulate_confidence to record the first evidential update.",
4114
4598
  parameters: {
4115
4599
  canonicalText: {
4116
4600
  type: "string",
@@ -4122,7 +4606,7 @@ var CREATE_BELIEF = {
4122
4606
  },
4123
4607
  baseRate: {
4124
4608
  type: "number",
4125
- description: "Required prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time."
4609
+ description: "Prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time. Defaults to 0.5 when omitted."
4126
4610
  },
4127
4611
  beliefType: {
4128
4612
  type: "string",
@@ -4133,7 +4617,7 @@ var CREATE_BELIEF = {
4133
4617
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
4134
4618
  }
4135
4619
  },
4136
- required: ["canonicalText", "baseRate"],
4620
+ required: ["canonicalText"],
4137
4621
  response: {
4138
4622
  description: "The created canonical belief record",
4139
4623
  fields: {
@@ -4196,7 +4680,7 @@ var REFINE_BELIEF = {
4196
4680
  };
4197
4681
  var MODULATE_CONFIDENCE = {
4198
4682
  name: "modulate_confidence",
4199
- description: "Record a confidence change for a belief. Like `git commit` to the credence log \u2014 an atomic, append-only write. Each modulation is a new entry in the history, not an overwrite. Scoring happens via merge; this tool records the individual data points. Pass the full subjective-logic tuple (`belief`, `disbelief`, `uncertainty`, `baseRate`) directly. If a caller only has a scalar probability, use `@lucern/sdk` helpers `opinionFromBaseRate`, `opinionFromDogmatic`, or `opinionFromProjected` to name the intended interpretation before calling this tool. Triggers: evidence_added, evidence_removed, contradiction_detected, contradiction_resolved, agent_assessment, worktree_outcome, worktree_completed, fusion, discount, deduction, manual, decay.",
4683
+ description: "Record a confidence change for a belief. Like `git commit` to the credence log \u2014 an atomic, append-only write. Each modulation is a new entry in the history, not an overwrite. Scoring happens via merge; this tool records the individual data points. Pass the full subjective-logic tuple (`belief`, `disbelief`, `uncertainty`, `baseRate`) directly. If a caller only has a scalar probability, use `@lucern/sdk` helpers `opinionFromBaseRate`, `opinionFromDogmatic`, or `opinionFromProjected` to name the intended interpretation before calling this tool. Every modulation must cite a truth-bearing artifact: triggeringEvidenceId, triggeringQuestionId, triggeringAnswerId, triggeringContradictionId, or triggeringWorktreeId. Triggers: evidence_added, evidence_removed, contradiction_detected, contradiction_resolved, agent_assessment, worktree_outcome, worktree_completed, fusion, discount, deduction.",
4200
4684
  parameters: {
4201
4685
  nodeId: { type: "string", description: "The belief to score" },
4202
4686
  belief: {
@@ -4215,9 +4699,9 @@ var MODULATE_CONFIDENCE = {
4215
4699
  type: "number",
4216
4700
  description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
4217
4701
  },
4218
- confidence: {
4219
- type: "number",
4220
- description: "Deprecated scalar confidence value in [0, 1]. Scalar-only payloads are rejected as AMBIGUOUS_SCALAR."
4702
+ worktreeId: {
4703
+ type: "string",
4704
+ description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
4221
4705
  },
4222
4706
  trigger: {
4223
4707
  type: "string",
@@ -4232,17 +4716,43 @@ var MODULATE_CONFIDENCE = {
4232
4716
  "worktree_completed",
4233
4717
  "fusion",
4234
4718
  "discount",
4235
- "deduction",
4236
- "manual",
4237
- "decay"
4719
+ "deduction"
4238
4720
  ]
4239
4721
  },
4722
+ triggeringEvidenceId: {
4723
+ type: "string",
4724
+ description: "Evidence node that caused an evidence-triggered modulation"
4725
+ },
4726
+ triggeringQuestionId: {
4727
+ type: "string",
4728
+ description: "Answered question whose resolution supports this modulation"
4729
+ },
4730
+ triggeringAnswerId: {
4731
+ type: "string",
4732
+ description: "Answer node whose content supports this modulation"
4733
+ },
4734
+ triggeringContradictionId: {
4735
+ type: "string",
4736
+ description: "Contradiction record that caused a contradiction-triggered modulation"
4737
+ },
4738
+ triggeringWorktreeId: {
4739
+ type: "string",
4740
+ description: "Completed worktree whose outcome caused a worktree-triggered modulation"
4741
+ },
4240
4742
  rationale: {
4241
4743
  type: "string",
4242
4744
  description: "Human-readable explanation of why confidence changed"
4243
4745
  }
4244
4746
  },
4245
- required: ["nodeId", "trigger", "rationale"],
4747
+ required: [
4748
+ "nodeId",
4749
+ "belief",
4750
+ "disbelief",
4751
+ "uncertainty",
4752
+ "baseRate",
4753
+ "trigger",
4754
+ "rationale"
4755
+ ],
4246
4756
  response: {
4247
4757
  description: "Confidence modulation result",
4248
4758
  fields: {
@@ -4436,7 +4946,7 @@ var ADD_EVIDENCE = {
4436
4946
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'], failedApproach: true } for coding intelligence)"
4437
4947
  }
4438
4948
  },
4439
- required: ["canonicalText", "targetNodeId"],
4949
+ required: ["canonicalText", "targetNodeId", "reasoning"],
4440
4950
  response: {
4441
4951
  description: "The created evidence node and its edge",
4442
4952
  fields: {
@@ -4517,9 +5027,21 @@ var ADD_WORKTREE = {
4517
5027
  type: "string",
4518
5028
  description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
4519
5029
  },
4520
- executionOrder: {
5030
+ campaign: {
4521
5031
  type: "number",
4522
- description: "Global execution order for this worktree"
5032
+ description: "Top-level pipeline campaign number. Campaigns define the outer execution slice."
5033
+ },
5034
+ lane: {
5035
+ type: "string",
5036
+ description: "GitButler-aligned workstream lane name inside the campaign."
5037
+ },
5038
+ laneOrderInCampaign: {
5039
+ type: "number",
5040
+ description: "Ordering for this lane within its campaign."
5041
+ },
5042
+ orderInLane: {
5043
+ type: "number",
5044
+ description: "Position of this worktree inside its lane."
4523
5045
  },
4524
5046
  dependsOn: {
4525
5047
  type: "array",
@@ -5177,6 +5699,10 @@ var CREATE_EVIDENCE = {
5177
5699
  type: "object",
5178
5700
  description: "Optional metadata merged into the canonical evidence node"
5179
5701
  },
5702
+ rationale: {
5703
+ type: "string",
5704
+ description: "Why this evidence should enter the reasoning graph"
5705
+ },
5180
5706
  title: { type: "string", description: "Optional short title" },
5181
5707
  content: { type: "string", description: "Optional long-form content" },
5182
5708
  contentType: {
@@ -5185,7 +5711,7 @@ var CREATE_EVIDENCE = {
5185
5711
  },
5186
5712
  kind: { type: "string", description: "Optional evidence kind" }
5187
5713
  },
5188
- required: ["text"],
5714
+ required: ["text", "rationale"],
5189
5715
  response: {
5190
5716
  description: "The created canonical evidence record",
5191
5717
  fields: {
@@ -5233,7 +5759,7 @@ var LIST_EVIDENCE = {
5233
5759
  limit: { type: "number", description: "Max results" },
5234
5760
  cursor: { type: "string", description: "Pagination cursor" }
5235
5761
  },
5236
- required: [],
5762
+ required: ["topicId"],
5237
5763
  response: {
5238
5764
  description: "Canonical evidence page",
5239
5765
  fields: {
@@ -5418,6 +5944,7 @@ var ANSWER_QUESTION = {
5418
5944
  description: "Answer a question with optional evidence links. Like `git commit` on the question thread \u2014 records the answer and closes the loop with a canonical answered state.",
5419
5945
  parameters: {
5420
5946
  id: { type: "string", description: "Canonical question ID" },
5947
+ topicId: { type: "string", description: "Topic scope for the answer" },
5421
5948
  text: { type: "string", description: "Answer text" },
5422
5949
  confidence: {
5423
5950
  type: "string",
@@ -5430,7 +5957,7 @@ var ANSWER_QUESTION = {
5430
5957
  },
5431
5958
  rationale: { type: "string", description: "Why this answer is credible" }
5432
5959
  },
5433
- required: ["id", "text"],
5960
+ required: ["id", "topicId", "text"],
5434
5961
  response: {
5435
5962
  description: "Answer result",
5436
5963
  fields: {
@@ -5649,6 +6176,10 @@ var LIST_BELIEFS = {
5649
6176
  minConfidence: {
5650
6177
  type: "number",
5651
6178
  description: "Minimum confidence threshold"
6179
+ },
6180
+ limit: {
6181
+ type: "number",
6182
+ description: "Maximum results"
5652
6183
  }
5653
6184
  },
5654
6185
  required: ["topicId"],
@@ -5665,20 +6196,37 @@ var LIST_BELIEFS = {
5665
6196
  };
5666
6197
  var LIST_WORKTREES = {
5667
6198
  name: "list_worktrees",
5668
- description: "List all worktrees for a topic. Like `git worktree list` \u2014 shows active and completed investigation branches with their phase, status, and belief counts.",
6199
+ description: "List all worktrees for a topic. Like `git worktree list` \u2014 shows active and completed investigation branches with lifecycle phase, pipeline campaign/lane, status, and belief counts.",
5669
6200
  parameters: {
5670
6201
  topicId: { type: "string", description: "Topic scope" },
5671
6202
  status: {
5672
6203
  type: "string",
5673
6204
  description: "Filter: active, merged, abandoned",
5674
6205
  enum: ["active", "merged", "abandoned"]
6206
+ },
6207
+ groupBy: {
6208
+ type: "string",
6209
+ description: "Optional grouping mode for the response.",
6210
+ enum: ["campaign", "lane", "flat"]
6211
+ },
6212
+ lane: {
6213
+ type: "string",
6214
+ description: "Filter by GitButler-aligned lane name."
6215
+ },
6216
+ campaign: {
6217
+ type: "number",
6218
+ description: "Filter by top-level pipeline campaign number."
6219
+ },
6220
+ limit: {
6221
+ type: "number",
6222
+ description: "Maximum results to return."
5675
6223
  }
5676
6224
  },
5677
6225
  required: ["topicId"],
5678
6226
  response: {
5679
- description: "Worktrees with phase, status, belief count, and creation time",
6227
+ description: "Worktrees with lifecycle phase, campaign, lane, status, belief count, and creation time",
5680
6228
  fields: {
5681
- worktrees: "array \u2014 { worktreeId, title, phase, status, beliefCount, createdAt }"
6229
+ worktrees: "array \u2014 { worktreeId, title, phase, campaign, lane, laneOrderInCampaign, orderInLane, status, beliefCount, createdAt }"
5682
6230
  }
5683
6231
  },
5684
6232
  ownerModule: "workflow-engine",
@@ -5687,7 +6235,7 @@ var LIST_WORKTREES = {
5687
6235
  };
5688
6236
  var LIST_ALL_WORKTREES = {
5689
6237
  name: "list_all_worktrees",
5690
- description: "List ALL worktrees across ALL topics in one query. No topic scope required. Like `git worktree list --all` \u2014 returns the complete pipeline inventory with track, trackPosition, executionBand, dependencies, and status. Supports filtering by status, track, and executionBand. This is the PM's primary pipeline query \u2014 one call, full picture.",
6238
+ description: "List ALL worktrees across ALL topics in one query. No topic scope required. Like `git worktree list --all` \u2014 returns the complete pipeline inventory with campaign, lane, lane order, dependencies, and status. Supports filtering by status, lane, and campaign. This is the PM's primary pipeline query \u2014 one call, full picture.",
5691
6239
  parameters: {
5692
6240
  status: {
5693
6241
  type: "string",
@@ -5705,13 +6253,18 @@ var LIST_ALL_WORKTREES = {
5705
6253
  "dismissed"
5706
6254
  ]
5707
6255
  },
5708
- track: {
6256
+ lane: {
5709
6257
  type: "string",
5710
- description: "Filter by track name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
6258
+ description: "Filter by lane name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
5711
6259
  },
5712
- executionBand: {
6260
+ campaign: {
5713
6261
  type: "number",
5714
- description: "Filter by execution band number (e.g., 1, 2, 3). Returns only worktrees in that parallel execution group."
6262
+ description: "Filter by campaign number (e.g., 1, 2, 3). Returns only worktrees in that campaign."
6263
+ },
6264
+ groupBy: {
6265
+ type: "string",
6266
+ description: "Optional grouping mode for the response.",
6267
+ enum: ["campaign", "lane", "flat"]
5715
6268
  },
5716
6269
  limit: {
5717
6270
  type: "number",
@@ -5722,10 +6275,39 @@ var LIST_ALL_WORKTREES = {
5722
6275
  response: {
5723
6276
  description: "All worktrees across all topics with full pipeline metadata",
5724
6277
  fields: {
5725
- worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, track, trackPosition, executionBand, executionOrder, dependsOn, blocks, gate, createdAt }",
6278
+ worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, campaign, lane, laneOrderInCampaign, orderInLane, dependsOn, blocks, gate, createdAt }",
5726
6279
  total: "number \u2014 total count after filtering",
5727
- tracks: "object \u2014 { trackName: count } summary of worktrees per track",
5728
- bands: "object \u2014 { bandNumber: count } summary of worktrees per execution band"
6280
+ lanes: "object \u2014 { laneName: count } summary of worktrees per lane",
6281
+ campaigns: "object \u2014 { campaignNumber: count } summary of worktrees per campaign"
6282
+ }
6283
+ },
6284
+ ownerModule: "workflow-engine",
6285
+ ontologyPrimitive: "worktree",
6286
+ tier: "showcase"
6287
+ };
6288
+ var LIST_CAMPAIGNS = {
6289
+ name: "list_campaigns",
6290
+ description: "List compact pipeline campaigns with their nested lanes. Use this to see the top-level campaign > lane > worktree shape without pulling the full worktree inventory.",
6291
+ parameters: {
6292
+ topicId: {
6293
+ type: "string",
6294
+ description: "Optional topic scope."
6295
+ },
6296
+ status: {
6297
+ type: "string",
6298
+ description: "Optional worktree status filter before grouping campaigns and lanes."
6299
+ },
6300
+ limit: {
6301
+ type: "number",
6302
+ description: "Maximum worktrees to scan before grouping."
6303
+ }
6304
+ },
6305
+ required: [],
6306
+ response: {
6307
+ description: "Pipeline campaigns with nested lane summaries.",
6308
+ fields: {
6309
+ campaigns: "array \u2014 { campaign, lanes: [{ lane, laneOrderInCampaign, worktreeCount, activeCount, readyCount, blockedCount, completedCount, nextWorktree }] }",
6310
+ totalWorktrees: "number \u2014 total worktrees scanned after filtering"
5729
6311
  }
5730
6312
  },
5731
6313
  ownerModule: "workflow-engine",
@@ -5788,16 +6370,28 @@ var UPDATE_WORKTREE_TARGETS = {
5788
6370
  };
5789
6371
  var UPDATE_WORKTREE_METADATA = {
5790
6372
  name: "update_worktree_metadata",
5791
- description: "Update worktree sequencing metadata \u2014 execution order, dependencies, blocking relations, and gates. Like `git config` for a worktree \u2014 sets the scheduling and dependency metadata that determines when this worktree can activate relative to others. Use to backfill or correct sequencing data.",
6373
+ description: "Update worktree sequencing metadata \u2014 campaign, lane, dependencies, blocking relations, and gates. Like `git config` for a worktree \u2014 sets the scheduling and dependency metadata that determines when this worktree can activate relative to others. Use to backfill or correct sequencing data.",
5792
6374
  parameters: {
5793
6375
  worktreeId: { type: "string", description: "The worktree to update" },
5794
6376
  hypothesis: {
5795
6377
  type: "string",
5796
6378
  description: "Testable claim this worktree investigates"
5797
6379
  },
5798
- executionOrder: {
6380
+ campaign: {
5799
6381
  type: "number",
5800
- description: "Global execution order (1 = first, higher = later)"
6382
+ description: "Top-level pipeline campaign number."
6383
+ },
6384
+ lane: {
6385
+ type: "string",
6386
+ description: "GitButler-aligned workstream lane name inside the campaign."
6387
+ },
6388
+ laneOrderInCampaign: {
6389
+ type: "number",
6390
+ description: "Ordering for this lane within the campaign."
6391
+ },
6392
+ orderInLane: {
6393
+ type: "number",
6394
+ description: "Position of this worktree inside its lane."
5801
6395
  },
5802
6396
  dependsOn: {
5803
6397
  type: "array",
@@ -5835,18 +6429,6 @@ var UPDATE_WORKTREE_METADATA = {
5835
6429
  type: "object",
5836
6430
  description: "Calibrated auto-fix policy controlling dry-run vs safe execution, per-run action caps, and permitted mutation tiers."
5837
6431
  },
5838
- track: {
5839
- type: "string",
5840
- description: "Parallel workstream name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity', 'execution-program'). Groups worktrees into named lanes for pipeline visualization and PM analysis."
5841
- },
5842
- trackPosition: {
5843
- type: "number",
5844
- description: "Position within the track (1-indexed). E.g., TC-A=1, TC-B=2, TC-C=3 within the 'tc-scope' track."
5845
- },
5846
- executionBand: {
5847
- type: "number",
5848
- description: "Parallel execution band number. All worktrees in the same band can run simultaneously. Band 2 = OE-B + TC-A, Band 3 = TC-B + 11D-R + S2-13A, etc."
5849
- },
5850
6432
  status: {
5851
6433
  type: "string",
5852
6434
  description: "Override the worktree status. Use for lifecycle transitions like marking a worktree superseded, long-term, or as a raw idea.",
@@ -6216,6 +6798,10 @@ var LIST_TASKS = {
6216
6798
  type: "string",
6217
6799
  description: "Filter to tasks linked to this worktree"
6218
6800
  },
6801
+ worktreeId: {
6802
+ type: "string",
6803
+ description: "Alias for linkedWorktreeId"
6804
+ },
6219
6805
  status: {
6220
6806
  type: "string",
6221
6807
  description: "Filter by status: todo, in_progress, blocked, done",
@@ -6303,7 +6889,7 @@ var GET_TOPIC = {
6303
6889
  description: "Legacy alias for topicId"
6304
6890
  }
6305
6891
  },
6306
- required: [],
6892
+ required: ["topicId"],
6307
6893
  response: {
6308
6894
  description: "Single topic record",
6309
6895
  fields: {
@@ -6658,7 +7244,7 @@ var GET_ONTOLOGY = {
6658
7244
  description: "Tenant scope for key lookup. Omit for platform-level."
6659
7245
  }
6660
7246
  },
6661
- required: [],
7247
+ required: ["id"],
6662
7248
  response: {
6663
7249
  description: "Ontology definition with latest published version",
6664
7250
  fields: {
@@ -6725,7 +7311,7 @@ var MATCH_ENTITY_TYPE = {
6725
7311
  description: "Optional maximum number of ranked matches to return"
6726
7312
  }
6727
7313
  },
6728
- required: ["text"],
7314
+ required: ["text", "ontologyId"],
6729
7315
  response: {
6730
7316
  description: "Ranked ontology entity type matches",
6731
7317
  fields: {
@@ -6979,7 +7565,7 @@ var RECORD_SCOPE_LEARNING = {
6979
7565
  };
6980
7566
  var PIPELINE_SNAPSHOT = {
6981
7567
  name: "pipeline_snapshot",
6982
- description: "Summarize a topic's worktree pipeline in band-and-lane form. Like `git status --short` for Lucern execution \u2014 returns the hinge worktree, next planned wave, blockers, critical path, superseded work, and graph hygiene debt.",
7568
+ description: "Summarize a topic's worktree pipeline in campaign-and-lane form. Like `git status --short` for Lucern execution \u2014 returns the hinge worktree, next planned wave, blockers, critical path, superseded work, and graph hygiene debt.",
6983
7569
  parameters: {
6984
7570
  topicId: { type: "string", description: "Topic scope ID" }
6985
7571
  },
@@ -6989,14 +7575,14 @@ var PIPELINE_SNAPSHOT = {
6989
7575
  fields: {
6990
7576
  topicId: "string",
6991
7577
  topicName: "string",
6992
- currentBand: "number | null",
6993
- nextBand: "number | null",
7578
+ currentCampaign: "number | null",
7579
+ nextCampaign: "number | null",
6994
7580
  activeWorktrees: "array \u2014 current hinge worktree(s)",
6995
- nextWave: "array \u2014 worktrees in the next planned band",
7581
+ nextWave: "array \u2014 worktrees in the next planned campaign",
6996
7582
  readyNow: "array \u2014 planning worktrees with dependencies completed",
6997
7583
  blockedBy: "array \u2014 grouped blockers",
6998
7584
  criticalPath: "array \u2014 ordered incomplete worktree chain",
6999
- bands: "array \u2014 incomplete worktrees grouped by executionBand",
7585
+ campaigns: "array \u2014 incomplete worktrees grouped by campaign",
7000
7586
  superseded: "array \u2014 worktrees marked superseded or not for activation",
7001
7587
  graphHygiene: "object \u2014 untargeted and taskless worktree debt",
7002
7588
  riskQuestions: "array \u2014 critical/high open questions",
@@ -7585,6 +8171,7 @@ var MCP_TOOL_CONTRACTS = {
7585
8171
  list_beliefs: LIST_BELIEFS,
7586
8172
  list_worktrees: LIST_WORKTREES,
7587
8173
  list_all_worktrees: LIST_ALL_WORKTREES,
8174
+ list_campaigns: LIST_CAMPAIGNS,
7588
8175
  activate_worktree: ACTIVATE_WORKTREE,
7589
8176
  update_worktree_targets: UPDATE_WORKTREE_TARGETS,
7590
8177
  update_worktree_metadata: UPDATE_WORKTREE_METADATA,
@@ -7767,6 +8354,7 @@ var MCP_WORKFLOW_PLATFORM_OPERATION_NAMES = [
7767
8354
  "activate_worktree",
7768
8355
  "list_worktrees",
7769
8356
  "list_all_worktrees",
8357
+ "list_campaigns",
7770
8358
  "update_worktree_targets",
7771
8359
  "update_worktree_metadata",
7772
8360
  "create_task",
@@ -7974,6 +8562,7 @@ var LUCERN_OPERATION_MANIFEST = {
7974
8562
 
7975
8563
  // ../contracts/src/function-registry/helpers.ts
7976
8564
  var jsonObjectSchema = z.record(z.unknown());
8565
+ var sdkSessionIdSchema = z.string().optional();
7977
8566
  function mcpContractShape(contract) {
7978
8567
  const required = new Set(contract.required);
7979
8568
  return Object.fromEntries(
@@ -8008,10 +8597,40 @@ function argsSchemaFromMcpContract(contract) {
8008
8597
  return z.object(mcpContractShape(contract));
8009
8598
  }
8010
8599
  function inputSchemaFromMcpContract(contract) {
8011
- return argsSchemaFromMcpContract(contract).passthrough();
8600
+ return withInternalSurfaceFields(argsSchemaFromMcpContract(contract));
8601
+ }
8602
+ function withInternalSurfaceFields(schema) {
8603
+ return schema.extend({ __sdkSessionId: sdkSessionIdSchema }).strict();
8604
+ }
8605
+ function normalizeInputSchema(schema) {
8606
+ if (schema instanceof z.ZodObject) {
8607
+ return withInternalSurfaceFields(schema);
8608
+ }
8609
+ return schema;
8610
+ }
8611
+ function unwrapObjectSchema(schema) {
8612
+ let current = schema;
8613
+ while (true) {
8614
+ switch (current._def.typeName) {
8615
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8616
+ current = current._def.schema;
8617
+ continue;
8618
+ case z.ZodFirstPartyTypeKind.ZodBranded:
8619
+ current = current._def.type;
8620
+ continue;
8621
+ default:
8622
+ return current instanceof z.ZodObject ? current : void 0;
8623
+ }
8624
+ }
8012
8625
  }
8013
8626
  function getObjectShape(schema) {
8014
- const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
8627
+ const objectSchema = unwrapObjectSchema(schema);
8628
+ if (!objectSchema) {
8629
+ throw new Error(
8630
+ `Expected a Zod object schema, received ${schema._def.typeName}.`
8631
+ );
8632
+ }
8633
+ const shape = typeof objectSchema._def.shape === "function" ? objectSchema._def.shape() : objectSchema._def.shape;
8015
8634
  return shape;
8016
8635
  }
8017
8636
  function unwrapMcpParameterSchema(schema) {
@@ -8032,6 +8651,9 @@ function unwrapMcpParameterSchema(schema) {
8032
8651
  case z.ZodFirstPartyTypeKind.ZodBranded:
8033
8652
  current = current._def.type;
8034
8653
  continue;
8654
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8655
+ current = current._def.schema;
8656
+ continue;
8035
8657
  default:
8036
8658
  return { schema: current, required, description: description ?? current.description };
8037
8659
  }
@@ -8051,6 +8673,7 @@ function mcpParameterFromZod(fieldName, schema, contractName) {
8051
8673
  return { parameter: { type: "array", description }, required };
8052
8674
  case z.ZodFirstPartyTypeKind.ZodObject:
8053
8675
  case z.ZodFirstPartyTypeKind.ZodRecord:
8676
+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
8054
8677
  return { parameter: { type: "object", description }, required };
8055
8678
  case z.ZodFirstPartyTypeKind.ZodEnum:
8056
8679
  return {
@@ -8112,6 +8735,14 @@ function withCreatedBy(input, context) {
8112
8735
  createdBy: typeof input.createdBy === "string" ? input.createdBy : authUserId(context)
8113
8736
  };
8114
8737
  }
8738
+ function compactRecord4(input) {
8739
+ return Object.fromEntries(
8740
+ Object.entries(input).filter(([, value]) => value !== void 0)
8741
+ );
8742
+ }
8743
+ function recordValue2(value) {
8744
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
8745
+ }
8115
8746
  function surfaceMcpContract(name) {
8116
8747
  const contract = MCP_TOOL_CONTRACTS[name];
8117
8748
  if (!contract) {
@@ -8156,7 +8787,9 @@ function surfaceContract(args) {
8156
8787
  const canonicalArgs = args.args ?? argsSchemaFromMcpContract(baseMcp);
8157
8788
  const mcp = args.args ? mcpContractFromArgsSchema(baseMcp, canonicalArgs, args.name) : baseMcp;
8158
8789
  const canonicalReturns = args.returns ?? jsonObjectSchema;
8159
- const input = args.input ?? inputSchemaFromMcpContract(mcp);
8790
+ const input = normalizeInputSchema(
8791
+ args.input ?? inputSchemaFromMcpContract(mcp)
8792
+ );
8160
8793
  const output = args.output ?? canonicalReturns;
8161
8794
  return defineFunctionContract({
8162
8795
  name: args.name,
@@ -8218,20 +8851,26 @@ function assertSurfaceCoverage(contracts) {
8218
8851
 
8219
8852
  // ../contracts/src/function-registry/context.ts
8220
8853
  var observationInput = (input, context) => withUserId(
8221
- {
8222
- ...input,
8854
+ compactRecord4({
8855
+ projectId: input.projectId,
8856
+ topicId: input.topicId,
8223
8857
  text: input.text ?? input.summary,
8224
8858
  title: input.title ?? input.summary,
8225
8859
  content: input.content ?? input.summary,
8860
+ contentType: input.contentType,
8226
8861
  kind: input.kind ?? input.observationType ?? "observation",
8227
- sourceType: input.sourceType ?? input.source ?? "agent",
8228
- metadata: {
8229
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
8862
+ tags: input.tags,
8863
+ sourceType: input.sourceType,
8864
+ externalSourceType: input.externalSourceType,
8865
+ sourceUrl: input.sourceUrl,
8866
+ metadata: compactRecord4({
8867
+ ...recordValue2(input.metadata),
8230
8868
  observationType: input.observationType,
8231
8869
  source: input.source
8232
- },
8870
+ }),
8871
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded observation",
8233
8872
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8234
- },
8873
+ }),
8235
8874
  context
8236
8875
  );
8237
8876
  var contextContracts = [
@@ -8283,7 +8922,13 @@ var contextContracts = [
8283
8922
  convex: {
8284
8923
  module: "evidence",
8285
8924
  functionName: "getByTopic",
8286
- kind: "query"
8925
+ kind: "query",
8926
+ inputProjection: (input) => compactRecord4({
8927
+ topicId: input.topicId,
8928
+ limit: input.limit,
8929
+ status: input.status,
8930
+ userId: input.userId
8931
+ })
8287
8932
  }
8288
8933
  })
8289
8934
  ];
@@ -8349,42 +8994,62 @@ var identityContracts = [
8349
8994
  ];
8350
8995
 
8351
8996
  // ../contracts/src/function-registry/beliefs.ts
8352
- var withBeliefId = (input) => ({
8353
- ...input,
8997
+ var beliefLookupInput = (input) => compactRecord4({
8354
8998
  nodeId: input.nodeId ?? input.id ?? input.beliefId,
8355
- beliefId: input.beliefId ?? input.id ?? input.nodeId
8999
+ beliefId: input.beliefId
8356
9000
  });
8357
- var createBeliefInput = (input, context) => withUserId(
8358
- {
8359
- ...input,
8360
- formulation: input.formulation ?? input.canonicalText,
8361
- baseRate: input.baseRate ?? 0.5,
8362
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8363
- },
8364
- context
8365
- );
9001
+ var beliefNodeInput = (input) => compactRecord4({
9002
+ nodeId: input.nodeId ?? input.id ?? input.beliefId
9003
+ });
9004
+ var beliefTopicInput = (input) => {
9005
+ const parsed = listBeliefsProjection.inputSchema.safeParse(input);
9006
+ if (!parsed.success) {
9007
+ throw new Error(
9008
+ `list_beliefs projection input rejected: ${parsed.error.message}`
9009
+ );
9010
+ }
9011
+ return compactRecord4(listBeliefsProjection.project(parsed.data));
9012
+ };
9013
+ var createBeliefInput = (input, context) => {
9014
+ return withUserId(
9015
+ compactRecord4({
9016
+ projectId: input.projectId,
9017
+ topicId: input.topicId,
9018
+ formulation: input.formulation ?? input.canonicalText,
9019
+ beliefType: input.beliefType,
9020
+ rationale: input.rationale,
9021
+ pillar: input.pillar,
9022
+ worktreeId: input.worktreeId,
9023
+ sourceBeliefIds: input.sourceBeliefIds,
9024
+ sourceType: input.sourceType,
9025
+ reversibility: input.reversibility,
9026
+ predictionMeta: input.predictionMeta,
9027
+ baseRate: input.baseRate ?? 0.5,
9028
+ metadata: input.metadata,
9029
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9030
+ }),
9031
+ context
9032
+ );
9033
+ };
8366
9034
  var forkBeliefInput = (input, context) => withUserId(
8367
- {
8368
- ...input,
9035
+ compactRecord4({
8369
9036
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
9037
+ newFormulation: input.newFormulation,
9038
+ forkReason: input.forkReason,
9039
+ rationale: input.rationale,
8370
9040
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8371
- },
9041
+ }),
8372
9042
  context
8373
9043
  );
8374
9044
  var confidenceInput = (input, context) => {
8375
- const confidence = typeof input.confidence === "number" ? input.confidence : void 0;
8376
- const belief = typeof input.belief === "number" ? input.belief : confidence ?? 0.5;
8377
- const disbelief = typeof input.disbelief === "number" ? input.disbelief : 0;
8378
- const uncertainty = typeof input.uncertainty === "number" ? input.uncertainty : Math.max(0, 1 - belief - disbelief);
9045
+ const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
9046
+ if (!parsed.success) {
9047
+ throw new Error(
9048
+ `modulate_confidence projection input rejected: ${parsed.error.message}`
9049
+ );
9050
+ }
8379
9051
  return withUserId(
8380
- {
8381
- ...input,
8382
- belief,
8383
- disbelief,
8384
- uncertainty,
8385
- baseRate: input.baseRate ?? 0.5,
8386
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8387
- },
9052
+ compactRecord4(modulateConfidenceProjection.project(parsed.data)),
8388
9053
  context
8389
9054
  );
8390
9055
  };
@@ -8419,7 +9084,7 @@ var beliefsContracts = [
8419
9084
  module: "beliefs",
8420
9085
  functionName: "getById",
8421
9086
  kind: "query",
8422
- inputProjection: withBeliefId
9087
+ inputProjection: beliefLookupInput
8423
9088
  }
8424
9089
  }),
8425
9090
  surfaceContract({
@@ -8435,8 +9100,10 @@ var beliefsContracts = [
8435
9100
  convex: {
8436
9101
  module: "beliefs",
8437
9102
  functionName: "getByTopic",
8438
- kind: "query"
8439
- }
9103
+ kind: "query",
9104
+ inputProjection: beliefTopicInput
9105
+ },
9106
+ args: listBeliefsInputSchema
8440
9107
  }),
8441
9108
  surfaceContract({
8442
9109
  name: "refine_belief",
@@ -8454,7 +9121,7 @@ var beliefsContracts = [
8454
9121
  kind: "mutation",
8455
9122
  inputProjection: (input, context) => withUserId(
8456
9123
  {
8457
- ...withBeliefId(input),
9124
+ ...beliefLookupInput(input),
8458
9125
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8459
9126
  },
8460
9127
  context
@@ -8475,7 +9142,8 @@ var beliefsContracts = [
8475
9142
  functionName: "modulateConfidence",
8476
9143
  kind: "mutation",
8477
9144
  inputProjection: confidenceInput
8478
- }
9145
+ },
9146
+ args: modulateConfidenceInputSchema
8479
9147
  }),
8480
9148
  surfaceContract({
8481
9149
  name: "fork_belief",
@@ -8508,10 +9176,10 @@ var beliefsContracts = [
8508
9176
  functionName: "archive",
8509
9177
  kind: "mutation",
8510
9178
  inputProjection: (input, context) => withUserId(
8511
- {
8512
- ...withBeliefId(input),
9179
+ compactRecord4({
9180
+ ...beliefNodeInput(input),
8513
9181
  reason: input.reason ?? input.rationale
8514
- },
9182
+ }),
8515
9183
  context
8516
9184
  )
8517
9185
  }
@@ -8529,10 +9197,12 @@ var beliefsContracts = [
8529
9197
  module: "nodes",
8530
9198
  functionName: "search",
8531
9199
  kind: "query",
8532
- inputProjection: (input) => ({
8533
- ...input,
9200
+ inputProjection: (input) => compactRecord4({
8534
9201
  searchQuery: input.searchQuery ?? input.query,
8535
- nodeType: "belief"
9202
+ projectId: input.projectId,
9203
+ topicId: input.topicId,
9204
+ nodeType: "belief",
9205
+ limit: input.limit
8536
9206
  })
8537
9207
  }
8538
9208
  }),
@@ -8549,7 +9219,7 @@ var beliefsContracts = [
8549
9219
  module: "beliefs",
8550
9220
  functionName: "getConfidenceHistory",
8551
9221
  kind: "query",
8552
- inputProjection: withBeliefId
9222
+ inputProjection: beliefNodeInput
8553
9223
  }
8554
9224
  }),
8555
9225
  surfaceContract({
@@ -8566,25 +9236,69 @@ var beliefsContracts = [
8566
9236
  module: "beliefs",
8567
9237
  functionName: "getConfidenceHistory",
8568
9238
  kind: "query",
8569
- inputProjection: withBeliefId
9239
+ inputProjection: beliefNodeInput
8570
9240
  }
8571
9241
  })
8572
9242
  ];
8573
9243
 
8574
9244
  // ../contracts/src/function-registry/evidence.ts
8575
- var evidenceIdInput = (input) => ({
8576
- ...input,
8577
- evidenceId: input.evidenceId ?? input.id ?? input.nodeId,
9245
+ var evidenceIdInput = (input) => compactRecord4({
9246
+ evidenceId: input.evidenceId,
9247
+ insightId: input.insightId,
8578
9248
  nodeId: input.nodeId ?? input.id ?? input.evidenceId
8579
9249
  });
8580
- var createEvidenceInput = (input, context) => withUserId(
8581
- {
8582
- ...input,
8583
- title: input.title ?? input.text,
8584
- content: input.content ?? input.text,
8585
- sourceType: input.sourceType ?? input.source ?? "agent",
9250
+ var evidenceTopicInput = (input) => compactRecord4({
9251
+ topicId: input.topicId,
9252
+ status: input.status,
9253
+ userId: input.userId,
9254
+ limit: input.limit
9255
+ });
9256
+ var createEvidenceInput = (input, context) => {
9257
+ const parsed = createEvidenceProjection.inputSchema.safeParse(input);
9258
+ if (!parsed.success) {
9259
+ throw new Error(
9260
+ `create_evidence projection input rejected: ${parsed.error.message}`
9261
+ );
9262
+ }
9263
+ return withUserId(
9264
+ compactRecord4(createEvidenceProjection.project(parsed.data)),
9265
+ context
9266
+ );
9267
+ };
9268
+ var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
9269
+ compactRecord4({
9270
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9271
+ toNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
9272
+ edgeType: "evidence_supports_belief",
9273
+ globalId: input.globalId ?? `edge:${String(
9274
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9275
+ )}:${String(
9276
+ input.beliefNodeId ?? input.beliefId ?? input.targetId
9277
+ )}:evidence_supports_belief`,
9278
+ weight: typeof input.weight === "number" ? input.weight : input.type === "contradicting" ? -1 : 1,
9279
+ context: input.rationale ?? input.context,
9280
+ skipLayerValidation: true,
9281
+ topicId: input.topicId,
8586
9282
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8587
- },
9283
+ }),
9284
+ context
9285
+ );
9286
+ var linkEvidenceToQuestionEdgeInput = (input, context) => withCreatedBy(
9287
+ compactRecord4({
9288
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9289
+ toNodeId: input.questionId ?? input.questionNodeId ?? input.targetId,
9290
+ edgeType: "evidence_supports_question",
9291
+ globalId: input.globalId ?? `edge:${String(
9292
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9293
+ )}:${String(
9294
+ input.questionId ?? input.questionNodeId ?? input.targetId
9295
+ )}:evidence_supports_question`,
9296
+ weight: input.impactScore ?? input.weight,
9297
+ context: input.rationale ?? input.context,
9298
+ skipLayerValidation: true,
9299
+ topicId: input.topicId,
9300
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9301
+ }),
8588
9302
  context
8589
9303
  );
8590
9304
  var evidenceContracts = [
@@ -8628,8 +9342,9 @@ var evidenceContracts = [
8628
9342
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
8629
9343
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
8630
9344
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
9345
+ rationale: input.reasoning,
8631
9346
  metadata: {
8632
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
9347
+ ...recordValue2(input.metadata),
8633
9348
  reasoning: input.reasoning,
8634
9349
  sourceUrl: input.sourceUrl
8635
9350
  }
@@ -8669,7 +9384,8 @@ var evidenceContracts = [
8669
9384
  convex: {
8670
9385
  module: "evidence",
8671
9386
  functionName: "getByTopic",
8672
- kind: "query"
9387
+ kind: "query",
9388
+ inputProjection: evidenceTopicInput
8673
9389
  }
8674
9390
  }),
8675
9391
  surfaceContract({
@@ -8685,10 +9401,12 @@ var evidenceContracts = [
8685
9401
  module: "nodes",
8686
9402
  functionName: "search",
8687
9403
  kind: "query",
8688
- inputProjection: (input) => ({
8689
- ...input,
9404
+ inputProjection: (input) => compactRecord4({
8690
9405
  searchQuery: input.searchQuery ?? input.q ?? input.query,
8691
- nodeType: "evidence"
9406
+ projectId: input.projectId,
9407
+ topicId: input.topicId,
9408
+ nodeType: "evidence",
9409
+ limit: input.limit
8692
9410
  })
8693
9411
  }
8694
9412
  }),
@@ -8702,17 +9420,10 @@ var evidenceContracts = [
8702
9420
  sdkMethod: "linkEvidenceToBelief",
8703
9421
  summary: "Link evidence to a belief.",
8704
9422
  convex: {
8705
- module: "beliefs",
8706
- functionName: "linkEvidence",
9423
+ module: "edges",
9424
+ functionName: "create",
8707
9425
  kind: "mutation",
8708
- inputProjection: (input, context) => withUserId(
8709
- {
8710
- ...input,
8711
- beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
8712
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8713
- },
8714
- context
8715
- )
9426
+ inputProjection: linkEvidenceToBeliefEdgeInput
8716
9427
  }
8717
9428
  }),
8718
9429
  surfaceContract({
@@ -8725,18 +9436,10 @@ var evidenceContracts = [
8725
9436
  sdkMethod: "linkEvidenceToQuestion",
8726
9437
  summary: "Link evidence to a question.",
8727
9438
  convex: {
8728
- module: "questionLinks",
9439
+ module: "edges",
8729
9440
  functionName: "create",
8730
9441
  kind: "mutation",
8731
- inputProjection: (input, context) => withCreatedBy(
8732
- {
8733
- ...input,
8734
- questionId: input.questionId,
8735
- insightId: input.insightId ?? input.evidenceId,
8736
- helpsAnswer: input.helpsAnswer ?? true
8737
- },
8738
- context
8739
- )
9442
+ inputProjection: linkEvidenceToQuestionEdgeInput
8740
9443
  }
8741
9444
  }),
8742
9445
  surfaceContract({
@@ -8749,35 +9452,46 @@ var evidenceContracts = [
8749
9452
  sdkMethod: "linkEvidence",
8750
9453
  summary: "Link evidence to a target node.",
8751
9454
  convex: {
8752
- module: "beliefs",
8753
- functionName: "linkEvidence",
9455
+ module: "edges",
9456
+ functionName: "create",
8754
9457
  kind: "mutation",
8755
- inputProjection: (input, context) => withUserId(
8756
- {
8757
- ...input,
8758
- beliefNodeId: input.beliefNodeId ?? input.targetId,
8759
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8760
- },
8761
- context
8762
- )
9458
+ inputProjection: linkEvidenceToBeliefEdgeInput
8763
9459
  }
8764
9460
  })
8765
9461
  ];
8766
9462
 
8767
9463
  // ../contracts/src/function-registry/questions.ts
8768
- var questionIdInput = (input) => ({
8769
- ...input,
8770
- questionId: input.questionId ?? input.id ?? input.nodeId,
8771
- nodeId: input.nodeId ?? input.id ?? input.questionId
9464
+ var questionNodeInput = (input) => compactRecord4({
9465
+ nodeId: input.nodeId ?? input.id ?? input.questionId,
9466
+ questionId: input.questionId
8772
9467
  });
8773
- var createQuestionInput = (input, context) => withUserId(
8774
- {
8775
- ...input,
8776
- text: input.text ?? input.question,
8777
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8778
- },
8779
- context
8780
- );
9468
+ var questionTopicInput = (input) => compactRecord4({
9469
+ topicId: input.topicId,
9470
+ status: input.status,
9471
+ userId: input.userId,
9472
+ limit: input.limit
9473
+ });
9474
+ var createQuestionInput = (input, context) => {
9475
+ const priority = input.priority === "urgent" ? "high" : input.priority;
9476
+ return withUserId(
9477
+ compactRecord4({
9478
+ topicId: input.topicId,
9479
+ question: input.question ?? input.text,
9480
+ category: input.category,
9481
+ priority,
9482
+ source: input.source,
9483
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.linkedBeliefId,
9484
+ testType: input.testType,
9485
+ importance: input.importance,
9486
+ epistemicUnlock: input.epistemicUnlock,
9487
+ sourceQuestionIds: input.sourceQuestionIds,
9488
+ linkedWorktreeId: input.linkedWorktreeId,
9489
+ questionType: input.questionType,
9490
+ questionPriority: input.questionPriority
9491
+ }),
9492
+ context
9493
+ );
9494
+ };
8781
9495
  var questionsContracts = [
8782
9496
  surfaceContract({
8783
9497
  name: "create_question",
@@ -8809,7 +9523,7 @@ var questionsContracts = [
8809
9523
  module: "questions",
8810
9524
  functionName: "getById",
8811
9525
  kind: "query",
8812
- inputProjection: questionIdInput
9526
+ inputProjection: questionNodeInput
8813
9527
  }
8814
9528
  }),
8815
9529
  surfaceContract({
@@ -8825,7 +9539,8 @@ var questionsContracts = [
8825
9539
  convex: {
8826
9540
  module: "questions",
8827
9541
  functionName: "getByTopic",
8828
- kind: "query"
9542
+ kind: "query",
9543
+ inputProjection: questionTopicInput
8829
9544
  }
8830
9545
  }),
8831
9546
  surfaceContract({
@@ -8842,7 +9557,12 @@ var questionsContracts = [
8842
9557
  module: "questions",
8843
9558
  functionName: "updateQuestion",
8844
9559
  kind: "mutation",
8845
- inputProjection: (input, context) => withUserId({ ...questionIdInput(input), text: input.text }, context)
9560
+ inputProjection: (input) => compactRecord4({
9561
+ questionId: input.questionId ?? input.id ?? input.nodeId,
9562
+ question: input.question ?? input.text,
9563
+ category: input.category,
9564
+ priority: input.priority
9565
+ })
8846
9566
  }
8847
9567
  }),
8848
9568
  surfaceContract({
@@ -8859,7 +9579,16 @@ var questionsContracts = [
8859
9579
  module: "questions",
8860
9580
  functionName: "updateStatus",
8861
9581
  kind: "mutation",
8862
- inputProjection: (input, context) => withUserId(questionIdInput(input), context)
9582
+ inputProjection: (input, context) => withUserId(
9583
+ compactRecord4({
9584
+ questionId: input.questionId ?? input.id,
9585
+ nodeId: input.nodeId,
9586
+ status: input.status,
9587
+ answer: input.answer,
9588
+ answerStatus: input.answerStatus
9589
+ }),
9590
+ context
9591
+ )
8863
9592
  }
8864
9593
  }),
8865
9594
  surfaceContract({
@@ -8876,7 +9605,12 @@ var questionsContracts = [
8876
9605
  module: "questions",
8877
9606
  functionName: "deleteQuestion",
8878
9607
  kind: "mutation",
8879
- inputProjection: questionIdInput
9608
+ inputProjection: (input, context) => withUserId(
9609
+ compactRecord4({
9610
+ questionId: input.questionId ?? input.id ?? input.nodeId
9611
+ }),
9612
+ context
9613
+ )
8880
9614
  }
8881
9615
  }),
8882
9616
  surfaceContract({
@@ -8893,10 +9627,16 @@ var questionsContracts = [
8893
9627
  functionName: "create",
8894
9628
  kind: "mutation",
8895
9629
  inputProjection: (input, context) => withUserId(
8896
- {
8897
- ...input,
8898
- questionNodeId: input.questionNodeId ?? input.questionId
8899
- },
9630
+ compactRecord4({
9631
+ topicId: input.topicId,
9632
+ questionNodeId: input.questionNodeId ?? input.questionId,
9633
+ answerText: input.answerText,
9634
+ confidence: input.confidence,
9635
+ evidenceNodeIds: input.evidenceNodeIds,
9636
+ answerSource: input.answerSource,
9637
+ worktreeId: input.worktreeId,
9638
+ sprintId: input.sprintId
9639
+ }),
8900
9640
  context
8901
9641
  )
8902
9642
  }
@@ -8916,13 +9656,16 @@ var questionsContracts = [
8916
9656
  functionName: "create",
8917
9657
  kind: "mutation",
8918
9658
  inputProjection: (input, context) => withUserId(
8919
- {
8920
- ...input,
9659
+ compactRecord4({
9660
+ topicId: input.topicId,
8921
9661
  questionNodeId: input.questionNodeId ?? input.questionId ?? input.id,
8922
9662
  answerText: input.answerText ?? input.text,
8923
9663
  evidenceNodeIds: input.evidenceNodeIds ?? input.evidenceIds,
8924
- answerSource: input.answerSource ?? "human"
8925
- },
9664
+ answerSource: input.answerSource ?? "human",
9665
+ confidence: input.confidence,
9666
+ worktreeId: input.worktreeId,
9667
+ sprintId: input.sprintId
9668
+ }),
8926
9669
  context
8927
9670
  )
8928
9671
  }
@@ -8955,7 +9698,8 @@ var questionsContracts = [
8955
9698
  convex: {
8956
9699
  module: "questions",
8957
9700
  functionName: "getByTopic",
8958
- kind: "query"
9701
+ kind: "query",
9702
+ inputProjection: questionTopicInput
8959
9703
  }
8960
9704
  }),
8961
9705
  surfaceContract({
@@ -8970,7 +9714,11 @@ var questionsContracts = [
8970
9714
  convex: {
8971
9715
  module: "questions",
8972
9716
  functionName: "getByTopic",
8973
- kind: "query"
9717
+ kind: "query",
9718
+ inputProjection: (input) => compactRecord4({
9719
+ ...questionTopicInput(input),
9720
+ status: input.includeAnswered === true ? void 0 : "open"
9721
+ })
8974
9722
  }
8975
9723
  }),
8976
9724
  surfaceContract({
@@ -8985,16 +9733,28 @@ var questionsContracts = [
8985
9733
  convex: {
8986
9734
  module: "questions",
8987
9735
  functionName: "getByTopic",
8988
- kind: "query"
9736
+ kind: "query",
9737
+ inputProjection: questionTopicInput
8989
9738
  }
8990
9739
  })
8991
9740
  ];
8992
9741
 
8993
9742
  // ../contracts/src/function-registry/topics.ts
8994
- var topicIdInput = (input) => ({
8995
- ...input,
9743
+ var topicIdInput = (input) => compactRecord4({
8996
9744
  id: input.id ?? input.topicId
8997
9745
  });
9746
+ var updateTopicInput = (input) => compactRecord4({
9747
+ id: input.id ?? input.topicId,
9748
+ name: input.name,
9749
+ description: input.description,
9750
+ type: input.type,
9751
+ status: input.status,
9752
+ visibility: input.visibility,
9753
+ ontologyId: input.ontologyId,
9754
+ clearOntologyId: input.clearOntologyId,
9755
+ graphScopeProjectId: input.graphScopeProjectId,
9756
+ metadata: input.metadata
9757
+ });
8998
9758
  var topicsContracts = [
8999
9759
  surfaceContract({
9000
9760
  name: "create_topic",
@@ -9059,7 +9819,7 @@ var topicsContracts = [
9059
9819
  module: "topics",
9060
9820
  functionName: "update",
9061
9821
  kind: "mutation",
9062
- inputProjection: topicIdInput
9822
+ inputProjection: updateTopicInput
9063
9823
  }
9064
9824
  }),
9065
9825
  surfaceContract({
@@ -9081,6 +9841,27 @@ var topicsContracts = [
9081
9841
  ];
9082
9842
 
9083
9843
  // ../contracts/src/function-registry/lenses.ts
9844
+ var createLensInput = (input, context) => compactRecord4({
9845
+ name: input.name,
9846
+ description: input.description,
9847
+ workspaceId: input.workspaceId,
9848
+ topicId: input.topicId,
9849
+ perspectiveType: input.perspectiveType,
9850
+ promptTemplates: input.promptTemplates,
9851
+ workflowTemplates: input.workflowTemplates,
9852
+ taskTemplates: input.taskTemplates,
9853
+ questionTemplates: input.questionTemplates,
9854
+ filterCriteria: input.filterCriteria,
9855
+ metadata: input.metadata,
9856
+ createdBy: authUserId(context)
9857
+ });
9858
+ var lensListInput = (input, context) => compactRecord4({
9859
+ actorId: input.actorId ?? authUserId(context),
9860
+ workspaceId: input.workspaceId,
9861
+ topicId: input.topicId,
9862
+ status: input.status,
9863
+ perspectiveType: input.perspectiveType
9864
+ });
9084
9865
  var lensesContracts = [
9085
9866
  surfaceContract({
9086
9867
  name: "create_lens",
@@ -9094,7 +9875,8 @@ var lensesContracts = [
9094
9875
  convex: {
9095
9876
  module: "lenses",
9096
9877
  functionName: "create",
9097
- kind: "mutation"
9878
+ kind: "mutation",
9879
+ inputProjection: createLensInput
9098
9880
  }
9099
9881
  }),
9100
9882
  surfaceContract({
@@ -9110,7 +9892,8 @@ var lensesContracts = [
9110
9892
  convex: {
9111
9893
  module: "lenses",
9112
9894
  functionName: "list",
9113
- kind: "query"
9895
+ kind: "query",
9896
+ inputProjection: lensListInput
9114
9897
  }
9115
9898
  }),
9116
9899
  surfaceContract({
@@ -9125,7 +9908,13 @@ var lensesContracts = [
9125
9908
  convex: {
9126
9909
  module: "lenses",
9127
9910
  functionName: "applyToTopic",
9128
- kind: "mutation"
9911
+ kind: "mutation",
9912
+ inputProjection: (input, context) => compactRecord4({
9913
+ lensId: input.lensId,
9914
+ topicId: input.topicId,
9915
+ metadata: input.metadata,
9916
+ appliedBy: authUserId(context)
9917
+ })
9129
9918
  }
9130
9919
  }),
9131
9920
  surfaceContract({
@@ -9141,12 +9930,28 @@ var lensesContracts = [
9141
9930
  convex: {
9142
9931
  module: "lenses",
9143
9932
  functionName: "removeFromTopic",
9144
- kind: "mutation"
9933
+ kind: "mutation",
9934
+ inputProjection: (input, context) => compactRecord4({
9935
+ lensId: input.lensId,
9936
+ topicId: input.topicId,
9937
+ removedBy: authUserId(context)
9938
+ })
9145
9939
  }
9146
9940
  })
9147
9941
  ];
9148
9942
 
9149
9943
  // ../contracts/src/function-registry/ontologies.ts
9944
+ var ontologyIdInput = (input) => compactRecord4({
9945
+ id: input.id ?? input.ontologyId
9946
+ });
9947
+ var ontologyVersionIdInput = (input) => compactRecord4({
9948
+ id: input.id ?? input.versionId,
9949
+ ontologyId: input.ontologyId,
9950
+ actorId: input.actorId
9951
+ });
9952
+ var effectiveOntologyInput = (input) => compactRecord4({
9953
+ ontologyId: input.ontologyId ?? input.id
9954
+ });
9150
9955
  var ontologiesContracts = [
9151
9956
  surfaceContract({
9152
9957
  name: "create_ontology",
@@ -9177,10 +9982,7 @@ var ontologiesContracts = [
9177
9982
  module: "ontologies",
9178
9983
  functionName: "getOntologyDefinition",
9179
9984
  kind: "query",
9180
- inputProjection: (input) => ({
9181
- ...input,
9182
- id: input.id ?? input.ontologyId
9183
- })
9985
+ inputProjection: ontologyIdInput
9184
9986
  }
9185
9987
  }),
9186
9988
  surfaceContract({
@@ -9213,9 +10015,13 @@ var ontologiesContracts = [
9213
10015
  module: "ontologies",
9214
10016
  functionName: "updateOntologyDefinition",
9215
10017
  kind: "mutation",
9216
- inputProjection: (input) => ({
9217
- ...input,
9218
- id: input.id ?? input.ontologyId
10018
+ inputProjection: (input) => compactRecord4({
10019
+ id: input.id ?? input.ontologyId,
10020
+ name: input.name,
10021
+ description: input.description,
10022
+ parentOntologyId: input.parentOntologyId,
10023
+ status: input.status,
10024
+ actorId: input.actorId
9219
10025
  })
9220
10026
  }
9221
10027
  }),
@@ -9233,10 +10039,7 @@ var ontologiesContracts = [
9233
10039
  module: "ontologies",
9234
10040
  functionName: "archiveOntologyDefinition",
9235
10041
  kind: "mutation",
9236
- inputProjection: (input) => ({
9237
- ...input,
9238
- id: input.id ?? input.ontologyId
9239
- })
10042
+ inputProjection: ontologyIdInput
9240
10043
  }
9241
10044
  }),
9242
10045
  surfaceContract({
@@ -9267,8 +10070,7 @@ var ontologiesContracts = [
9267
10070
  module: "topics",
9268
10071
  functionName: "update",
9269
10072
  kind: "mutation",
9270
- inputProjection: (input) => ({
9271
- ...input,
10073
+ inputProjection: (input) => compactRecord4({
9272
10074
  id: input.topicId ?? input.id,
9273
10075
  ontologyId: input.ontologyId ?? input.id
9274
10076
  })
@@ -9286,7 +10088,8 @@ var ontologiesContracts = [
9286
10088
  convex: {
9287
10089
  module: "ontologies",
9288
10090
  functionName: "resolveEffectiveOntology",
9289
- kind: "query"
10091
+ kind: "query",
10092
+ inputProjection: effectiveOntologyInput
9290
10093
  }
9291
10094
  }),
9292
10095
  surfaceContract({
@@ -9302,10 +10105,7 @@ var ontologiesContracts = [
9302
10105
  module: "ontologies",
9303
10106
  functionName: "publishOntologyVersion",
9304
10107
  kind: "mutation",
9305
- inputProjection: (input) => ({
9306
- ...input,
9307
- id: input.id ?? input.versionId
9308
- })
10108
+ inputProjection: ontologyVersionIdInput
9309
10109
  }
9310
10110
  }),
9311
10111
  surfaceContract({
@@ -9321,10 +10121,7 @@ var ontologiesContracts = [
9321
10121
  module: "ontologies",
9322
10122
  functionName: "deprecateOntologyVersion",
9323
10123
  kind: "mutation",
9324
- inputProjection: (input) => ({
9325
- ...input,
9326
- id: input.id ?? input.versionId
9327
- })
10124
+ inputProjection: ontologyVersionIdInput
9328
10125
  }
9329
10126
  }),
9330
10127
  surfaceContract({
@@ -9339,16 +10136,51 @@ var ontologiesContracts = [
9339
10136
  convex: {
9340
10137
  module: "ontologies",
9341
10138
  functionName: "resolveEffectiveOntology",
9342
- kind: "query"
10139
+ kind: "query",
10140
+ inputProjection: effectiveOntologyInput
9343
10141
  }
9344
10142
  })
9345
10143
  ];
9346
10144
 
9347
10145
  // ../contracts/src/function-registry/worktrees.ts
9348
- var worktreeInput = (input) => ({
9349
- ...input,
10146
+ var worktreeIdInput = (input) => compactRecord4({
9350
10147
  worktreeId: input.worktreeId ?? input.id
9351
10148
  });
10149
+ var activateWorktreeInput = (input, context) => withUserId(worktreeIdInput(input), context);
10150
+ var worktreeTargetsInput = (input) => compactRecord4({
10151
+ worktreeId: input.worktreeId ?? input.id,
10152
+ addBeliefIds: input.addBeliefIds,
10153
+ removeBeliefIds: input.removeBeliefIds,
10154
+ addQuestionIds: input.addQuestionIds,
10155
+ removeQuestionIds: input.removeQuestionIds
10156
+ });
10157
+ var worktreeMetadataInput = (input) => compactRecord4({
10158
+ worktreeId: input.worktreeId ?? input.id,
10159
+ topicId: input.topicId,
10160
+ additionalTopicIds: input.additionalTopicIds,
10161
+ status: input.status,
10162
+ campaign: input.campaign,
10163
+ lane: input.lane,
10164
+ laneOrderInCampaign: input.laneOrderInCampaign,
10165
+ orderInLane: input.orderInLane,
10166
+ gate: input.gate,
10167
+ hypothesis: input.hypothesis,
10168
+ objective: input.objective,
10169
+ rationale: input.rationale,
10170
+ proofArtifacts: input.proofArtifacts,
10171
+ staffingHint: input.staffingHint,
10172
+ blocks: input.blocks,
10173
+ dependsOn: input.dependsOn,
10174
+ lensId: input.lensId,
10175
+ autoFixPolicy: input.autoFixPolicy,
10176
+ lastReconciledAt: input.lastReconciledAt
10177
+ });
10178
+ var listAllWorktreesInput = (input) => compactRecord4({
10179
+ status: input.status,
10180
+ lane: input.lane,
10181
+ campaign: input.campaign,
10182
+ limit: input.limit
10183
+ });
9352
10184
  var worktreesContracts = [
9353
10185
  surfaceContract({
9354
10186
  name: "add_worktree",
@@ -9364,11 +10196,43 @@ var worktreesContracts = [
9364
10196
  functionName: "create",
9365
10197
  kind: "mutation",
9366
10198
  inputProjection: (input, context) => withCreatedBy(
9367
- {
9368
- ...input,
10199
+ compactRecord4({
9369
10200
  name: input.name ?? input.title,
9370
- targetBeliefIds: input.targetBeliefIds ?? input.beliefIds
9371
- },
10201
+ topicId: input.topicId,
10202
+ worktreeType: input.worktreeType,
10203
+ objective: input.objective,
10204
+ gate: input.gate,
10205
+ hypothesis: input.hypothesis,
10206
+ rationale: input.rationale,
10207
+ signal: input.signal,
10208
+ startDate: input.startDate,
10209
+ endDate: input.endDate,
10210
+ durationWeeks: input.durationWeeks,
10211
+ confidenceImpact: input.confidenceImpact,
10212
+ autoShape: input.autoShape,
10213
+ autoFixPolicy: input.autoFixPolicy,
10214
+ beliefFocus: input.beliefFocus,
10215
+ targetQuestionIds: input.targetQuestionIds,
10216
+ targetBeliefIds: input.targetBeliefIds ?? input.beliefIds,
10217
+ keyQuestions: input.keyQuestions,
10218
+ proofArtifacts: input.proofArtifacts,
10219
+ decisionGate: input.decisionGate ?? (input.goCriteria || input.noGoSignals ? compactRecord4({
10220
+ goCriteria: input.goCriteria,
10221
+ noGoSignals: input.noGoSignals
10222
+ }) : void 0),
10223
+ evidenceSignals: input.evidenceSignals,
10224
+ dependsOn: input.dependsOn,
10225
+ blocks: input.blocks,
10226
+ campaign: input.campaign,
10227
+ lane: input.lane,
10228
+ laneOrderInCampaign: input.laneOrderInCampaign,
10229
+ orderInLane: input.orderInLane,
10230
+ staffingHint: input.staffingHint,
10231
+ domainPackId: input.domainPackId,
10232
+ lensId: input.lensId,
10233
+ linkedQuestionId: input.linkedQuestionId,
10234
+ lastReconciledAt: input.lastReconciledAt
10235
+ }),
9372
10236
  context
9373
10237
  )
9374
10238
  }
@@ -9386,7 +10250,7 @@ var worktreesContracts = [
9386
10250
  module: "worktrees",
9387
10251
  functionName: "activate",
9388
10252
  kind: "mutation",
9389
- inputProjection: worktreeInput
10253
+ inputProjection: activateWorktreeInput
9390
10254
  }
9391
10255
  }),
9392
10256
  surfaceContract({
@@ -9402,7 +10266,36 @@ var worktreesContracts = [
9402
10266
  convex: {
9403
10267
  module: "worktrees",
9404
10268
  functionName: "list",
9405
- kind: "query"
10269
+ kind: "query",
10270
+ inputProjection: (input) => compactRecord4({
10271
+ topicId: input.topicId,
10272
+ status: input.status,
10273
+ groupBy: input.groupBy,
10274
+ lane: input.lane,
10275
+ campaign: input.campaign,
10276
+ limit: input.limit
10277
+ })
10278
+ }
10279
+ }),
10280
+ surfaceContract({
10281
+ name: "list_campaigns",
10282
+ kind: "query",
10283
+ domain: "worktrees",
10284
+ surfaceClass: "platform_public",
10285
+ method: "GET",
10286
+ path: "/worktrees/campaigns",
10287
+ sdkNamespace: "worktrees",
10288
+ sdkMethod: "listCampaigns",
10289
+ summary: "List compact pipeline campaigns with nested lanes.",
10290
+ convex: {
10291
+ module: "worktrees",
10292
+ functionName: "listCampaigns",
10293
+ kind: "query",
10294
+ inputProjection: (input) => compactRecord4({
10295
+ topicId: input.topicId,
10296
+ status: input.status,
10297
+ limit: input.limit
10298
+ })
9406
10299
  }
9407
10300
  }),
9408
10301
  surfaceContract({
@@ -9418,7 +10311,8 @@ var worktreesContracts = [
9418
10311
  convex: {
9419
10312
  module: "worktrees",
9420
10313
  functionName: "listAll",
9421
- kind: "query"
10314
+ kind: "query",
10315
+ inputProjection: listAllWorktreesInput
9422
10316
  }
9423
10317
  }),
9424
10318
  surfaceContract({
@@ -9435,7 +10329,7 @@ var worktreesContracts = [
9435
10329
  module: "worktrees",
9436
10330
  functionName: "updateTargets",
9437
10331
  kind: "mutation",
9438
- inputProjection: worktreeInput
10332
+ inputProjection: worktreeTargetsInput
9439
10333
  }
9440
10334
  }),
9441
10335
  surfaceContract({
@@ -9452,7 +10346,7 @@ var worktreesContracts = [
9452
10346
  module: "worktrees",
9453
10347
  functionName: "updateMetadata",
9454
10348
  kind: "mutation",
9455
- inputProjection: worktreeInput
10349
+ inputProjection: worktreeMetadataInput
9456
10350
  }
9457
10351
  }),
9458
10352
  surfaceContract({
@@ -9468,12 +10362,17 @@ var worktreesContracts = [
9468
10362
  module: "worktrees",
9469
10363
  functionName: "complete",
9470
10364
  kind: "mutation",
9471
- inputProjection: (input) => ({
9472
- ...worktreeInput(input),
9473
- keyFindings: input.keyFindings ?? [input.summary ?? "Merged worktree"],
9474
- decisionsReached: input.decisionsReached ?? [],
9475
- nextSteps: input.nextSteps ?? []
9476
- })
10365
+ inputProjection: (input, context) => withUserId(
10366
+ {
10367
+ ...worktreeIdInput(input),
10368
+ keyFindings: input.keyFindings ?? [
10369
+ input.summary ?? "Merged worktree"
10370
+ ],
10371
+ decisionsReached: input.decisionsReached ?? [],
10372
+ nextSteps: input.nextSteps ?? []
10373
+ },
10374
+ context
10375
+ )
9477
10376
  }
9478
10377
  }),
9479
10378
  surfaceContract({
@@ -9489,11 +10388,7 @@ var worktreesContracts = [
9489
10388
  module: "worktrees",
9490
10389
  functionName: "updateMetadata",
9491
10390
  kind: "mutation",
9492
- inputProjection: (input) => ({
9493
- ...worktreeInput(input),
9494
- lastPushTargetContext: input.targetContext,
9495
- lastPushBeliefIds: input.beliefIds
9496
- })
10391
+ inputProjection: worktreeMetadataInput
9497
10392
  }
9498
10393
  }),
9499
10394
  surfaceContract({
@@ -9509,20 +10404,30 @@ var worktreesContracts = [
9509
10404
  module: "worktrees",
9510
10405
  functionName: "updateMetadata",
9511
10406
  kind: "mutation",
9512
- inputProjection: (input) => ({
9513
- ...worktreeInput(input),
9514
- lastPullRequestSummary: input.summary,
9515
- lastPullRequestReviewers: input.reviewers
9516
- })
10407
+ inputProjection: worktreeMetadataInput
9517
10408
  }
9518
10409
  })
9519
10410
  ];
9520
10411
 
9521
10412
  // ../contracts/src/function-registry/tasks.ts
9522
- var taskInput = (input) => ({
10413
+ var taskInput = (input) => compactRecord4({
9523
10414
  ...input,
9524
10415
  taskId: input.taskId ?? input.id
9525
10416
  });
10417
+ var taskTopicInput = (input) => {
10418
+ const parsed = listTasksProjection.inputSchema.safeParse(input);
10419
+ if (!parsed.success) {
10420
+ throw new Error(
10421
+ `list_tasks projection input rejected: ${parsed.error.message}`
10422
+ );
10423
+ }
10424
+ return compactRecord4(listTasksProjection.project(parsed.data));
10425
+ };
10426
+ var completeTaskInput = (input) => compactRecord4({
10427
+ taskId: input.taskId ?? input.id,
10428
+ outputSummary: input.outputSummary ?? input.summary,
10429
+ userId: input.userId
10430
+ });
9526
10431
  var tasksContracts = [
9527
10432
  surfaceContract({
9528
10433
  name: "create_task",
@@ -9552,8 +10457,10 @@ var tasksContracts = [
9552
10457
  convex: {
9553
10458
  module: "tasks",
9554
10459
  functionName: "getByTopic",
9555
- kind: "query"
9556
- }
10460
+ kind: "query",
10461
+ inputProjection: taskTopicInput
10462
+ },
10463
+ args: listTasksInputSchema
9557
10464
  }),
9558
10465
  surfaceContract({
9559
10466
  name: "update_task",
@@ -9585,12 +10492,29 @@ var tasksContracts = [
9585
10492
  module: "tasks",
9586
10493
  functionName: "complete",
9587
10494
  kind: "mutation",
9588
- inputProjection: taskInput
10495
+ inputProjection: completeTaskInput
9589
10496
  }
9590
10497
  })
9591
10498
  ];
9592
-
9593
- // ../contracts/src/function-registry/edges.ts
10499
+ var createEdgeArgs = z.object({
10500
+ from: GraphRefSchema,
10501
+ to: GraphRefSchema,
10502
+ edgeType: z.string(),
10503
+ globalId: z.string().optional(),
10504
+ weight: z.number().optional(),
10505
+ confidence: z.number().optional(),
10506
+ context: z.string().optional(),
10507
+ reasoning: z.string().optional(),
10508
+ derivationType: z.string().optional(),
10509
+ topicId: z.string().optional(),
10510
+ trustedBypassAccessCheck: z.boolean().optional()
10511
+ });
10512
+ function graphRefNodeId(ref) {
10513
+ if (ref.kind === "epistemic_node") {
10514
+ return ref.nodeId;
10515
+ }
10516
+ return `external_belief:${ref.ref.tenantId}:${ref.ref.beliefId}`;
10517
+ }
9594
10518
  var edgesContracts = [
9595
10519
  surfaceContract({
9596
10520
  name: "create_edge",
@@ -9605,16 +10529,35 @@ var edgesContracts = [
9605
10529
  module: "edges",
9606
10530
  functionName: "create",
9607
10531
  kind: "mutation",
9608
- inputProjection: (input, context) => withCreatedBy(
9609
- {
9610
- ...input,
9611
- fromNodeId: input.fromNodeId ?? input.sourceId,
9612
- toNodeId: input.toNodeId ?? input.targetId,
9613
- context: input.context ?? input.reasoning
9614
- },
9615
- context
9616
- )
9617
- }
10532
+ inputProjection: (input, context) => {
10533
+ const parsed = createEdgeArgs.parse(input);
10534
+ assertEdgePolicyAllowed(
10535
+ edgePolicyManifest,
10536
+ parsed.edgeType,
10537
+ parsed.from,
10538
+ parsed.to
10539
+ );
10540
+ const fromNodeId = graphRefNodeId(parsed.from);
10541
+ const toNodeId = graphRefNodeId(parsed.to);
10542
+ return withCreatedBy(
10543
+ compactRecord4({
10544
+ fromNodeId,
10545
+ toNodeId,
10546
+ edgeType: parsed.edgeType,
10547
+ globalId: parsed.globalId ?? `edge:${fromNodeId}:${toNodeId}:${parsed.edgeType}`,
10548
+ weight: parsed.weight,
10549
+ confidence: parsed.confidence,
10550
+ context: parsed.context ?? parsed.reasoning,
10551
+ derivationType: parsed.derivationType,
10552
+ skipLayerValidation: true,
10553
+ topicId: parsed.topicId,
10554
+ trustedBypassAccessCheck: parsed.trustedBypassAccessCheck
10555
+ }),
10556
+ context
10557
+ );
10558
+ }
10559
+ },
10560
+ args: createEdgeArgs
9618
10561
  }),
9619
10562
  surfaceContract({
9620
10563
  name: "query_lineage",
@@ -9629,9 +10572,12 @@ var edgesContracts = [
9629
10572
  module: "edges",
9630
10573
  functionName: "getLineage",
9631
10574
  kind: "query",
9632
- inputProjection: (input) => ({
9633
- ...input,
9634
- maxDepth: input.maxDepth ?? input.depth
10575
+ inputProjection: (input) => compactRecord4({
10576
+ nodeId: input.nodeId ?? input.startNode,
10577
+ maxDepth: input.maxDepth ?? input.depth,
10578
+ mode: input.mode,
10579
+ minLayer: input.minLayer,
10580
+ maxLayer: input.maxLayer
9635
10581
  })
9636
10582
  }
9637
10583
  })
@@ -9651,8 +10597,7 @@ var contradictionSeverity = (value) => {
9651
10597
  return "significant";
9652
10598
  }
9653
10599
  };
9654
- var flagContradictionInput = (input, context) => ({
9655
- ...input,
10600
+ var flagContradictionInput = (input, context) => compactRecord4({
9656
10601
  beliefId: input.beliefId ?? input.beliefA,
9657
10602
  supportingInsightIds: Array.isArray(input.supportingInsightIds) ? input.supportingInsightIds : [],
9658
10603
  contradictingInsightIds: Array.isArray(input.contradictingInsightIds) ? input.contradictingInsightIds : [input.beliefB].filter((value) => typeof value === "string"),
@@ -9666,6 +10611,18 @@ var flagContradictionInput = (input, context) => ({
9666
10611
  },
9667
10612
  createdBy: authUserId(context)
9668
10613
  });
10614
+ var lineageInput = (input) => compactRecord4({
10615
+ nodeId: input.nodeId ?? input.startNode ?? input.entityId,
10616
+ maxDepth: input.maxDepth ?? input.depth,
10617
+ mode: input.mode,
10618
+ minLayer: input.minLayer,
10619
+ maxLayer: input.maxLayer
10620
+ });
10621
+ var topicEdgesInput = (input) => compactRecord4({
10622
+ topicId: input.topicId,
10623
+ userId: input.userId,
10624
+ limit: input.limit
10625
+ });
9669
10626
  var graphContracts = [
9670
10627
  surfaceContract({
9671
10628
  name: "traverse_graph",
@@ -9679,7 +10636,8 @@ var graphContracts = [
9679
10636
  convex: {
9680
10637
  module: "edges",
9681
10638
  functionName: "getLineage",
9682
- kind: "query"
10639
+ kind: "query",
10640
+ inputProjection: lineageInput
9683
10641
  }
9684
10642
  }),
9685
10643
  surfaceContract({
@@ -9694,7 +10652,8 @@ var graphContracts = [
9694
10652
  convex: {
9695
10653
  module: "edges",
9696
10654
  functionName: "getByTopic",
9697
- kind: "query"
10655
+ kind: "query",
10656
+ inputProjection: topicEdgesInput
9698
10657
  }
9699
10658
  }),
9700
10659
  surfaceContract({
@@ -9724,7 +10683,10 @@ var graphContracts = [
9724
10683
  convex: {
9725
10684
  module: "edges",
9726
10685
  functionName: "findContradictions",
9727
- kind: "query"
10686
+ kind: "query",
10687
+ inputProjection: (input) => compactRecord4({
10688
+ nodeId: input.nodeId ?? input.beliefId
10689
+ })
9728
10690
  }
9729
10691
  }),
9730
10692
  surfaceContract({
@@ -9829,8 +10791,9 @@ var graphContracts = [
9829
10791
  summary: "Discover graph connections for an entity.",
9830
10792
  convex: {
9831
10793
  module: "edges",
9832
- functionName: "getByTopic",
9833
- kind: "query"
10794
+ functionName: "getLineage",
10795
+ kind: "query",
10796
+ inputProjection: lineageInput
9834
10797
  }
9835
10798
  }),
9836
10799
  surfaceContract({
@@ -9861,10 +10824,7 @@ var graphContracts = [
9861
10824
  module: "edges",
9862
10825
  functionName: "getLineage",
9863
10826
  kind: "query",
9864
- inputProjection: (input) => ({
9865
- ...input,
9866
- nodeId: input.nodeId ?? input.entityId
9867
- })
10827
+ inputProjection: lineageInput
9868
10828
  }
9869
10829
  })
9870
10830
  ];
@@ -9934,19 +10894,21 @@ var judgmentsContracts = [
9934
10894
  functionName: "create",
9935
10895
  kind: "mutation",
9936
10896
  inputProjection: (input, context) => withUserId(
9937
- {
9938
- ...input,
10897
+ compactRecord4({
10898
+ projectId: input.projectId,
10899
+ topicId: input.topicId,
9939
10900
  text: input.rationale,
9940
10901
  title: input.title,
9941
10902
  content: input.rationale,
9942
10903
  kind: "judgment",
9943
- sourceType: "agent",
9944
- metadata: {
10904
+ sourceType: "ai_generated",
10905
+ metadata: compactRecord4({
9945
10906
  confidence: input.confidence,
9946
10907
  beliefIds: input.beliefIds
9947
- },
10908
+ }),
10909
+ rationale: input.rationale ?? input.reasoning ?? "Recorded judgment evidence",
9948
10910
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9949
- },
10911
+ }),
9950
10912
  context
9951
10913
  )
9952
10914
  }
@@ -9964,9 +10926,12 @@ var judgmentsContracts = [
9964
10926
  module: "edges",
9965
10927
  functionName: "getLineage",
9966
10928
  kind: "query",
9967
- inputProjection: (input) => ({
9968
- ...input,
9969
- nodeId: input.nodeId ?? input.id
10929
+ inputProjection: (input) => compactRecord4({
10930
+ nodeId: input.nodeId ?? input.id,
10931
+ maxDepth: input.maxDepth ?? input.depth,
10932
+ mode: input.mode,
10933
+ minLayer: input.minLayer,
10934
+ maxLayer: input.maxLayer
9970
10935
  })
9971
10936
  }
9972
10937
  })
@@ -10092,7 +11057,10 @@ var coordinationContracts = [
10092
11057
  module: "coordination",
10093
11058
  functionName: "getInbox",
10094
11059
  kind: "query",
10095
- injectSessionId: "sessionId"
11060
+ injectSessionId: "sessionId",
11061
+ inputProjection: (input) => compactRecord4({
11062
+ limit: input.limit
11063
+ })
10096
11064
  }
10097
11065
  }),
10098
11066
  surfaceContract({
@@ -10110,7 +11078,6 @@ var coordinationContracts = [
10110
11078
  kind: "mutation",
10111
11079
  injectSessionId: "sessionId",
10112
11080
  inputProjection: (input) => ({
10113
- ...input,
10114
11081
  touchedFiles: stringArray(input.touchedFiles) ?? stringArray(input.files) ?? stringArray(input.paths) ?? []
10115
11082
  })
10116
11083
  }
@@ -10127,7 +11094,10 @@ var coordinationContracts = [
10127
11094
  convex: {
10128
11095
  module: "worktrees",
10129
11096
  functionName: "get",
10130
- kind: "query"
11097
+ kind: "query",
11098
+ inputProjection: (input) => compactRecord4({
11099
+ worktreeId: input.worktreeId ?? input.id
11100
+ })
10131
11101
  }
10132
11102
  })
10133
11103
  ];
@@ -10146,7 +11116,13 @@ var pipelineContracts = [
10146
11116
  convex: {
10147
11117
  module: "worktrees",
10148
11118
  functionName: "listAll",
10149
- kind: "query"
11119
+ kind: "query",
11120
+ inputProjection: (input) => compactRecord4({
11121
+ status: input.status,
11122
+ lane: input.lane,
11123
+ campaign: input.campaign,
11124
+ limit: input.limit
11125
+ })
10150
11126
  }
10151
11127
  }),
10152
11128
  surfaceContract({
@@ -10196,43 +11172,63 @@ var recordScopeLearningArgs = z.object({
10196
11172
  linkedBeliefNodeId: z.string().optional().describe("Optional belief to attach evidence to"),
10197
11173
  evidenceRelation: z.enum(["supports", "contradicts"]).optional().describe("Relation to linked belief"),
10198
11174
  confidence: z.number().optional().describe("Optional confidence in [0,1]"),
11175
+ rationale: z.string().optional().describe("Why this learning should enter the reasoning graph"),
10199
11176
  createQuestionText: z.string().optional().describe("Optional follow-up question text"),
10200
11177
  createBeliefText: z.string().optional().describe("Optional new belief text"),
10201
11178
  beliefType: z.string().optional().describe("Optional belief type for createBeliefText")
10202
11179
  });
10203
- var learningInput = (input, context) => withUserId(
10204
- {
10205
- ...input,
10206
- text: input.summary ?? input.text,
10207
- title: input.title ?? input.summary ?? "Scope learning",
10208
- content: input.body ?? input.content ?? input.summary,
10209
- kind: input.kind ?? input.sourceKind ?? "learning",
10210
- tags: input.tags ?? [],
10211
- metadata: {
10212
- sourceRef: input.sourceRef,
10213
- sourceKind: input.sourceKind,
10214
- touchedPaths: input.touchedPaths
10215
- },
10216
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10217
- },
10218
- context
10219
- );
11180
+ var learningInput = (input, context) => {
11181
+ const sourceKind = input.sourceKind ?? input.externalSourceType;
11182
+ return withUserId(
11183
+ compactRecord4({
11184
+ projectId: input.projectId,
11185
+ topicId: input.topicId,
11186
+ text: input.summary ?? input.text,
11187
+ title: input.title ?? input.summary ?? "Scope learning",
11188
+ content: input.body ?? input.content ?? input.summary,
11189
+ contentType: input.contentType,
11190
+ kind: input.kind ?? "learning",
11191
+ tags: input.tags ?? [],
11192
+ sourceType: input.sourceType,
11193
+ externalSourceType: input.externalSourceType ?? input.sourceKind,
11194
+ sourceUrl: input.sourceUrl,
11195
+ metadata: compactRecord4({
11196
+ ...recordValue2(input.metadata),
11197
+ sourceRef: input.sourceRef,
11198
+ sourceKind,
11199
+ touchedPaths: input.touchedPaths,
11200
+ createQuestionText: input.createQuestionText,
11201
+ createBeliefText: input.createBeliefText,
11202
+ beliefType: input.beliefType
11203
+ }),
11204
+ linkedBeliefNodeId: input.linkedBeliefNodeId,
11205
+ evidenceRelation: input.evidenceRelation,
11206
+ confidence: input.confidence,
11207
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded scope learning",
11208
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
11209
+ }),
11210
+ context
11211
+ );
11212
+ };
10220
11213
  var attemptInput = (input, context) => withUserId(
10221
- {
10222
- ...input,
11214
+ compactRecord4({
11215
+ projectId: input.projectId,
11216
+ topicId: input.topicId,
10223
11217
  text: input.description,
10224
11218
  title: input.title ?? input.description,
10225
11219
  content: input.errorMessage ?? input.description,
10226
11220
  kind: "code_attempt",
10227
11221
  tags: ["code_attempt"],
10228
- metadata: {
11222
+ metadata: compactRecord4({
11223
+ ...recordValue2(input.metadata),
10229
11224
  filePaths: input.filePaths,
10230
11225
  filePath: input.filePath,
10231
11226
  errorMessage: input.errorMessage,
10232
11227
  linkedBeliefId: input.linkedBeliefId
10233
- },
11228
+ }),
11229
+ rationale: input.rationale ?? input.reasoning ?? input.errorMessage ?? input.description ?? "Recorded implementation attempt",
10234
11230
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10235
- },
11231
+ }),
10236
11232
  context
10237
11233
  );
10238
11234
  var codingContracts = [
@@ -10289,7 +11285,13 @@ var codingContracts = [
10289
11285
  convex: {
10290
11286
  module: "evidence",
10291
11287
  functionName: "getByTopic",
10292
- kind: "query"
11288
+ kind: "query",
11289
+ inputProjection: (input) => compactRecord4({
11290
+ topicId: input.topicId,
11291
+ limit: input.limit,
11292
+ status: input.status,
11293
+ userId: input.userId
11294
+ })
10293
11295
  }
10294
11296
  }),
10295
11297
  surfaceContract({
@@ -10304,7 +11306,13 @@ var codingContracts = [
10304
11306
  convex: {
10305
11307
  module: "evidence",
10306
11308
  functionName: "getByTopic",
10307
- kind: "query"
11309
+ kind: "query",
11310
+ inputProjection: (input) => compactRecord4({
11311
+ topicId: input.topicId,
11312
+ limit: input.limit,
11313
+ status: input.status,
11314
+ userId: input.userId
11315
+ })
10308
11316
  }
10309
11317
  }),
10310
11318
  surfaceContract({
@@ -10336,9 +11344,11 @@ var codingContracts = [
10336
11344
  module: "evidence",
10337
11345
  functionName: "getByTopic",
10338
11346
  kind: "query",
10339
- inputProjection: (input) => ({
10340
- ...input,
10341
- topicId: input.topicId ?? input.query
11347
+ inputProjection: (input) => compactRecord4({
11348
+ topicId: input.topicId ?? input.query,
11349
+ limit: input.limit,
11350
+ status: input.status,
11351
+ userId: input.userId
10342
11352
  })
10343
11353
  }
10344
11354
  })