@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/outbox.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 DOMAIN_EVENT_VERSION = "1.0";
@@ -495,6 +496,28 @@ defineTable({
495
496
  { kind: "index", name: "by_createdAt", columns: ["createdAt"] }
496
497
  ]
497
498
  });
499
+ defineTable({
500
+ name: "neo4jSyncQueue",
501
+ component: "kernel",
502
+ category: "infra",
503
+ shape: z.object({
504
+ "entityType": z.enum(["node", "edge"]),
505
+ "entityId": z.string(),
506
+ "operation": z.enum(["upsert", "delete"]),
507
+ "attempts": z.number(),
508
+ "maxAttempts": z.number(),
509
+ "lastAttemptAt": z.number().optional(),
510
+ "lastError": z.string().optional(),
511
+ "status": z.enum(["pending", "in_progress", "failed", "succeeded"]),
512
+ "createdAt": z.number(),
513
+ "updatedAt": z.number()
514
+ }),
515
+ indices: [
516
+ { kind: "index", name: "by_status", columns: ["status"] },
517
+ { kind: "index", name: "by_entity", columns: ["entityType", "entityId"] },
518
+ { kind: "index", name: "by_status_attempts", columns: ["status", "attempts"] }
519
+ ]
520
+ });
498
521
  defineTable({
499
522
  name: "backgroundJobRuns",
500
523
  component: "kernel",
@@ -564,9 +587,9 @@ defineTable({
564
587
  category: "epistemic",
565
588
  shape: z.object({
566
589
  "beliefId": z.string(),
567
- "belief": z.number().optional(),
568
- "disbelief": z.number().optional(),
569
- "uncertainty": z.number().optional(),
590
+ "belief": z.number(),
591
+ "disbelief": z.number(),
592
+ "uncertainty": z.number(),
570
593
  "baseRate": z.number(),
571
594
  "slOperator": z.string().optional(),
572
595
  "confidence": z.number(),
@@ -575,10 +598,12 @@ defineTable({
575
598
  "certainty": z.number().optional(),
576
599
  "assessedAt": z.number(),
577
600
  "assessedBy": z.string(),
578
- "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"]),
601
+ "trigger": z.enum(["initial", "evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "propagation", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction", "backfill_synthetic"]),
579
602
  "rationale": z.string().optional(),
580
603
  "triggeringEvidenceId": z.string().optional(),
581
604
  "triggeringEvidenceIds": z.array(z.string()).optional(),
605
+ "triggeringQuestionId": z.string().optional(),
606
+ "triggeringAnswerId": z.string().optional(),
582
607
  "triggeringContradictionId": idOf("contradictions").optional(),
583
608
  "triggeringWorktreeId": z.string().optional(),
584
609
  "triggeringAgentId": z.string().optional(),
@@ -1261,7 +1286,7 @@ defineTable({
1261
1286
  "credentialRef": z.string(),
1262
1287
  "tenantId": idOf("tenants"),
1263
1288
  "target": z.enum(["kernelDeployment", "appDeployment"]),
1264
- "environment": z.enum(["dev", "prod"]),
1289
+ "environment": z.enum(["dev", "staging", "prod"]),
1265
1290
  "encryptedDeployKey": z.string(),
1266
1291
  "encryptionVersion": z.string(),
1267
1292
  "keyFingerprint": z.string(),
@@ -3930,13 +3955,13 @@ defineTable({
3930
3955
  "rationale": z.string().optional(),
3931
3956
  "confidenceImpact": z.enum(["high", "medium", "low"]).optional(),
3932
3957
  "hypothesis": z.string().optional(),
3933
- "executionOrder": z.number().optional(),
3934
3958
  "dependsOn": z.array(idOf("worktrees")).optional(),
3935
3959
  "blocks": z.array(idOf("worktrees")).optional(),
3936
3960
  "gate": z.string().optional(),
3937
- "track": z.string().optional(),
3938
- "trackPosition": z.number().optional(),
3939
- "executionBand": z.number().optional(),
3961
+ "campaign": z.number().optional(),
3962
+ "lane": z.string().optional(),
3963
+ "laneOrderInCampaign": z.number().optional(),
3964
+ "orderInLane": z.number().optional(),
3940
3965
  "startDate": z.number(),
3941
3966
  "endDate": z.number(),
3942
3967
  "durationWeeks": z.number(),
@@ -4184,10 +4209,469 @@ defineTable({
4184
4209
  { kind: "index", name: "by_topicId_index", columns: ["topicId", "index"] },
4185
4210
  { kind: "index", name: "by_worktreeType", columns: ["topicId", "worktreeType"] },
4186
4211
  { kind: "index", name: "by_topicId_priority", columns: ["topicId", "priority"] },
4212
+ { kind: "index", name: "by_topicId_campaign_lane_order", columns: ["topicId", "campaign", "laneOrderInCampaign", "orderInLane"] },
4213
+ { kind: "index", name: "by_topicId_lane_order", columns: ["topicId", "lane", "orderInLane"] },
4187
4214
  { kind: "index", name: "by_topicId_branch", columns: ["topicId", "targetBranch"] },
4188
4215
  { kind: "index", name: "by_topicId_scope", columns: ["topicId", "worktreeScope"] }
4189
4216
  ]
4190
4217
  });
4218
+ z.object({
4219
+ manifestVersion: z.string(),
4220
+ componentName: z.enum(["kernel", "identity"]),
4221
+ tier: z.enum(["K", "I"]),
4222
+ packageVersion: z.string(),
4223
+ tables: z.array(
4224
+ z.object({
4225
+ name: z.string(),
4226
+ fields: z.array(
4227
+ z.object({
4228
+ name: z.string(),
4229
+ type: z.string(),
4230
+ optional: z.boolean(),
4231
+ validator: z.string().optional()
4232
+ })
4233
+ )
4234
+ })
4235
+ )
4236
+ });
4237
+ var SL_EPSILON = 1e-9;
4238
+ z.object({
4239
+ belief: z.number(),
4240
+ disbelief: z.number(),
4241
+ uncertainty: z.number(),
4242
+ baseRate: z.number()
4243
+ }).refine(
4244
+ (o) => Math.abs(o.belief + o.disbelief + o.uncertainty - 1) < SL_EPSILON,
4245
+ {
4246
+ message: "SL invariant b+d+u=1 violated at API boundary"
4247
+ }
4248
+ );
4249
+ var EpistemicNodeTypeSchema = z.enum([
4250
+ "belief",
4251
+ "evidence",
4252
+ "question",
4253
+ "answer",
4254
+ "topic",
4255
+ "edge",
4256
+ "ontology",
4257
+ "lens",
4258
+ "contradiction"
4259
+ ]);
4260
+ var GraphRefSchema = z.discriminatedUnion("kind", [
4261
+ z.object({
4262
+ kind: z.literal("epistemic_node"),
4263
+ nodeId: z.string(),
4264
+ nodeType: EpistemicNodeTypeSchema
4265
+ }),
4266
+ z.object({
4267
+ kind: z.literal("external_belief"),
4268
+ ref: z.object({
4269
+ tenantId: z.string(),
4270
+ beliefId: z.string()
4271
+ })
4272
+ })
4273
+ ]);
4274
+ var graphRefKind = z.enum(["epistemic_node", "external_belief"]);
4275
+ var EdgePolicyEntrySchema = z.object({
4276
+ edgeType: z.string(),
4277
+ fromKinds: z.array(graphRefKind),
4278
+ fromNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4279
+ toKinds: z.array(graphRefKind),
4280
+ toNodeTypes: z.array(EpistemicNodeTypeSchema).optional(),
4281
+ description: z.string()
4282
+ });
4283
+ z.object({
4284
+ manifestVersion: z.literal("1.0.0"),
4285
+ policies: z.array(EdgePolicyEntrySchema)
4286
+ });
4287
+ function findEdgePolicy(manifest, edgeType) {
4288
+ return manifest.policies.find((policy) => policy.edgeType === edgeType);
4289
+ }
4290
+ function nodeTypeAllowed(allowed, ref) {
4291
+ return ref.kind !== "epistemic_node" || !allowed || allowed.includes(ref.nodeType);
4292
+ }
4293
+ function assertEdgePolicyAllowed(manifest, edgeType, from, to) {
4294
+ const policy = findEdgePolicy(manifest, edgeType);
4295
+ const allowed = Boolean(policy) && policy.fromKinds.includes(from.kind) && policy.toKinds.includes(to.kind) && nodeTypeAllowed(policy.fromNodeTypes, from) && nodeTypeAllowed(policy.toNodeTypes, to);
4296
+ if (!allowed) {
4297
+ const error = new Error(
4298
+ `Edge policy violation for ${edgeType}: ${from.kind} -> ${to.kind}`
4299
+ );
4300
+ error.code = "POLICY_VIOLATION";
4301
+ error.details = { code: "POLICY_VIOLATION", edgeType, from, to };
4302
+ throw error;
4303
+ }
4304
+ }
4305
+
4306
+ // ../contracts/src/manifests/edge-policy-manifest.data.ts
4307
+ var edgePolicyManifest = {
4308
+ policies: [
4309
+ {
4310
+ edgeType: "evidence_derived_from_evidence",
4311
+ fromKinds: ["epistemic_node"],
4312
+ fromNodeTypes: ["evidence"],
4313
+ toKinds: ["epistemic_node"],
4314
+ toNodeTypes: ["evidence"],
4315
+ description: "Evidence E2 was synthesized from evidence E1 by a transformation. Provides chain-of-evidence lineage."
4316
+ },
4317
+ {
4318
+ edgeType: "evidence_supports_belief",
4319
+ fromKinds: ["epistemic_node"],
4320
+ fromNodeTypes: ["evidence"],
4321
+ toKinds: ["epistemic_node"],
4322
+ toNodeTypes: ["belief"],
4323
+ description: "Existing link_evidence_to_belief semantics promoted to the create_edge policy source."
4324
+ },
4325
+ {
4326
+ edgeType: "evidence_supports_question",
4327
+ fromKinds: ["epistemic_node"],
4328
+ fromNodeTypes: ["evidence"],
4329
+ toKinds: ["epistemic_node"],
4330
+ toNodeTypes: ["question"],
4331
+ description: "Existing link_evidence_to_question semantics promoted to the create_edge policy source."
4332
+ }
4333
+ ]
4334
+ };
4335
+ z.object({
4336
+ manifestVersion: z.literal("1.0.0"),
4337
+ rules: z.array(
4338
+ z.object({
4339
+ invariant: z.string(),
4340
+ description: z.string(),
4341
+ checker: z.enum(["ast", "manifest", "runtime"]),
4342
+ severity: z.enum(["block_publish", "block_pr", "warn"])
4343
+ })
4344
+ )
4345
+ });
4346
+
4347
+ // ../contracts/src/projections/projection-dsl.ts
4348
+ function defineProjection(def) {
4349
+ return def;
4350
+ }
4351
+
4352
+ // ../contracts/src/projections/create-evidence.projection.ts
4353
+ var jsonRecordSchema = z.record(z.unknown());
4354
+ var createEvidenceInputSchemaBase = z.object({
4355
+ projectId: z.string().optional(),
4356
+ topicId: z.string().optional(),
4357
+ text: z.string().optional(),
4358
+ canonicalText: z.string().optional(),
4359
+ title: z.string().optional(),
4360
+ content: z.string().optional(),
4361
+ contentType: z.string().optional(),
4362
+ kind: z.string().optional(),
4363
+ tags: z.array(z.string()).optional(),
4364
+ source: z.string().optional(),
4365
+ sourceUrl: z.string().optional(),
4366
+ sourceType: z.string().optional(),
4367
+ externalSourceType: z.string().optional(),
4368
+ sourceQuestionId: z.string().optional(),
4369
+ methodology: z.string().optional(),
4370
+ informationAsymmetry: z.string().optional(),
4371
+ sourceDescription: z.string().optional(),
4372
+ targetId: z.string().optional(),
4373
+ targetNodeId: z.string().optional(),
4374
+ linkedBeliefNodeId: z.string().optional(),
4375
+ evidenceRelation: z.enum(["supports", "contradicts", "neutral"]).optional(),
4376
+ confidence: z.number().optional(),
4377
+ weight: z.number().optional(),
4378
+ reasoning: z.string().optional(),
4379
+ rationale: z.string(),
4380
+ metadata: jsonRecordSchema.optional(),
4381
+ trustedBypassAccessCheck: z.boolean().optional()
4382
+ }).passthrough();
4383
+ var createEvidenceInputSchema = createEvidenceInputSchemaBase.refine(
4384
+ (input) => Boolean(input.text ?? input.canonicalText),
4385
+ {
4386
+ message: "create_evidence requires text",
4387
+ path: ["text"]
4388
+ }
4389
+ );
4390
+ function compactRecord(input) {
4391
+ return Object.fromEntries(
4392
+ Object.entries(input).filter(([, value]) => value !== void 0)
4393
+ );
4394
+ }
4395
+ function recordValue(value) {
4396
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4397
+ }
4398
+ var createEvidenceProjection = defineProjection({
4399
+ contractName: "create_evidence",
4400
+ inputSchema: createEvidenceInputSchema,
4401
+ project: (input) => {
4402
+ const text = input.text ?? input.canonicalText;
4403
+ const weight = typeof input.weight === "number" ? input.weight : void 0;
4404
+ return compactRecord({
4405
+ projectId: input.projectId,
4406
+ topicId: input.topicId,
4407
+ text,
4408
+ title: input.title ?? text,
4409
+ content: input.content ?? text,
4410
+ contentType: input.contentType,
4411
+ kind: input.kind,
4412
+ tags: input.tags,
4413
+ sourceType: input.sourceType,
4414
+ externalSourceType: input.externalSourceType,
4415
+ sourceUrl: input.sourceUrl ?? input.source,
4416
+ sourceQuestionId: input.sourceQuestionId,
4417
+ methodology: input.methodology,
4418
+ informationAsymmetry: input.informationAsymmetry,
4419
+ sourceDescription: input.sourceDescription,
4420
+ metadata: compactRecord({
4421
+ ...recordValue(input.metadata),
4422
+ source: input.source,
4423
+ targetId: input.targetId,
4424
+ targetNodeId: input.targetNodeId,
4425
+ weight,
4426
+ reasoning: input.reasoning,
4427
+ rationale: input.rationale
4428
+ }),
4429
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
4430
+ evidenceRelation: input.evidenceRelation ?? (weight === void 0 ? void 0 : weight < 0 ? "contradicts" : "supports"),
4431
+ confidence: input.confidence ?? (weight === void 0 ? void 0 : Math.min(1, Math.max(0, Math.abs(weight)))),
4432
+ rationale: input.rationale,
4433
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4434
+ });
4435
+ },
4436
+ convexArgsValidator: v.object({
4437
+ projectId: v.optional(v.string()),
4438
+ topicId: v.optional(v.string()),
4439
+ text: v.string(),
4440
+ title: v.optional(v.string()),
4441
+ content: v.optional(v.string()),
4442
+ contentType: v.optional(v.string()),
4443
+ kind: v.optional(v.string()),
4444
+ tags: v.optional(v.array(v.string())),
4445
+ sourceType: v.optional(v.string()),
4446
+ externalSourceType: v.optional(v.string()),
4447
+ sourceUrl: v.optional(v.string()),
4448
+ sourceQuestionId: v.optional(v.string()),
4449
+ methodology: v.optional(v.string()),
4450
+ informationAsymmetry: v.optional(v.string()),
4451
+ sourceDescription: v.optional(v.string()),
4452
+ metadata: v.optional(v.record(v.string(), v.any())),
4453
+ linkedBeliefNodeId: v.optional(v.string()),
4454
+ evidenceRelation: v.optional(
4455
+ v.union(
4456
+ v.literal("supports"),
4457
+ v.literal("contradicts"),
4458
+ v.literal("neutral")
4459
+ )
4460
+ ),
4461
+ confidence: v.optional(v.number()),
4462
+ rationale: v.string(),
4463
+ trustedBypassAccessCheck: v.optional(v.boolean())
4464
+ })
4465
+ });
4466
+ var beliefStatusSchema = z.enum(["active", "superseded", "archived", "unscored", "scored"]).optional().describe("Filter by belief lifecycle or scoring status");
4467
+ var listBeliefsInputSchema = z.object({
4468
+ topicId: z.string().describe("Topic scope"),
4469
+ worktreeId: z.string().optional().describe("Filter to worktree scope"),
4470
+ status: beliefStatusSchema,
4471
+ minConfidence: z.number().optional().describe("Minimum confidence threshold"),
4472
+ limit: z.number().optional().describe("Maximum results"),
4473
+ includeEdgeAssociated: z.boolean().optional().describe("Include beliefs associated to the topic through edges")
4474
+ });
4475
+ function kernelStatus(status) {
4476
+ return status === "active" || status === "superseded" || status === "archived" ? status : void 0;
4477
+ }
4478
+ function compactRecord2(input) {
4479
+ return Object.fromEntries(
4480
+ Object.entries(input).filter(([, value]) => value !== void 0)
4481
+ );
4482
+ }
4483
+ var listBeliefsProjection = defineProjection({
4484
+ contractName: "list_beliefs",
4485
+ inputSchema: listBeliefsInputSchema,
4486
+ project: (input) => compactRecord2({
4487
+ topicId: input.topicId,
4488
+ status: kernelStatus(input.status),
4489
+ limit: input.limit,
4490
+ includeEdgeAssociated: input.includeEdgeAssociated
4491
+ }),
4492
+ convexArgsValidator: v.object({
4493
+ topicId: v.string(),
4494
+ status: v.optional(
4495
+ v.union(
4496
+ v.literal("active"),
4497
+ v.literal("superseded"),
4498
+ v.literal("archived")
4499
+ )
4500
+ ),
4501
+ limit: v.optional(v.number()),
4502
+ includeEdgeAssociated: v.optional(v.boolean())
4503
+ })
4504
+ });
4505
+ var taskStatusSchema = z.enum(["todo", "in_progress", "blocked", "done"]).optional().describe("Filter by task status");
4506
+ var listTasksInputSchema = z.object({
4507
+ topicId: z.string().describe("Topic scope"),
4508
+ worktreeId: z.string().optional().describe("Alias for linkedWorktreeId"),
4509
+ linkedWorktreeId: z.string().optional().describe("Filter to tasks linked to this worktree"),
4510
+ status: taskStatusSchema,
4511
+ limit: z.number().optional().describe("Maximum results")
4512
+ });
4513
+ function compactRecord3(input) {
4514
+ return Object.fromEntries(
4515
+ Object.entries(input).filter(([, value]) => value !== void 0)
4516
+ );
4517
+ }
4518
+ var listTasksProjection = defineProjection({
4519
+ contractName: "list_tasks",
4520
+ inputSchema: listTasksInputSchema,
4521
+ project: (input) => compactRecord3({
4522
+ topicId: input.topicId,
4523
+ status: input.status,
4524
+ userId: void 0,
4525
+ limit: input.limit,
4526
+ linkedWorktreeId: input.linkedWorktreeId ?? input.worktreeId
4527
+ }),
4528
+ convexArgsValidator: v.object({
4529
+ topicId: v.string(),
4530
+ status: v.optional(
4531
+ v.union(
4532
+ v.literal("todo"),
4533
+ v.literal("in_progress"),
4534
+ v.literal("blocked"),
4535
+ v.literal("done")
4536
+ )
4537
+ ),
4538
+ limit: v.optional(v.number()),
4539
+ linkedWorktreeId: v.optional(v.string())
4540
+ })
4541
+ });
4542
+ var confidenceTriggerSchema = z.enum([
4543
+ "evidence_added",
4544
+ "evidence_removed",
4545
+ "contradiction_resolved",
4546
+ "agent_assessment",
4547
+ "worktree_outcome",
4548
+ "worktree_completed",
4549
+ "contradiction_detected",
4550
+ "answer_recorded",
4551
+ "fusion",
4552
+ "discount",
4553
+ "deduction",
4554
+ "backfill_synthetic"
4555
+ ]);
4556
+ var provenanceSchema = z.object({
4557
+ evidence: z.string().optional(),
4558
+ question: z.string().optional(),
4559
+ answer: z.string().optional(),
4560
+ contradiction: z.string().optional(),
4561
+ worktree: z.string().optional()
4562
+ });
4563
+ var slOpinionProjectionSchema = z.object({
4564
+ belief: z.number(),
4565
+ disbelief: z.number(),
4566
+ uncertainty: z.number(),
4567
+ baseRate: z.number()
4568
+ });
4569
+ var modulateConfidenceInputObjectSchema = z.object({
4570
+ nodeId: z.string().optional(),
4571
+ beliefNodeId: z.string().optional(),
4572
+ worktreeId: z.string().optional(),
4573
+ opinion: slOpinionProjectionSchema.optional(),
4574
+ belief: z.number().optional(),
4575
+ disbelief: z.number().optional(),
4576
+ uncertainty: z.number().optional(),
4577
+ baseRate: z.number().optional(),
4578
+ trigger: confidenceTriggerSchema,
4579
+ provenance: provenanceSchema.optional(),
4580
+ triggeringEvidenceId: z.string().optional(),
4581
+ triggeringQuestionId: z.string().optional(),
4582
+ triggeringAnswerId: z.string().optional(),
4583
+ triggeringContradictionId: z.string().optional(),
4584
+ triggeringWorktreeId: z.string().optional(),
4585
+ rationale: z.string(),
4586
+ trustedBypassAccessCheck: z.boolean().optional()
4587
+ });
4588
+ var modulateConfidenceInputSchema = modulateConfidenceInputObjectSchema.superRefine((input, ctx) => {
4589
+ if (hasProvenance(input)) {
4590
+ return;
4591
+ }
4592
+ ctx.addIssue({
4593
+ code: z.ZodIssueCode.custom,
4594
+ message: "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance",
4595
+ path: ["provenance"]
4596
+ });
4597
+ });
4598
+ var modulateConfidenceProjection = defineProjection({
4599
+ contractName: "modulate_confidence",
4600
+ inputSchema: modulateConfidenceInputSchema,
4601
+ project: (input) => {
4602
+ const nodeId = input.beliefNodeId ?? input.nodeId;
4603
+ if (!nodeId) {
4604
+ throw new Error("modulate_confidence requires beliefNodeId or nodeId");
4605
+ }
4606
+ const opinion = input.opinion ?? {
4607
+ belief: requireNumber(input.belief, "belief"),
4608
+ disbelief: requireNumber(input.disbelief, "disbelief"),
4609
+ uncertainty: requireNumber(input.uncertainty, "uncertainty"),
4610
+ baseRate: requireNumber(input.baseRate, "baseRate")
4611
+ };
4612
+ assertProvenance(input);
4613
+ return {
4614
+ nodeId,
4615
+ worktreeId: input.worktreeId,
4616
+ belief: opinion.belief,
4617
+ disbelief: opinion.disbelief,
4618
+ uncertainty: opinion.uncertainty,
4619
+ baseRate: opinion.baseRate,
4620
+ trigger: input.trigger === "answer_recorded" ? "agent_assessment" : input.trigger,
4621
+ triggeringEvidenceId: input.provenance?.evidence ?? input.triggeringEvidenceId,
4622
+ triggeringQuestionId: input.provenance?.question ?? input.triggeringQuestionId,
4623
+ triggeringAnswerId: input.provenance?.answer ?? input.triggeringAnswerId,
4624
+ triggeringContradictionId: input.provenance?.contradiction ?? input.triggeringContradictionId,
4625
+ triggeringWorktreeId: input.provenance?.worktree ?? input.triggeringWorktreeId,
4626
+ rationale: input.rationale,
4627
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
4628
+ };
4629
+ },
4630
+ convexArgsValidator: v.object({
4631
+ nodeId: v.string(),
4632
+ worktreeId: v.optional(v.string()),
4633
+ belief: v.number(),
4634
+ disbelief: v.number(),
4635
+ uncertainty: v.number(),
4636
+ baseRate: v.number(),
4637
+ trigger: v.union(
4638
+ v.literal("evidence_added"),
4639
+ v.literal("evidence_removed"),
4640
+ v.literal("worktree_completed"),
4641
+ v.literal("contradiction_detected"),
4642
+ v.literal("contradiction_resolved"),
4643
+ v.literal("agent_assessment"),
4644
+ v.literal("worktree_outcome"),
4645
+ v.literal("fusion"),
4646
+ v.literal("discount"),
4647
+ v.literal("deduction"),
4648
+ v.literal("backfill_synthetic")
4649
+ ),
4650
+ triggeringEvidenceId: v.optional(v.string()),
4651
+ triggeringQuestionId: v.optional(v.string()),
4652
+ triggeringAnswerId: v.optional(v.string()),
4653
+ triggeringContradictionId: v.optional(v.string()),
4654
+ triggeringWorktreeId: v.optional(v.string()),
4655
+ rationale: v.string(),
4656
+ trustedBypassAccessCheck: v.optional(v.boolean())
4657
+ })
4658
+ });
4659
+ function requireNumber(value, field) {
4660
+ if (value === void 0) {
4661
+ throw new Error(`modulate_confidence requires ${field}`);
4662
+ }
4663
+ return value;
4664
+ }
4665
+ function assertProvenance(input) {
4666
+ if (!hasProvenance(input)) {
4667
+ throw new Error(
4668
+ "modulate_confidence requires evidence, question, answer, contradiction, or worktree provenance"
4669
+ );
4670
+ }
4671
+ }
4672
+ function hasProvenance(input) {
4673
+ 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);
4674
+ }
4191
4675
 
4192
4676
  // ../contracts/src/lens-workflow.contract.ts
4193
4677
  var LENS_PERSPECTIVE_TYPES = [
@@ -4201,7 +4685,7 @@ var LENS_PERSPECTIVE_TYPES = [
4201
4685
  // ../contracts/src/tool-contracts.ts
4202
4686
  var CREATE_BELIEF = {
4203
4687
  name: "create_belief",
4204
- 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.",
4688
+ 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.",
4205
4689
  parameters: {
4206
4690
  canonicalText: {
4207
4691
  type: "string",
@@ -4213,7 +4697,7 @@ var CREATE_BELIEF = {
4213
4697
  },
4214
4698
  baseRate: {
4215
4699
  type: "number",
4216
- description: "Required prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time."
4700
+ description: "Prior probability used to seed the vacuous opinion `(0, 0, 1, a)` at creation time. Defaults to 0.5 when omitted."
4217
4701
  },
4218
4702
  beliefType: {
4219
4703
  type: "string",
@@ -4224,7 +4708,7 @@ var CREATE_BELIEF = {
4224
4708
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'] } for coding intelligence)"
4225
4709
  }
4226
4710
  },
4227
- required: ["canonicalText", "baseRate"],
4711
+ required: ["canonicalText"],
4228
4712
  response: {
4229
4713
  description: "The created canonical belief record",
4230
4714
  fields: {
@@ -4287,7 +4771,7 @@ var REFINE_BELIEF = {
4287
4771
  };
4288
4772
  var MODULATE_CONFIDENCE = {
4289
4773
  name: "modulate_confidence",
4290
- 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.",
4774
+ 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.",
4291
4775
  parameters: {
4292
4776
  nodeId: { type: "string", description: "The belief to score" },
4293
4777
  belief: {
@@ -4306,9 +4790,9 @@ var MODULATE_CONFIDENCE = {
4306
4790
  type: "number",
4307
4791
  description: "Subjective-logic base rate `a` in [0, 1]. Required for tuple payloads."
4308
4792
  },
4309
- confidence: {
4310
- type: "number",
4311
- description: "Deprecated scalar confidence value in [0, 1]. Scalar-only payloads are rejected as AMBIGUOUS_SCALAR."
4793
+ worktreeId: {
4794
+ type: "string",
4795
+ description: "Completed worktree that tested this belief when confidence policy requires merge-backed scoring."
4312
4796
  },
4313
4797
  trigger: {
4314
4798
  type: "string",
@@ -4323,17 +4807,43 @@ var MODULATE_CONFIDENCE = {
4323
4807
  "worktree_completed",
4324
4808
  "fusion",
4325
4809
  "discount",
4326
- "deduction",
4327
- "manual",
4328
- "decay"
4810
+ "deduction"
4329
4811
  ]
4330
4812
  },
4813
+ triggeringEvidenceId: {
4814
+ type: "string",
4815
+ description: "Evidence node that caused an evidence-triggered modulation"
4816
+ },
4817
+ triggeringQuestionId: {
4818
+ type: "string",
4819
+ description: "Answered question whose resolution supports this modulation"
4820
+ },
4821
+ triggeringAnswerId: {
4822
+ type: "string",
4823
+ description: "Answer node whose content supports this modulation"
4824
+ },
4825
+ triggeringContradictionId: {
4826
+ type: "string",
4827
+ description: "Contradiction record that caused a contradiction-triggered modulation"
4828
+ },
4829
+ triggeringWorktreeId: {
4830
+ type: "string",
4831
+ description: "Completed worktree whose outcome caused a worktree-triggered modulation"
4832
+ },
4331
4833
  rationale: {
4332
4834
  type: "string",
4333
4835
  description: "Human-readable explanation of why confidence changed"
4334
4836
  }
4335
4837
  },
4336
- required: ["nodeId", "trigger", "rationale"],
4838
+ required: [
4839
+ "nodeId",
4840
+ "belief",
4841
+ "disbelief",
4842
+ "uncertainty",
4843
+ "baseRate",
4844
+ "trigger",
4845
+ "rationale"
4846
+ ],
4337
4847
  response: {
4338
4848
  description: "Confidence modulation result",
4339
4849
  fields: {
@@ -4527,7 +5037,7 @@ var ADD_EVIDENCE = {
4527
5037
  description: "Optional extra metadata merged into the node (e.g., { codeAnchors: ['path/to/file.ts'], failedApproach: true } for coding intelligence)"
4528
5038
  }
4529
5039
  },
4530
- required: ["canonicalText", "targetNodeId"],
5040
+ required: ["canonicalText", "targetNodeId", "reasoning"],
4531
5041
  response: {
4532
5042
  description: "The created evidence node and its edge",
4533
5043
  fields: {
@@ -4608,9 +5118,21 @@ var ADD_WORKTREE = {
4608
5118
  type: "string",
4609
5119
  description: "Optional domain pack whose shaping hooks should influence generated questions and tasks"
4610
5120
  },
4611
- executionOrder: {
5121
+ campaign: {
5122
+ type: "number",
5123
+ description: "Top-level pipeline campaign number. Campaigns define the outer execution slice."
5124
+ },
5125
+ lane: {
5126
+ type: "string",
5127
+ description: "GitButler-aligned workstream lane name inside the campaign."
5128
+ },
5129
+ laneOrderInCampaign: {
5130
+ type: "number",
5131
+ description: "Ordering for this lane within its campaign."
5132
+ },
5133
+ orderInLane: {
4612
5134
  type: "number",
4613
- description: "Global execution order for this worktree"
5135
+ description: "Position of this worktree inside its lane."
4614
5136
  },
4615
5137
  dependsOn: {
4616
5138
  type: "array",
@@ -5268,6 +5790,10 @@ var CREATE_EVIDENCE = {
5268
5790
  type: "object",
5269
5791
  description: "Optional metadata merged into the canonical evidence node"
5270
5792
  },
5793
+ rationale: {
5794
+ type: "string",
5795
+ description: "Why this evidence should enter the reasoning graph"
5796
+ },
5271
5797
  title: { type: "string", description: "Optional short title" },
5272
5798
  content: { type: "string", description: "Optional long-form content" },
5273
5799
  contentType: {
@@ -5276,7 +5802,7 @@ var CREATE_EVIDENCE = {
5276
5802
  },
5277
5803
  kind: { type: "string", description: "Optional evidence kind" }
5278
5804
  },
5279
- required: ["text"],
5805
+ required: ["text", "rationale"],
5280
5806
  response: {
5281
5807
  description: "The created canonical evidence record",
5282
5808
  fields: {
@@ -5324,7 +5850,7 @@ var LIST_EVIDENCE = {
5324
5850
  limit: { type: "number", description: "Max results" },
5325
5851
  cursor: { type: "string", description: "Pagination cursor" }
5326
5852
  },
5327
- required: [],
5853
+ required: ["topicId"],
5328
5854
  response: {
5329
5855
  description: "Canonical evidence page",
5330
5856
  fields: {
@@ -5509,6 +6035,7 @@ var ANSWER_QUESTION = {
5509
6035
  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.",
5510
6036
  parameters: {
5511
6037
  id: { type: "string", description: "Canonical question ID" },
6038
+ topicId: { type: "string", description: "Topic scope for the answer" },
5512
6039
  text: { type: "string", description: "Answer text" },
5513
6040
  confidence: {
5514
6041
  type: "string",
@@ -5521,7 +6048,7 @@ var ANSWER_QUESTION = {
5521
6048
  },
5522
6049
  rationale: { type: "string", description: "Why this answer is credible" }
5523
6050
  },
5524
- required: ["id", "text"],
6051
+ required: ["id", "topicId", "text"],
5525
6052
  response: {
5526
6053
  description: "Answer result",
5527
6054
  fields: {
@@ -5740,6 +6267,10 @@ var LIST_BELIEFS = {
5740
6267
  minConfidence: {
5741
6268
  type: "number",
5742
6269
  description: "Minimum confidence threshold"
6270
+ },
6271
+ limit: {
6272
+ type: "number",
6273
+ description: "Maximum results"
5743
6274
  }
5744
6275
  },
5745
6276
  required: ["topicId"],
@@ -5756,20 +6287,37 @@ var LIST_BELIEFS = {
5756
6287
  };
5757
6288
  var LIST_WORKTREES = {
5758
6289
  name: "list_worktrees",
5759
- 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.",
6290
+ 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.",
5760
6291
  parameters: {
5761
6292
  topicId: { type: "string", description: "Topic scope" },
5762
6293
  status: {
5763
6294
  type: "string",
5764
6295
  description: "Filter: active, merged, abandoned",
5765
6296
  enum: ["active", "merged", "abandoned"]
6297
+ },
6298
+ groupBy: {
6299
+ type: "string",
6300
+ description: "Optional grouping mode for the response.",
6301
+ enum: ["campaign", "lane", "flat"]
6302
+ },
6303
+ lane: {
6304
+ type: "string",
6305
+ description: "Filter by GitButler-aligned lane name."
6306
+ },
6307
+ campaign: {
6308
+ type: "number",
6309
+ description: "Filter by top-level pipeline campaign number."
6310
+ },
6311
+ limit: {
6312
+ type: "number",
6313
+ description: "Maximum results to return."
5766
6314
  }
5767
6315
  },
5768
6316
  required: ["topicId"],
5769
6317
  response: {
5770
- description: "Worktrees with phase, status, belief count, and creation time",
6318
+ description: "Worktrees with lifecycle phase, campaign, lane, status, belief count, and creation time",
5771
6319
  fields: {
5772
- worktrees: "array \u2014 { worktreeId, title, phase, status, beliefCount, createdAt }"
6320
+ worktrees: "array \u2014 { worktreeId, title, phase, campaign, lane, laneOrderInCampaign, orderInLane, status, beliefCount, createdAt }"
5773
6321
  }
5774
6322
  },
5775
6323
  ownerModule: "workflow-engine",
@@ -5778,7 +6326,7 @@ var LIST_WORKTREES = {
5778
6326
  };
5779
6327
  var LIST_ALL_WORKTREES = {
5780
6328
  name: "list_all_worktrees",
5781
- 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.",
6329
+ 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.",
5782
6330
  parameters: {
5783
6331
  status: {
5784
6332
  type: "string",
@@ -5796,13 +6344,18 @@ var LIST_ALL_WORKTREES = {
5796
6344
  "dismissed"
5797
6345
  ]
5798
6346
  },
5799
- track: {
6347
+ lane: {
5800
6348
  type: "string",
5801
- description: "Filter by track name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
6349
+ description: "Filter by lane name (e.g., 'ontology', 'tc-scope', 'control-plane', 'dev-portal', 'mcp-sdk-parity')"
5802
6350
  },
5803
- executionBand: {
6351
+ campaign: {
5804
6352
  type: "number",
5805
- description: "Filter by execution band number (e.g., 1, 2, 3). Returns only worktrees in that parallel execution group."
6353
+ description: "Filter by campaign number (e.g., 1, 2, 3). Returns only worktrees in that campaign."
6354
+ },
6355
+ groupBy: {
6356
+ type: "string",
6357
+ description: "Optional grouping mode for the response.",
6358
+ enum: ["campaign", "lane", "flat"]
5806
6359
  },
5807
6360
  limit: {
5808
6361
  type: "number",
@@ -5813,10 +6366,39 @@ var LIST_ALL_WORKTREES = {
5813
6366
  response: {
5814
6367
  description: "All worktrees across all topics with full pipeline metadata",
5815
6368
  fields: {
5816
- worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, track, trackPosition, executionBand, executionOrder, dependsOn, blocks, gate, createdAt }",
6369
+ worktrees: "array \u2014 { worktreeId, title, topicId, topicName, phase, status, hypothesis, campaign, lane, laneOrderInCampaign, orderInLane, dependsOn, blocks, gate, createdAt }",
5817
6370
  total: "number \u2014 total count after filtering",
5818
- tracks: "object \u2014 { trackName: count } summary of worktrees per track",
5819
- bands: "object \u2014 { bandNumber: count } summary of worktrees per execution band"
6371
+ lanes: "object \u2014 { laneName: count } summary of worktrees per lane",
6372
+ campaigns: "object \u2014 { campaignNumber: count } summary of worktrees per campaign"
6373
+ }
6374
+ },
6375
+ ownerModule: "workflow-engine",
6376
+ ontologyPrimitive: "worktree",
6377
+ tier: "showcase"
6378
+ };
6379
+ var LIST_CAMPAIGNS = {
6380
+ name: "list_campaigns",
6381
+ 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.",
6382
+ parameters: {
6383
+ topicId: {
6384
+ type: "string",
6385
+ description: "Optional topic scope."
6386
+ },
6387
+ status: {
6388
+ type: "string",
6389
+ description: "Optional worktree status filter before grouping campaigns and lanes."
6390
+ },
6391
+ limit: {
6392
+ type: "number",
6393
+ description: "Maximum worktrees to scan before grouping."
6394
+ }
6395
+ },
6396
+ required: [],
6397
+ response: {
6398
+ description: "Pipeline campaigns with nested lane summaries.",
6399
+ fields: {
6400
+ campaigns: "array \u2014 { campaign, lanes: [{ lane, laneOrderInCampaign, worktreeCount, activeCount, readyCount, blockedCount, completedCount, nextWorktree }] }",
6401
+ totalWorktrees: "number \u2014 total worktrees scanned after filtering"
5820
6402
  }
5821
6403
  },
5822
6404
  ownerModule: "workflow-engine",
@@ -5879,16 +6461,28 @@ var UPDATE_WORKTREE_TARGETS = {
5879
6461
  };
5880
6462
  var UPDATE_WORKTREE_METADATA = {
5881
6463
  name: "update_worktree_metadata",
5882
- 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.",
6464
+ 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.",
5883
6465
  parameters: {
5884
6466
  worktreeId: { type: "string", description: "The worktree to update" },
5885
6467
  hypothesis: {
5886
6468
  type: "string",
5887
6469
  description: "Testable claim this worktree investigates"
5888
6470
  },
5889
- executionOrder: {
6471
+ campaign: {
6472
+ type: "number",
6473
+ description: "Top-level pipeline campaign number."
6474
+ },
6475
+ lane: {
6476
+ type: "string",
6477
+ description: "GitButler-aligned workstream lane name inside the campaign."
6478
+ },
6479
+ laneOrderInCampaign: {
6480
+ type: "number",
6481
+ description: "Ordering for this lane within the campaign."
6482
+ },
6483
+ orderInLane: {
5890
6484
  type: "number",
5891
- description: "Global execution order (1 = first, higher = later)"
6485
+ description: "Position of this worktree inside its lane."
5892
6486
  },
5893
6487
  dependsOn: {
5894
6488
  type: "array",
@@ -5926,18 +6520,6 @@ var UPDATE_WORKTREE_METADATA = {
5926
6520
  type: "object",
5927
6521
  description: "Calibrated auto-fix policy controlling dry-run vs safe execution, per-run action caps, and permitted mutation tiers."
5928
6522
  },
5929
- track: {
5930
- type: "string",
5931
- 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."
5932
- },
5933
- trackPosition: {
5934
- type: "number",
5935
- description: "Position within the track (1-indexed). E.g., TC-A=1, TC-B=2, TC-C=3 within the 'tc-scope' track."
5936
- },
5937
- executionBand: {
5938
- type: "number",
5939
- 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."
5940
- },
5941
6523
  status: {
5942
6524
  type: "string",
5943
6525
  description: "Override the worktree status. Use for lifecycle transitions like marking a worktree superseded, long-term, or as a raw idea.",
@@ -6307,6 +6889,10 @@ var LIST_TASKS = {
6307
6889
  type: "string",
6308
6890
  description: "Filter to tasks linked to this worktree"
6309
6891
  },
6892
+ worktreeId: {
6893
+ type: "string",
6894
+ description: "Alias for linkedWorktreeId"
6895
+ },
6310
6896
  status: {
6311
6897
  type: "string",
6312
6898
  description: "Filter by status: todo, in_progress, blocked, done",
@@ -6394,7 +6980,7 @@ var GET_TOPIC = {
6394
6980
  description: "Legacy alias for topicId"
6395
6981
  }
6396
6982
  },
6397
- required: [],
6983
+ required: ["topicId"],
6398
6984
  response: {
6399
6985
  description: "Single topic record",
6400
6986
  fields: {
@@ -6749,7 +7335,7 @@ var GET_ONTOLOGY = {
6749
7335
  description: "Tenant scope for key lookup. Omit for platform-level."
6750
7336
  }
6751
7337
  },
6752
- required: [],
7338
+ required: ["id"],
6753
7339
  response: {
6754
7340
  description: "Ontology definition with latest published version",
6755
7341
  fields: {
@@ -6816,7 +7402,7 @@ var MATCH_ENTITY_TYPE = {
6816
7402
  description: "Optional maximum number of ranked matches to return"
6817
7403
  }
6818
7404
  },
6819
- required: ["text"],
7405
+ required: ["text", "ontologyId"],
6820
7406
  response: {
6821
7407
  description: "Ranked ontology entity type matches",
6822
7408
  fields: {
@@ -7070,7 +7656,7 @@ var RECORD_SCOPE_LEARNING = {
7070
7656
  };
7071
7657
  var PIPELINE_SNAPSHOT = {
7072
7658
  name: "pipeline_snapshot",
7073
- 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.",
7659
+ 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.",
7074
7660
  parameters: {
7075
7661
  topicId: { type: "string", description: "Topic scope ID" }
7076
7662
  },
@@ -7080,14 +7666,14 @@ var PIPELINE_SNAPSHOT = {
7080
7666
  fields: {
7081
7667
  topicId: "string",
7082
7668
  topicName: "string",
7083
- currentBand: "number | null",
7084
- nextBand: "number | null",
7669
+ currentCampaign: "number | null",
7670
+ nextCampaign: "number | null",
7085
7671
  activeWorktrees: "array \u2014 current hinge worktree(s)",
7086
- nextWave: "array \u2014 worktrees in the next planned band",
7672
+ nextWave: "array \u2014 worktrees in the next planned campaign",
7087
7673
  readyNow: "array \u2014 planning worktrees with dependencies completed",
7088
7674
  blockedBy: "array \u2014 grouped blockers",
7089
7675
  criticalPath: "array \u2014 ordered incomplete worktree chain",
7090
- bands: "array \u2014 incomplete worktrees grouped by executionBand",
7676
+ campaigns: "array \u2014 incomplete worktrees grouped by campaign",
7091
7677
  superseded: "array \u2014 worktrees marked superseded or not for activation",
7092
7678
  graphHygiene: "object \u2014 untargeted and taskless worktree debt",
7093
7679
  riskQuestions: "array \u2014 critical/high open questions",
@@ -7676,6 +8262,7 @@ var MCP_TOOL_CONTRACTS = {
7676
8262
  list_beliefs: LIST_BELIEFS,
7677
8263
  list_worktrees: LIST_WORKTREES,
7678
8264
  list_all_worktrees: LIST_ALL_WORKTREES,
8265
+ list_campaigns: LIST_CAMPAIGNS,
7679
8266
  activate_worktree: ACTIVATE_WORKTREE,
7680
8267
  update_worktree_targets: UPDATE_WORKTREE_TARGETS,
7681
8268
  update_worktree_metadata: UPDATE_WORKTREE_METADATA,
@@ -7858,6 +8445,7 @@ var MCP_WORKFLOW_PLATFORM_OPERATION_NAMES = [
7858
8445
  "activate_worktree",
7859
8446
  "list_worktrees",
7860
8447
  "list_all_worktrees",
8448
+ "list_campaigns",
7861
8449
  "update_worktree_targets",
7862
8450
  "update_worktree_metadata",
7863
8451
  "create_task",
@@ -8065,6 +8653,7 @@ var LUCERN_OPERATION_MANIFEST = {
8065
8653
 
8066
8654
  // ../contracts/src/function-registry/helpers.ts
8067
8655
  var jsonObjectSchema = z.record(z.unknown());
8656
+ var sdkSessionIdSchema = z.string().optional();
8068
8657
  function mcpContractShape(contract) {
8069
8658
  const required = new Set(contract.required);
8070
8659
  return Object.fromEntries(
@@ -8099,10 +8688,40 @@ function argsSchemaFromMcpContract(contract) {
8099
8688
  return z.object(mcpContractShape(contract));
8100
8689
  }
8101
8690
  function inputSchemaFromMcpContract(contract) {
8102
- return argsSchemaFromMcpContract(contract).passthrough();
8691
+ return withInternalSurfaceFields(argsSchemaFromMcpContract(contract));
8692
+ }
8693
+ function withInternalSurfaceFields(schema) {
8694
+ return schema.extend({ __sdkSessionId: sdkSessionIdSchema }).strict();
8695
+ }
8696
+ function normalizeInputSchema(schema) {
8697
+ if (schema instanceof z.ZodObject) {
8698
+ return withInternalSurfaceFields(schema);
8699
+ }
8700
+ return schema;
8701
+ }
8702
+ function unwrapObjectSchema(schema) {
8703
+ let current = schema;
8704
+ while (true) {
8705
+ switch (current._def.typeName) {
8706
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8707
+ current = current._def.schema;
8708
+ continue;
8709
+ case z.ZodFirstPartyTypeKind.ZodBranded:
8710
+ current = current._def.type;
8711
+ continue;
8712
+ default:
8713
+ return current instanceof z.ZodObject ? current : void 0;
8714
+ }
8715
+ }
8103
8716
  }
8104
8717
  function getObjectShape(schema) {
8105
- const shape = typeof schema._def.shape === "function" ? schema._def.shape() : schema._def.shape;
8718
+ const objectSchema = unwrapObjectSchema(schema);
8719
+ if (!objectSchema) {
8720
+ throw new Error(
8721
+ `Expected a Zod object schema, received ${schema._def.typeName}.`
8722
+ );
8723
+ }
8724
+ const shape = typeof objectSchema._def.shape === "function" ? objectSchema._def.shape() : objectSchema._def.shape;
8106
8725
  return shape;
8107
8726
  }
8108
8727
  function unwrapMcpParameterSchema(schema) {
@@ -8123,6 +8742,9 @@ function unwrapMcpParameterSchema(schema) {
8123
8742
  case z.ZodFirstPartyTypeKind.ZodBranded:
8124
8743
  current = current._def.type;
8125
8744
  continue;
8745
+ case z.ZodFirstPartyTypeKind.ZodEffects:
8746
+ current = current._def.schema;
8747
+ continue;
8126
8748
  default:
8127
8749
  return { schema: current, required, description: description ?? current.description };
8128
8750
  }
@@ -8142,6 +8764,7 @@ function mcpParameterFromZod(fieldName, schema, contractName) {
8142
8764
  return { parameter: { type: "array", description }, required };
8143
8765
  case z.ZodFirstPartyTypeKind.ZodObject:
8144
8766
  case z.ZodFirstPartyTypeKind.ZodRecord:
8767
+ case z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
8145
8768
  return { parameter: { type: "object", description }, required };
8146
8769
  case z.ZodFirstPartyTypeKind.ZodEnum:
8147
8770
  return {
@@ -8203,6 +8826,14 @@ function withCreatedBy(input, context) {
8203
8826
  createdBy: typeof input.createdBy === "string" ? input.createdBy : authUserId(context)
8204
8827
  };
8205
8828
  }
8829
+ function compactRecord4(input) {
8830
+ return Object.fromEntries(
8831
+ Object.entries(input).filter(([, value]) => value !== void 0)
8832
+ );
8833
+ }
8834
+ function recordValue2(value) {
8835
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
8836
+ }
8206
8837
  function surfaceMcpContract(name) {
8207
8838
  const contract = MCP_TOOL_CONTRACTS[name];
8208
8839
  if (!contract) {
@@ -8247,7 +8878,9 @@ function surfaceContract(args) {
8247
8878
  const canonicalArgs = args.args ?? argsSchemaFromMcpContract(baseMcp);
8248
8879
  const mcp = args.args ? mcpContractFromArgsSchema(baseMcp, canonicalArgs, args.name) : baseMcp;
8249
8880
  const canonicalReturns = args.returns ?? jsonObjectSchema;
8250
- const input = args.input ?? inputSchemaFromMcpContract(mcp);
8881
+ const input = normalizeInputSchema(
8882
+ args.input ?? inputSchemaFromMcpContract(mcp)
8883
+ );
8251
8884
  const output = args.output ?? canonicalReturns;
8252
8885
  return defineFunctionContract({
8253
8886
  name: args.name,
@@ -8309,20 +8942,26 @@ function assertSurfaceCoverage(contracts) {
8309
8942
 
8310
8943
  // ../contracts/src/function-registry/context.ts
8311
8944
  var observationInput = (input, context) => withUserId(
8312
- {
8313
- ...input,
8945
+ compactRecord4({
8946
+ projectId: input.projectId,
8947
+ topicId: input.topicId,
8314
8948
  text: input.text ?? input.summary,
8315
8949
  title: input.title ?? input.summary,
8316
8950
  content: input.content ?? input.summary,
8951
+ contentType: input.contentType,
8317
8952
  kind: input.kind ?? input.observationType ?? "observation",
8318
- sourceType: input.sourceType ?? input.source ?? "agent",
8319
- metadata: {
8320
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
8953
+ tags: input.tags,
8954
+ sourceType: input.sourceType,
8955
+ externalSourceType: input.externalSourceType,
8956
+ sourceUrl: input.sourceUrl,
8957
+ metadata: compactRecord4({
8958
+ ...recordValue2(input.metadata),
8321
8959
  observationType: input.observationType,
8322
8960
  source: input.source
8323
- },
8961
+ }),
8962
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded observation",
8324
8963
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8325
- },
8964
+ }),
8326
8965
  context
8327
8966
  );
8328
8967
  var contextContracts = [
@@ -8374,7 +9013,13 @@ var contextContracts = [
8374
9013
  convex: {
8375
9014
  module: "evidence",
8376
9015
  functionName: "getByTopic",
8377
- kind: "query"
9016
+ kind: "query",
9017
+ inputProjection: (input) => compactRecord4({
9018
+ topicId: input.topicId,
9019
+ limit: input.limit,
9020
+ status: input.status,
9021
+ userId: input.userId
9022
+ })
8378
9023
  }
8379
9024
  })
8380
9025
  ];
@@ -8440,42 +9085,62 @@ var identityContracts = [
8440
9085
  ];
8441
9086
 
8442
9087
  // ../contracts/src/function-registry/beliefs.ts
8443
- var withBeliefId = (input) => ({
8444
- ...input,
9088
+ var beliefLookupInput = (input) => compactRecord4({
8445
9089
  nodeId: input.nodeId ?? input.id ?? input.beliefId,
8446
- beliefId: input.beliefId ?? input.id ?? input.nodeId
9090
+ beliefId: input.beliefId
8447
9091
  });
8448
- var createBeliefInput = (input, context) => withUserId(
8449
- {
8450
- ...input,
8451
- formulation: input.formulation ?? input.canonicalText,
8452
- baseRate: input.baseRate ?? 0.5,
8453
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8454
- },
8455
- context
8456
- );
9092
+ var beliefNodeInput = (input) => compactRecord4({
9093
+ nodeId: input.nodeId ?? input.id ?? input.beliefId
9094
+ });
9095
+ var beliefTopicInput = (input) => {
9096
+ const parsed = listBeliefsProjection.inputSchema.safeParse(input);
9097
+ if (!parsed.success) {
9098
+ throw new Error(
9099
+ `list_beliefs projection input rejected: ${parsed.error.message}`
9100
+ );
9101
+ }
9102
+ return compactRecord4(listBeliefsProjection.project(parsed.data));
9103
+ };
9104
+ var createBeliefInput = (input, context) => {
9105
+ return withUserId(
9106
+ compactRecord4({
9107
+ projectId: input.projectId,
9108
+ topicId: input.topicId,
9109
+ formulation: input.formulation ?? input.canonicalText,
9110
+ beliefType: input.beliefType,
9111
+ rationale: input.rationale,
9112
+ pillar: input.pillar,
9113
+ worktreeId: input.worktreeId,
9114
+ sourceBeliefIds: input.sourceBeliefIds,
9115
+ sourceType: input.sourceType,
9116
+ reversibility: input.reversibility,
9117
+ predictionMeta: input.predictionMeta,
9118
+ baseRate: input.baseRate ?? 0.5,
9119
+ metadata: input.metadata,
9120
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9121
+ }),
9122
+ context
9123
+ );
9124
+ };
8457
9125
  var forkBeliefInput = (input, context) => withUserId(
8458
- {
8459
- ...input,
9126
+ compactRecord4({
8460
9127
  parentNodeId: input.parentNodeId ?? input.nodeId ?? input.id,
9128
+ newFormulation: input.newFormulation,
9129
+ forkReason: input.forkReason,
9130
+ rationale: input.rationale,
8461
9131
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8462
- },
9132
+ }),
8463
9133
  context
8464
9134
  );
8465
9135
  var confidenceInput = (input, context) => {
8466
- const confidence = typeof input.confidence === "number" ? input.confidence : void 0;
8467
- const belief = typeof input.belief === "number" ? input.belief : confidence ?? 0.5;
8468
- const disbelief = typeof input.disbelief === "number" ? input.disbelief : 0;
8469
- const uncertainty = typeof input.uncertainty === "number" ? input.uncertainty : Math.max(0, 1 - belief - disbelief);
9136
+ const parsed = modulateConfidenceProjection.inputSchema.safeParse(input);
9137
+ if (!parsed.success) {
9138
+ throw new Error(
9139
+ `modulate_confidence projection input rejected: ${parsed.error.message}`
9140
+ );
9141
+ }
8470
9142
  return withUserId(
8471
- {
8472
- ...input,
8473
- belief,
8474
- disbelief,
8475
- uncertainty,
8476
- baseRate: input.baseRate ?? 0.5,
8477
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8478
- },
9143
+ compactRecord4(modulateConfidenceProjection.project(parsed.data)),
8479
9144
  context
8480
9145
  );
8481
9146
  };
@@ -8510,7 +9175,7 @@ var beliefsContracts = [
8510
9175
  module: "beliefs",
8511
9176
  functionName: "getById",
8512
9177
  kind: "query",
8513
- inputProjection: withBeliefId
9178
+ inputProjection: beliefLookupInput
8514
9179
  }
8515
9180
  }),
8516
9181
  surfaceContract({
@@ -8526,8 +9191,10 @@ var beliefsContracts = [
8526
9191
  convex: {
8527
9192
  module: "beliefs",
8528
9193
  functionName: "getByTopic",
8529
- kind: "query"
8530
- }
9194
+ kind: "query",
9195
+ inputProjection: beliefTopicInput
9196
+ },
9197
+ args: listBeliefsInputSchema
8531
9198
  }),
8532
9199
  surfaceContract({
8533
9200
  name: "refine_belief",
@@ -8545,7 +9212,7 @@ var beliefsContracts = [
8545
9212
  kind: "mutation",
8546
9213
  inputProjection: (input, context) => withUserId(
8547
9214
  {
8548
- ...withBeliefId(input),
9215
+ ...beliefLookupInput(input),
8549
9216
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8550
9217
  },
8551
9218
  context
@@ -8566,7 +9233,8 @@ var beliefsContracts = [
8566
9233
  functionName: "modulateConfidence",
8567
9234
  kind: "mutation",
8568
9235
  inputProjection: confidenceInput
8569
- }
9236
+ },
9237
+ args: modulateConfidenceInputSchema
8570
9238
  }),
8571
9239
  surfaceContract({
8572
9240
  name: "fork_belief",
@@ -8599,10 +9267,10 @@ var beliefsContracts = [
8599
9267
  functionName: "archive",
8600
9268
  kind: "mutation",
8601
9269
  inputProjection: (input, context) => withUserId(
8602
- {
8603
- ...withBeliefId(input),
9270
+ compactRecord4({
9271
+ ...beliefNodeInput(input),
8604
9272
  reason: input.reason ?? input.rationale
8605
- },
9273
+ }),
8606
9274
  context
8607
9275
  )
8608
9276
  }
@@ -8620,10 +9288,12 @@ var beliefsContracts = [
8620
9288
  module: "nodes",
8621
9289
  functionName: "search",
8622
9290
  kind: "query",
8623
- inputProjection: (input) => ({
8624
- ...input,
9291
+ inputProjection: (input) => compactRecord4({
8625
9292
  searchQuery: input.searchQuery ?? input.query,
8626
- nodeType: "belief"
9293
+ projectId: input.projectId,
9294
+ topicId: input.topicId,
9295
+ nodeType: "belief",
9296
+ limit: input.limit
8627
9297
  })
8628
9298
  }
8629
9299
  }),
@@ -8640,7 +9310,7 @@ var beliefsContracts = [
8640
9310
  module: "beliefs",
8641
9311
  functionName: "getConfidenceHistory",
8642
9312
  kind: "query",
8643
- inputProjection: withBeliefId
9313
+ inputProjection: beliefNodeInput
8644
9314
  }
8645
9315
  }),
8646
9316
  surfaceContract({
@@ -8657,25 +9327,69 @@ var beliefsContracts = [
8657
9327
  module: "beliefs",
8658
9328
  functionName: "getConfidenceHistory",
8659
9329
  kind: "query",
8660
- inputProjection: withBeliefId
9330
+ inputProjection: beliefNodeInput
8661
9331
  }
8662
9332
  })
8663
9333
  ];
8664
9334
 
8665
9335
  // ../contracts/src/function-registry/evidence.ts
8666
- var evidenceIdInput = (input) => ({
8667
- ...input,
8668
- evidenceId: input.evidenceId ?? input.id ?? input.nodeId,
9336
+ var evidenceIdInput = (input) => compactRecord4({
9337
+ evidenceId: input.evidenceId,
9338
+ insightId: input.insightId,
8669
9339
  nodeId: input.nodeId ?? input.id ?? input.evidenceId
8670
9340
  });
8671
- var createEvidenceInput = (input, context) => withUserId(
8672
- {
8673
- ...input,
8674
- title: input.title ?? input.text,
8675
- content: input.content ?? input.text,
8676
- sourceType: input.sourceType ?? input.source ?? "agent",
9341
+ var evidenceTopicInput = (input) => compactRecord4({
9342
+ topicId: input.topicId,
9343
+ status: input.status,
9344
+ userId: input.userId,
9345
+ limit: input.limit
9346
+ });
9347
+ var createEvidenceInput = (input, context) => {
9348
+ const parsed = createEvidenceProjection.inputSchema.safeParse(input);
9349
+ if (!parsed.success) {
9350
+ throw new Error(
9351
+ `create_evidence projection input rejected: ${parsed.error.message}`
9352
+ );
9353
+ }
9354
+ return withUserId(
9355
+ compactRecord4(createEvidenceProjection.project(parsed.data)),
9356
+ context
9357
+ );
9358
+ };
9359
+ var linkEvidenceToBeliefEdgeInput = (input, context) => withCreatedBy(
9360
+ compactRecord4({
9361
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9362
+ toNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
9363
+ edgeType: "evidence_supports_belief",
9364
+ globalId: input.globalId ?? `edge:${String(
9365
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9366
+ )}:${String(
9367
+ input.beliefNodeId ?? input.beliefId ?? input.targetId
9368
+ )}:evidence_supports_belief`,
9369
+ weight: typeof input.weight === "number" ? input.weight : input.type === "contradicting" ? -1 : 1,
9370
+ context: input.rationale ?? input.context,
9371
+ skipLayerValidation: true,
9372
+ topicId: input.topicId,
8677
9373
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8678
- },
9374
+ }),
9375
+ context
9376
+ );
9377
+ var linkEvidenceToQuestionEdgeInput = (input, context) => withCreatedBy(
9378
+ compactRecord4({
9379
+ fromNodeId: input.insightId ?? input.evidenceNodeId ?? input.evidenceId,
9380
+ toNodeId: input.questionId ?? input.questionNodeId ?? input.targetId,
9381
+ edgeType: "evidence_supports_question",
9382
+ globalId: input.globalId ?? `edge:${String(
9383
+ input.insightId ?? input.evidenceNodeId ?? input.evidenceId
9384
+ )}:${String(
9385
+ input.questionId ?? input.questionNodeId ?? input.targetId
9386
+ )}:evidence_supports_question`,
9387
+ weight: input.impactScore ?? input.weight,
9388
+ context: input.rationale ?? input.context,
9389
+ skipLayerValidation: true,
9390
+ topicId: input.topicId,
9391
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
9392
+ }),
8679
9393
  context
8680
9394
  );
8681
9395
  var evidenceContracts = [
@@ -8719,8 +9433,9 @@ var evidenceContracts = [
8719
9433
  linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.targetNodeId ?? input.targetId,
8720
9434
  evidenceRelation: weight < 0 ? "contradicts" : "supports",
8721
9435
  confidence: Math.min(1, Math.max(0, Math.abs(weight))),
9436
+ rationale: input.reasoning,
8722
9437
  metadata: {
8723
- ...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : {},
9438
+ ...recordValue2(input.metadata),
8724
9439
  reasoning: input.reasoning,
8725
9440
  sourceUrl: input.sourceUrl
8726
9441
  }
@@ -8760,7 +9475,8 @@ var evidenceContracts = [
8760
9475
  convex: {
8761
9476
  module: "evidence",
8762
9477
  functionName: "getByTopic",
8763
- kind: "query"
9478
+ kind: "query",
9479
+ inputProjection: evidenceTopicInput
8764
9480
  }
8765
9481
  }),
8766
9482
  surfaceContract({
@@ -8776,10 +9492,12 @@ var evidenceContracts = [
8776
9492
  module: "nodes",
8777
9493
  functionName: "search",
8778
9494
  kind: "query",
8779
- inputProjection: (input) => ({
8780
- ...input,
9495
+ inputProjection: (input) => compactRecord4({
8781
9496
  searchQuery: input.searchQuery ?? input.q ?? input.query,
8782
- nodeType: "evidence"
9497
+ projectId: input.projectId,
9498
+ topicId: input.topicId,
9499
+ nodeType: "evidence",
9500
+ limit: input.limit
8783
9501
  })
8784
9502
  }
8785
9503
  }),
@@ -8793,17 +9511,10 @@ var evidenceContracts = [
8793
9511
  sdkMethod: "linkEvidenceToBelief",
8794
9512
  summary: "Link evidence to a belief.",
8795
9513
  convex: {
8796
- module: "beliefs",
8797
- functionName: "linkEvidence",
9514
+ module: "edges",
9515
+ functionName: "create",
8798
9516
  kind: "mutation",
8799
- inputProjection: (input, context) => withUserId(
8800
- {
8801
- ...input,
8802
- beliefNodeId: input.beliefNodeId ?? input.beliefId ?? input.targetId,
8803
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8804
- },
8805
- context
8806
- )
9517
+ inputProjection: linkEvidenceToBeliefEdgeInput
8807
9518
  }
8808
9519
  }),
8809
9520
  surfaceContract({
@@ -8816,18 +9527,10 @@ var evidenceContracts = [
8816
9527
  sdkMethod: "linkEvidenceToQuestion",
8817
9528
  summary: "Link evidence to a question.",
8818
9529
  convex: {
8819
- module: "questionLinks",
9530
+ module: "edges",
8820
9531
  functionName: "create",
8821
9532
  kind: "mutation",
8822
- inputProjection: (input, context) => withCreatedBy(
8823
- {
8824
- ...input,
8825
- questionId: input.questionId,
8826
- insightId: input.insightId ?? input.evidenceId,
8827
- helpsAnswer: input.helpsAnswer ?? true
8828
- },
8829
- context
8830
- )
9533
+ inputProjection: linkEvidenceToQuestionEdgeInput
8831
9534
  }
8832
9535
  }),
8833
9536
  surfaceContract({
@@ -8840,35 +9543,46 @@ var evidenceContracts = [
8840
9543
  sdkMethod: "linkEvidence",
8841
9544
  summary: "Link evidence to a target node.",
8842
9545
  convex: {
8843
- module: "beliefs",
8844
- functionName: "linkEvidence",
9546
+ module: "edges",
9547
+ functionName: "create",
8845
9548
  kind: "mutation",
8846
- inputProjection: (input, context) => withUserId(
8847
- {
8848
- ...input,
8849
- beliefNodeId: input.beliefNodeId ?? input.targetId,
8850
- evidenceNodeId: input.evidenceNodeId ?? input.evidenceId
8851
- },
8852
- context
8853
- )
9549
+ inputProjection: linkEvidenceToBeliefEdgeInput
8854
9550
  }
8855
9551
  })
8856
9552
  ];
8857
9553
 
8858
9554
  // ../contracts/src/function-registry/questions.ts
8859
- var questionIdInput = (input) => ({
8860
- ...input,
8861
- questionId: input.questionId ?? input.id ?? input.nodeId,
8862
- nodeId: input.nodeId ?? input.id ?? input.questionId
9555
+ var questionNodeInput = (input) => compactRecord4({
9556
+ nodeId: input.nodeId ?? input.id ?? input.questionId,
9557
+ questionId: input.questionId
8863
9558
  });
8864
- var createQuestionInput = (input, context) => withUserId(
8865
- {
8866
- ...input,
8867
- text: input.text ?? input.question,
8868
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
8869
- },
8870
- context
8871
- );
9559
+ var questionTopicInput = (input) => compactRecord4({
9560
+ topicId: input.topicId,
9561
+ status: input.status,
9562
+ userId: input.userId,
9563
+ limit: input.limit
9564
+ });
9565
+ var createQuestionInput = (input, context) => {
9566
+ const priority = input.priority === "urgent" ? "high" : input.priority;
9567
+ return withUserId(
9568
+ compactRecord4({
9569
+ topicId: input.topicId,
9570
+ question: input.question ?? input.text,
9571
+ category: input.category,
9572
+ priority,
9573
+ source: input.source,
9574
+ linkedBeliefNodeId: input.linkedBeliefNodeId ?? input.linkedBeliefId,
9575
+ testType: input.testType,
9576
+ importance: input.importance,
9577
+ epistemicUnlock: input.epistemicUnlock,
9578
+ sourceQuestionIds: input.sourceQuestionIds,
9579
+ linkedWorktreeId: input.linkedWorktreeId,
9580
+ questionType: input.questionType,
9581
+ questionPriority: input.questionPriority
9582
+ }),
9583
+ context
9584
+ );
9585
+ };
8872
9586
  var questionsContracts = [
8873
9587
  surfaceContract({
8874
9588
  name: "create_question",
@@ -8900,7 +9614,7 @@ var questionsContracts = [
8900
9614
  module: "questions",
8901
9615
  functionName: "getById",
8902
9616
  kind: "query",
8903
- inputProjection: questionIdInput
9617
+ inputProjection: questionNodeInput
8904
9618
  }
8905
9619
  }),
8906
9620
  surfaceContract({
@@ -8916,7 +9630,8 @@ var questionsContracts = [
8916
9630
  convex: {
8917
9631
  module: "questions",
8918
9632
  functionName: "getByTopic",
8919
- kind: "query"
9633
+ kind: "query",
9634
+ inputProjection: questionTopicInput
8920
9635
  }
8921
9636
  }),
8922
9637
  surfaceContract({
@@ -8933,7 +9648,12 @@ var questionsContracts = [
8933
9648
  module: "questions",
8934
9649
  functionName: "updateQuestion",
8935
9650
  kind: "mutation",
8936
- inputProjection: (input, context) => withUserId({ ...questionIdInput(input), text: input.text }, context)
9651
+ inputProjection: (input) => compactRecord4({
9652
+ questionId: input.questionId ?? input.id ?? input.nodeId,
9653
+ question: input.question ?? input.text,
9654
+ category: input.category,
9655
+ priority: input.priority
9656
+ })
8937
9657
  }
8938
9658
  }),
8939
9659
  surfaceContract({
@@ -8950,7 +9670,16 @@ var questionsContracts = [
8950
9670
  module: "questions",
8951
9671
  functionName: "updateStatus",
8952
9672
  kind: "mutation",
8953
- inputProjection: (input, context) => withUserId(questionIdInput(input), context)
9673
+ inputProjection: (input, context) => withUserId(
9674
+ compactRecord4({
9675
+ questionId: input.questionId ?? input.id,
9676
+ nodeId: input.nodeId,
9677
+ status: input.status,
9678
+ answer: input.answer,
9679
+ answerStatus: input.answerStatus
9680
+ }),
9681
+ context
9682
+ )
8954
9683
  }
8955
9684
  }),
8956
9685
  surfaceContract({
@@ -8967,7 +9696,12 @@ var questionsContracts = [
8967
9696
  module: "questions",
8968
9697
  functionName: "deleteQuestion",
8969
9698
  kind: "mutation",
8970
- inputProjection: questionIdInput
9699
+ inputProjection: (input, context) => withUserId(
9700
+ compactRecord4({
9701
+ questionId: input.questionId ?? input.id ?? input.nodeId
9702
+ }),
9703
+ context
9704
+ )
8971
9705
  }
8972
9706
  }),
8973
9707
  surfaceContract({
@@ -8984,10 +9718,16 @@ var questionsContracts = [
8984
9718
  functionName: "create",
8985
9719
  kind: "mutation",
8986
9720
  inputProjection: (input, context) => withUserId(
8987
- {
8988
- ...input,
8989
- questionNodeId: input.questionNodeId ?? input.questionId
8990
- },
9721
+ compactRecord4({
9722
+ topicId: input.topicId,
9723
+ questionNodeId: input.questionNodeId ?? input.questionId,
9724
+ answerText: input.answerText,
9725
+ confidence: input.confidence,
9726
+ evidenceNodeIds: input.evidenceNodeIds,
9727
+ answerSource: input.answerSource,
9728
+ worktreeId: input.worktreeId,
9729
+ sprintId: input.sprintId
9730
+ }),
8991
9731
  context
8992
9732
  )
8993
9733
  }
@@ -9007,13 +9747,16 @@ var questionsContracts = [
9007
9747
  functionName: "create",
9008
9748
  kind: "mutation",
9009
9749
  inputProjection: (input, context) => withUserId(
9010
- {
9011
- ...input,
9750
+ compactRecord4({
9751
+ topicId: input.topicId,
9012
9752
  questionNodeId: input.questionNodeId ?? input.questionId ?? input.id,
9013
9753
  answerText: input.answerText ?? input.text,
9014
9754
  evidenceNodeIds: input.evidenceNodeIds ?? input.evidenceIds,
9015
- answerSource: input.answerSource ?? "human"
9016
- },
9755
+ answerSource: input.answerSource ?? "human",
9756
+ confidence: input.confidence,
9757
+ worktreeId: input.worktreeId,
9758
+ sprintId: input.sprintId
9759
+ }),
9017
9760
  context
9018
9761
  )
9019
9762
  }
@@ -9046,7 +9789,8 @@ var questionsContracts = [
9046
9789
  convex: {
9047
9790
  module: "questions",
9048
9791
  functionName: "getByTopic",
9049
- kind: "query"
9792
+ kind: "query",
9793
+ inputProjection: questionTopicInput
9050
9794
  }
9051
9795
  }),
9052
9796
  surfaceContract({
@@ -9061,7 +9805,11 @@ var questionsContracts = [
9061
9805
  convex: {
9062
9806
  module: "questions",
9063
9807
  functionName: "getByTopic",
9064
- kind: "query"
9808
+ kind: "query",
9809
+ inputProjection: (input) => compactRecord4({
9810
+ ...questionTopicInput(input),
9811
+ status: input.includeAnswered === true ? void 0 : "open"
9812
+ })
9065
9813
  }
9066
9814
  }),
9067
9815
  surfaceContract({
@@ -9076,16 +9824,28 @@ var questionsContracts = [
9076
9824
  convex: {
9077
9825
  module: "questions",
9078
9826
  functionName: "getByTopic",
9079
- kind: "query"
9827
+ kind: "query",
9828
+ inputProjection: questionTopicInput
9080
9829
  }
9081
9830
  })
9082
9831
  ];
9083
9832
 
9084
9833
  // ../contracts/src/function-registry/topics.ts
9085
- var topicIdInput = (input) => ({
9086
- ...input,
9834
+ var topicIdInput = (input) => compactRecord4({
9087
9835
  id: input.id ?? input.topicId
9088
9836
  });
9837
+ var updateTopicInput = (input) => compactRecord4({
9838
+ id: input.id ?? input.topicId,
9839
+ name: input.name,
9840
+ description: input.description,
9841
+ type: input.type,
9842
+ status: input.status,
9843
+ visibility: input.visibility,
9844
+ ontologyId: input.ontologyId,
9845
+ clearOntologyId: input.clearOntologyId,
9846
+ graphScopeProjectId: input.graphScopeProjectId,
9847
+ metadata: input.metadata
9848
+ });
9089
9849
  var topicsContracts = [
9090
9850
  surfaceContract({
9091
9851
  name: "create_topic",
@@ -9150,7 +9910,7 @@ var topicsContracts = [
9150
9910
  module: "topics",
9151
9911
  functionName: "update",
9152
9912
  kind: "mutation",
9153
- inputProjection: topicIdInput
9913
+ inputProjection: updateTopicInput
9154
9914
  }
9155
9915
  }),
9156
9916
  surfaceContract({
@@ -9172,6 +9932,27 @@ var topicsContracts = [
9172
9932
  ];
9173
9933
 
9174
9934
  // ../contracts/src/function-registry/lenses.ts
9935
+ var createLensInput = (input, context) => compactRecord4({
9936
+ name: input.name,
9937
+ description: input.description,
9938
+ workspaceId: input.workspaceId,
9939
+ topicId: input.topicId,
9940
+ perspectiveType: input.perspectiveType,
9941
+ promptTemplates: input.promptTemplates,
9942
+ workflowTemplates: input.workflowTemplates,
9943
+ taskTemplates: input.taskTemplates,
9944
+ questionTemplates: input.questionTemplates,
9945
+ filterCriteria: input.filterCriteria,
9946
+ metadata: input.metadata,
9947
+ createdBy: authUserId(context)
9948
+ });
9949
+ var lensListInput = (input, context) => compactRecord4({
9950
+ actorId: input.actorId ?? authUserId(context),
9951
+ workspaceId: input.workspaceId,
9952
+ topicId: input.topicId,
9953
+ status: input.status,
9954
+ perspectiveType: input.perspectiveType
9955
+ });
9175
9956
  var lensesContracts = [
9176
9957
  surfaceContract({
9177
9958
  name: "create_lens",
@@ -9185,7 +9966,8 @@ var lensesContracts = [
9185
9966
  convex: {
9186
9967
  module: "lenses",
9187
9968
  functionName: "create",
9188
- kind: "mutation"
9969
+ kind: "mutation",
9970
+ inputProjection: createLensInput
9189
9971
  }
9190
9972
  }),
9191
9973
  surfaceContract({
@@ -9201,7 +9983,8 @@ var lensesContracts = [
9201
9983
  convex: {
9202
9984
  module: "lenses",
9203
9985
  functionName: "list",
9204
- kind: "query"
9986
+ kind: "query",
9987
+ inputProjection: lensListInput
9205
9988
  }
9206
9989
  }),
9207
9990
  surfaceContract({
@@ -9216,7 +9999,13 @@ var lensesContracts = [
9216
9999
  convex: {
9217
10000
  module: "lenses",
9218
10001
  functionName: "applyToTopic",
9219
- kind: "mutation"
10002
+ kind: "mutation",
10003
+ inputProjection: (input, context) => compactRecord4({
10004
+ lensId: input.lensId,
10005
+ topicId: input.topicId,
10006
+ metadata: input.metadata,
10007
+ appliedBy: authUserId(context)
10008
+ })
9220
10009
  }
9221
10010
  }),
9222
10011
  surfaceContract({
@@ -9232,12 +10021,28 @@ var lensesContracts = [
9232
10021
  convex: {
9233
10022
  module: "lenses",
9234
10023
  functionName: "removeFromTopic",
9235
- kind: "mutation"
10024
+ kind: "mutation",
10025
+ inputProjection: (input, context) => compactRecord4({
10026
+ lensId: input.lensId,
10027
+ topicId: input.topicId,
10028
+ removedBy: authUserId(context)
10029
+ })
9236
10030
  }
9237
10031
  })
9238
10032
  ];
9239
10033
 
9240
10034
  // ../contracts/src/function-registry/ontologies.ts
10035
+ var ontologyIdInput = (input) => compactRecord4({
10036
+ id: input.id ?? input.ontologyId
10037
+ });
10038
+ var ontologyVersionIdInput = (input) => compactRecord4({
10039
+ id: input.id ?? input.versionId,
10040
+ ontologyId: input.ontologyId,
10041
+ actorId: input.actorId
10042
+ });
10043
+ var effectiveOntologyInput = (input) => compactRecord4({
10044
+ ontologyId: input.ontologyId ?? input.id
10045
+ });
9241
10046
  var ontologiesContracts = [
9242
10047
  surfaceContract({
9243
10048
  name: "create_ontology",
@@ -9268,10 +10073,7 @@ var ontologiesContracts = [
9268
10073
  module: "ontologies",
9269
10074
  functionName: "getOntologyDefinition",
9270
10075
  kind: "query",
9271
- inputProjection: (input) => ({
9272
- ...input,
9273
- id: input.id ?? input.ontologyId
9274
- })
10076
+ inputProjection: ontologyIdInput
9275
10077
  }
9276
10078
  }),
9277
10079
  surfaceContract({
@@ -9304,9 +10106,13 @@ var ontologiesContracts = [
9304
10106
  module: "ontologies",
9305
10107
  functionName: "updateOntologyDefinition",
9306
10108
  kind: "mutation",
9307
- inputProjection: (input) => ({
9308
- ...input,
9309
- id: input.id ?? input.ontologyId
10109
+ inputProjection: (input) => compactRecord4({
10110
+ id: input.id ?? input.ontologyId,
10111
+ name: input.name,
10112
+ description: input.description,
10113
+ parentOntologyId: input.parentOntologyId,
10114
+ status: input.status,
10115
+ actorId: input.actorId
9310
10116
  })
9311
10117
  }
9312
10118
  }),
@@ -9324,10 +10130,7 @@ var ontologiesContracts = [
9324
10130
  module: "ontologies",
9325
10131
  functionName: "archiveOntologyDefinition",
9326
10132
  kind: "mutation",
9327
- inputProjection: (input) => ({
9328
- ...input,
9329
- id: input.id ?? input.ontologyId
9330
- })
10133
+ inputProjection: ontologyIdInput
9331
10134
  }
9332
10135
  }),
9333
10136
  surfaceContract({
@@ -9358,8 +10161,7 @@ var ontologiesContracts = [
9358
10161
  module: "topics",
9359
10162
  functionName: "update",
9360
10163
  kind: "mutation",
9361
- inputProjection: (input) => ({
9362
- ...input,
10164
+ inputProjection: (input) => compactRecord4({
9363
10165
  id: input.topicId ?? input.id,
9364
10166
  ontologyId: input.ontologyId ?? input.id
9365
10167
  })
@@ -9377,7 +10179,8 @@ var ontologiesContracts = [
9377
10179
  convex: {
9378
10180
  module: "ontologies",
9379
10181
  functionName: "resolveEffectiveOntology",
9380
- kind: "query"
10182
+ kind: "query",
10183
+ inputProjection: effectiveOntologyInput
9381
10184
  }
9382
10185
  }),
9383
10186
  surfaceContract({
@@ -9393,10 +10196,7 @@ var ontologiesContracts = [
9393
10196
  module: "ontologies",
9394
10197
  functionName: "publishOntologyVersion",
9395
10198
  kind: "mutation",
9396
- inputProjection: (input) => ({
9397
- ...input,
9398
- id: input.id ?? input.versionId
9399
- })
10199
+ inputProjection: ontologyVersionIdInput
9400
10200
  }
9401
10201
  }),
9402
10202
  surfaceContract({
@@ -9412,10 +10212,7 @@ var ontologiesContracts = [
9412
10212
  module: "ontologies",
9413
10213
  functionName: "deprecateOntologyVersion",
9414
10214
  kind: "mutation",
9415
- inputProjection: (input) => ({
9416
- ...input,
9417
- id: input.id ?? input.versionId
9418
- })
10215
+ inputProjection: ontologyVersionIdInput
9419
10216
  }
9420
10217
  }),
9421
10218
  surfaceContract({
@@ -9430,16 +10227,51 @@ var ontologiesContracts = [
9430
10227
  convex: {
9431
10228
  module: "ontologies",
9432
10229
  functionName: "resolveEffectiveOntology",
9433
- kind: "query"
10230
+ kind: "query",
10231
+ inputProjection: effectiveOntologyInput
9434
10232
  }
9435
10233
  })
9436
10234
  ];
9437
10235
 
9438
10236
  // ../contracts/src/function-registry/worktrees.ts
9439
- var worktreeInput = (input) => ({
9440
- ...input,
10237
+ var worktreeIdInput = (input) => compactRecord4({
9441
10238
  worktreeId: input.worktreeId ?? input.id
9442
10239
  });
10240
+ var activateWorktreeInput = (input, context) => withUserId(worktreeIdInput(input), context);
10241
+ var worktreeTargetsInput = (input) => compactRecord4({
10242
+ worktreeId: input.worktreeId ?? input.id,
10243
+ addBeliefIds: input.addBeliefIds,
10244
+ removeBeliefIds: input.removeBeliefIds,
10245
+ addQuestionIds: input.addQuestionIds,
10246
+ removeQuestionIds: input.removeQuestionIds
10247
+ });
10248
+ var worktreeMetadataInput = (input) => compactRecord4({
10249
+ worktreeId: input.worktreeId ?? input.id,
10250
+ topicId: input.topicId,
10251
+ additionalTopicIds: input.additionalTopicIds,
10252
+ status: input.status,
10253
+ campaign: input.campaign,
10254
+ lane: input.lane,
10255
+ laneOrderInCampaign: input.laneOrderInCampaign,
10256
+ orderInLane: input.orderInLane,
10257
+ gate: input.gate,
10258
+ hypothesis: input.hypothesis,
10259
+ objective: input.objective,
10260
+ rationale: input.rationale,
10261
+ proofArtifacts: input.proofArtifacts,
10262
+ staffingHint: input.staffingHint,
10263
+ blocks: input.blocks,
10264
+ dependsOn: input.dependsOn,
10265
+ lensId: input.lensId,
10266
+ autoFixPolicy: input.autoFixPolicy,
10267
+ lastReconciledAt: input.lastReconciledAt
10268
+ });
10269
+ var listAllWorktreesInput = (input) => compactRecord4({
10270
+ status: input.status,
10271
+ lane: input.lane,
10272
+ campaign: input.campaign,
10273
+ limit: input.limit
10274
+ });
9443
10275
  var worktreesContracts = [
9444
10276
  surfaceContract({
9445
10277
  name: "add_worktree",
@@ -9455,11 +10287,43 @@ var worktreesContracts = [
9455
10287
  functionName: "create",
9456
10288
  kind: "mutation",
9457
10289
  inputProjection: (input, context) => withCreatedBy(
9458
- {
9459
- ...input,
10290
+ compactRecord4({
9460
10291
  name: input.name ?? input.title,
9461
- targetBeliefIds: input.targetBeliefIds ?? input.beliefIds
9462
- },
10292
+ topicId: input.topicId,
10293
+ worktreeType: input.worktreeType,
10294
+ objective: input.objective,
10295
+ gate: input.gate,
10296
+ hypothesis: input.hypothesis,
10297
+ rationale: input.rationale,
10298
+ signal: input.signal,
10299
+ startDate: input.startDate,
10300
+ endDate: input.endDate,
10301
+ durationWeeks: input.durationWeeks,
10302
+ confidenceImpact: input.confidenceImpact,
10303
+ autoShape: input.autoShape,
10304
+ autoFixPolicy: input.autoFixPolicy,
10305
+ beliefFocus: input.beliefFocus,
10306
+ targetQuestionIds: input.targetQuestionIds,
10307
+ targetBeliefIds: input.targetBeliefIds ?? input.beliefIds,
10308
+ keyQuestions: input.keyQuestions,
10309
+ proofArtifacts: input.proofArtifacts,
10310
+ decisionGate: input.decisionGate ?? (input.goCriteria || input.noGoSignals ? compactRecord4({
10311
+ goCriteria: input.goCriteria,
10312
+ noGoSignals: input.noGoSignals
10313
+ }) : void 0),
10314
+ evidenceSignals: input.evidenceSignals,
10315
+ dependsOn: input.dependsOn,
10316
+ blocks: input.blocks,
10317
+ campaign: input.campaign,
10318
+ lane: input.lane,
10319
+ laneOrderInCampaign: input.laneOrderInCampaign,
10320
+ orderInLane: input.orderInLane,
10321
+ staffingHint: input.staffingHint,
10322
+ domainPackId: input.domainPackId,
10323
+ lensId: input.lensId,
10324
+ linkedQuestionId: input.linkedQuestionId,
10325
+ lastReconciledAt: input.lastReconciledAt
10326
+ }),
9463
10327
  context
9464
10328
  )
9465
10329
  }
@@ -9477,7 +10341,7 @@ var worktreesContracts = [
9477
10341
  module: "worktrees",
9478
10342
  functionName: "activate",
9479
10343
  kind: "mutation",
9480
- inputProjection: worktreeInput
10344
+ inputProjection: activateWorktreeInput
9481
10345
  }
9482
10346
  }),
9483
10347
  surfaceContract({
@@ -9493,7 +10357,36 @@ var worktreesContracts = [
9493
10357
  convex: {
9494
10358
  module: "worktrees",
9495
10359
  functionName: "list",
9496
- kind: "query"
10360
+ kind: "query",
10361
+ inputProjection: (input) => compactRecord4({
10362
+ topicId: input.topicId,
10363
+ status: input.status,
10364
+ groupBy: input.groupBy,
10365
+ lane: input.lane,
10366
+ campaign: input.campaign,
10367
+ limit: input.limit
10368
+ })
10369
+ }
10370
+ }),
10371
+ surfaceContract({
10372
+ name: "list_campaigns",
10373
+ kind: "query",
10374
+ domain: "worktrees",
10375
+ surfaceClass: "platform_public",
10376
+ method: "GET",
10377
+ path: "/worktrees/campaigns",
10378
+ sdkNamespace: "worktrees",
10379
+ sdkMethod: "listCampaigns",
10380
+ summary: "List compact pipeline campaigns with nested lanes.",
10381
+ convex: {
10382
+ module: "worktrees",
10383
+ functionName: "listCampaigns",
10384
+ kind: "query",
10385
+ inputProjection: (input) => compactRecord4({
10386
+ topicId: input.topicId,
10387
+ status: input.status,
10388
+ limit: input.limit
10389
+ })
9497
10390
  }
9498
10391
  }),
9499
10392
  surfaceContract({
@@ -9509,7 +10402,8 @@ var worktreesContracts = [
9509
10402
  convex: {
9510
10403
  module: "worktrees",
9511
10404
  functionName: "listAll",
9512
- kind: "query"
10405
+ kind: "query",
10406
+ inputProjection: listAllWorktreesInput
9513
10407
  }
9514
10408
  }),
9515
10409
  surfaceContract({
@@ -9526,7 +10420,7 @@ var worktreesContracts = [
9526
10420
  module: "worktrees",
9527
10421
  functionName: "updateTargets",
9528
10422
  kind: "mutation",
9529
- inputProjection: worktreeInput
10423
+ inputProjection: worktreeTargetsInput
9530
10424
  }
9531
10425
  }),
9532
10426
  surfaceContract({
@@ -9543,7 +10437,7 @@ var worktreesContracts = [
9543
10437
  module: "worktrees",
9544
10438
  functionName: "updateMetadata",
9545
10439
  kind: "mutation",
9546
- inputProjection: worktreeInput
10440
+ inputProjection: worktreeMetadataInput
9547
10441
  }
9548
10442
  }),
9549
10443
  surfaceContract({
@@ -9559,12 +10453,17 @@ var worktreesContracts = [
9559
10453
  module: "worktrees",
9560
10454
  functionName: "complete",
9561
10455
  kind: "mutation",
9562
- inputProjection: (input) => ({
9563
- ...worktreeInput(input),
9564
- keyFindings: input.keyFindings ?? [input.summary ?? "Merged worktree"],
9565
- decisionsReached: input.decisionsReached ?? [],
9566
- nextSteps: input.nextSteps ?? []
9567
- })
10456
+ inputProjection: (input, context) => withUserId(
10457
+ {
10458
+ ...worktreeIdInput(input),
10459
+ keyFindings: input.keyFindings ?? [
10460
+ input.summary ?? "Merged worktree"
10461
+ ],
10462
+ decisionsReached: input.decisionsReached ?? [],
10463
+ nextSteps: input.nextSteps ?? []
10464
+ },
10465
+ context
10466
+ )
9568
10467
  }
9569
10468
  }),
9570
10469
  surfaceContract({
@@ -9580,11 +10479,7 @@ var worktreesContracts = [
9580
10479
  module: "worktrees",
9581
10480
  functionName: "updateMetadata",
9582
10481
  kind: "mutation",
9583
- inputProjection: (input) => ({
9584
- ...worktreeInput(input),
9585
- lastPushTargetContext: input.targetContext,
9586
- lastPushBeliefIds: input.beliefIds
9587
- })
10482
+ inputProjection: worktreeMetadataInput
9588
10483
  }
9589
10484
  }),
9590
10485
  surfaceContract({
@@ -9600,20 +10495,30 @@ var worktreesContracts = [
9600
10495
  module: "worktrees",
9601
10496
  functionName: "updateMetadata",
9602
10497
  kind: "mutation",
9603
- inputProjection: (input) => ({
9604
- ...worktreeInput(input),
9605
- lastPullRequestSummary: input.summary,
9606
- lastPullRequestReviewers: input.reviewers
9607
- })
10498
+ inputProjection: worktreeMetadataInput
9608
10499
  }
9609
10500
  })
9610
10501
  ];
9611
10502
 
9612
10503
  // ../contracts/src/function-registry/tasks.ts
9613
- var taskInput = (input) => ({
10504
+ var taskInput = (input) => compactRecord4({
9614
10505
  ...input,
9615
10506
  taskId: input.taskId ?? input.id
9616
10507
  });
10508
+ var taskTopicInput = (input) => {
10509
+ const parsed = listTasksProjection.inputSchema.safeParse(input);
10510
+ if (!parsed.success) {
10511
+ throw new Error(
10512
+ `list_tasks projection input rejected: ${parsed.error.message}`
10513
+ );
10514
+ }
10515
+ return compactRecord4(listTasksProjection.project(parsed.data));
10516
+ };
10517
+ var completeTaskInput = (input) => compactRecord4({
10518
+ taskId: input.taskId ?? input.id,
10519
+ outputSummary: input.outputSummary ?? input.summary,
10520
+ userId: input.userId
10521
+ });
9617
10522
  var tasksContracts = [
9618
10523
  surfaceContract({
9619
10524
  name: "create_task",
@@ -9643,8 +10548,10 @@ var tasksContracts = [
9643
10548
  convex: {
9644
10549
  module: "tasks",
9645
10550
  functionName: "getByTopic",
9646
- kind: "query"
9647
- }
10551
+ kind: "query",
10552
+ inputProjection: taskTopicInput
10553
+ },
10554
+ args: listTasksInputSchema
9648
10555
  }),
9649
10556
  surfaceContract({
9650
10557
  name: "update_task",
@@ -9676,12 +10583,29 @@ var tasksContracts = [
9676
10583
  module: "tasks",
9677
10584
  functionName: "complete",
9678
10585
  kind: "mutation",
9679
- inputProjection: taskInput
10586
+ inputProjection: completeTaskInput
9680
10587
  }
9681
10588
  })
9682
10589
  ];
9683
-
9684
- // ../contracts/src/function-registry/edges.ts
10590
+ var createEdgeArgs = z.object({
10591
+ from: GraphRefSchema,
10592
+ to: GraphRefSchema,
10593
+ edgeType: z.string(),
10594
+ globalId: z.string().optional(),
10595
+ weight: z.number().optional(),
10596
+ confidence: z.number().optional(),
10597
+ context: z.string().optional(),
10598
+ reasoning: z.string().optional(),
10599
+ derivationType: z.string().optional(),
10600
+ topicId: z.string().optional(),
10601
+ trustedBypassAccessCheck: z.boolean().optional()
10602
+ });
10603
+ function graphRefNodeId(ref) {
10604
+ if (ref.kind === "epistemic_node") {
10605
+ return ref.nodeId;
10606
+ }
10607
+ return `external_belief:${ref.ref.tenantId}:${ref.ref.beliefId}`;
10608
+ }
9685
10609
  var edgesContracts = [
9686
10610
  surfaceContract({
9687
10611
  name: "create_edge",
@@ -9696,16 +10620,35 @@ var edgesContracts = [
9696
10620
  module: "edges",
9697
10621
  functionName: "create",
9698
10622
  kind: "mutation",
9699
- inputProjection: (input, context) => withCreatedBy(
9700
- {
9701
- ...input,
9702
- fromNodeId: input.fromNodeId ?? input.sourceId,
9703
- toNodeId: input.toNodeId ?? input.targetId,
9704
- context: input.context ?? input.reasoning
9705
- },
9706
- context
9707
- )
9708
- }
10623
+ inputProjection: (input, context) => {
10624
+ const parsed = createEdgeArgs.parse(input);
10625
+ assertEdgePolicyAllowed(
10626
+ edgePolicyManifest,
10627
+ parsed.edgeType,
10628
+ parsed.from,
10629
+ parsed.to
10630
+ );
10631
+ const fromNodeId = graphRefNodeId(parsed.from);
10632
+ const toNodeId = graphRefNodeId(parsed.to);
10633
+ return withCreatedBy(
10634
+ compactRecord4({
10635
+ fromNodeId,
10636
+ toNodeId,
10637
+ edgeType: parsed.edgeType,
10638
+ globalId: parsed.globalId ?? `edge:${fromNodeId}:${toNodeId}:${parsed.edgeType}`,
10639
+ weight: parsed.weight,
10640
+ confidence: parsed.confidence,
10641
+ context: parsed.context ?? parsed.reasoning,
10642
+ derivationType: parsed.derivationType,
10643
+ skipLayerValidation: true,
10644
+ topicId: parsed.topicId,
10645
+ trustedBypassAccessCheck: parsed.trustedBypassAccessCheck
10646
+ }),
10647
+ context
10648
+ );
10649
+ }
10650
+ },
10651
+ args: createEdgeArgs
9709
10652
  }),
9710
10653
  surfaceContract({
9711
10654
  name: "query_lineage",
@@ -9720,9 +10663,12 @@ var edgesContracts = [
9720
10663
  module: "edges",
9721
10664
  functionName: "getLineage",
9722
10665
  kind: "query",
9723
- inputProjection: (input) => ({
9724
- ...input,
9725
- maxDepth: input.maxDepth ?? input.depth
10666
+ inputProjection: (input) => compactRecord4({
10667
+ nodeId: input.nodeId ?? input.startNode,
10668
+ maxDepth: input.maxDepth ?? input.depth,
10669
+ mode: input.mode,
10670
+ minLayer: input.minLayer,
10671
+ maxLayer: input.maxLayer
9726
10672
  })
9727
10673
  }
9728
10674
  })
@@ -9742,8 +10688,7 @@ var contradictionSeverity = (value) => {
9742
10688
  return "significant";
9743
10689
  }
9744
10690
  };
9745
- var flagContradictionInput = (input, context) => ({
9746
- ...input,
10691
+ var flagContradictionInput = (input, context) => compactRecord4({
9747
10692
  beliefId: input.beliefId ?? input.beliefA,
9748
10693
  supportingInsightIds: Array.isArray(input.supportingInsightIds) ? input.supportingInsightIds : [],
9749
10694
  contradictingInsightIds: Array.isArray(input.contradictingInsightIds) ? input.contradictingInsightIds : [input.beliefB].filter((value) => typeof value === "string"),
@@ -9757,6 +10702,18 @@ var flagContradictionInput = (input, context) => ({
9757
10702
  },
9758
10703
  createdBy: authUserId(context)
9759
10704
  });
10705
+ var lineageInput = (input) => compactRecord4({
10706
+ nodeId: input.nodeId ?? input.startNode ?? input.entityId,
10707
+ maxDepth: input.maxDepth ?? input.depth,
10708
+ mode: input.mode,
10709
+ minLayer: input.minLayer,
10710
+ maxLayer: input.maxLayer
10711
+ });
10712
+ var topicEdgesInput = (input) => compactRecord4({
10713
+ topicId: input.topicId,
10714
+ userId: input.userId,
10715
+ limit: input.limit
10716
+ });
9760
10717
  var graphContracts = [
9761
10718
  surfaceContract({
9762
10719
  name: "traverse_graph",
@@ -9770,7 +10727,8 @@ var graphContracts = [
9770
10727
  convex: {
9771
10728
  module: "edges",
9772
10729
  functionName: "getLineage",
9773
- kind: "query"
10730
+ kind: "query",
10731
+ inputProjection: lineageInput
9774
10732
  }
9775
10733
  }),
9776
10734
  surfaceContract({
@@ -9785,7 +10743,8 @@ var graphContracts = [
9785
10743
  convex: {
9786
10744
  module: "edges",
9787
10745
  functionName: "getByTopic",
9788
- kind: "query"
10746
+ kind: "query",
10747
+ inputProjection: topicEdgesInput
9789
10748
  }
9790
10749
  }),
9791
10750
  surfaceContract({
@@ -9815,7 +10774,10 @@ var graphContracts = [
9815
10774
  convex: {
9816
10775
  module: "edges",
9817
10776
  functionName: "findContradictions",
9818
- kind: "query"
10777
+ kind: "query",
10778
+ inputProjection: (input) => compactRecord4({
10779
+ nodeId: input.nodeId ?? input.beliefId
10780
+ })
9819
10781
  }
9820
10782
  }),
9821
10783
  surfaceContract({
@@ -9920,8 +10882,9 @@ var graphContracts = [
9920
10882
  summary: "Discover graph connections for an entity.",
9921
10883
  convex: {
9922
10884
  module: "edges",
9923
- functionName: "getByTopic",
9924
- kind: "query"
10885
+ functionName: "getLineage",
10886
+ kind: "query",
10887
+ inputProjection: lineageInput
9925
10888
  }
9926
10889
  }),
9927
10890
  surfaceContract({
@@ -9952,10 +10915,7 @@ var graphContracts = [
9952
10915
  module: "edges",
9953
10916
  functionName: "getLineage",
9954
10917
  kind: "query",
9955
- inputProjection: (input) => ({
9956
- ...input,
9957
- nodeId: input.nodeId ?? input.entityId
9958
- })
10918
+ inputProjection: lineageInput
9959
10919
  }
9960
10920
  })
9961
10921
  ];
@@ -10025,19 +10985,21 @@ var judgmentsContracts = [
10025
10985
  functionName: "create",
10026
10986
  kind: "mutation",
10027
10987
  inputProjection: (input, context) => withUserId(
10028
- {
10029
- ...input,
10988
+ compactRecord4({
10989
+ projectId: input.projectId,
10990
+ topicId: input.topicId,
10030
10991
  text: input.rationale,
10031
10992
  title: input.title,
10032
10993
  content: input.rationale,
10033
10994
  kind: "judgment",
10034
- sourceType: "agent",
10035
- metadata: {
10995
+ sourceType: "ai_generated",
10996
+ metadata: compactRecord4({
10036
10997
  confidence: input.confidence,
10037
10998
  beliefIds: input.beliefIds
10038
- },
10999
+ }),
11000
+ rationale: input.rationale ?? input.reasoning ?? "Recorded judgment evidence",
10039
11001
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10040
- },
11002
+ }),
10041
11003
  context
10042
11004
  )
10043
11005
  }
@@ -10055,9 +11017,12 @@ var judgmentsContracts = [
10055
11017
  module: "edges",
10056
11018
  functionName: "getLineage",
10057
11019
  kind: "query",
10058
- inputProjection: (input) => ({
10059
- ...input,
10060
- nodeId: input.nodeId ?? input.id
11020
+ inputProjection: (input) => compactRecord4({
11021
+ nodeId: input.nodeId ?? input.id,
11022
+ maxDepth: input.maxDepth ?? input.depth,
11023
+ mode: input.mode,
11024
+ minLayer: input.minLayer,
11025
+ maxLayer: input.maxLayer
10061
11026
  })
10062
11027
  }
10063
11028
  })
@@ -10183,7 +11148,10 @@ var coordinationContracts = [
10183
11148
  module: "coordination",
10184
11149
  functionName: "getInbox",
10185
11150
  kind: "query",
10186
- injectSessionId: "sessionId"
11151
+ injectSessionId: "sessionId",
11152
+ inputProjection: (input) => compactRecord4({
11153
+ limit: input.limit
11154
+ })
10187
11155
  }
10188
11156
  }),
10189
11157
  surfaceContract({
@@ -10201,7 +11169,6 @@ var coordinationContracts = [
10201
11169
  kind: "mutation",
10202
11170
  injectSessionId: "sessionId",
10203
11171
  inputProjection: (input) => ({
10204
- ...input,
10205
11172
  touchedFiles: stringArray(input.touchedFiles) ?? stringArray(input.files) ?? stringArray(input.paths) ?? []
10206
11173
  })
10207
11174
  }
@@ -10218,7 +11185,10 @@ var coordinationContracts = [
10218
11185
  convex: {
10219
11186
  module: "worktrees",
10220
11187
  functionName: "get",
10221
- kind: "query"
11188
+ kind: "query",
11189
+ inputProjection: (input) => compactRecord4({
11190
+ worktreeId: input.worktreeId ?? input.id
11191
+ })
10222
11192
  }
10223
11193
  })
10224
11194
  ];
@@ -10237,7 +11207,13 @@ var pipelineContracts = [
10237
11207
  convex: {
10238
11208
  module: "worktrees",
10239
11209
  functionName: "listAll",
10240
- kind: "query"
11210
+ kind: "query",
11211
+ inputProjection: (input) => compactRecord4({
11212
+ status: input.status,
11213
+ lane: input.lane,
11214
+ campaign: input.campaign,
11215
+ limit: input.limit
11216
+ })
10241
11217
  }
10242
11218
  }),
10243
11219
  surfaceContract({
@@ -10287,43 +11263,63 @@ var recordScopeLearningArgs = z.object({
10287
11263
  linkedBeliefNodeId: z.string().optional().describe("Optional belief to attach evidence to"),
10288
11264
  evidenceRelation: z.enum(["supports", "contradicts"]).optional().describe("Relation to linked belief"),
10289
11265
  confidence: z.number().optional().describe("Optional confidence in [0,1]"),
11266
+ rationale: z.string().optional().describe("Why this learning should enter the reasoning graph"),
10290
11267
  createQuestionText: z.string().optional().describe("Optional follow-up question text"),
10291
11268
  createBeliefText: z.string().optional().describe("Optional new belief text"),
10292
11269
  beliefType: z.string().optional().describe("Optional belief type for createBeliefText")
10293
11270
  });
10294
- var learningInput = (input, context) => withUserId(
10295
- {
10296
- ...input,
10297
- text: input.summary ?? input.text,
10298
- title: input.title ?? input.summary ?? "Scope learning",
10299
- content: input.body ?? input.content ?? input.summary,
10300
- kind: input.kind ?? input.sourceKind ?? "learning",
10301
- tags: input.tags ?? [],
10302
- metadata: {
10303
- sourceRef: input.sourceRef,
10304
- sourceKind: input.sourceKind,
10305
- touchedPaths: input.touchedPaths
10306
- },
10307
- trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10308
- },
10309
- context
10310
- );
11271
+ var learningInput = (input, context) => {
11272
+ const sourceKind = input.sourceKind ?? input.externalSourceType;
11273
+ return withUserId(
11274
+ compactRecord4({
11275
+ projectId: input.projectId,
11276
+ topicId: input.topicId,
11277
+ text: input.summary ?? input.text,
11278
+ title: input.title ?? input.summary ?? "Scope learning",
11279
+ content: input.body ?? input.content ?? input.summary,
11280
+ contentType: input.contentType,
11281
+ kind: input.kind ?? "learning",
11282
+ tags: input.tags ?? [],
11283
+ sourceType: input.sourceType,
11284
+ externalSourceType: input.externalSourceType ?? input.sourceKind,
11285
+ sourceUrl: input.sourceUrl,
11286
+ metadata: compactRecord4({
11287
+ ...recordValue2(input.metadata),
11288
+ sourceRef: input.sourceRef,
11289
+ sourceKind,
11290
+ touchedPaths: input.touchedPaths,
11291
+ createQuestionText: input.createQuestionText,
11292
+ createBeliefText: input.createBeliefText,
11293
+ beliefType: input.beliefType
11294
+ }),
11295
+ linkedBeliefNodeId: input.linkedBeliefNodeId,
11296
+ evidenceRelation: input.evidenceRelation,
11297
+ confidence: input.confidence,
11298
+ rationale: input.rationale ?? input.reasoning ?? input.summary ?? input.text ?? "Recorded scope learning",
11299
+ trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
11300
+ }),
11301
+ context
11302
+ );
11303
+ };
10311
11304
  var attemptInput = (input, context) => withUserId(
10312
- {
10313
- ...input,
11305
+ compactRecord4({
11306
+ projectId: input.projectId,
11307
+ topicId: input.topicId,
10314
11308
  text: input.description,
10315
11309
  title: input.title ?? input.description,
10316
11310
  content: input.errorMessage ?? input.description,
10317
11311
  kind: "code_attempt",
10318
11312
  tags: ["code_attempt"],
10319
- metadata: {
11313
+ metadata: compactRecord4({
11314
+ ...recordValue2(input.metadata),
10320
11315
  filePaths: input.filePaths,
10321
11316
  filePath: input.filePath,
10322
11317
  errorMessage: input.errorMessage,
10323
11318
  linkedBeliefId: input.linkedBeliefId
10324
- },
11319
+ }),
11320
+ rationale: input.rationale ?? input.reasoning ?? input.errorMessage ?? input.description ?? "Recorded implementation attempt",
10325
11321
  trustedBypassAccessCheck: input.trustedBypassAccessCheck ?? true
10326
- },
11322
+ }),
10327
11323
  context
10328
11324
  );
10329
11325
  var codingContracts = [
@@ -10380,7 +11376,13 @@ var codingContracts = [
10380
11376
  convex: {
10381
11377
  module: "evidence",
10382
11378
  functionName: "getByTopic",
10383
- kind: "query"
11379
+ kind: "query",
11380
+ inputProjection: (input) => compactRecord4({
11381
+ topicId: input.topicId,
11382
+ limit: input.limit,
11383
+ status: input.status,
11384
+ userId: input.userId
11385
+ })
10384
11386
  }
10385
11387
  }),
10386
11388
  surfaceContract({
@@ -10395,7 +11397,13 @@ var codingContracts = [
10395
11397
  convex: {
10396
11398
  module: "evidence",
10397
11399
  functionName: "getByTopic",
10398
- kind: "query"
11400
+ kind: "query",
11401
+ inputProjection: (input) => compactRecord4({
11402
+ topicId: input.topicId,
11403
+ limit: input.limit,
11404
+ status: input.status,
11405
+ userId: input.userId
11406
+ })
10399
11407
  }
10400
11408
  }),
10401
11409
  surfaceContract({
@@ -10427,9 +11435,11 @@ var codingContracts = [
10427
11435
  module: "evidence",
10428
11436
  functionName: "getByTopic",
10429
11437
  kind: "query",
10430
- inputProjection: (input) => ({
10431
- ...input,
10432
- topicId: input.topicId ?? input.query
11438
+ inputProjection: (input) => compactRecord4({
11439
+ topicId: input.topicId ?? input.query,
11440
+ limit: input.limit,
11441
+ status: input.status,
11442
+ userId: input.userId
10433
11443
  })
10434
11444
  }
10435
11445
  })