dxcomplete 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +0 -7
- package/README.md +68 -103
- package/dist/cli.js +2 -24
- package/dist/validate.js +10 -26
- package/docs/cost-model.md +2 -2
- package/docs/decision-basis.md +5 -11
- package/docs/diagrams.md +3 -3
- package/docs/index.md +25 -39
- package/docs/model.md +15 -23
- package/docs/open-questions.md +1 -1
- package/docs/taxonomy.md +7 -8
- package/docs/workflows.md +3 -3
- package/package.json +24 -24
- package/templates/process/README.md +11 -11
- package/templates/process/controls.yml +19 -19
- package/templates/process/cost-model.yml +3 -3
- package/templates/process/decision-basis.yml +4 -4
- package/templates/process/diagrams/00-decision-basis.mmd +1 -1
- package/templates/process/diagrams/00-overview.mmd +1 -1
- package/templates/process/diagrams/01-intake-triage.mmd +4 -4
- package/templates/process/diagrams/02-product-definition.mmd +3 -3
- package/templates/process/diagrams/03-engineering-execution.mmd +1 -1
- package/templates/process/diagrams/04-qa-verification.mmd +1 -1
- package/templates/process/diagrams/05-product-validation.mmd +1 -1
- package/templates/process/diagrams/06-change-release-control.mmd +1 -1
- package/templates/process/diagrams/07-deployment-operations.mmd +1 -1
- package/templates/process/diagrams/08-support-incident-management.mmd +1 -1
- package/templates/process/diagrams/09-problem-improvement.mmd +1 -1
- package/templates/process/diagrams/10-risk-control-management.mmd +1 -1
- package/templates/process/diagrams/11-audit-evidence-capture.mmd +1 -1
- package/templates/process/roles.yml +6 -6
- package/templates/process/taxonomy.yml +46 -46
- package/templates/process/workflows.yml +29 -29
- package/website/account.html +57 -0
- package/website/app.js +177 -0
- package/website/flow.html +4 -0
- package/website/glossary.html +4 -0
- package/website/index.html +4 -0
- package/website/objects.html +4 -0
- package/website/operating-guide.html +4 -0
- package/website/outcomes.html +4 -0
- package/website/phase-build.html +4 -0
- package/website/phase-elicit.html +4 -0
- package/website/phase-go-live.html +4 -0
- package/website/phase-measure.html +4 -0
- package/website/phase-operate.html +4 -0
- package/website/phase-orient.html +4 -0
- package/website/phase-weigh.html +4 -0
- package/website/roles.html +4 -0
- package/website/styles.css +217 -1
- package/dist/http/service.d.ts +0 -7
- package/dist/http/service.js +0 -725
- package/dist/mcp/docs.d.ts +0 -114
- package/dist/mcp/docs.js +0 -626
- package/dist/mcp/server.d.ts +0 -20
- package/dist/mcp/server.js +0 -3059
- package/dist/runtime/auth.d.ts +0 -162
- package/dist/runtime/auth.js +0 -394
- package/dist/runtime/check.d.ts +0 -7
- package/dist/runtime/check.js +0 -16
- package/dist/runtime/config.d.ts +0 -17
- package/dist/runtime/config.js +0 -93
- package/dist/runtime/mongo.d.ts +0 -9
- package/dist/runtime/mongo.js +0 -56
- package/dist/runtime/records.d.ts +0 -427
- package/dist/runtime/records.js +0 -2092
- package/scripts/check-env-surface.mjs +0 -136
- package/scripts/check-public-copy.mjs +0 -263
- package/scripts/check-service-boundary.mjs +0 -63
- package/scripts/runtime-work-order.mjs +0 -506
- package/scripts/smoke-mcp-http.mjs +0 -4026
- package/src/cli.ts +0 -268
- package/src/http/server.ts +0 -314
- package/src/http/service.ts +0 -934
- package/src/init.ts +0 -262
- package/src/install-manifest.ts +0 -144
- package/src/mcp/docs.ts +0 -777
- package/src/mcp/server.ts +0 -4580
- package/src/package-root.ts +0 -31
- package/src/runtime/actor.ts +0 -61
- package/src/runtime/auth.ts +0 -673
- package/src/runtime/check.ts +0 -18
- package/src/runtime/config.ts +0 -128
- package/src/runtime/mongo.ts +0 -89
- package/src/runtime/records.ts +0 -3205
- package/src/runtime/workspace.ts +0 -155
- package/src/upgrade.ts +0 -356
- package/src/validate.ts +0 -141
- package/src/version.ts +0 -16
package/dist/mcp/server.js
DELETED
|
@@ -1,3059 +0,0 @@
|
|
|
1
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
-
import * as z from "zod/v4";
|
|
4
|
-
import { DOC_PAGE_IDS, DOC_REFERENCE, getDocReference } from "./docs.js";
|
|
5
|
-
import { createLocalActorContext } from "../runtime/actor.js";
|
|
6
|
-
import { DXCOMPLETE_PACKAGE_VERSION, MCP_SURFACE_ID, WORKSPACE_COMPATIBILITY_VERSION } from "../version.js";
|
|
7
|
-
import { COLLECTION_NAMES, RUNTIME_ACTOR_ID, appendChangeEvent, appendDecisionEntry, appendDeferralEvent, appendIncidentEntry, appendJournalNote, appendJournalSummary, appendProblemEntry, appendReviewNote, appendRiskEntry, appendSupportRequestEntry, appendTaskEntry, archiveRecord, appendDxcompleteTicket, archiveDxcompleteTicket, decisionEntryToCurrentDecision, createDxcompleteTicket, createRecord, getJournalEntry, getRecord, incidentEntryToCurrentSeverity, incidentEntryToCurrentStatus, linkRecords, listDxcompleteTickets, listLinkedRecords, listUnreadDxcompleteTicketReplies, listRecords, readJournal, readDxcompleteTicket, problemEntryToCurrentStatus, riskEntryToCurrentAssessment, riskEntryToCurrentStatus, riskEntryToCurrentTreatment, supportRequestEntryToCurrentStatus, taskEntryToCurrentStatus, unlinkRecords, updateRecord } from "../runtime/records.js";
|
|
8
|
-
const collectionSchema = z.enum(COLLECTION_NAMES);
|
|
9
|
-
const workspaceScopedCollectionNames = COLLECTION_NAMES.filter((name) => name !== "workspaces");
|
|
10
|
-
const hostedCollectionSchema = z.enum(workspaceScopedCollectionNames);
|
|
11
|
-
const amountSchema = z.number().finite().optional();
|
|
12
|
-
const requiredAmountSchema = z.number().finite().nonnegative();
|
|
13
|
-
const currencySchema = z.string().min(3).max(12).optional();
|
|
14
|
-
const requiredCurrencySchema = z.string().min(3).max(12);
|
|
15
|
-
const workspaceIdSchema = z.string().min(1);
|
|
16
|
-
const workspaceModeSchema = z.enum(["transformation", "greenfield", "limited-disclosure"]);
|
|
17
|
-
const expectationApprovalStateSchema = z.enum(["draft", "approved", "not_approved", "superseded"]);
|
|
18
|
-
const requirementStatusSchema = z.enum(["draft", "ready", "approved", "superseded"]);
|
|
19
|
-
const taskStatusSchema = z.enum(["open", "in_progress", "blocked", "done"]);
|
|
20
|
-
const decisionEntryTypeSchema = z.enum(["argument", "decision", "note"]);
|
|
21
|
-
const taskEntryTypeSchema = z.enum(["comment", "status_change", "note"]);
|
|
22
|
-
const riskEntryTypeSchema = z.enum(["identified", "assessment", "treatment", "monitor_note", "closed", "reopened"]);
|
|
23
|
-
const riskLevelSchema = z.enum(["low", "medium", "high"]);
|
|
24
|
-
const riskTreatmentSchema = z.enum(["accept", "mitigate", "transfer", "avoid"]);
|
|
25
|
-
const incidentEntryTypeSchema = z.enum(["detected", "update", "severity", "resolved", "reopened", "note"]);
|
|
26
|
-
const incidentSeveritySchema = z.enum(["low", "medium", "high", "critical"]);
|
|
27
|
-
const problemEntryTypeSchema = z.enum([
|
|
28
|
-
"identified",
|
|
29
|
-
"investigation",
|
|
30
|
-
"root_cause",
|
|
31
|
-
"known_error",
|
|
32
|
-
"resolved",
|
|
33
|
-
"reopened",
|
|
34
|
-
"note"
|
|
35
|
-
]);
|
|
36
|
-
const supportRequestEntryTypeSchema = z.enum(["raised", "triage", "update", "escalated", "resolved", "reopened", "note"]);
|
|
37
|
-
const maintenanceCadenceSchema = z.object({
|
|
38
|
-
count: z.number().int().min(1),
|
|
39
|
-
unit: z.enum(["day", "week", "month", "quarter", "year"])
|
|
40
|
-
}).strict();
|
|
41
|
-
const valueMetricMeasurementSchema = z.object({
|
|
42
|
-
value: z.number().finite(),
|
|
43
|
-
measuredAt: z.string().min(1)
|
|
44
|
-
}).strict();
|
|
45
|
-
const valueMetricSchema = z.object({
|
|
46
|
-
id: z.string().min(1).optional(),
|
|
47
|
-
name: z.string().min(1),
|
|
48
|
-
unit: z.string().min(1),
|
|
49
|
-
direction: z.enum(["lower_is_better", "higher_is_better"]),
|
|
50
|
-
baseline: valueMetricMeasurementSchema,
|
|
51
|
-
actual: valueMetricMeasurementSchema.optional()
|
|
52
|
-
}).strict();
|
|
53
|
-
const reviewableRecordTypeSchema = z.enum(["expectations", "requirements"]);
|
|
54
|
-
const decisionInputRecordTypes = [
|
|
55
|
-
"expectations",
|
|
56
|
-
"requirements",
|
|
57
|
-
"commitments",
|
|
58
|
-
"deferrals",
|
|
59
|
-
"journal_entries",
|
|
60
|
-
"environments",
|
|
61
|
-
"components",
|
|
62
|
-
"estimates",
|
|
63
|
-
"benefits",
|
|
64
|
-
"maintenance_schedules",
|
|
65
|
-
"support_requests",
|
|
66
|
-
"value_realizations",
|
|
67
|
-
"risks",
|
|
68
|
-
"changes",
|
|
69
|
-
"incidents",
|
|
70
|
-
"problems",
|
|
71
|
-
"decisions"
|
|
72
|
-
];
|
|
73
|
-
const decisionInputRecordTypeSchema = z.enum(decisionInputRecordTypes);
|
|
74
|
-
const changeEventTypeSchema = z.enum([
|
|
75
|
-
"notice_given",
|
|
76
|
-
"veto_recorded",
|
|
77
|
-
"decision_recorded",
|
|
78
|
-
"result_reported",
|
|
79
|
-
"recovery_recorded",
|
|
80
|
-
"plan_revised",
|
|
81
|
-
"note_added"
|
|
82
|
-
]);
|
|
83
|
-
const changeTypeSchema = z.enum(["standard", "normal", "emergency"]);
|
|
84
|
-
const changeImpactGradeSchema = z.enum(["minor", "significant", "major"]);
|
|
85
|
-
const changeVetoRoleSchema = z.enum(["Owner", "Engineer"]);
|
|
86
|
-
const changeDecisionSchema = z.enum(["proceed", "defer", "cancel"]);
|
|
87
|
-
const changeResultSchema = z.enum(["completed", "failed", "rolled_back"]);
|
|
88
|
-
const gitCommitReferenceSchema = z.object({
|
|
89
|
-
commit: z.string().min(1),
|
|
90
|
-
repository: z.string().min(1).optional(),
|
|
91
|
-
url: z.string().min(1).optional()
|
|
92
|
-
});
|
|
93
|
-
const deferralEventTypeSchema = z.enum([
|
|
94
|
-
"condition_addressed",
|
|
95
|
-
"condition_reopened",
|
|
96
|
-
"condition_note_added",
|
|
97
|
-
"deferral_resolved",
|
|
98
|
-
"deferral_abandoned"
|
|
99
|
-
]);
|
|
100
|
-
const journalTagSchema = z.string().min(1).max(80);
|
|
101
|
-
const recordFieldsSchema = z.record(z.string(), z.unknown()).optional();
|
|
102
|
-
const amountInputSchema = z.union([
|
|
103
|
-
z.object({
|
|
104
|
-
kind: z.literal("single"),
|
|
105
|
-
value: requiredAmountSchema
|
|
106
|
-
}),
|
|
107
|
-
z.object({
|
|
108
|
-
kind: z.literal("range"),
|
|
109
|
-
min: requiredAmountSchema,
|
|
110
|
-
expected: requiredAmountSchema,
|
|
111
|
-
max: requiredAmountSchema
|
|
112
|
-
})
|
|
113
|
-
]);
|
|
114
|
-
const timingSchema = z.enum(["one_time", "recurring"]);
|
|
115
|
-
const estimateLineItemSchema = z.object({
|
|
116
|
-
id: z.string().min(1).optional(),
|
|
117
|
-
label: z.string().min(1),
|
|
118
|
-
timing: timingSchema,
|
|
119
|
-
period: z.string().min(1).optional(),
|
|
120
|
-
currency: requiredCurrencySchema,
|
|
121
|
-
amount: amountInputSchema
|
|
122
|
-
}).strict();
|
|
123
|
-
const benefitItemSchema = z.object({
|
|
124
|
-
id: z.string().min(1).optional(),
|
|
125
|
-
label: z.string().min(1),
|
|
126
|
-
timing: timingSchema.optional(),
|
|
127
|
-
period: z.string().min(1).optional(),
|
|
128
|
-
currency: requiredCurrencySchema.optional(),
|
|
129
|
-
amount: amountInputSchema.optional()
|
|
130
|
-
}).strict();
|
|
131
|
-
const componentLocatorSchema = z.record(z.string().min(1), z.unknown()).refine((value) => Object.keys(value).length > 0, "locator must be a non-empty structured object.");
|
|
132
|
-
const componentIdentifiersSchema = z.record(z.string().min(1), z.unknown()).optional();
|
|
133
|
-
const secretPointerSchema = z.object({
|
|
134
|
-
store: z.string().min(1),
|
|
135
|
-
key: z.string().min(1),
|
|
136
|
-
location: z.string().min(1).optional(),
|
|
137
|
-
url: z.string().min(1).optional(),
|
|
138
|
-
note: z.string().min(1).optional()
|
|
139
|
-
}).strict();
|
|
140
|
-
const decisionInitialEntrySchema = z.object({
|
|
141
|
-
entryType: decisionEntryTypeSchema,
|
|
142
|
-
body: z.string().min(1),
|
|
143
|
-
decidedBy: z.string().min(1).optional(),
|
|
144
|
-
rationale: z.string().min(1).optional()
|
|
145
|
-
}).strict();
|
|
146
|
-
const initialDecisionSchema = z.object({
|
|
147
|
-
body: z.string().min(1),
|
|
148
|
-
decidedBy: z.string().min(1).optional(),
|
|
149
|
-
rationale: z.string().min(1).optional()
|
|
150
|
-
}).strict();
|
|
151
|
-
const fieldNameSchema = z
|
|
152
|
-
.string()
|
|
153
|
-
.regex(/^[A-Za-z_][A-Za-z0-9_-]*$/, "Only top-level field names are supported.");
|
|
154
|
-
const SERVER_STARTED_AT = new Date().toISOString();
|
|
155
|
-
const STATEMENT_TYPED_FIELDS = ["statement", "source"];
|
|
156
|
-
const EXPECTATION_TYPED_FIELDS = [
|
|
157
|
-
"statement",
|
|
158
|
-
"successRecognition",
|
|
159
|
-
"approvalState",
|
|
160
|
-
"approvedBy",
|
|
161
|
-
"approvedAt",
|
|
162
|
-
"source"
|
|
163
|
-
];
|
|
164
|
-
const REQUIREMENT_TYPED_FIELDS = [
|
|
165
|
-
"statement",
|
|
166
|
-
"acceptanceCriteria",
|
|
167
|
-
"priority",
|
|
168
|
-
"status"
|
|
169
|
-
];
|
|
170
|
-
const CHANGE_TYPED_FIELDS = [
|
|
171
|
-
"changePlan",
|
|
172
|
-
"executionSteps",
|
|
173
|
-
"rollbackPlan",
|
|
174
|
-
"riskImpact",
|
|
175
|
-
"changeType",
|
|
176
|
-
"impactGrade",
|
|
177
|
-
"emergencyImportance",
|
|
178
|
-
"emergencyImmediacy",
|
|
179
|
-
"emergencyRationaleGaps",
|
|
180
|
-
"plannedFor",
|
|
181
|
-
"events"
|
|
182
|
-
];
|
|
183
|
-
const COMMITMENT_TYPED_FIELDS = ["commitmentStatement", "reservations"];
|
|
184
|
-
const DEFERRAL_TYPED_FIELDS = ["reason", "status", "conditions", "conditionEvents"];
|
|
185
|
-
const ESTIMATE_TYPED_FIELDS = ["lineItems", "rollup", "versionHistory"];
|
|
186
|
-
const BENEFITS_TYPED_FIELDS = ["benefitItems", "rollup", "versionHistory"];
|
|
187
|
-
const ENVIRONMENT_TYPED_FIELDS = ["name", "description", "versionHistory"];
|
|
188
|
-
const COMPONENT_TYPED_FIELDS = [
|
|
189
|
-
"name",
|
|
190
|
-
"environmentId",
|
|
191
|
-
"kind",
|
|
192
|
-
"locator",
|
|
193
|
-
"identifiers",
|
|
194
|
-
"secretPointers",
|
|
195
|
-
"notes",
|
|
196
|
-
"versionHistory"
|
|
197
|
-
];
|
|
198
|
-
const MAINTENANCE_SCHEDULE_TYPED_FIELDS = [
|
|
199
|
-
"name",
|
|
200
|
-
"kind",
|
|
201
|
-
"cadence",
|
|
202
|
-
"startDate",
|
|
203
|
-
"rationale",
|
|
204
|
-
"notes",
|
|
205
|
-
"versionHistory"
|
|
206
|
-
];
|
|
207
|
-
const SUPPORT_REQUEST_TYPED_FIELDS = [
|
|
208
|
-
"workspaceId",
|
|
209
|
-
"reporter",
|
|
210
|
-
"kind",
|
|
211
|
-
"reportedExperience",
|
|
212
|
-
"entries",
|
|
213
|
-
"currentStatus",
|
|
214
|
-
"status"
|
|
215
|
-
];
|
|
216
|
-
const VALUE_REALIZATION_TYPED_FIELDS = ["metrics", "versionHistory"];
|
|
217
|
-
const OBSOLETE_EXPECTATION_FIELDS = ["confirmationState", "ratifiedBy", "ratifiedAt"];
|
|
218
|
-
const DECISION_INPUT_FIELDS = ["informedBy", "informedByIds", "inputRecords"];
|
|
219
|
-
const DECISION_TYPED_FIELDS = [
|
|
220
|
-
"workspaceId",
|
|
221
|
-
"matter",
|
|
222
|
-
"entries",
|
|
223
|
-
"currentDecision",
|
|
224
|
-
"question",
|
|
225
|
-
"decision",
|
|
226
|
-
"decidedBy",
|
|
227
|
-
"rationale",
|
|
228
|
-
"argumentsConsidered",
|
|
229
|
-
"concerns",
|
|
230
|
-
"status"
|
|
231
|
-
];
|
|
232
|
-
const TASK_TYPED_FIELDS = ["workspaceId", "description", "assignee", "assignor", "entries", "currentStatus", "details", "status"];
|
|
233
|
-
const RISK_TYPED_FIELDS = [
|
|
234
|
-
"workspaceId",
|
|
235
|
-
"topic",
|
|
236
|
-
"entries",
|
|
237
|
-
"currentStatus",
|
|
238
|
-
"currentAssessment",
|
|
239
|
-
"currentTreatment",
|
|
240
|
-
"likelihood",
|
|
241
|
-
"impact",
|
|
242
|
-
"mitigation"
|
|
243
|
-
];
|
|
244
|
-
const INCIDENT_TYPED_FIELDS = ["workspaceId", "description", "entries", "currentStatus", "currentSeverity", "status", "severity"];
|
|
245
|
-
const PROBLEM_TYPED_FIELDS = ["workspaceId", "description", "entries", "currentStatus", "currentRootCause", "status", "rootCause"];
|
|
246
|
-
const PROCESS_GUIDE = {
|
|
247
|
-
name: "DX Complete process guide",
|
|
248
|
-
status: "Current operating guidance for working inside DX Complete. It is a lean guide for MCP clients; it is not the full reference, not a final model, and not a validation rule.",
|
|
249
|
-
currentFlow: ["Statement", "Expectation", "Requirement", "Commitment"],
|
|
250
|
-
phaseGuidance: [
|
|
251
|
-
"These phases describe a typical first-pass order and each has a target end-state, but they are non-terminal and re-enterable: at any point the most useful next activity may belong to any phase, including returning to an earlier one, and no phase is ever closed or locked behind you."
|
|
252
|
-
],
|
|
253
|
-
crossCuttingRecords: [
|
|
254
|
-
{
|
|
255
|
-
record: "Journal",
|
|
256
|
-
use: "Shared workspace context that does not yet belong in a dedicated record; use dedicated records first and Journal only as the fallback."
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
record: "Task",
|
|
260
|
-
use: "Execution work that can be created whenever a phase needs concrete action; Task is not part of the Statement, Expectation, Requirement, Commitment sequence."
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
record: "Decision",
|
|
264
|
-
use: "A recorded choice that can appear in any phase when a meaningful decision needs to remain legible."
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
record: "Support Request",
|
|
268
|
-
use: "Shared user-facing support follow-up for a reported experience, question, request, or issue."
|
|
269
|
-
}
|
|
270
|
-
],
|
|
271
|
-
recordRoutingGuidance: {
|
|
272
|
-
principle: "Use the dedicated record first. Journal is the fallback for relevant workspace context only when no dedicated record fits.",
|
|
273
|
-
sharpTest: "Will anything reference or depend on this? If yes, prefer a dedicated record that can carry the relationship.",
|
|
274
|
-
routingOrder: [
|
|
275
|
-
{
|
|
276
|
-
when: "The information is desired truth, success criteria, or a buildable commitment.",
|
|
277
|
-
use: "Use Statement, Expectation, or Requirement."
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
when: "The information is a choice weighed between alternatives.",
|
|
281
|
-
use: "Use Decision."
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
when: "The information is an action someone needs to do.",
|
|
285
|
-
use: "Use Task."
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
when: "The information is a discrete alteration to the running service.",
|
|
289
|
-
use: "Use Change."
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
when: "The information is a specific service-impacting occurrence that needs response.",
|
|
293
|
-
use: "Use Incident."
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
when: "The information is an underlying or recurring cause behind one or more incidents.",
|
|
297
|
-
use: "Use Problem."
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
when: "The information is uncertainty or exposure.",
|
|
301
|
-
use: "Use Risk."
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
when: "The information is operational infrastructure state.",
|
|
305
|
-
use: "Use Environment and Component records in the Operational Registry; do not use Journal as the long-term home."
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
when: "The information is recurring operational hygiene, such as a scheduled review, rotation, backup check, or maintenance duty.",
|
|
309
|
-
use: "Use Maintenance Schedule."
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
when: "The information is a user-facing question, request, or issue that needs shared support follow-up.",
|
|
313
|
-
use: "Use Support Request."
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
when: "The information is measured before/after value for an approved outcome or commitment.",
|
|
317
|
-
use: "Use Value Realization."
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
when: "The information is a private question, report, request, correction, or follow-up with DX Complete.",
|
|
321
|
-
use: "Use DX Complete Ticket."
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
when: "The information is relevant context with no better home.",
|
|
325
|
-
use: "Use Journal."
|
|
326
|
-
}
|
|
327
|
-
],
|
|
328
|
-
promotion: "If Journal content becomes load-bearing, promote it to the appropriate dedicated record and link back where useful."
|
|
329
|
-
},
|
|
330
|
-
roleOperatingGuidance: [
|
|
331
|
-
{
|
|
332
|
-
role: "Owner",
|
|
333
|
-
guidance: "Use Statement, Expectation, Benefits, Commitment, Deferral, Decision, Value Realization, and Risk records for direction, expected value, measured value, commitment, deferral, formal risk acceptance, and authority decisions."
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
role: "Engineer",
|
|
337
|
-
guidance: "Default to Requirement -> Task for implementation work. Use Decision for meaningful choices, Risk for uncertainty, Journal for relevant context with no better home, and Change only when the work becomes a run-side alteration."
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
role: "Codex assistance",
|
|
341
|
-
guidance: "Codex is a coding-capable tool used by the Engineer, not a DX Complete role. A fresh Codex instance should orient from get_process_guide, get_doc({ page: \"operating_guide\" }), and the installed Codex guidance before choosing records."
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
role: "Tester",
|
|
345
|
-
guidance: "Use Task entries, review notes, Risk, Decision, or Journal to keep verification evidence visible. Do not create Change records merely because testing is happening."
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
role: "Operator",
|
|
349
|
-
guidance: "Use Change for discrete run-side alterations, Incident for specific service-impacting occurrences, Problem for underlying or recurring causes, Environment and Component for operational inventory, Maintenance Schedule for recurring operational hygiene, and Risk or Decision where operations need accountability. Administration duties such as users, permissions, settings, provisioning, and run-side security live here."
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
role: "Support Agent",
|
|
353
|
-
guidance: "Use Support Request for shared user-facing support follow-up. Use DX Complete Ticket only for private questions, reports, requests, corrections, and follow-ups with DX Complete itself. Promote to Statement, Requirement, Task, Incident, Problem, Risk, Decision, Change, or Journal only when the signal has that meaning."
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
role: "End User",
|
|
357
|
-
guidance: "End User is not a DX Complete operator and does not approve records. Their input is captured by another role as Statement, report, request, correction, feedback signal, or ticket."
|
|
358
|
-
}
|
|
359
|
-
],
|
|
360
|
-
itsmGuidance: [
|
|
361
|
-
"Change is the current first-class run-side control record.",
|
|
362
|
-
"Incident is the current first-class record for a specific service-impacting or potentially service-impacting occurrence.",
|
|
363
|
-
"Problem is the current first-class record for an underlying or recurring cause evidenced by one or more incidents.",
|
|
364
|
-
"Do not create ITSM-style records merely because work is happening; use Change, Incident, Problem, and Risk only when the record meaning fits."
|
|
365
|
-
],
|
|
366
|
-
phases: [
|
|
367
|
-
{
|
|
368
|
-
id: "orient",
|
|
369
|
-
name: "Orient",
|
|
370
|
-
purpose: "Capture the desired outcome in plain terms, restate expectations, and confirm how success will be recognized where possible.",
|
|
371
|
-
commonRecords: ["Workspace", "Statement", "Expectation", "DX Complete Ticket"],
|
|
372
|
-
processConcepts: [],
|
|
373
|
-
handoff: "Expectations describe the desired outcome clearly enough to elicit requirements, or any missing approval is visible as open risk.",
|
|
374
|
-
operatingGuidance: {
|
|
375
|
-
clientRole: "Help the user express the desired outcome in their terms, confirm captured wording before recording, and prepare expectations for approval where needed.",
|
|
376
|
-
conductRules: [
|
|
377
|
-
"Elicit the person's Statement; do not invent it.",
|
|
378
|
-
"When the client articulates Statement or Expectation wording on a user's behalf, confirm that wording before recording it.",
|
|
379
|
-
"Do not store same-person capture-confirmation as record state.",
|
|
380
|
-
"Stay in plain outcome language.",
|
|
381
|
-
"Do not move into technical solution design during Orient.",
|
|
382
|
-
"Treat missing separate authority approval as visible open risk, not as a process block."
|
|
383
|
-
],
|
|
384
|
-
questionsToAsk: [
|
|
385
|
-
"What problem, need, or outcome should DX Complete help clarify?",
|
|
386
|
-
"What would make this successful from the user's point of view?",
|
|
387
|
-
"How will people recognize that the expected outcome has been met?",
|
|
388
|
-
"Is this wording accurate enough to record and use as the basis for requirements?"
|
|
389
|
-
],
|
|
390
|
-
expectedOutput: [
|
|
391
|
-
"Statement record in the person's language.",
|
|
392
|
-
"Restated Expectations with success recognition.",
|
|
393
|
-
"Owner approval where available, or visible open risk where approval is missing."
|
|
394
|
-
],
|
|
395
|
-
exitCheck: "Move to Elicit when expectations are clear enough to translate into requirements, or when proceeding without separate authority approval is visible as open risk.",
|
|
396
|
-
checkpointNotes: [
|
|
397
|
-
"Owner approval reduces wrong-outcome risk.",
|
|
398
|
-
"Unapproved expectations can move forward only when the risk is explicit."
|
|
399
|
-
]
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
id: "elicit",
|
|
404
|
-
name: "Elicit",
|
|
405
|
-
purpose: "Translate expectations into requirements, dependencies, assumptions, unknowns, and risk.",
|
|
406
|
-
commonRecords: ["Statement", "Expectation", "Requirement", "Risk", "Decision", "DX Complete Ticket"],
|
|
407
|
-
processConcepts: ["Requirement"],
|
|
408
|
-
handoff: "The requirement set is clear enough to estimate cost, value, risk, and confidence, or the open risk is visible.",
|
|
409
|
-
operatingGuidance: {
|
|
410
|
-
clientRole: "Translate approved or visibly unapproved expectations into requirements and related delivery facts.",
|
|
411
|
-
conductRules: [
|
|
412
|
-
"Keep each requirement tied to the expectation it is meant to satisfy.",
|
|
413
|
-
"Separate requirements from implementation tasks.",
|
|
414
|
-
"Surface dependencies, assumptions, unknowns, and risks before estimating.",
|
|
415
|
-
"Use review notes for Engineer input on expectations or requirements; do not treat review notes as approval, objection state, or blockers.",
|
|
416
|
-
"Do not treat uncertain details as settled requirements."
|
|
417
|
-
],
|
|
418
|
-
questionsToAsk: [
|
|
419
|
-
"What must be true for each expectation to be satisfied?",
|
|
420
|
-
"What dependencies, constraints, or unknowns could affect the work?",
|
|
421
|
-
"What assumptions are being made because information is incomplete?",
|
|
422
|
-
"Which risks should be visible before the Owner weighs the work?"
|
|
423
|
-
],
|
|
424
|
-
expectedOutput: [
|
|
425
|
-
"A requirement set.",
|
|
426
|
-
"Review notes where Engineer input should stay visible.",
|
|
427
|
-
"Known dependencies, assumptions, unknowns, and risks.",
|
|
428
|
-
"Open questions, visible risks, or follow-ups where clarity is incomplete."
|
|
429
|
-
],
|
|
430
|
-
exitCheck: "Move to Weigh when the requirement set is clear enough to support cost, value, risk, and confidence discussion.",
|
|
431
|
-
checkpointNotes: [
|
|
432
|
-
"Requirement clarity reduces estimate risk.",
|
|
433
|
-
"Open unknowns can move forward when they are recorded as visible risk or follow-up."
|
|
434
|
-
]
|
|
435
|
-
}
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
id: "weigh",
|
|
439
|
-
name: "Weigh",
|
|
440
|
-
purpose: "Compare expected cost, expected value, risks, and confidence before recording a Commitment or Deferral.",
|
|
441
|
-
commonRecords: [
|
|
442
|
-
"Estimate",
|
|
443
|
-
"Benefits",
|
|
444
|
-
"Commitment",
|
|
445
|
-
"Deferral",
|
|
446
|
-
"Decision",
|
|
447
|
-
"Risk"
|
|
448
|
-
],
|
|
449
|
-
handoff: "The Owner records a Commitment that can move into Build, or a Deferral that makes unmet conditions visible.",
|
|
450
|
-
operatingGuidance: {
|
|
451
|
-
clientRole: "Help the decision authority compare the requirement set against cost, value, risk, and confidence.",
|
|
452
|
-
conductRules: [
|
|
453
|
-
"Make current-state cost context visible where relevant, but do not require complete baseline data.",
|
|
454
|
-
"Generate or review a scope-linked Engineer cost Estimate by default from the elicited requirement set.",
|
|
455
|
-
"Record Owner-authored Benefits separately from Engineer cost Estimates.",
|
|
456
|
-
"Consider important review notes, but do not require the Owner to acknowledge or answer them.",
|
|
457
|
-
"Keep the phase outcome-neutral; do not force a Commitment.",
|
|
458
|
-
"If budget or benefit basis was considered, link the Estimate, Benefits, or Decision rationale to the Commitment; if not, do not fabricate a waiver.",
|
|
459
|
-
"Use Commitment when the Owner is moving forward, with any reservations recorded.",
|
|
460
|
-
"Use Deferral when the Owner is not moving forward yet and wants the unmet conditions made explicit.",
|
|
461
|
-
"Record uncertainty and confidence rather than hiding it.",
|
|
462
|
-
"Do not compute a verdict; DX Complete preserves the basis for the Owner's judgment."
|
|
463
|
-
],
|
|
464
|
-
questionsToAsk: [
|
|
465
|
-
"What is known about current cost, proposed cost, and expected benefit?",
|
|
466
|
-
"How confident is the cost estimate?",
|
|
467
|
-
"Which Benefits, Estimate, or Decision rationale, if any, should inform the Commitment?",
|
|
468
|
-
"What risks or missing information affect whether the Owner can commit?",
|
|
469
|
-
"Is the Owner committing now, or deferring until named conditions are addressed?",
|
|
470
|
-
"If committing, what reservations should be kept visible?",
|
|
471
|
-
"If deferring, what conditions would make a future Commitment possible?"
|
|
472
|
-
],
|
|
473
|
-
expectedOutput: [
|
|
474
|
-
"Decision basis for the Owner's judgment.",
|
|
475
|
-
"Scope-linked Engineer cost Estimate where available.",
|
|
476
|
-
"Owner-authored Benefits where available, including qualitative benefits when they cannot be quantified.",
|
|
477
|
-
"Important review notes considered as input where they exist.",
|
|
478
|
-
"Commitment with linked requirements or expectations, or Deferral with explicit conditions.",
|
|
479
|
-
"Decision with linked inputs where a separate rationale record is useful.",
|
|
480
|
-
"Visible risks."
|
|
481
|
-
],
|
|
482
|
-
exitCheck: "Move to Build only after a Commitment; otherwise keep the Deferral conditions visible or return to Elicit as recorded.",
|
|
483
|
-
checkpointNotes: [
|
|
484
|
-
"Incomplete cost or benefit data does not block the decision.",
|
|
485
|
-
"Proceeding with low confidence should leave the open risk visible.",
|
|
486
|
-
"A Deferral is not failure; it is the recorded path to a possible future Commitment."
|
|
487
|
-
]
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
id: "build",
|
|
492
|
-
name: "Build",
|
|
493
|
-
purpose: "Turn committed requirements into working changes.",
|
|
494
|
-
commonRecords: ["Commitment", "Requirement", "Task", "Decision", "Risk"],
|
|
495
|
-
handoff: "The change is ready for release preparation and readiness checks.",
|
|
496
|
-
operatingGuidance: {
|
|
497
|
-
clientRole: "Help the team break committed requirements into tasks and track implementation evidence.",
|
|
498
|
-
conductRules: [
|
|
499
|
-
"Create tasks from requirements covered by a Commitment.",
|
|
500
|
-
"Keep implementation detail connected to the requirement it supports.",
|
|
501
|
-
"Use decisions for meaningful design or tradeoff choices.",
|
|
502
|
-
"Surface blockers and delivery risk early."
|
|
503
|
-
],
|
|
504
|
-
questionsToAsk: [
|
|
505
|
-
"Which requirement does this task implement?",
|
|
506
|
-
"What working change will satisfy the requirement?",
|
|
507
|
-
"What decision, risk, or blocker affects the build?",
|
|
508
|
-
"What evidence will show that the task is complete?"
|
|
509
|
-
],
|
|
510
|
-
expectedOutput: [
|
|
511
|
-
"Tasks linked to requirements.",
|
|
512
|
-
"Working changes or implementation evidence.",
|
|
513
|
-
"Recorded decisions and risks where needed."
|
|
514
|
-
],
|
|
515
|
-
exitCheck: "Move to Go Live when the committed change is built and ready for release preparation.",
|
|
516
|
-
checkpointNotes: [
|
|
517
|
-
"Task completion does not replace requirement verification.",
|
|
518
|
-
"Known build risk should remain visible through release preparation."
|
|
519
|
-
]
|
|
520
|
-
}
|
|
521
|
-
},
|
|
522
|
-
{
|
|
523
|
-
id: "go_live",
|
|
524
|
-
name: "Go Live",
|
|
525
|
-
purpose: "Prepare the change, confirm readiness, and put it into use.",
|
|
526
|
-
commonRecords: ["Change", "Task", "Decision", "Risk"],
|
|
527
|
-
handoff: "The change is completed, deferred, cancelled, rolled back, or left with its event history visible.",
|
|
528
|
-
operatingGuidance: {
|
|
529
|
-
clientRole: "Help the Operator record the intended service change, readiness basis, execution path, rollback path, and resulting events.",
|
|
530
|
-
conductRules: [
|
|
531
|
-
"Use Change for a discrete alteration to the running service; reserve Operations Plan for a future standing operating model.",
|
|
532
|
-
"Record the original change plan, execution steps, rollback plan, and risk, impact, and downstream impact as the baseline.",
|
|
533
|
-
"Classify the Change as standard, normal, or emergency, then use append-only Change events for notice, veto, decision, result, recovery, notes, and plan revisions.",
|
|
534
|
-
"When result or recovery events have Git commits behind them, record optional Git commit references for that execution attempt or rollback.",
|
|
535
|
-
"Check readiness before putting the change into use.",
|
|
536
|
-
"Make release, rollback, notice, veto, change type, and communication risks visible.",
|
|
537
|
-
"Do not treat vetoes or readiness checks as mechanical blockers; DX Complete records accountability and does not perform or enforce the operation.",
|
|
538
|
-
"Record open readiness risk when a readiness concern remains open."
|
|
539
|
-
],
|
|
540
|
-
questionsToAsk: [
|
|
541
|
-
"What is changing, why, and when is it planned?",
|
|
542
|
-
"What steps will carry out the change?",
|
|
543
|
-
"What rollback or recovery path exists if something goes wrong?",
|
|
544
|
-
"What else may be affected, and what depends on what is changing?",
|
|
545
|
-
"Who needs to know about the change?",
|
|
546
|
-
"Has anyone recorded a veto or concern?",
|
|
547
|
-
"What readiness concerns are still open?"
|
|
548
|
-
],
|
|
549
|
-
expectedOutput: [
|
|
550
|
-
"Change record with change plan, execution steps, rollback plan, and risk, impact, and downstream-impact notes.",
|
|
551
|
-
"Append-only Change events for notice, veto, decision, result, recovery, notes, or revisions where they occur.",
|
|
552
|
-
"Optional Git commit references on result or recovery events where they help trace the execution attempt.",
|
|
553
|
-
"Readiness basis.",
|
|
554
|
-
"Release or service-change decision context.",
|
|
555
|
-
"Visible open risks and any Owner risk-acceptance decisions."
|
|
556
|
-
],
|
|
557
|
-
exitCheck: "Move to Operate when the change event history shows the change is completed, deferred, cancelled, rolled back, or ready to be monitored.",
|
|
558
|
-
checkpointNotes: [
|
|
559
|
-
"Readiness checks reduce launch risk.",
|
|
560
|
-
"A veto by Owner or Engineer is a serious recorded event, not a mechanical stop.",
|
|
561
|
-
"Emergency changes should record both importance and immediacy where available; missing rationale remains visible but does not block the record.",
|
|
562
|
-
"Open readiness concerns can move forward only when the risk remains visible or is formally accepted by the Owner."
|
|
563
|
-
]
|
|
564
|
-
}
|
|
565
|
-
},
|
|
566
|
-
{
|
|
567
|
-
id: "operate",
|
|
568
|
-
name: "Operate",
|
|
569
|
-
purpose: "Run the service, help users, and respond when something goes wrong.",
|
|
570
|
-
commonRecords: ["Incident", "Problem", "Support Request", "Change", "Environment", "Component", "Maintenance Schedule", "DX Complete Ticket", "Risk", "Decision", "Task"],
|
|
571
|
-
handoff: "Operational signals are handled or sent into measurement, improvement, or new work.",
|
|
572
|
-
operatingGuidance: {
|
|
573
|
-
clientRole: "Help keep the service legible while it is running and route operational signals to the right follow-up.",
|
|
574
|
-
conductRules: [
|
|
575
|
-
"Separate immediate user-facing help from deeper improvement work.",
|
|
576
|
-
"Record Incident for a specific service-impacting occurrence, Problem for an underlying or recurring cause, and Risk, Decision, or Task when those meanings fit.",
|
|
577
|
-
"Use Support Request for shared user-facing support follow-up.",
|
|
578
|
-
"Use Change when the follow-up is a discrete alteration to the running service.",
|
|
579
|
-
"Use Maintenance Schedule for recurring operational hygiene and link completed Changes or Tasks to it when the work is performed.",
|
|
580
|
-
"Do not assume the service is finished just because there is no active build.",
|
|
581
|
-
"Surface recurring signals for later improvement or measurement."
|
|
582
|
-
],
|
|
583
|
-
questionsToAsk: [
|
|
584
|
-
"Is the service running as intended?",
|
|
585
|
-
"What user-facing issue, operational issue, or risk needs attention?",
|
|
586
|
-
"Does this signal need immediate response, a task, a decision, or later improvement?",
|
|
587
|
-
"Is this a shared support request, an incident, a problem, or recurring maintenance?",
|
|
588
|
-
"What operational follow-up remains open?"
|
|
589
|
-
],
|
|
590
|
-
expectedOutput: [
|
|
591
|
-
"Handled operational signal or routed follow-up.",
|
|
592
|
-
"Visible support requests, incidents, problems, maintenance schedules, risks, decisions, or tasks where needed.",
|
|
593
|
-
"Ongoing operating state."
|
|
594
|
-
],
|
|
595
|
-
exitCheck: "Move to Measure when cost, benefit, reliability, or other operating data is available for comparison or learning.",
|
|
596
|
-
checkpointNotes: [
|
|
597
|
-
"Operational work is part of the lifecycle, not an exception.",
|
|
598
|
-
"Unresolved operating signals should remain visible until handled or accepted."
|
|
599
|
-
]
|
|
600
|
-
}
|
|
601
|
-
},
|
|
602
|
-
{
|
|
603
|
-
id: "measure",
|
|
604
|
-
name: "Measure",
|
|
605
|
-
purpose: "Compare expected and actual cost or benefit when data is available.",
|
|
606
|
-
commonRecords: ["Value Realization", "Estimate", "Benefits", "Decision", "Risk"],
|
|
607
|
-
handoff: "Learning from actuals is available for future estimates and decisions.",
|
|
608
|
-
operatingGuidance: {
|
|
609
|
-
clientRole: "Help compare estimates to actuals where data exists and feed learning into future decisions.",
|
|
610
|
-
conductRules: [
|
|
611
|
-
"Capture actual cost or benefit observations when available.",
|
|
612
|
-
"Use Value Realization for before/after metrics tied to expectations, requirements, or commitments.",
|
|
613
|
-
"Do not block closure or continued operation because actuals are unavailable.",
|
|
614
|
-
"Compare measured results to earlier estimates where possible.",
|
|
615
|
-
"Turn meaningful differences into learning, risk, decision context, or future work."
|
|
616
|
-
],
|
|
617
|
-
questionsToAsk: [
|
|
618
|
-
"What actual cost or benefit data is available?",
|
|
619
|
-
"How does it compare with the estimate?",
|
|
620
|
-
"Which value metric has a baseline, an actual measurement, or an open measurement gap?",
|
|
621
|
-
"What should future estimates or decisions learn from this?",
|
|
622
|
-
"Is new work, risk, or a decision needed because of the measurement?"
|
|
623
|
-
],
|
|
624
|
-
expectedOutput: [
|
|
625
|
-
"Actual cost or benefit observations where available.",
|
|
626
|
-
"Value Realization records for measured or still-open value metrics where useful.",
|
|
627
|
-
"Comparison to estimates where possible.",
|
|
628
|
-
"Learning for future estimates and decisions."
|
|
629
|
-
],
|
|
630
|
-
exitCheck: "Keep operating, refine estimates, or start new Orient/Elicit work when measurement reveals a new need.",
|
|
631
|
-
checkpointNotes: [
|
|
632
|
-
"Actuals improve future estimates but do not block project closure.",
|
|
633
|
-
"Missing measurement data should be visible without being treated as failure."
|
|
634
|
-
]
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
],
|
|
638
|
-
processConcepts: [
|
|
639
|
-
{
|
|
640
|
-
name: "Statement",
|
|
641
|
-
status: "runtime_record",
|
|
642
|
-
currentRuntimeRecordType: "statements",
|
|
643
|
-
use: "The user's own words before DX Complete interprets or translates them.",
|
|
644
|
-
handling: "Track as a workspace-scoped record. Expectations can derive from Statement records through the derives_from relationship."
|
|
645
|
-
},
|
|
646
|
-
{
|
|
647
|
-
name: "Expectation",
|
|
648
|
-
status: "runtime_record",
|
|
649
|
-
currentRuntimeRecordType: "expectations",
|
|
650
|
-
use: "The expected result and how success will be recognized, captured in user-facing language.",
|
|
651
|
-
handling: "Track as a workspace-scoped record that can link to statements, requirements, risks, and decisions. Separate authority approval is tracked as risk-reducing state; same-person capture-confirmation is client conduct."
|
|
652
|
-
},
|
|
653
|
-
{
|
|
654
|
-
name: "Requirement detail",
|
|
655
|
-
status: "requirement_detail",
|
|
656
|
-
currentRuntimeRecordType: "requirements",
|
|
657
|
-
use: "Optional implementation or verification detail kept with the requirement when needed.",
|
|
658
|
-
handling: "Do not treat Specification as a current first-class runtime record."
|
|
659
|
-
}
|
|
660
|
-
],
|
|
661
|
-
checkpointGuidance: [
|
|
662
|
-
"Approval and other checkpoints reduce risk; they do not block progress by themselves.",
|
|
663
|
-
"A checkpoint can be approved or mitigated, formally accepted as risk by the Owner, or proceeded past with open risk still visible.",
|
|
664
|
-
"Formal risk acceptance is an Owner-level decision; domain actors may proceed, but proceeding does not close or accept the risk.",
|
|
665
|
-
"Use Risk and Decision records to capture Owner risk acceptance or proceeding past an open checkpoint until dedicated checkpoint fields or tools are proven necessary.",
|
|
666
|
-
"Use Decision input links to preserve which records informed important choices.",
|
|
667
|
-
"Use Change records for run-side service changes where change type, notice, veto, execution, rollback, result, and optional Git commit references need an ordered audit trail."
|
|
668
|
-
],
|
|
669
|
-
nextStepGuidance: {
|
|
670
|
-
responsibility: "The MCP client derives the next step from the current records, phase handoffs, operating guidance, open risks, and unanswered questions. DX Complete does not compute or prescribe a single server-side next step.",
|
|
671
|
-
conductRules: [
|
|
672
|
-
"Use the current phase, record state, links, open questions, risks, and decisions to reason about what should happen next.",
|
|
673
|
-
"When the next step is uncertain, name the missing information or checkpoint rather than inventing certainty.",
|
|
674
|
-
"Treat the next-step answer as guidance for the user, not as a hidden server decision."
|
|
675
|
-
]
|
|
676
|
-
},
|
|
677
|
-
runtimeRecordTypes: COLLECTION_NAMES,
|
|
678
|
-
deploymentModel: {
|
|
679
|
-
default: "one_mcp_endpoint_per_workspace",
|
|
680
|
-
workspaceBinding: "Hosted MCP endpoints get workspace scope from installed repo config, then proxy to the central DX Complete service. Shared record access is scoped by authenticated actor and authorized workspace context. Workspace scope is not an environment variable.",
|
|
681
|
-
databaseModel: "Workspace MCP servers do not hold database credentials. The central service owns database access, OAuth exchange, membership checks, readable ID allocation, and MCP tool execution.",
|
|
682
|
-
authorizationModel: "Workspace servers authenticate to the central service with a workspace service client. The central service verifies the human actor and derives allowed tool access from stored workspace roles."
|
|
683
|
-
},
|
|
684
|
-
recordGuidance: [
|
|
685
|
-
{
|
|
686
|
-
record: "Workspace",
|
|
687
|
-
use: "The boundary for one service scope, including its name, summary, and mode when useful."
|
|
688
|
-
},
|
|
689
|
-
{
|
|
690
|
-
record: "Statement",
|
|
691
|
-
use: "A user's own words before interpretation, kept as the traceable root for expectations and downstream work."
|
|
692
|
-
},
|
|
693
|
-
{
|
|
694
|
-
record: "Journal",
|
|
695
|
-
use: "Shared, append-only workspace notes for relevant background, preferences, observations, and context that has no dedicated record home. Journal notes are visible to workspace members and compacted through summary entries when the hot context grows."
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
record: "DX Complete Ticket",
|
|
699
|
-
use: "Private, appendable communication between the current actor and DX Complete before anyone decides whether shared follow-up is needed."
|
|
700
|
-
},
|
|
701
|
-
{
|
|
702
|
-
record: "Expectation",
|
|
703
|
-
use: "A user-facing condition of satisfaction that can be approved by separate authority, left not approved with open risk visible, linked to requirements, reviewed with non-blocking notes, and revised with version history."
|
|
704
|
-
},
|
|
705
|
-
{
|
|
706
|
-
record: "Requirement",
|
|
707
|
-
use: "A team-owned commitment that translates expectations into something buildable and verifiable, with optional non-blocking review notes and version history."
|
|
708
|
-
},
|
|
709
|
-
{
|
|
710
|
-
record: "Commitment",
|
|
711
|
-
use: "An Owner point-in-time authority record that commits requirements or expectations into Build, with optional reservations kept visible."
|
|
712
|
-
},
|
|
713
|
-
{
|
|
714
|
-
record: "Deferral",
|
|
715
|
-
use: "An Owner record for not committing yet, with explicit conditions and append-only condition history that can resolve into a Commitment."
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
record: "Task",
|
|
719
|
-
use: "Execution work with an append-only entry log; current status comes from the latest status_change entry."
|
|
720
|
-
},
|
|
721
|
-
{
|
|
722
|
-
record: "Change",
|
|
723
|
-
use: "A discrete service change record with baseline change type, plan sections, and append-only events for notice, veto, decision, result, recovery, notes, and revisions."
|
|
724
|
-
},
|
|
725
|
-
{
|
|
726
|
-
record: "Incident",
|
|
727
|
-
use: "A specific service-impacting or potentially service-impacting occurrence with an append-only entry log; current status and severity come from the latest relevant entries."
|
|
728
|
-
},
|
|
729
|
-
{
|
|
730
|
-
record: "Problem",
|
|
731
|
-
use: "An underlying or recurring cause evidenced by one or more Incidents, with an append-only entry log and current root cause derived from entries."
|
|
732
|
-
},
|
|
733
|
-
{
|
|
734
|
-
record: "Environment",
|
|
735
|
-
use: "A named operating context such as local, staging, or production, with version history for operational-state changes."
|
|
736
|
-
},
|
|
737
|
-
{
|
|
738
|
-
record: "Component",
|
|
739
|
-
use: "One environment-specific operational component with kind, structured locator, identifiers, secret pointers, notes, and version history."
|
|
740
|
-
},
|
|
741
|
-
{
|
|
742
|
-
record: "Maintenance Schedule",
|
|
743
|
-
use: "A recurring operational hygiene record with cadence, start date, rationale, version history, and due state derived from linked completed Changes or Tasks."
|
|
744
|
-
},
|
|
745
|
-
{
|
|
746
|
-
record: "Estimate",
|
|
747
|
-
use: "An Engineer cost input for Weigh, with itemized line items, scope links, cost-only roll-up totals, and version history."
|
|
748
|
-
},
|
|
749
|
-
{
|
|
750
|
-
record: "Benefits",
|
|
751
|
-
use: "An Owner-authored benefit input for Weigh, with qualitative or quantified benefit items, scope links, quantified roll-up totals where amounts exist, and version history."
|
|
752
|
-
},
|
|
753
|
-
{
|
|
754
|
-
record: "Value Realization",
|
|
755
|
-
use: "A measured-value record for before/after metrics tied to expectations, requirements, or commitments, with comparisons derived from baseline and actual values."
|
|
756
|
-
},
|
|
757
|
-
{
|
|
758
|
-
record: "Support Request",
|
|
759
|
-
use: "A shared support ledger for a user-facing reported experience, question, request, or issue; current status comes from ordered entries."
|
|
760
|
-
},
|
|
761
|
-
{
|
|
762
|
-
record: "Decision",
|
|
763
|
-
use: "A revisitable choice record with an append-only entry log; current decision comes from the latest decision entry while earlier arguments and decisions remain visible."
|
|
764
|
-
}
|
|
765
|
-
],
|
|
766
|
-
clientGuidance: [
|
|
767
|
-
"Use get_process_guide when you need the current DX Complete phase language.",
|
|
768
|
-
"Use get_doc for the fuller reference on outcomes, flow, records, roles, operating guide, and glossary terms.",
|
|
769
|
-
"Use get_doc({ page: \"operating_guide\" }) when a fresh client or agent needs role-by-role record routing.",
|
|
770
|
-
"Use DX Complete Ticket tools for private questions, reports, requests, corrections, or follow-ups.",
|
|
771
|
-
"Use Journal tools only after checking whether the information belongs in Statement, Expectation, Requirement, Decision, Task, Change, Incident, Problem, Support Request, Risk, Environment, Component, Maintenance Schedule, Value Realization, or another dedicated record.",
|
|
772
|
-
"Use workspace-scoped records for shared process work.",
|
|
773
|
-
"Use readableId values such as REQ-0001 as human-facing references when a tool accepts an existing record id; UUID remains the primary key and link target.",
|
|
774
|
-
"Hosted MCP access derives workspace scope from installed repo config and actor scope from OAuth.",
|
|
775
|
-
"Use update_expectation and update_requirement for current content changes so prior versions are preserved.",
|
|
776
|
-
"Use append_decision_entry and append_task_entry for Decision and Task history; do not rewrite their current decision or status directly.",
|
|
777
|
-
"Use link_decision_input when a record informed a Decision; use list_linked_records with relationship informed_by to review the decision inputs.",
|
|
778
|
-
"Use Benefits for Owner-authored benefit lists; use Estimate for Engineer cost estimates.",
|
|
779
|
-
"Use Value Realization for measured before/after value, not for expected benefits.",
|
|
780
|
-
"Use Support Request for shared user-facing support follow-up; use DX Complete Ticket for private communication with DX Complete.",
|
|
781
|
-
"Use link_records and unlink_records for other relationships between records."
|
|
782
|
-
]
|
|
783
|
-
};
|
|
784
|
-
export function createMcpServer(runtime, options = {}) {
|
|
785
|
-
const server = new McpServer({
|
|
786
|
-
name: "dxcomplete",
|
|
787
|
-
version: DXCOMPLETE_PACKAGE_VERSION
|
|
788
|
-
});
|
|
789
|
-
const actor = options.actor ?? createLocalActorContext();
|
|
790
|
-
const recordActorId = options.recordActorId ?? (options.actor ? actor.actorId : RUNTIME_ACTOR_ID);
|
|
791
|
-
const hostedWorkspace = options.hostedWorkspace;
|
|
792
|
-
const hostedHttp = options.hostedHttp;
|
|
793
|
-
const activeCollectionSchema = hostedWorkspace ? hostedCollectionSchema : collectionSchema;
|
|
794
|
-
const toolManifestEntries = [];
|
|
795
|
-
function registerDxcTool(name, config, handler) {
|
|
796
|
-
if (hostedWorkspace && name === "create_workspace") {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
const inputSchema = hostedWorkspace ? omitWorkspaceId(config.inputSchema) : config.inputSchema;
|
|
800
|
-
toolManifestEntries.push({
|
|
801
|
-
name,
|
|
802
|
-
description: config.description,
|
|
803
|
-
inputFields: Object.keys(inputSchema).sort(),
|
|
804
|
-
inputSchemaFingerprint: getInputSchemaFingerprint(inputSchema)
|
|
805
|
-
});
|
|
806
|
-
server.registerTool(name, {
|
|
807
|
-
...config,
|
|
808
|
-
inputSchema
|
|
809
|
-
}, (async (input) => {
|
|
810
|
-
const handlerInput = hostedWorkspace
|
|
811
|
-
? injectHostedWorkspace(input, config.inputSchema, hostedWorkspace.workspaceId)
|
|
812
|
-
: input;
|
|
813
|
-
assertHostedWorkspaceAccess(name, handlerInput, hostedWorkspace?.workspaceId);
|
|
814
|
-
assertToolRoleAccess(name, options.workspaceRoles, handlerInput);
|
|
815
|
-
return handler(handlerInput);
|
|
816
|
-
}));
|
|
817
|
-
}
|
|
818
|
-
function getToolManifest() {
|
|
819
|
-
const tools = [...toolManifestEntries].sort((left, right) => left.name.localeCompare(right.name));
|
|
820
|
-
return {
|
|
821
|
-
toolCount: tools.length,
|
|
822
|
-
tools
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
function getMcpSurface() {
|
|
826
|
-
const toolManifest = getToolManifest();
|
|
827
|
-
const fingerprint = createHash("sha256")
|
|
828
|
-
.update(stableStringify({
|
|
829
|
-
surfaceId: MCP_SURFACE_ID,
|
|
830
|
-
workspaceCompatibility: WORKSPACE_COMPATIBILITY_VERSION,
|
|
831
|
-
tools: toolManifest.tools,
|
|
832
|
-
processGuide: PROCESS_GUIDE,
|
|
833
|
-
docReferences: DOC_REFERENCE
|
|
834
|
-
}))
|
|
835
|
-
.digest("hex")
|
|
836
|
-
.slice(0, 16);
|
|
837
|
-
return {
|
|
838
|
-
version: MCP_SURFACE_ID,
|
|
839
|
-
fingerprint,
|
|
840
|
-
workspaceCompatibility: WORKSPACE_COMPATIBILITY_VERSION,
|
|
841
|
-
...toolManifest
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
registerDxcTool("runtime_status", {
|
|
845
|
-
description: "Check the DX Complete runtime connection and configured record collections.",
|
|
846
|
-
inputSchema: {}
|
|
847
|
-
}, async () => {
|
|
848
|
-
const surface = getMcpSurface();
|
|
849
|
-
return jsonResult({
|
|
850
|
-
ok: true,
|
|
851
|
-
databaseName: runtime.config.databaseName,
|
|
852
|
-
actorId: recordActorId,
|
|
853
|
-
actor,
|
|
854
|
-
...(hostedWorkspace
|
|
855
|
-
? {
|
|
856
|
-
workspace: {
|
|
857
|
-
workspaceId: hostedWorkspace.workspaceId,
|
|
858
|
-
...(hostedWorkspace.name ? { name: hostedWorkspace.name } : {}),
|
|
859
|
-
source: "central_service_membership",
|
|
860
|
-
...(options.workspaceRoles ? { roles: options.workspaceRoles } : {})
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
: {}),
|
|
864
|
-
collections: COLLECTION_NAMES,
|
|
865
|
-
server: {
|
|
866
|
-
pid: process.pid,
|
|
867
|
-
version: DXCOMPLETE_PACKAGE_VERSION,
|
|
868
|
-
packageVersion: DXCOMPLETE_PACKAGE_VERSION,
|
|
869
|
-
workspaceCompatibility: surface.workspaceCompatibility,
|
|
870
|
-
startedAt: SERVER_STARTED_AT,
|
|
871
|
-
surfaceVersion: surface.version,
|
|
872
|
-
surfaceFingerprint: surface.fingerprint,
|
|
873
|
-
surfaceIncludes: ["tools", "toolSchemas", "processGuide", "docReferences"],
|
|
874
|
-
...(hostedHttp
|
|
875
|
-
? {
|
|
876
|
-
http: hostedHttp
|
|
877
|
-
}
|
|
878
|
-
: {}),
|
|
879
|
-
toolCount: surface.toolCount,
|
|
880
|
-
tools: surface.tools.map((tool) => tool.name),
|
|
881
|
-
toolManifest: surface.tools
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
});
|
|
885
|
-
registerDxcTool("get_process_guide", {
|
|
886
|
-
description: "Get the current DX Complete process guide, including phases, common records, and handoff guidance.",
|
|
887
|
-
inputSchema: {}
|
|
888
|
-
}, async () => {
|
|
889
|
-
const surface = getMcpSurface();
|
|
890
|
-
return jsonResult({
|
|
891
|
-
surfaceVersion: surface.version,
|
|
892
|
-
surfaceFingerprint: surface.fingerprint,
|
|
893
|
-
workspaceCompatibility: surface.workspaceCompatibility,
|
|
894
|
-
...PROCESS_GUIDE
|
|
895
|
-
});
|
|
896
|
-
});
|
|
897
|
-
registerDxcTool("get_doc", {
|
|
898
|
-
description: "Get an on-demand DX Complete reference page for MCP clients. Use this for fuller outcomes, flow, records, roles, operating guide, and glossary content without loading all documentation into the process guide.",
|
|
899
|
-
inputSchema: {
|
|
900
|
-
page: z.enum(DOC_PAGE_IDS),
|
|
901
|
-
term: z.string().min(1).optional()
|
|
902
|
-
}
|
|
903
|
-
}, async ({ page, term }) => {
|
|
904
|
-
const surface = getMcpSurface();
|
|
905
|
-
const doc = getDocReference(page, term);
|
|
906
|
-
return jsonResult({
|
|
907
|
-
surfaceVersion: surface.version,
|
|
908
|
-
surfaceFingerprint: surface.fingerprint,
|
|
909
|
-
workspaceCompatibility: surface.workspaceCompatibility,
|
|
910
|
-
...doc
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
registerDxcTool("create_workspace", {
|
|
914
|
-
description: "Create a workspace, the shared-runtime boundary for one service scope.",
|
|
915
|
-
inputSchema: {
|
|
916
|
-
id: workspaceIdSchema.optional(),
|
|
917
|
-
name: z.string().min(1),
|
|
918
|
-
summary: z.string().min(1).optional(),
|
|
919
|
-
mode: workspaceModeSchema.optional(),
|
|
920
|
-
fields: recordFieldsSchema
|
|
921
|
-
}
|
|
922
|
-
}, async ({ id, name, summary, mode, fields }) => {
|
|
923
|
-
const existing = id
|
|
924
|
-
? await getRecord(runtime.db, "workspaces", id, { allowAnyWorkspace: true })
|
|
925
|
-
: null;
|
|
926
|
-
if (existing) {
|
|
927
|
-
return jsonResult(existing);
|
|
928
|
-
}
|
|
929
|
-
return jsonResult(await createRecord(runtime.db, "workspaces", {
|
|
930
|
-
...(id ? { id } : {}),
|
|
931
|
-
title: name,
|
|
932
|
-
summary,
|
|
933
|
-
fields: {
|
|
934
|
-
name,
|
|
935
|
-
...(mode ? { mode } : {}),
|
|
936
|
-
...(fields ?? {})
|
|
937
|
-
}
|
|
938
|
-
}, recordActorId));
|
|
939
|
-
});
|
|
940
|
-
registerDxcTool("create_record", {
|
|
941
|
-
description: "Create a record in one of the DX Complete collections.",
|
|
942
|
-
inputSchema: {
|
|
943
|
-
recordType: activeCollectionSchema,
|
|
944
|
-
workspaceId: workspaceIdSchema.optional(),
|
|
945
|
-
title: z.string().min(1).optional(),
|
|
946
|
-
summary: z.string().min(1).optional(),
|
|
947
|
-
fields: recordFieldsSchema
|
|
948
|
-
}
|
|
949
|
-
}, async ({ recordType, workspaceId, title, summary, fields }) => jsonResult(await createRecord(runtime.db, recordType, { workspaceId, title, summary, fields }, recordActorId)));
|
|
950
|
-
registerDxcTool("get_record", {
|
|
951
|
-
description: "Get one DX Complete record by type and id.",
|
|
952
|
-
inputSchema: {
|
|
953
|
-
recordType: activeCollectionSchema,
|
|
954
|
-
workspaceId: workspaceIdSchema.optional(),
|
|
955
|
-
id: z.string().min(1)
|
|
956
|
-
}
|
|
957
|
-
}, async ({ recordType, workspaceId, id }) => {
|
|
958
|
-
const record = await getRecord(runtime.db, recordType, id, { workspaceId });
|
|
959
|
-
if (!record) {
|
|
960
|
-
throw new Error(`Record not found: ${recordType}/${id}`);
|
|
961
|
-
}
|
|
962
|
-
return jsonResult(record);
|
|
963
|
-
});
|
|
964
|
-
registerDxcTool("create_dxcomplete_ticket", {
|
|
965
|
-
description: "Create a private DX Complete Ticket for a question, report, request, correction, or follow-up from the current actor. The body is stored as the first entry; summary is optional and is not generated automatically.",
|
|
966
|
-
inputSchema: {
|
|
967
|
-
title: z.string().min(1),
|
|
968
|
-
body: z.string().min(1)
|
|
969
|
-
}
|
|
970
|
-
}, async (input) => jsonResult(await createDxcompleteTicket(runtime.db, input, actor)));
|
|
971
|
-
registerDxcTool("append_dxcomplete_ticket", {
|
|
972
|
-
description: "Append a follow-up entry to one of the current actor's DX Complete Tickets while preserving earlier entries.",
|
|
973
|
-
inputSchema: {
|
|
974
|
-
id: z.string().min(1),
|
|
975
|
-
body: z.string().min(1)
|
|
976
|
-
}
|
|
977
|
-
}, async (input) => jsonResult(await appendDxcompleteTicket(runtime.db, input, actor)));
|
|
978
|
-
registerDxcTool("list_dxcomplete_tickets", {
|
|
979
|
-
description: "List the current actor's own DX Complete Tickets. Archived tickets are hidden unless includeArchived is true.",
|
|
980
|
-
inputSchema: {
|
|
981
|
-
limit: z.number().int().min(1).max(100).optional(),
|
|
982
|
-
includeArchived: z.boolean().optional()
|
|
983
|
-
}
|
|
984
|
-
}, async ({ limit, includeArchived }) => jsonResult(await listDxcompleteTickets(runtime.db, actor, limit ?? 20, { includeArchived })));
|
|
985
|
-
registerDxcTool("list_unread_dxcomplete_ticket_replies", {
|
|
986
|
-
description: "List tickets with unread DX Complete replies addressed to the current actor. This returns reply identifiers and timestamps only; use read_dxcomplete_ticket to read the ticket and mark replies read.",
|
|
987
|
-
inputSchema: {
|
|
988
|
-
limit: z.number().int().min(1).max(100).optional()
|
|
989
|
-
}
|
|
990
|
-
}, async ({ limit }) => jsonResult(await listUnreadDxcompleteTicketReplies(runtime.db, actor, limit ?? 20)));
|
|
991
|
-
registerDxcTool("read_dxcomplete_ticket", {
|
|
992
|
-
description: "Read one DX Complete Ticket owned by the current actor. Reading the ticket marks its unread DX Complete replies as read.",
|
|
993
|
-
inputSchema: {
|
|
994
|
-
id: z.string().min(1)
|
|
995
|
-
}
|
|
996
|
-
}, async (input) => jsonResult(await readDxcompleteTicket(runtime.db, input, actor)));
|
|
997
|
-
registerDxcTool("archive_dxcomplete_ticket", {
|
|
998
|
-
description: "Hide one DX Complete Ticket from the current actor's active ticket list. This is personal cleanup.",
|
|
999
|
-
inputSchema: {
|
|
1000
|
-
id: z.string().min(1)
|
|
1001
|
-
}
|
|
1002
|
-
}, async ({ id }) => jsonResult(await archiveDxcompleteTicket(runtime.db, { id }, actor)));
|
|
1003
|
-
registerDxcTool("append_journal_note", {
|
|
1004
|
-
description: "Append a shared workspace Journal note only after checking that the information has no better dedicated record home. Any workspace member may append; author and timestamp are captured automatically.",
|
|
1005
|
-
inputSchema: {
|
|
1006
|
-
workspaceId: workspaceIdSchema,
|
|
1007
|
-
body: z.string().min(1),
|
|
1008
|
-
tag: journalTagSchema.optional()
|
|
1009
|
-
}
|
|
1010
|
-
}, async (input) => jsonResult(await appendJournalNote(runtime.db, input, recordActorId)));
|
|
1011
|
-
registerDxcTool("read_journal", {
|
|
1012
|
-
description: "Read the workspace Journal fallback context. By default this returns the hot tier: active summaries plus active raw notes, not the full archive.",
|
|
1013
|
-
inputSchema: {
|
|
1014
|
-
workspaceId: workspaceIdSchema,
|
|
1015
|
-
limit: z.number().int().min(1).max(500).optional(),
|
|
1016
|
-
includeArchived: z.boolean().optional()
|
|
1017
|
-
}
|
|
1018
|
-
}, async (input) => jsonResult(await readJournal(runtime.db, input)));
|
|
1019
|
-
registerDxcTool("get_journal_entry", {
|
|
1020
|
-
description: "Fetch one Journal entry by UUID or readable ID, including fallback context entries that have aged out of the hot Journal read.",
|
|
1021
|
-
inputSchema: {
|
|
1022
|
-
workspaceId: workspaceIdSchema,
|
|
1023
|
-
id: z.string().min(1)
|
|
1024
|
-
}
|
|
1025
|
-
}, async (input) => jsonResult(await getJournalEntry(runtime.db, input)));
|
|
1026
|
-
registerDxcTool("append_journal_summary", {
|
|
1027
|
-
description: "Append a Journal summary for fallback context that covers existing Journal entries by UUID or readable ID, then archives the covered entries out of the hot read without deleting them.",
|
|
1028
|
-
inputSchema: {
|
|
1029
|
-
workspaceId: workspaceIdSchema,
|
|
1030
|
-
body: z.string().min(1),
|
|
1031
|
-
covers: z.array(z.string().min(1)).min(1),
|
|
1032
|
-
tag: journalTagSchema.optional()
|
|
1033
|
-
}
|
|
1034
|
-
}, async (input) => jsonResult(await appendJournalSummary(runtime.db, input, recordActorId)));
|
|
1035
|
-
registerDxcTool("create_statement", {
|
|
1036
|
-
description: "Create a Statement record that preserves a person's own words before interpretation.",
|
|
1037
|
-
inputSchema: {
|
|
1038
|
-
workspaceId: workspaceIdSchema,
|
|
1039
|
-
title: z.string().min(1),
|
|
1040
|
-
statement: z.string().min(1),
|
|
1041
|
-
source: z.string().min(1).optional(),
|
|
1042
|
-
fields: recordFieldsSchema
|
|
1043
|
-
}
|
|
1044
|
-
}, async (input) => jsonResult(await createStatement(runtime, input, recordActorId)));
|
|
1045
|
-
registerDxcTool("update_statement", {
|
|
1046
|
-
description: "Update a Statement record while preserving prior versions.",
|
|
1047
|
-
inputSchema: {
|
|
1048
|
-
workspaceId: workspaceIdSchema,
|
|
1049
|
-
id: z.string().min(1),
|
|
1050
|
-
title: z.string().min(1).optional(),
|
|
1051
|
-
statement: z.string().min(1).optional(),
|
|
1052
|
-
source: z.string().min(1).optional(),
|
|
1053
|
-
fields: recordFieldsSchema,
|
|
1054
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1055
|
-
revisionNote: z.string().min(1).optional()
|
|
1056
|
-
}
|
|
1057
|
-
}, async (input) => jsonResult(await updateStatement(runtime, input, recordActorId)));
|
|
1058
|
-
registerDxcTool("list_environments", {
|
|
1059
|
-
description: "List Operational Registry Environment records for the workspace.",
|
|
1060
|
-
inputSchema: {
|
|
1061
|
-
workspaceId: workspaceIdSchema,
|
|
1062
|
-
limit: z.number().int().min(1).max(100).optional(),
|
|
1063
|
-
includeArchived: z.boolean().optional()
|
|
1064
|
-
}
|
|
1065
|
-
}, async ({ workspaceId, limit, includeArchived }) => jsonResult(await listRecords(runtime.db, "environments", limit ?? 20, { workspaceId, includeArchived })));
|
|
1066
|
-
registerDxcTool("create_environment", {
|
|
1067
|
-
description: "Create an Operational Registry Environment, such as local, staging, or production.",
|
|
1068
|
-
inputSchema: {
|
|
1069
|
-
workspaceId: workspaceIdSchema,
|
|
1070
|
-
name: z.string().min(1),
|
|
1071
|
-
summary: z.string().min(1).optional(),
|
|
1072
|
-
description: z.string().min(1).optional(),
|
|
1073
|
-
fields: recordFieldsSchema
|
|
1074
|
-
}
|
|
1075
|
-
}, async (input) => jsonResult(await createEnvironment(runtime, input, recordActorId)));
|
|
1076
|
-
registerDxcTool("update_environment", {
|
|
1077
|
-
description: "Update an Operational Registry Environment while preserving prior versions.",
|
|
1078
|
-
inputSchema: {
|
|
1079
|
-
workspaceId: workspaceIdSchema,
|
|
1080
|
-
id: z.string().min(1),
|
|
1081
|
-
name: z.string().min(1).optional(),
|
|
1082
|
-
summary: z.string().min(1).optional(),
|
|
1083
|
-
description: z.string().min(1).optional(),
|
|
1084
|
-
fields: recordFieldsSchema,
|
|
1085
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1086
|
-
revisionNote: z.string().min(1).optional()
|
|
1087
|
-
}
|
|
1088
|
-
}, async (input) => jsonResult(await updateEnvironment(runtime, input, recordActorId)));
|
|
1089
|
-
registerDxcTool("list_components", {
|
|
1090
|
-
description: "List Operational Registry Components that belong to one Environment.",
|
|
1091
|
-
inputSchema: {
|
|
1092
|
-
workspaceId: workspaceIdSchema,
|
|
1093
|
-
environmentId: z.string().min(1),
|
|
1094
|
-
limit: z.number().int().min(1).max(100).optional(),
|
|
1095
|
-
includeArchived: z.boolean().optional()
|
|
1096
|
-
}
|
|
1097
|
-
}, async (input) => jsonResult(await listComponents(runtime, input)));
|
|
1098
|
-
registerDxcTool("create_component", {
|
|
1099
|
-
description: "Create an Operational Registry Component for one Environment. Secret pointers are pointers only; do not paste credentials or secret values.",
|
|
1100
|
-
inputSchema: {
|
|
1101
|
-
workspaceId: workspaceIdSchema,
|
|
1102
|
-
name: z.string().min(1),
|
|
1103
|
-
environmentId: z.string().min(1),
|
|
1104
|
-
kind: z.string().min(1),
|
|
1105
|
-
locator: componentLocatorSchema,
|
|
1106
|
-
summary: z.string().min(1).optional(),
|
|
1107
|
-
identifiers: componentIdentifiersSchema,
|
|
1108
|
-
secretPointers: z.array(secretPointerSchema).optional(),
|
|
1109
|
-
notes: z.string().min(1).optional(),
|
|
1110
|
-
fields: recordFieldsSchema
|
|
1111
|
-
}
|
|
1112
|
-
}, async (input) => jsonResult(await createComponent(runtime, input, recordActorId)));
|
|
1113
|
-
registerDxcTool("update_component", {
|
|
1114
|
-
description: "Update an Operational Registry Component while preserving prior versions. Secret pointers are pointers only; do not paste credentials or secret values.",
|
|
1115
|
-
inputSchema: {
|
|
1116
|
-
workspaceId: workspaceIdSchema,
|
|
1117
|
-
id: z.string().min(1),
|
|
1118
|
-
name: z.string().min(1).optional(),
|
|
1119
|
-
kind: z.string().min(1).optional(),
|
|
1120
|
-
locator: componentLocatorSchema.optional(),
|
|
1121
|
-
summary: z.string().min(1).optional(),
|
|
1122
|
-
identifiers: componentIdentifiersSchema,
|
|
1123
|
-
secretPointers: z.array(secretPointerSchema).optional(),
|
|
1124
|
-
notes: z.string().min(1).optional(),
|
|
1125
|
-
fields: recordFieldsSchema,
|
|
1126
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1127
|
-
revisionNote: z.string().min(1).optional()
|
|
1128
|
-
}
|
|
1129
|
-
}, async (input) => jsonResult(await updateComponent(runtime, input, recordActorId)));
|
|
1130
|
-
registerDxcTool("create_maintenance_schedule", {
|
|
1131
|
-
description: "Create a Maintenance Schedule for recurring operational hygiene. Due state is derived from cadence and linked completed Changes or Tasks.",
|
|
1132
|
-
inputSchema: {
|
|
1133
|
-
workspaceId: workspaceIdSchema,
|
|
1134
|
-
name: z.string().min(1),
|
|
1135
|
-
kind: z.string().min(1),
|
|
1136
|
-
cadence: maintenanceCadenceSchema,
|
|
1137
|
-
startDate: z.string().min(1),
|
|
1138
|
-
summary: z.string().min(1).optional(),
|
|
1139
|
-
rationale: z.string().min(1).optional(),
|
|
1140
|
-
notes: z.string().min(1).optional(),
|
|
1141
|
-
fields: recordFieldsSchema
|
|
1142
|
-
}
|
|
1143
|
-
}, async (input) => jsonResult(await createMaintenanceSchedule(runtime, input, recordActorId)));
|
|
1144
|
-
registerDxcTool("update_maintenance_schedule", {
|
|
1145
|
-
description: "Update a Maintenance Schedule while preserving prior versions.",
|
|
1146
|
-
inputSchema: {
|
|
1147
|
-
workspaceId: workspaceIdSchema,
|
|
1148
|
-
id: z.string().min(1),
|
|
1149
|
-
name: z.string().min(1).optional(),
|
|
1150
|
-
kind: z.string().min(1).optional(),
|
|
1151
|
-
cadence: maintenanceCadenceSchema.optional(),
|
|
1152
|
-
startDate: z.string().min(1).optional(),
|
|
1153
|
-
summary: z.string().min(1).optional(),
|
|
1154
|
-
rationale: z.string().min(1).optional(),
|
|
1155
|
-
notes: z.string().min(1).optional(),
|
|
1156
|
-
fields: recordFieldsSchema,
|
|
1157
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1158
|
-
revisionNote: z.string().min(1).optional()
|
|
1159
|
-
}
|
|
1160
|
-
}, async (input) => jsonResult(await updateMaintenanceSchedule(runtime, input, recordActorId)));
|
|
1161
|
-
registerDxcTool("create_estimate", {
|
|
1162
|
-
description: "Create an itemized Engineer cost estimate for Weigh.",
|
|
1163
|
-
inputSchema: {
|
|
1164
|
-
workspaceId: workspaceIdSchema,
|
|
1165
|
-
title: z.string().min(1),
|
|
1166
|
-
summary: z.string().min(1).optional(),
|
|
1167
|
-
lineItems: z.array(estimateLineItemSchema).min(1),
|
|
1168
|
-
requirementIds: z.array(z.string().min(1)).optional(),
|
|
1169
|
-
expectationIds: z.array(z.string().min(1)).optional(),
|
|
1170
|
-
fields: recordFieldsSchema
|
|
1171
|
-
}
|
|
1172
|
-
}, async (input) => jsonResult(await createEstimate(runtime, input, recordActorId)));
|
|
1173
|
-
registerDxcTool("update_estimate", {
|
|
1174
|
-
description: "Update an itemized Engineer cost estimate while preserving prior versions.",
|
|
1175
|
-
inputSchema: {
|
|
1176
|
-
workspaceId: workspaceIdSchema,
|
|
1177
|
-
id: z.string().min(1),
|
|
1178
|
-
title: z.string().min(1).optional(),
|
|
1179
|
-
summary: z.string().min(1).optional(),
|
|
1180
|
-
lineItems: z.array(estimateLineItemSchema).min(1).optional(),
|
|
1181
|
-
fields: recordFieldsSchema,
|
|
1182
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1183
|
-
revisionNote: z.string().min(1).optional()
|
|
1184
|
-
}
|
|
1185
|
-
}, async (input) => jsonResult(await updateEstimate(runtime, input, recordActorId)));
|
|
1186
|
-
registerDxcTool("create_benefits", {
|
|
1187
|
-
description: "Create an Owner-authored Benefits record for Weigh.",
|
|
1188
|
-
inputSchema: {
|
|
1189
|
-
workspaceId: workspaceIdSchema,
|
|
1190
|
-
title: z.string().min(1),
|
|
1191
|
-
summary: z.string().min(1).optional(),
|
|
1192
|
-
benefitItems: z.array(benefitItemSchema).min(1),
|
|
1193
|
-
requirementIds: z.array(z.string().min(1)).optional(),
|
|
1194
|
-
expectationIds: z.array(z.string().min(1)).optional(),
|
|
1195
|
-
fields: recordFieldsSchema
|
|
1196
|
-
}
|
|
1197
|
-
}, async (input) => jsonResult(await createBenefits(runtime, input, recordActorId)));
|
|
1198
|
-
registerDxcTool("update_benefits", {
|
|
1199
|
-
description: "Update an Owner-authored Benefits record while preserving prior versions.",
|
|
1200
|
-
inputSchema: {
|
|
1201
|
-
workspaceId: workspaceIdSchema,
|
|
1202
|
-
id: z.string().min(1),
|
|
1203
|
-
title: z.string().min(1).optional(),
|
|
1204
|
-
summary: z.string().min(1).optional(),
|
|
1205
|
-
benefitItems: z.array(benefitItemSchema).min(1).optional(),
|
|
1206
|
-
fields: recordFieldsSchema,
|
|
1207
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1208
|
-
revisionNote: z.string().min(1).optional()
|
|
1209
|
-
}
|
|
1210
|
-
}, async (input) => jsonResult(await updateBenefits(runtime, input, recordActorId)));
|
|
1211
|
-
registerDxcTool("create_value_realization", {
|
|
1212
|
-
description: "Create a Value Realization record for measured before/after value. Comparisons are derived from baseline and actual metric values.",
|
|
1213
|
-
inputSchema: {
|
|
1214
|
-
workspaceId: workspaceIdSchema,
|
|
1215
|
-
title: z.string().min(1),
|
|
1216
|
-
summary: z.string().min(1).optional(),
|
|
1217
|
-
metrics: z.array(valueMetricSchema).min(1),
|
|
1218
|
-
requirementIds: z.array(z.string().min(1)).optional(),
|
|
1219
|
-
expectationIds: z.array(z.string().min(1)).optional(),
|
|
1220
|
-
commitmentIds: z.array(z.string().min(1)).optional(),
|
|
1221
|
-
fields: recordFieldsSchema
|
|
1222
|
-
}
|
|
1223
|
-
}, async (input) => jsonResult(await createValueRealization(runtime, input, recordActorId)));
|
|
1224
|
-
registerDxcTool("update_value_realization", {
|
|
1225
|
-
description: "Update a Value Realization record while preserving prior metric versions.",
|
|
1226
|
-
inputSchema: {
|
|
1227
|
-
workspaceId: workspaceIdSchema,
|
|
1228
|
-
id: z.string().min(1),
|
|
1229
|
-
title: z.string().min(1).optional(),
|
|
1230
|
-
summary: z.string().min(1).optional(),
|
|
1231
|
-
metrics: z.array(valueMetricSchema).min(1).optional(),
|
|
1232
|
-
fields: recordFieldsSchema,
|
|
1233
|
-
unsetFields: z.array(fieldNameSchema).optional(),
|
|
1234
|
-
revisionNote: z.string().min(1).optional()
|
|
1235
|
-
}
|
|
1236
|
-
}, async (input) => jsonResult(await updateValueRealization(runtime, input, recordActorId)));
|
|
1237
|
-
registerDxcTool("create_expectation", {
|
|
1238
|
-
description: "Create an expectation record.",
|
|
1239
|
-
inputSchema: {
|
|
1240
|
-
workspaceId: workspaceIdSchema,
|
|
1241
|
-
title: z.string().min(1),
|
|
1242
|
-
statement: z.string().min(1),
|
|
1243
|
-
successRecognition: z.string().min(1).optional(),
|
|
1244
|
-
approvalState: expectationApprovalStateSchema.optional(),
|
|
1245
|
-
approvedBy: z.string().min(1).optional(),
|
|
1246
|
-
approvedAt: z.string().min(1).optional(),
|
|
1247
|
-
source: z.string().min(1).optional(),
|
|
1248
|
-
statementId: z.string().min(1).optional(),
|
|
1249
|
-
fields: recordFieldsSchema
|
|
1250
|
-
}
|
|
1251
|
-
}, async ({ workspaceId, title, statement, successRecognition, approvalState, approvedBy, approvedAt, source, statementId, fields }) => jsonResult(await createExpectation(runtime, {
|
|
1252
|
-
workspaceId,
|
|
1253
|
-
title,
|
|
1254
|
-
statement,
|
|
1255
|
-
successRecognition,
|
|
1256
|
-
approvalState,
|
|
1257
|
-
approvedBy,
|
|
1258
|
-
approvedAt,
|
|
1259
|
-
source,
|
|
1260
|
-
statementId,
|
|
1261
|
-
fields
|
|
1262
|
-
}, recordActorId)));
|
|
1263
|
-
registerDxcTool("create_requirement", {
|
|
1264
|
-
description: "Create a requirement record.",
|
|
1265
|
-
inputSchema: {
|
|
1266
|
-
workspaceId: workspaceIdSchema,
|
|
1267
|
-
title: z.string().min(1),
|
|
1268
|
-
expectationId: z.string().min(1).optional(),
|
|
1269
|
-
statement: z.string().min(1),
|
|
1270
|
-
acceptanceCriteria: z.array(z.string().min(1)).optional(),
|
|
1271
|
-
priority: z.enum(["low", "medium", "high"]).optional(),
|
|
1272
|
-
status: requirementStatusSchema.optional(),
|
|
1273
|
-
fields: recordFieldsSchema
|
|
1274
|
-
}
|
|
1275
|
-
}, async ({ workspaceId, title, expectationId, statement, acceptanceCriteria, priority, status, fields }) => jsonResult(await createRequirement(runtime, { workspaceId, title, expectationId, statement, acceptanceCriteria, priority, status, fields }, recordActorId)));
|
|
1276
|
-
registerDxcTool("create_task", {
|
|
1277
|
-
description: "Create an execution task ledger. Current status is derived from the latest status_change entry.",
|
|
1278
|
-
inputSchema: {
|
|
1279
|
-
workspaceId: workspaceIdSchema,
|
|
1280
|
-
title: z.string().min(1),
|
|
1281
|
-
description: z.string().min(1),
|
|
1282
|
-
assignee: z.string().min(1).optional(),
|
|
1283
|
-
assignor: z.string().min(1).optional(),
|
|
1284
|
-
requirementId: z.string().min(1).optional(),
|
|
1285
|
-
initialStatus: taskStatusSchema.optional(),
|
|
1286
|
-
fields: recordFieldsSchema
|
|
1287
|
-
}
|
|
1288
|
-
}, async (input) => jsonResult(await createTask(runtime, input, recordActorId)));
|
|
1289
|
-
registerDxcTool("append_task_entry", {
|
|
1290
|
-
description: "Append an immutable entry to a Task. Use status_change entries to change the derived current status.",
|
|
1291
|
-
inputSchema: {
|
|
1292
|
-
workspaceId: workspaceIdSchema,
|
|
1293
|
-
taskId: z.string().min(1),
|
|
1294
|
-
entryType: taskEntryTypeSchema,
|
|
1295
|
-
body: z.string().min(1),
|
|
1296
|
-
status: taskStatusSchema.optional()
|
|
1297
|
-
}
|
|
1298
|
-
}, async (input) => jsonResult(await appendTaskEntry(runtime.db, input, recordActorId)));
|
|
1299
|
-
registerDxcTool("create_commitment", {
|
|
1300
|
-
description: "Create an Owner commitment record that moves requirements or expectations toward Build.",
|
|
1301
|
-
inputSchema: {
|
|
1302
|
-
workspaceId: workspaceIdSchema,
|
|
1303
|
-
title: z.string().min(1),
|
|
1304
|
-
summary: z.string().min(1).optional(),
|
|
1305
|
-
commitmentStatement: z.string().min(1),
|
|
1306
|
-
requirementIds: z.array(z.string().min(1)).optional(),
|
|
1307
|
-
expectationIds: z.array(z.string().min(1)).optional(),
|
|
1308
|
-
reservationNotes: z.array(z.string().min(1)).optional(),
|
|
1309
|
-
deferralId: z.string().min(1).optional(),
|
|
1310
|
-
fields: recordFieldsSchema
|
|
1311
|
-
}
|
|
1312
|
-
}, async (input) => jsonResult(await createCommitment(runtime, input, recordActorId)));
|
|
1313
|
-
registerDxcTool("create_deferral", {
|
|
1314
|
-
description: "Create an Owner deferral record with explicit conditions required for a future Commitment.",
|
|
1315
|
-
inputSchema: {
|
|
1316
|
-
workspaceId: workspaceIdSchema,
|
|
1317
|
-
title: z.string().min(1),
|
|
1318
|
-
summary: z.string().min(1).optional(),
|
|
1319
|
-
reason: z.string().min(1),
|
|
1320
|
-
conditions: z.array(z.string().min(1)).min(1),
|
|
1321
|
-
requirementIds: z.array(z.string().min(1)).optional(),
|
|
1322
|
-
expectationIds: z.array(z.string().min(1)).optional(),
|
|
1323
|
-
fields: recordFieldsSchema
|
|
1324
|
-
}
|
|
1325
|
-
}, async (input) => jsonResult(await createDeferral(runtime, input, recordActorId)));
|
|
1326
|
-
registerDxcTool("append_deferral_event", {
|
|
1327
|
-
description: "Append an immutable event to a Deferral record. Use this for condition updates, notes, resolution into Commitment, or abandonment.",
|
|
1328
|
-
inputSchema: {
|
|
1329
|
-
workspaceId: workspaceIdSchema,
|
|
1330
|
-
deferralId: z.string().min(1),
|
|
1331
|
-
eventType: deferralEventTypeSchema,
|
|
1332
|
-
conditionId: z.string().min(1).optional(),
|
|
1333
|
-
note: z.string().min(1).optional(),
|
|
1334
|
-
summary: z.string().min(1).optional(),
|
|
1335
|
-
reason: z.string().min(1).optional(),
|
|
1336
|
-
commitmentId: z.string().min(1).optional()
|
|
1337
|
-
}
|
|
1338
|
-
}, async (input) => jsonResult(await appendDeferralEventForTool(runtime, input, recordActorId)));
|
|
1339
|
-
registerDxcTool("create_change", {
|
|
1340
|
-
description: "Create a service change record with baseline type, plan, execution, rollback, and risk/impact sections. Use riskImpact to include downstream impact or blast radius when known.",
|
|
1341
|
-
inputSchema: {
|
|
1342
|
-
workspaceId: workspaceIdSchema,
|
|
1343
|
-
title: z.string().min(1),
|
|
1344
|
-
summary: z.string().min(1).optional(),
|
|
1345
|
-
changeType: changeTypeSchema.optional(),
|
|
1346
|
-
impactGrade: changeImpactGradeSchema.optional(),
|
|
1347
|
-
emergencyImportance: z.string().min(1).optional(),
|
|
1348
|
-
emergencyImmediacy: z.string().min(1).optional(),
|
|
1349
|
-
changePlan: z.string().min(1),
|
|
1350
|
-
executionSteps: z.array(z.string().min(1)).min(1),
|
|
1351
|
-
rollbackPlan: z.string().min(1),
|
|
1352
|
-
riskImpact: z
|
|
1353
|
-
.string()
|
|
1354
|
-
.min(1)
|
|
1355
|
-
.describe("Risk, impact, open concerns, and downstream impact for this Change. Include what else may be affected, what depends on what is changing, and the blast-radius conclusion identified by the Engineer or their tool when available. This is documentary and absence of analysis is visible; it is not a separate blocker."),
|
|
1356
|
-
plannedFor: z.string().min(1).optional(),
|
|
1357
|
-
requirementId: z.string().min(1).optional(),
|
|
1358
|
-
fields: recordFieldsSchema
|
|
1359
|
-
}
|
|
1360
|
-
}, async (input) => jsonResult(await createChange(runtime, input, recordActorId)));
|
|
1361
|
-
registerDxcTool("append_change_event", {
|
|
1362
|
-
description: "Append an immutable event to a Change record. Use this for notice, veto, decision, result, recovery, plan revisions, and notes. Result and recovery events may include optional Git commit references as documentary traceability.",
|
|
1363
|
-
inputSchema: {
|
|
1364
|
-
workspaceId: workspaceIdSchema,
|
|
1365
|
-
changeId: z.string().min(1),
|
|
1366
|
-
eventType: changeEventTypeSchema,
|
|
1367
|
-
notice: z.string().min(1).optional(),
|
|
1368
|
-
noticeTo: z.array(z.string().min(1)).optional(),
|
|
1369
|
-
effectiveAt: z.string().min(1).optional(),
|
|
1370
|
-
vetoByRole: changeVetoRoleSchema.optional(),
|
|
1371
|
-
reason: z.string().min(1).optional(),
|
|
1372
|
-
decision: changeDecisionSchema.optional(),
|
|
1373
|
-
result: changeResultSchema.optional(),
|
|
1374
|
-
gitCommitReferences: z
|
|
1375
|
-
.array(gitCommitReferenceSchema)
|
|
1376
|
-
.min(1)
|
|
1377
|
-
.optional()
|
|
1378
|
-
.describe("Optional Git commit references for result or recovery events. Each reference stores a commit identifier plus optional repository and URL. DX Complete records these as provided and does not validate or inspect Git."),
|
|
1379
|
-
summary: z.string().min(1).optional(),
|
|
1380
|
-
note: z.string().min(1).optional(),
|
|
1381
|
-
revisedChangeType: changeTypeSchema.optional(),
|
|
1382
|
-
revisedImpactGrade: changeImpactGradeSchema.optional(),
|
|
1383
|
-
revisedEmergencyImportance: z.string().min(1).optional(),
|
|
1384
|
-
revisedEmergencyImmediacy: z.string().min(1).optional(),
|
|
1385
|
-
revisedChangePlan: z.string().min(1).optional(),
|
|
1386
|
-
revisedExecutionSteps: z.array(z.string().min(1)).optional(),
|
|
1387
|
-
revisedRollbackPlan: z.string().min(1).optional(),
|
|
1388
|
-
revisedRiskImpact: z.string().min(1).optional(),
|
|
1389
|
-
revisedPlannedFor: z.string().min(1).optional()
|
|
1390
|
-
}
|
|
1391
|
-
}, async (input) => jsonResult(await appendChangeEvent(runtime.db, {
|
|
1392
|
-
workspaceId: input.workspaceId,
|
|
1393
|
-
changeId: input.changeId,
|
|
1394
|
-
eventType: input.eventType,
|
|
1395
|
-
event: buildChangeEventContent(input)
|
|
1396
|
-
}, recordActorId)));
|
|
1397
|
-
registerDxcTool("create_decision", {
|
|
1398
|
-
description: "Create a revisitable decision ledger. Current decision is derived from the latest decision entry.",
|
|
1399
|
-
inputSchema: {
|
|
1400
|
-
workspaceId: workspaceIdSchema,
|
|
1401
|
-
title: z.string().min(1),
|
|
1402
|
-
matter: z.string().min(1),
|
|
1403
|
-
initialEntries: z.array(decisionInitialEntrySchema).optional(),
|
|
1404
|
-
initialDecision: initialDecisionSchema.optional(),
|
|
1405
|
-
fields: recordFieldsSchema
|
|
1406
|
-
}
|
|
1407
|
-
}, async ({ workspaceId, title, matter, initialEntries, initialDecision, fields }) => {
|
|
1408
|
-
assertNoTypedFields(fields, "create_decision", DECISION_TYPED_FIELDS);
|
|
1409
|
-
assertNoDecisionInputFields(fields);
|
|
1410
|
-
return jsonResult(await createDecision(runtime, { workspaceId, title, matter, initialEntries, initialDecision, fields }, recordActorId));
|
|
1411
|
-
});
|
|
1412
|
-
registerDxcTool("append_decision_entry", {
|
|
1413
|
-
description: "Append an immutable entry to a Decision. Use decision entries to change the derived current decision.",
|
|
1414
|
-
inputSchema: {
|
|
1415
|
-
workspaceId: workspaceIdSchema,
|
|
1416
|
-
decisionId: z.string().min(1),
|
|
1417
|
-
entryType: decisionEntryTypeSchema,
|
|
1418
|
-
body: z.string().min(1),
|
|
1419
|
-
decidedBy: z.string().min(1).optional(),
|
|
1420
|
-
rationale: z.string().min(1).optional()
|
|
1421
|
-
}
|
|
1422
|
-
}, async (input) => jsonResult(await appendDecisionEntry(runtime.db, input, recordActorId)));
|
|
1423
|
-
registerDxcTool("create_risk", {
|
|
1424
|
-
description: "Create a Risk ledger for uncertainty or exposure. Current status, assessment, and treatment derive from entries.",
|
|
1425
|
-
inputSchema: {
|
|
1426
|
-
workspaceId: workspaceIdSchema,
|
|
1427
|
-
title: z.string().min(1),
|
|
1428
|
-
topic: z.string().min(1),
|
|
1429
|
-
summary: z.string().min(1).optional(),
|
|
1430
|
-
body: z.string().min(1).optional(),
|
|
1431
|
-
likelihood: riskLevelSchema.optional(),
|
|
1432
|
-
impact: riskLevelSchema.optional(),
|
|
1433
|
-
treatment: riskTreatmentSchema.optional(),
|
|
1434
|
-
treatmentRationale: z.string().min(1).optional(),
|
|
1435
|
-
fields: recordFieldsSchema
|
|
1436
|
-
}
|
|
1437
|
-
}, async (input) => jsonResult(await createRisk(runtime, input, recordActorId, options.workspaceRoles)));
|
|
1438
|
-
registerDxcTool("append_risk_entry", {
|
|
1439
|
-
description: "Append an immutable entry to a Risk. Use assessment entries for likelihood/impact and treatment entries for accept, mitigate, transfer, or avoid.",
|
|
1440
|
-
inputSchema: {
|
|
1441
|
-
workspaceId: workspaceIdSchema,
|
|
1442
|
-
riskId: z.string().min(1),
|
|
1443
|
-
entryType: riskEntryTypeSchema,
|
|
1444
|
-
body: z.string().min(1),
|
|
1445
|
-
likelihood: riskLevelSchema.optional(),
|
|
1446
|
-
impact: riskLevelSchema.optional(),
|
|
1447
|
-
treatment: riskTreatmentSchema.optional(),
|
|
1448
|
-
treatmentRationale: z.string().min(1).optional()
|
|
1449
|
-
}
|
|
1450
|
-
}, async (input) => {
|
|
1451
|
-
assertRiskAcceptanceAccess(input.treatment, options.workspaceRoles);
|
|
1452
|
-
return jsonResult(await appendRiskEntry(runtime.db, input, recordActorId));
|
|
1453
|
-
});
|
|
1454
|
-
registerDxcTool("create_incident", {
|
|
1455
|
-
description: "Create an Incident ledger for a specific service-impacting or potentially service-impacting occurrence.",
|
|
1456
|
-
inputSchema: {
|
|
1457
|
-
workspaceId: workspaceIdSchema,
|
|
1458
|
-
title: z.string().min(1),
|
|
1459
|
-
description: z.string().min(1),
|
|
1460
|
-
summary: z.string().min(1).optional(),
|
|
1461
|
-
severity: incidentSeveritySchema.optional(),
|
|
1462
|
-
componentIds: z.array(z.string().min(1)).optional(),
|
|
1463
|
-
fields: recordFieldsSchema
|
|
1464
|
-
}
|
|
1465
|
-
}, async (input) => jsonResult(await createIncident(runtime, input, recordActorId)));
|
|
1466
|
-
registerDxcTool("append_incident_entry", {
|
|
1467
|
-
description: "Append an immutable entry to an Incident. Current status and severity derive from the latest relevant entries.",
|
|
1468
|
-
inputSchema: {
|
|
1469
|
-
workspaceId: workspaceIdSchema,
|
|
1470
|
-
incidentId: z.string().min(1),
|
|
1471
|
-
entryType: incidentEntryTypeSchema,
|
|
1472
|
-
body: z.string().min(1),
|
|
1473
|
-
severity: incidentSeveritySchema.optional()
|
|
1474
|
-
}
|
|
1475
|
-
}, async (input) => jsonResult(await appendIncidentEntry(runtime.db, input, recordActorId)));
|
|
1476
|
-
registerDxcTool("create_support_request", {
|
|
1477
|
-
description: "Create a shared Support Request ledger for a reported user experience, question, request, or issue. This is distinct from a private DX Complete Ticket.",
|
|
1478
|
-
inputSchema: {
|
|
1479
|
-
workspaceId: workspaceIdSchema,
|
|
1480
|
-
title: z.string().min(1),
|
|
1481
|
-
reporter: z.string().min(1),
|
|
1482
|
-
kind: z.string().min(1),
|
|
1483
|
-
reportedExperience: z.string().min(1),
|
|
1484
|
-
summary: z.string().min(1).optional(),
|
|
1485
|
-
fields: recordFieldsSchema
|
|
1486
|
-
}
|
|
1487
|
-
}, async (input) => jsonResult(await createSupportRequest(runtime, input, recordActorId)));
|
|
1488
|
-
registerDxcTool("append_support_request_entry", {
|
|
1489
|
-
description: "Append an immutable entry to a Support Request. Escalated entries require an Incident link; current status derives from the latest status-bearing entry.",
|
|
1490
|
-
inputSchema: {
|
|
1491
|
-
workspaceId: workspaceIdSchema,
|
|
1492
|
-
supportRequestId: z.string().min(1),
|
|
1493
|
-
entryType: supportRequestEntryTypeSchema,
|
|
1494
|
-
body: z.string().min(1),
|
|
1495
|
-
incidentId: z.string().min(1).optional()
|
|
1496
|
-
}
|
|
1497
|
-
}, async (input) => jsonResult(await appendSupportRequestEntryForTool(runtime, input, recordActorId)));
|
|
1498
|
-
registerDxcTool("create_problem", {
|
|
1499
|
-
description: "Create a Problem ledger for an underlying or recurring cause evidenced by one or more Incidents.",
|
|
1500
|
-
inputSchema: {
|
|
1501
|
-
workspaceId: workspaceIdSchema,
|
|
1502
|
-
title: z.string().min(1),
|
|
1503
|
-
description: z.string().min(1),
|
|
1504
|
-
summary: z.string().min(1).optional(),
|
|
1505
|
-
incidentIds: z.array(z.string().min(1)).min(1),
|
|
1506
|
-
componentIds: z.array(z.string().min(1)).optional(),
|
|
1507
|
-
fields: recordFieldsSchema
|
|
1508
|
-
}
|
|
1509
|
-
}, async (input) => jsonResult(await createProblem(runtime, input, recordActorId)));
|
|
1510
|
-
registerDxcTool("append_problem_entry", {
|
|
1511
|
-
description: "Append an immutable entry to a Problem. Current status and root cause derive from the latest relevant entries.",
|
|
1512
|
-
inputSchema: {
|
|
1513
|
-
workspaceId: workspaceIdSchema,
|
|
1514
|
-
problemId: z.string().min(1),
|
|
1515
|
-
entryType: problemEntryTypeSchema,
|
|
1516
|
-
body: z.string().min(1),
|
|
1517
|
-
rootCause: z.string().min(1).optional()
|
|
1518
|
-
}
|
|
1519
|
-
}, async (input) => jsonResult(await appendProblemEntry(runtime.db, input, recordActorId)));
|
|
1520
|
-
registerDxcTool("list_records", {
|
|
1521
|
-
description: "List records from a DX Complete collection.",
|
|
1522
|
-
inputSchema: {
|
|
1523
|
-
recordType: activeCollectionSchema,
|
|
1524
|
-
workspaceId: workspaceIdSchema.optional(),
|
|
1525
|
-
limit: z.number().int().min(1).max(100).optional(),
|
|
1526
|
-
includeArchived: z.boolean().optional()
|
|
1527
|
-
}
|
|
1528
|
-
}, async ({ recordType, workspaceId, limit, includeArchived }) => jsonResult(await listRecords(runtime.db, recordType, limit ?? 20, { workspaceId, includeArchived })));
|
|
1529
|
-
registerDxcTool("list_linked_records", {
|
|
1530
|
-
description: "List records linked to or from a DX Complete record.",
|
|
1531
|
-
inputSchema: {
|
|
1532
|
-
recordType: activeCollectionSchema,
|
|
1533
|
-
workspaceId: workspaceIdSchema.optional(),
|
|
1534
|
-
id: z.string().min(1),
|
|
1535
|
-
direction: z.enum(["outbound", "inbound", "both"]).optional(),
|
|
1536
|
-
relationship: z.string().min(1).optional(),
|
|
1537
|
-
includeArchived: z.boolean().optional()
|
|
1538
|
-
}
|
|
1539
|
-
}, async (input) => jsonResult(await listLinkedRecords(runtime.db, input)));
|
|
1540
|
-
registerDxcTool("link_decision_input", {
|
|
1541
|
-
description: "Link a Decision to one record that informed it using the informed_by relationship.",
|
|
1542
|
-
inputSchema: {
|
|
1543
|
-
workspaceId: workspaceIdSchema,
|
|
1544
|
-
decisionId: z.string().min(1),
|
|
1545
|
-
inputRecordType: decisionInputRecordTypeSchema,
|
|
1546
|
-
inputId: z.string().min(1)
|
|
1547
|
-
}
|
|
1548
|
-
}, async (input) => jsonResult(await linkDecisionInput(runtime, input, recordActorId)));
|
|
1549
|
-
registerDxcTool("update_record", {
|
|
1550
|
-
description: "Update a DX Complete record and optionally clear top-level fields.",
|
|
1551
|
-
inputSchema: {
|
|
1552
|
-
recordType: activeCollectionSchema,
|
|
1553
|
-
workspaceId: workspaceIdSchema.optional(),
|
|
1554
|
-
id: z.string().min(1),
|
|
1555
|
-
title: z.string().min(1).optional(),
|
|
1556
|
-
summary: z.string().min(1).optional(),
|
|
1557
|
-
fields: recordFieldsSchema,
|
|
1558
|
-
unsetFields: z.array(fieldNameSchema).optional()
|
|
1559
|
-
}
|
|
1560
|
-
}, async (input) => jsonResult(await updateRecord(runtime.db, input, recordActorId)));
|
|
1561
|
-
registerDxcTool("update_expectation", {
|
|
1562
|
-
description: "Update an expectation record with typed expectation fields.",
|
|
1563
|
-
inputSchema: {
|
|
1564
|
-
workspaceId: workspaceIdSchema,
|
|
1565
|
-
id: z.string().min(1),
|
|
1566
|
-
title: z.string().min(1).optional(),
|
|
1567
|
-
statement: z.string().min(1).optional(),
|
|
1568
|
-
successRecognition: z.string().min(1).optional(),
|
|
1569
|
-
approvalState: expectationApprovalStateSchema.optional(),
|
|
1570
|
-
approvedBy: z.string().min(1).optional(),
|
|
1571
|
-
approvedAt: z.string().min(1).optional(),
|
|
1572
|
-
source: z.string().min(1).optional(),
|
|
1573
|
-
revisionNote: z.string().min(1).optional(),
|
|
1574
|
-
fields: recordFieldsSchema,
|
|
1575
|
-
unsetFields: z.array(fieldNameSchema).optional()
|
|
1576
|
-
}
|
|
1577
|
-
}, async (input) => jsonResult(await updateExpectation(runtime, input, recordActorId)));
|
|
1578
|
-
registerDxcTool("update_requirement", {
|
|
1579
|
-
description: "Update a requirement record with typed requirement fields.",
|
|
1580
|
-
inputSchema: {
|
|
1581
|
-
workspaceId: workspaceIdSchema,
|
|
1582
|
-
id: z.string().min(1),
|
|
1583
|
-
title: z.string().min(1).optional(),
|
|
1584
|
-
statement: z.string().min(1).optional(),
|
|
1585
|
-
acceptanceCriteria: z.array(z.string().min(1)).optional(),
|
|
1586
|
-
priority: z.enum(["low", "medium", "high"]).optional(),
|
|
1587
|
-
status: requirementStatusSchema.optional(),
|
|
1588
|
-
revisionNote: z.string().min(1).optional(),
|
|
1589
|
-
fields: recordFieldsSchema,
|
|
1590
|
-
unsetFields: z.array(fieldNameSchema).optional()
|
|
1591
|
-
}
|
|
1592
|
-
}, async (input) => jsonResult(await updateRequirement(runtime, input, recordActorId)));
|
|
1593
|
-
registerDxcTool("append_review_note", {
|
|
1594
|
-
description: "Append a non-blocking review note to an expectation or requirement. The optional important flag only surfaces the note; it does not create an approval duty or workflow block.",
|
|
1595
|
-
inputSchema: {
|
|
1596
|
-
workspaceId: workspaceIdSchema,
|
|
1597
|
-
recordType: reviewableRecordTypeSchema,
|
|
1598
|
-
id: z.string().min(1),
|
|
1599
|
-
body: z.string().min(1),
|
|
1600
|
-
important: z.boolean().optional()
|
|
1601
|
-
}
|
|
1602
|
-
}, async (input) => jsonResult(await appendReviewNote(runtime.db, input, recordActorId)));
|
|
1603
|
-
registerDxcTool("archive_record", {
|
|
1604
|
-
description: "Archive a DX Complete record without deleting it.",
|
|
1605
|
-
inputSchema: {
|
|
1606
|
-
recordType: activeCollectionSchema,
|
|
1607
|
-
workspaceId: workspaceIdSchema.optional(),
|
|
1608
|
-
id: z.string().min(1),
|
|
1609
|
-
reason: z.string().min(1).optional(),
|
|
1610
|
-
supersededByType: activeCollectionSchema.optional(),
|
|
1611
|
-
supersededById: z.string().min(1).optional()
|
|
1612
|
-
}
|
|
1613
|
-
}, async (input) => jsonResult(await archiveRecord(runtime.db, input, recordActorId)));
|
|
1614
|
-
registerDxcTool("link_records", {
|
|
1615
|
-
description: "Link one DX Complete record to another.",
|
|
1616
|
-
inputSchema: {
|
|
1617
|
-
workspaceId: workspaceIdSchema,
|
|
1618
|
-
fromType: activeCollectionSchema,
|
|
1619
|
-
fromId: z.string().min(1),
|
|
1620
|
-
toType: activeCollectionSchema,
|
|
1621
|
-
toId: z.string().min(1),
|
|
1622
|
-
relationship: z.string().min(1).optional()
|
|
1623
|
-
}
|
|
1624
|
-
}, async (input) => jsonResult(await linkRecords(runtime.db, input, recordActorId)));
|
|
1625
|
-
registerDxcTool("unlink_records", {
|
|
1626
|
-
description: "Remove one relationship link from a DX Complete record to another record.",
|
|
1627
|
-
inputSchema: {
|
|
1628
|
-
workspaceId: workspaceIdSchema,
|
|
1629
|
-
fromType: activeCollectionSchema,
|
|
1630
|
-
fromId: z.string().min(1),
|
|
1631
|
-
toType: activeCollectionSchema,
|
|
1632
|
-
toId: z.string().min(1),
|
|
1633
|
-
relationship: z.string().min(1).optional()
|
|
1634
|
-
}
|
|
1635
|
-
}, async (input) => jsonResult(await unlinkRecords(runtime.db, input, recordActorId)));
|
|
1636
|
-
return server;
|
|
1637
|
-
}
|
|
1638
|
-
function omitWorkspaceId(schema) {
|
|
1639
|
-
const result = {};
|
|
1640
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
1641
|
-
if (key !== "workspaceId") {
|
|
1642
|
-
result[key] = value;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return result;
|
|
1646
|
-
}
|
|
1647
|
-
function injectHostedWorkspace(input, originalSchema, workspaceId) {
|
|
1648
|
-
if (!Object.hasOwn(originalSchema, "workspaceId")) {
|
|
1649
|
-
return input;
|
|
1650
|
-
}
|
|
1651
|
-
return {
|
|
1652
|
-
...input,
|
|
1653
|
-
workspaceId
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
function assertHostedWorkspaceAccess(toolName, input, workspaceId) {
|
|
1657
|
-
if (!workspaceId) {
|
|
1658
|
-
return;
|
|
1659
|
-
}
|
|
1660
|
-
for (const key of ["recordType", "fromType", "toType", "supersededByType"]) {
|
|
1661
|
-
if (input[key] === "workspaces") {
|
|
1662
|
-
throw new Error(`${toolName} cannot operate on workspace records through a hosted workspace MCP endpoint.`);
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
if (typeof input.workspaceId === "string" && input.workspaceId !== workspaceId) {
|
|
1666
|
-
throw new Error("Hosted MCP workspace scope mismatch.");
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
function assertToolRoleAccess(toolName, roles, input) {
|
|
1670
|
-
if (!roles) {
|
|
1671
|
-
return;
|
|
1672
|
-
}
|
|
1673
|
-
if (roles.includes("owner") || memberAllowedTools.has(toolName)) {
|
|
1674
|
-
return;
|
|
1675
|
-
}
|
|
1676
|
-
if (roles.includes("engineer") && engineerAllowedTools.has(toolName)) {
|
|
1677
|
-
return;
|
|
1678
|
-
}
|
|
1679
|
-
if (roles.includes("tester") && testerAllowedTools.has(toolName)) {
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
if (roles.includes("operator") && operatorAllowedTools.has(toolName)) {
|
|
1683
|
-
return;
|
|
1684
|
-
}
|
|
1685
|
-
if (roles.includes("support_agent") && supportAgentAllowedTools.has(toolName)) {
|
|
1686
|
-
return;
|
|
1687
|
-
}
|
|
1688
|
-
if (roles.includes("operator") &&
|
|
1689
|
-
toolName === "archive_record" &&
|
|
1690
|
-
(input.recordType === "environments" || input.recordType === "components" || input.recordType === "maintenance_schedules")) {
|
|
1691
|
-
return;
|
|
1692
|
-
}
|
|
1693
|
-
throw new Error(`Workspace role access denied for ${toolName}.`);
|
|
1694
|
-
}
|
|
1695
|
-
const memberAllowedTools = new Set([
|
|
1696
|
-
"runtime_status",
|
|
1697
|
-
"get_process_guide",
|
|
1698
|
-
"get_doc",
|
|
1699
|
-
"get_record",
|
|
1700
|
-
"list_records",
|
|
1701
|
-
"list_linked_records",
|
|
1702
|
-
"list_environments",
|
|
1703
|
-
"list_components",
|
|
1704
|
-
"create_dxcomplete_ticket",
|
|
1705
|
-
"append_dxcomplete_ticket",
|
|
1706
|
-
"list_dxcomplete_tickets",
|
|
1707
|
-
"list_unread_dxcomplete_ticket_replies",
|
|
1708
|
-
"read_dxcomplete_ticket",
|
|
1709
|
-
"archive_dxcomplete_ticket",
|
|
1710
|
-
"append_journal_note",
|
|
1711
|
-
"read_journal",
|
|
1712
|
-
"get_journal_entry",
|
|
1713
|
-
"append_journal_summary"
|
|
1714
|
-
]);
|
|
1715
|
-
const engineerAllowedTools = new Set([
|
|
1716
|
-
"create_estimate",
|
|
1717
|
-
"update_estimate",
|
|
1718
|
-
"create_task",
|
|
1719
|
-
"append_task_entry",
|
|
1720
|
-
"create_risk",
|
|
1721
|
-
"append_risk_entry",
|
|
1722
|
-
"append_review_note"
|
|
1723
|
-
]);
|
|
1724
|
-
const testerAllowedTools = new Set([
|
|
1725
|
-
"create_risk",
|
|
1726
|
-
"append_risk_entry",
|
|
1727
|
-
"append_review_note"
|
|
1728
|
-
]);
|
|
1729
|
-
const operatorAllowedTools = new Set([
|
|
1730
|
-
"create_change",
|
|
1731
|
-
"append_change_event",
|
|
1732
|
-
"create_risk",
|
|
1733
|
-
"append_risk_entry",
|
|
1734
|
-
"create_incident",
|
|
1735
|
-
"append_incident_entry",
|
|
1736
|
-
"create_problem",
|
|
1737
|
-
"append_problem_entry",
|
|
1738
|
-
"create_environment",
|
|
1739
|
-
"update_environment",
|
|
1740
|
-
"create_component",
|
|
1741
|
-
"update_component",
|
|
1742
|
-
"create_maintenance_schedule",
|
|
1743
|
-
"update_maintenance_schedule"
|
|
1744
|
-
]);
|
|
1745
|
-
const supportAgentAllowedTools = new Set([
|
|
1746
|
-
"create_incident",
|
|
1747
|
-
"append_incident_entry",
|
|
1748
|
-
"create_support_request",
|
|
1749
|
-
"append_support_request_entry"
|
|
1750
|
-
]);
|
|
1751
|
-
function jsonResult(value) {
|
|
1752
|
-
return {
|
|
1753
|
-
content: [
|
|
1754
|
-
{
|
|
1755
|
-
type: "text",
|
|
1756
|
-
text: JSON.stringify(value, null, 2)
|
|
1757
|
-
}
|
|
1758
|
-
]
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
function getInputSchemaFingerprint(inputSchema) {
|
|
1762
|
-
return createHash("sha256")
|
|
1763
|
-
.update(stableStringify(z.toJSONSchema(z.object(inputSchema))))
|
|
1764
|
-
.digest("hex")
|
|
1765
|
-
.slice(0, 16);
|
|
1766
|
-
}
|
|
1767
|
-
function stableStringify(value) {
|
|
1768
|
-
return JSON.stringify(sortJsonValue(value));
|
|
1769
|
-
}
|
|
1770
|
-
function sortJsonValue(value) {
|
|
1771
|
-
if (Array.isArray(value)) {
|
|
1772
|
-
return value.map(sortJsonValue);
|
|
1773
|
-
}
|
|
1774
|
-
if (value && typeof value === "object") {
|
|
1775
|
-
const input = value;
|
|
1776
|
-
const output = {};
|
|
1777
|
-
for (const key of Object.keys(input).sort()) {
|
|
1778
|
-
output[key] = sortJsonValue(input[key]);
|
|
1779
|
-
}
|
|
1780
|
-
return output;
|
|
1781
|
-
}
|
|
1782
|
-
return value;
|
|
1783
|
-
}
|
|
1784
|
-
async function createStatement(runtime, input, actorId) {
|
|
1785
|
-
assertNoTypedFields(input.fields, "create_statement", STATEMENT_TYPED_FIELDS);
|
|
1786
|
-
return createRecord(runtime.db, "statements", {
|
|
1787
|
-
workspaceId: input.workspaceId,
|
|
1788
|
-
title: input.title,
|
|
1789
|
-
summary: input.statement,
|
|
1790
|
-
fields: {
|
|
1791
|
-
...(input.fields ?? {}),
|
|
1792
|
-
statement: input.statement,
|
|
1793
|
-
...(input.source !== undefined ? { source: input.source } : {})
|
|
1794
|
-
}
|
|
1795
|
-
}, actorId);
|
|
1796
|
-
}
|
|
1797
|
-
async function updateStatement(runtime, input, actorId) {
|
|
1798
|
-
assertNoTypedFields(input.fields, "update_statement", STATEMENT_TYPED_FIELDS);
|
|
1799
|
-
return updateRecord(runtime.db, {
|
|
1800
|
-
recordType: "statements",
|
|
1801
|
-
workspaceId: input.workspaceId,
|
|
1802
|
-
id: input.id,
|
|
1803
|
-
title: input.title,
|
|
1804
|
-
summary: input.statement,
|
|
1805
|
-
fields: {
|
|
1806
|
-
...(input.fields ?? {}),
|
|
1807
|
-
...(input.statement !== undefined ? { statement: input.statement } : {}),
|
|
1808
|
-
...(input.source !== undefined ? { source: input.source } : {})
|
|
1809
|
-
},
|
|
1810
|
-
unsetFields: input.unsetFields,
|
|
1811
|
-
allowManagedFields: true,
|
|
1812
|
-
revisionNote: input.revisionNote
|
|
1813
|
-
}, actorId);
|
|
1814
|
-
}
|
|
1815
|
-
async function createEnvironment(runtime, input, actorId) {
|
|
1816
|
-
assertNoTypedFields(input.fields, "create_environment", ENVIRONMENT_TYPED_FIELDS);
|
|
1817
|
-
return createRecord(runtime.db, "environments", {
|
|
1818
|
-
workspaceId: input.workspaceId,
|
|
1819
|
-
title: input.name,
|
|
1820
|
-
summary: input.summary,
|
|
1821
|
-
allowManagedFields: true,
|
|
1822
|
-
fields: {
|
|
1823
|
-
...(input.fields ?? {}),
|
|
1824
|
-
name: input.name,
|
|
1825
|
-
...(input.description !== undefined ? { description: input.description } : {})
|
|
1826
|
-
}
|
|
1827
|
-
}, actorId);
|
|
1828
|
-
}
|
|
1829
|
-
async function updateEnvironment(runtime, input, actorId) {
|
|
1830
|
-
assertNoTypedFields(input.fields, "update_environment", ENVIRONMENT_TYPED_FIELDS);
|
|
1831
|
-
assertNoTypedUnsetFields(input.unsetFields, "update_environment", ENVIRONMENT_TYPED_FIELDS);
|
|
1832
|
-
return updateRecord(runtime.db, {
|
|
1833
|
-
recordType: "environments",
|
|
1834
|
-
workspaceId: input.workspaceId,
|
|
1835
|
-
id: input.id,
|
|
1836
|
-
title: input.name,
|
|
1837
|
-
summary: input.summary,
|
|
1838
|
-
fields: {
|
|
1839
|
-
...(input.fields ?? {}),
|
|
1840
|
-
...(input.name !== undefined ? { name: input.name } : {}),
|
|
1841
|
-
...(input.description !== undefined ? { description: input.description } : {})
|
|
1842
|
-
},
|
|
1843
|
-
unsetFields: input.unsetFields,
|
|
1844
|
-
allowManagedFields: true,
|
|
1845
|
-
revisionNote: input.revisionNote
|
|
1846
|
-
}, actorId);
|
|
1847
|
-
}
|
|
1848
|
-
async function listComponents(runtime, input) {
|
|
1849
|
-
const environment = await getRecord(runtime.db, "environments", input.environmentId, {
|
|
1850
|
-
workspaceId: input.workspaceId
|
|
1851
|
-
});
|
|
1852
|
-
if (!environment) {
|
|
1853
|
-
throw new Error(`Environment not found: environments/${input.environmentId}`);
|
|
1854
|
-
}
|
|
1855
|
-
const filter = {
|
|
1856
|
-
workspaceId: input.workspaceId,
|
|
1857
|
-
"fields.environmentId": environment._id
|
|
1858
|
-
};
|
|
1859
|
-
if (!input.includeArchived) {
|
|
1860
|
-
filter.archivedAt = { $exists: false };
|
|
1861
|
-
}
|
|
1862
|
-
return runtime.db
|
|
1863
|
-
.collection("components")
|
|
1864
|
-
.find(filter)
|
|
1865
|
-
.sort({ createdAt: 1, _id: 1 })
|
|
1866
|
-
.limit(input.limit ?? 20)
|
|
1867
|
-
.toArray();
|
|
1868
|
-
}
|
|
1869
|
-
async function createComponent(runtime, input, actorId) {
|
|
1870
|
-
assertNoReservedFields(input.fields, ["workspaceId", "environmentId"]);
|
|
1871
|
-
assertNoTypedFields(input.fields, "create_component", COMPONENT_TYPED_FIELDS);
|
|
1872
|
-
const environment = await getRecord(runtime.db, "environments", input.environmentId, {
|
|
1873
|
-
workspaceId: input.workspaceId
|
|
1874
|
-
});
|
|
1875
|
-
if (!environment) {
|
|
1876
|
-
throw new Error(`Environment not found: environments/${input.environmentId}`);
|
|
1877
|
-
}
|
|
1878
|
-
const component = await createRecord(runtime.db, "components", {
|
|
1879
|
-
workspaceId: input.workspaceId,
|
|
1880
|
-
title: input.name,
|
|
1881
|
-
summary: input.summary,
|
|
1882
|
-
allowManagedFields: true,
|
|
1883
|
-
fields: {
|
|
1884
|
-
...(input.fields ?? {}),
|
|
1885
|
-
name: input.name,
|
|
1886
|
-
environmentId: environment._id,
|
|
1887
|
-
kind: input.kind,
|
|
1888
|
-
locator: input.locator,
|
|
1889
|
-
...(input.identifiers !== undefined ? { identifiers: input.identifiers } : {}),
|
|
1890
|
-
...(input.secretPointers !== undefined ? { secretPointers: input.secretPointers } : {}),
|
|
1891
|
-
...(input.notes !== undefined ? { notes: input.notes } : {})
|
|
1892
|
-
}
|
|
1893
|
-
}, actorId);
|
|
1894
|
-
return ensureLinkRecords(runtime, {
|
|
1895
|
-
workspaceId: input.workspaceId,
|
|
1896
|
-
fromType: "components",
|
|
1897
|
-
fromId: component._id,
|
|
1898
|
-
toType: "environments",
|
|
1899
|
-
toId: environment._id,
|
|
1900
|
-
relationship: "belongs_to_environment"
|
|
1901
|
-
}, actorId);
|
|
1902
|
-
}
|
|
1903
|
-
async function updateComponent(runtime, input, actorId) {
|
|
1904
|
-
assertNoTypedFields(input.fields, "update_component", COMPONENT_TYPED_FIELDS);
|
|
1905
|
-
assertNoTypedUnsetFields(input.unsetFields, "update_component", COMPONENT_TYPED_FIELDS);
|
|
1906
|
-
return updateRecord(runtime.db, {
|
|
1907
|
-
recordType: "components",
|
|
1908
|
-
workspaceId: input.workspaceId,
|
|
1909
|
-
id: input.id,
|
|
1910
|
-
title: input.name,
|
|
1911
|
-
summary: input.summary,
|
|
1912
|
-
fields: {
|
|
1913
|
-
...(input.fields ?? {}),
|
|
1914
|
-
...(input.name !== undefined ? { name: input.name } : {}),
|
|
1915
|
-
...(input.kind !== undefined ? { kind: input.kind } : {}),
|
|
1916
|
-
...(input.locator !== undefined ? { locator: input.locator } : {}),
|
|
1917
|
-
...(input.identifiers !== undefined ? { identifiers: input.identifiers } : {}),
|
|
1918
|
-
...(input.secretPointers !== undefined ? { secretPointers: input.secretPointers } : {}),
|
|
1919
|
-
...(input.notes !== undefined ? { notes: input.notes } : {})
|
|
1920
|
-
},
|
|
1921
|
-
unsetFields: input.unsetFields,
|
|
1922
|
-
allowManagedFields: true,
|
|
1923
|
-
revisionNote: input.revisionNote
|
|
1924
|
-
}, actorId);
|
|
1925
|
-
}
|
|
1926
|
-
async function createMaintenanceSchedule(runtime, input, actorId) {
|
|
1927
|
-
assertNoTypedFields(input.fields, "create_maintenance_schedule", MAINTENANCE_SCHEDULE_TYPED_FIELDS);
|
|
1928
|
-
return createRecord(runtime.db, "maintenance_schedules", {
|
|
1929
|
-
workspaceId: input.workspaceId,
|
|
1930
|
-
title: input.name,
|
|
1931
|
-
summary: input.summary ?? input.rationale,
|
|
1932
|
-
allowManagedFields: true,
|
|
1933
|
-
fields: {
|
|
1934
|
-
...(input.fields ?? {}),
|
|
1935
|
-
name: input.name,
|
|
1936
|
-
kind: input.kind,
|
|
1937
|
-
cadence: input.cadence,
|
|
1938
|
-
startDate: input.startDate,
|
|
1939
|
-
...(input.rationale !== undefined ? { rationale: input.rationale } : {}),
|
|
1940
|
-
...(input.notes !== undefined ? { notes: input.notes } : {})
|
|
1941
|
-
}
|
|
1942
|
-
}, actorId);
|
|
1943
|
-
}
|
|
1944
|
-
async function updateMaintenanceSchedule(runtime, input, actorId) {
|
|
1945
|
-
assertNoTypedFields(input.fields, "update_maintenance_schedule", MAINTENANCE_SCHEDULE_TYPED_FIELDS);
|
|
1946
|
-
assertNoTypedUnsetFields(input.unsetFields, "update_maintenance_schedule", MAINTENANCE_SCHEDULE_TYPED_FIELDS);
|
|
1947
|
-
return updateRecord(runtime.db, {
|
|
1948
|
-
recordType: "maintenance_schedules",
|
|
1949
|
-
workspaceId: input.workspaceId,
|
|
1950
|
-
id: input.id,
|
|
1951
|
-
title: input.name,
|
|
1952
|
-
summary: input.summary,
|
|
1953
|
-
fields: {
|
|
1954
|
-
...(input.fields ?? {}),
|
|
1955
|
-
...(input.name !== undefined ? { name: input.name } : {}),
|
|
1956
|
-
...(input.kind !== undefined ? { kind: input.kind } : {}),
|
|
1957
|
-
...(input.cadence !== undefined ? { cadence: input.cadence } : {}),
|
|
1958
|
-
...(input.startDate !== undefined ? { startDate: input.startDate } : {}),
|
|
1959
|
-
...(input.rationale !== undefined ? { rationale: input.rationale } : {}),
|
|
1960
|
-
...(input.notes !== undefined ? { notes: input.notes } : {})
|
|
1961
|
-
},
|
|
1962
|
-
unsetFields: input.unsetFields,
|
|
1963
|
-
allowManagedFields: true,
|
|
1964
|
-
revisionNote: input.revisionNote
|
|
1965
|
-
}, actorId);
|
|
1966
|
-
}
|
|
1967
|
-
async function createExpectation(runtime, input, actorId) {
|
|
1968
|
-
assertNoTypedFields(input.fields, "create_expectation", EXPECTATION_TYPED_FIELDS);
|
|
1969
|
-
assertNoObsoleteExpectationFields(input.fields, "create_expectation");
|
|
1970
|
-
if (input.statementId) {
|
|
1971
|
-
const statement = await getRecord(runtime.db, "statements", input.statementId, {
|
|
1972
|
-
workspaceId: input.workspaceId
|
|
1973
|
-
});
|
|
1974
|
-
if (!statement) {
|
|
1975
|
-
throw new Error(`Statement not found: statements/${input.statementId}`);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
const expectation = await createRecord(runtime.db, "expectations", {
|
|
1979
|
-
workspaceId: input.workspaceId,
|
|
1980
|
-
title: input.title,
|
|
1981
|
-
summary: input.statement,
|
|
1982
|
-
fields: {
|
|
1983
|
-
...(input.fields ?? {}),
|
|
1984
|
-
statement: input.statement,
|
|
1985
|
-
...(input.successRecognition !== undefined ? { successRecognition: input.successRecognition } : {}),
|
|
1986
|
-
approvalState: input.approvalState ?? "draft",
|
|
1987
|
-
...(input.approvedBy !== undefined ? { approvedBy: input.approvedBy } : {}),
|
|
1988
|
-
...(input.approvedAt !== undefined ? { approvedAt: input.approvedAt } : {}),
|
|
1989
|
-
...(input.source !== undefined ? { source: input.source } : {})
|
|
1990
|
-
}
|
|
1991
|
-
}, actorId);
|
|
1992
|
-
if (!input.statementId) {
|
|
1993
|
-
return expectation;
|
|
1994
|
-
}
|
|
1995
|
-
return linkRecords(runtime.db, {
|
|
1996
|
-
workspaceId: input.workspaceId,
|
|
1997
|
-
fromType: "expectations",
|
|
1998
|
-
fromId: expectation._id,
|
|
1999
|
-
toType: "statements",
|
|
2000
|
-
toId: input.statementId,
|
|
2001
|
-
relationship: "derives_from"
|
|
2002
|
-
}, actorId);
|
|
2003
|
-
}
|
|
2004
|
-
async function createEstimate(runtime, input, actorId) {
|
|
2005
|
-
assertNoReservedFields(input.fields, ["workspaceId", "initiativeId", "requirementIds", "expectationIds"]);
|
|
2006
|
-
assertNoTypedFields(input.fields, "create_estimate", ESTIMATE_TYPED_FIELDS);
|
|
2007
|
-
assertAtLeastOneEstimateTarget(input.requirementIds, input.expectationIds);
|
|
2008
|
-
await assertRecordsExist(runtime, "requirements", input.requirementIds ?? [], input.workspaceId);
|
|
2009
|
-
await assertRecordsExist(runtime, "expectations", input.expectationIds ?? [], input.workspaceId);
|
|
2010
|
-
const lineItems = normalizeEstimateLineItems(input.lineItems);
|
|
2011
|
-
let estimate = await createRecord(runtime.db, "estimates", {
|
|
2012
|
-
workspaceId: input.workspaceId,
|
|
2013
|
-
title: input.title,
|
|
2014
|
-
summary: input.summary,
|
|
2015
|
-
allowManagedFields: true,
|
|
2016
|
-
fields: {
|
|
2017
|
-
...(input.fields ?? {}),
|
|
2018
|
-
lineItems,
|
|
2019
|
-
rollup: computeQuantifiedRollup(lineItems)
|
|
2020
|
-
}
|
|
2021
|
-
}, actorId);
|
|
2022
|
-
estimate = await linkManyRecords(runtime, estimate, "requirements", input.requirementIds ?? [], "estimates", actorId);
|
|
2023
|
-
estimate = await linkManyRecords(runtime, estimate, "expectations", input.expectationIds ?? [], "estimates", actorId);
|
|
2024
|
-
return estimate;
|
|
2025
|
-
}
|
|
2026
|
-
async function updateEstimate(runtime, input, actorId) {
|
|
2027
|
-
assertNoTypedFields(input.fields, "update_estimate", ESTIMATE_TYPED_FIELDS);
|
|
2028
|
-
assertNoTypedUnsetFields(input.unsetFields, "update_estimate", ESTIMATE_TYPED_FIELDS);
|
|
2029
|
-
const lineItems = input.lineItems ? normalizeEstimateLineItems(input.lineItems) : undefined;
|
|
2030
|
-
return updateRecord(runtime.db, {
|
|
2031
|
-
recordType: "estimates",
|
|
2032
|
-
workspaceId: input.workspaceId,
|
|
2033
|
-
id: input.id,
|
|
2034
|
-
title: input.title,
|
|
2035
|
-
summary: input.summary,
|
|
2036
|
-
fields: {
|
|
2037
|
-
...(input.fields ?? {}),
|
|
2038
|
-
...(lineItems ? { lineItems, rollup: computeQuantifiedRollup(lineItems) } : {})
|
|
2039
|
-
},
|
|
2040
|
-
unsetFields: input.unsetFields,
|
|
2041
|
-
allowManagedFields: true,
|
|
2042
|
-
revisionNote: input.revisionNote
|
|
2043
|
-
}, actorId);
|
|
2044
|
-
}
|
|
2045
|
-
function normalizeEstimateLineItems(lineItems) {
|
|
2046
|
-
const seenIds = new Set();
|
|
2047
|
-
return lineItems.map((item, index) => {
|
|
2048
|
-
const id = item.id ?? randomUUID();
|
|
2049
|
-
if (seenIds.has(id)) {
|
|
2050
|
-
throw new Error(`Estimate line item id must be unique: ${id}.`);
|
|
2051
|
-
}
|
|
2052
|
-
seenIds.add(id);
|
|
2053
|
-
if (item.timing === "recurring" && !item.period) {
|
|
2054
|
-
throw new Error(`Estimate line item ${index + 1} is recurring and requires period.`);
|
|
2055
|
-
}
|
|
2056
|
-
if (item.timing === "one_time" && item.period) {
|
|
2057
|
-
throw new Error(`Estimate line item ${index + 1} is one_time and must omit period.`);
|
|
2058
|
-
}
|
|
2059
|
-
if (item.amount.kind === "range" && !(item.amount.min <= item.amount.expected && item.amount.expected <= item.amount.max)) {
|
|
2060
|
-
throw new Error(`Estimate line item ${index + 1} range must satisfy min <= expected <= max.`);
|
|
2061
|
-
}
|
|
2062
|
-
return {
|
|
2063
|
-
id,
|
|
2064
|
-
label: item.label,
|
|
2065
|
-
timing: item.timing,
|
|
2066
|
-
...(item.period ? { period: item.period } : {}),
|
|
2067
|
-
currency: item.currency,
|
|
2068
|
-
amount: item.amount
|
|
2069
|
-
};
|
|
2070
|
-
});
|
|
2071
|
-
}
|
|
2072
|
-
async function createBenefits(runtime, input, actorId) {
|
|
2073
|
-
assertNoReservedFields(input.fields, ["workspaceId", "initiativeId", "requirementIds", "expectationIds"]);
|
|
2074
|
-
assertNoTypedFields(input.fields, "create_benefits", BENEFITS_TYPED_FIELDS);
|
|
2075
|
-
assertAtLeastOneBenefitsTarget(input.requirementIds, input.expectationIds);
|
|
2076
|
-
await assertRecordsExist(runtime, "requirements", input.requirementIds ?? [], input.workspaceId);
|
|
2077
|
-
await assertRecordsExist(runtime, "expectations", input.expectationIds ?? [], input.workspaceId);
|
|
2078
|
-
const benefitItems = normalizeBenefitItems(input.benefitItems);
|
|
2079
|
-
let benefits = await createRecord(runtime.db, "benefits", {
|
|
2080
|
-
workspaceId: input.workspaceId,
|
|
2081
|
-
title: input.title,
|
|
2082
|
-
summary: input.summary,
|
|
2083
|
-
allowManagedFields: true,
|
|
2084
|
-
fields: {
|
|
2085
|
-
...(input.fields ?? {}),
|
|
2086
|
-
benefitItems,
|
|
2087
|
-
rollup: computeQuantifiedRollup(benefitItems.filter(isQuantifiedBenefitItem))
|
|
2088
|
-
}
|
|
2089
|
-
}, actorId);
|
|
2090
|
-
benefits = await linkManyRecords(runtime, benefits, "requirements", input.requirementIds ?? [], "benefits", actorId);
|
|
2091
|
-
benefits = await linkManyRecords(runtime, benefits, "expectations", input.expectationIds ?? [], "benefits", actorId);
|
|
2092
|
-
return benefits;
|
|
2093
|
-
}
|
|
2094
|
-
async function updateBenefits(runtime, input, actorId) {
|
|
2095
|
-
assertNoTypedFields(input.fields, "update_benefits", BENEFITS_TYPED_FIELDS);
|
|
2096
|
-
assertNoTypedUnsetFields(input.unsetFields, "update_benefits", BENEFITS_TYPED_FIELDS);
|
|
2097
|
-
const benefitItems = input.benefitItems ? normalizeBenefitItems(input.benefitItems) : undefined;
|
|
2098
|
-
return updateRecord(runtime.db, {
|
|
2099
|
-
recordType: "benefits",
|
|
2100
|
-
workspaceId: input.workspaceId,
|
|
2101
|
-
id: input.id,
|
|
2102
|
-
title: input.title,
|
|
2103
|
-
summary: input.summary,
|
|
2104
|
-
fields: {
|
|
2105
|
-
...(input.fields ?? {}),
|
|
2106
|
-
...(benefitItems ? { benefitItems, rollup: computeQuantifiedRollup(benefitItems.filter(isQuantifiedBenefitItem)) } : {})
|
|
2107
|
-
},
|
|
2108
|
-
unsetFields: input.unsetFields,
|
|
2109
|
-
allowManagedFields: true,
|
|
2110
|
-
revisionNote: input.revisionNote
|
|
2111
|
-
}, actorId);
|
|
2112
|
-
}
|
|
2113
|
-
async function createValueRealization(runtime, input, actorId) {
|
|
2114
|
-
assertNoReservedFields(input.fields, ["workspaceId", "requirementIds", "expectationIds", "commitmentIds"]);
|
|
2115
|
-
assertNoTypedFields(input.fields, "create_value_realization", VALUE_REALIZATION_TYPED_FIELDS);
|
|
2116
|
-
assertAtLeastOneValueRealizationTarget(input.requirementIds, input.expectationIds, input.commitmentIds);
|
|
2117
|
-
await assertRuntimeRecordsExist(runtime, input.workspaceId, "requirements", uniqueIds(input.requirementIds ?? []));
|
|
2118
|
-
await assertRuntimeRecordsExist(runtime, input.workspaceId, "expectations", uniqueIds(input.expectationIds ?? []));
|
|
2119
|
-
await assertRuntimeRecordsExist(runtime, input.workspaceId, "commitments", uniqueIds(input.commitmentIds ?? []));
|
|
2120
|
-
let valueRealization = await createRecord(runtime.db, "value_realizations", {
|
|
2121
|
-
workspaceId: input.workspaceId,
|
|
2122
|
-
title: input.title,
|
|
2123
|
-
summary: input.summary,
|
|
2124
|
-
allowManagedFields: true,
|
|
2125
|
-
fields: {
|
|
2126
|
-
...(input.fields ?? {}),
|
|
2127
|
-
metrics: normalizeValueMetrics(input.metrics)
|
|
2128
|
-
}
|
|
2129
|
-
}, actorId);
|
|
2130
|
-
valueRealization = await linkManyRecords(runtime, valueRealization, "requirements", input.requirementIds ?? [], "realizes_value_for", actorId);
|
|
2131
|
-
valueRealization = await linkManyRecords(runtime, valueRealization, "expectations", input.expectationIds ?? [], "realizes_value_for", actorId);
|
|
2132
|
-
valueRealization = await linkManyRecords(runtime, valueRealization, "commitments", input.commitmentIds ?? [], "realizes_value_for", actorId);
|
|
2133
|
-
return valueRealization;
|
|
2134
|
-
}
|
|
2135
|
-
async function updateValueRealization(runtime, input, actorId) {
|
|
2136
|
-
assertNoTypedFields(input.fields, "update_value_realization", VALUE_REALIZATION_TYPED_FIELDS);
|
|
2137
|
-
assertNoTypedUnsetFields(input.unsetFields, "update_value_realization", VALUE_REALIZATION_TYPED_FIELDS);
|
|
2138
|
-
return updateRecord(runtime.db, {
|
|
2139
|
-
recordType: "value_realizations",
|
|
2140
|
-
workspaceId: input.workspaceId,
|
|
2141
|
-
id: input.id,
|
|
2142
|
-
title: input.title,
|
|
2143
|
-
summary: input.summary,
|
|
2144
|
-
fields: {
|
|
2145
|
-
...(input.fields ?? {}),
|
|
2146
|
-
...(input.metrics ? { metrics: normalizeValueMetrics(input.metrics) } : {})
|
|
2147
|
-
},
|
|
2148
|
-
unsetFields: input.unsetFields,
|
|
2149
|
-
allowManagedFields: true,
|
|
2150
|
-
revisionNote: input.revisionNote
|
|
2151
|
-
}, actorId);
|
|
2152
|
-
}
|
|
2153
|
-
function normalizeValueMetrics(metrics) {
|
|
2154
|
-
const seenIds = new Set();
|
|
2155
|
-
return metrics.map((metric, index) => {
|
|
2156
|
-
const id = metric.id ?? randomUUID();
|
|
2157
|
-
if (seenIds.has(id)) {
|
|
2158
|
-
throw new Error(`Value metric id must be unique: ${id}.`);
|
|
2159
|
-
}
|
|
2160
|
-
seenIds.add(id);
|
|
2161
|
-
assertMeasuredAtDate(metric.baseline.measuredAt, `Value metric ${index + 1} baseline`);
|
|
2162
|
-
if (metric.actual) {
|
|
2163
|
-
assertMeasuredAtDate(metric.actual.measuredAt, `Value metric ${index + 1} actual`);
|
|
2164
|
-
}
|
|
2165
|
-
return {
|
|
2166
|
-
...metric,
|
|
2167
|
-
id
|
|
2168
|
-
};
|
|
2169
|
-
});
|
|
2170
|
-
}
|
|
2171
|
-
function assertMeasuredAtDate(value, label) {
|
|
2172
|
-
if (Number.isNaN(new Date(value).getTime())) {
|
|
2173
|
-
throw new Error(`${label} measuredAt must be a valid date string.`);
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
function normalizeBenefitItems(benefitItems) {
|
|
2177
|
-
const seenIds = new Set();
|
|
2178
|
-
return benefitItems.map((item, index) => {
|
|
2179
|
-
const id = item.id ?? randomUUID();
|
|
2180
|
-
if (seenIds.has(id)) {
|
|
2181
|
-
throw new Error(`Benefit item id must be unique: ${id}.`);
|
|
2182
|
-
}
|
|
2183
|
-
seenIds.add(id);
|
|
2184
|
-
if (!item.amount) {
|
|
2185
|
-
if (item.timing || item.period || item.currency) {
|
|
2186
|
-
throw new Error(`Benefit item ${index + 1} is qualitative and must omit timing, period, and currency.`);
|
|
2187
|
-
}
|
|
2188
|
-
return {
|
|
2189
|
-
id,
|
|
2190
|
-
label: item.label
|
|
2191
|
-
};
|
|
2192
|
-
}
|
|
2193
|
-
if (!item.timing) {
|
|
2194
|
-
throw new Error(`Benefit item ${index + 1} has amount and requires timing.`);
|
|
2195
|
-
}
|
|
2196
|
-
if (!item.currency) {
|
|
2197
|
-
throw new Error(`Benefit item ${index + 1} has amount and requires currency.`);
|
|
2198
|
-
}
|
|
2199
|
-
if (item.timing === "recurring" && !item.period) {
|
|
2200
|
-
throw new Error(`Benefit item ${index + 1} is recurring and requires period.`);
|
|
2201
|
-
}
|
|
2202
|
-
if (item.timing === "one_time" && item.period) {
|
|
2203
|
-
throw new Error(`Benefit item ${index + 1} is one_time and must omit period.`);
|
|
2204
|
-
}
|
|
2205
|
-
if (item.amount.kind === "range" && !(item.amount.min <= item.amount.expected && item.amount.expected <= item.amount.max)) {
|
|
2206
|
-
throw new Error(`Benefit item ${index + 1} range must satisfy min <= expected <= max.`);
|
|
2207
|
-
}
|
|
2208
|
-
return {
|
|
2209
|
-
id,
|
|
2210
|
-
label: item.label,
|
|
2211
|
-
timing: item.timing,
|
|
2212
|
-
...(item.period ? { period: item.period } : {}),
|
|
2213
|
-
currency: item.currency,
|
|
2214
|
-
amount: item.amount
|
|
2215
|
-
};
|
|
2216
|
-
});
|
|
2217
|
-
}
|
|
2218
|
-
function isQuantifiedBenefitItem(item) {
|
|
2219
|
-
return !!item.amount && !!item.timing && !!item.currency;
|
|
2220
|
-
}
|
|
2221
|
-
function computeQuantifiedRollup(lineItems) {
|
|
2222
|
-
const currencies = {};
|
|
2223
|
-
for (const item of lineItems) {
|
|
2224
|
-
const currency = (currencies[item.currency] ??= createEmptyRollupTimingGroup());
|
|
2225
|
-
const amount = normalizeRollupAmount(item.amount);
|
|
2226
|
-
if (item.timing === "one_time") {
|
|
2227
|
-
currency.one_time = addRollupAmounts(currency.one_time, amount);
|
|
2228
|
-
continue;
|
|
2229
|
-
}
|
|
2230
|
-
const recurring = currency.recurring;
|
|
2231
|
-
recurring[item.period ?? ""] = addRollupAmounts(recurring[item.period ?? ""], amount);
|
|
2232
|
-
}
|
|
2233
|
-
return { currencies };
|
|
2234
|
-
}
|
|
2235
|
-
function createEmptyRollupTimingGroup() {
|
|
2236
|
-
return {
|
|
2237
|
-
one_time: createZeroRollupAmount(),
|
|
2238
|
-
recurring: {}
|
|
2239
|
-
};
|
|
2240
|
-
}
|
|
2241
|
-
function createZeroRollupAmount() {
|
|
2242
|
-
return { min: 0, expected: 0, max: 0 };
|
|
2243
|
-
}
|
|
2244
|
-
function normalizeRollupAmount(amount) {
|
|
2245
|
-
if (amount.kind === "single") {
|
|
2246
|
-
return { min: amount.value, expected: amount.value, max: amount.value };
|
|
2247
|
-
}
|
|
2248
|
-
return { min: amount.min, expected: amount.expected, max: amount.max };
|
|
2249
|
-
}
|
|
2250
|
-
function addRollupAmounts(left, right) {
|
|
2251
|
-
const base = left ?? createZeroRollupAmount();
|
|
2252
|
-
return {
|
|
2253
|
-
min: base.min + right.min,
|
|
2254
|
-
expected: base.expected + right.expected,
|
|
2255
|
-
max: base.max + right.max
|
|
2256
|
-
};
|
|
2257
|
-
}
|
|
2258
|
-
async function createRequirement(runtime, input, actorId) {
|
|
2259
|
-
assertNoReservedFields(input.fields, ["workspaceId", "expectationId"]);
|
|
2260
|
-
assertNoTypedFields(input.fields, "create_requirement", REQUIREMENT_TYPED_FIELDS);
|
|
2261
|
-
if (input.expectationId) {
|
|
2262
|
-
const expectation = await getRecord(runtime.db, "expectations", input.expectationId, {
|
|
2263
|
-
workspaceId: input.workspaceId
|
|
2264
|
-
});
|
|
2265
|
-
if (!expectation) {
|
|
2266
|
-
throw new Error(`Expectation not found: expectations/${input.expectationId}`);
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
const requirement = await createRecord(runtime.db, "requirements", {
|
|
2270
|
-
workspaceId: input.workspaceId,
|
|
2271
|
-
title: input.title,
|
|
2272
|
-
summary: input.statement,
|
|
2273
|
-
fields: {
|
|
2274
|
-
...(input.fields ?? {}),
|
|
2275
|
-
statement: input.statement,
|
|
2276
|
-
...(input.acceptanceCriteria ? { acceptanceCriteria: input.acceptanceCriteria } : {}),
|
|
2277
|
-
...(input.priority ? { priority: input.priority } : {}),
|
|
2278
|
-
status: input.status ?? "draft"
|
|
2279
|
-
}
|
|
2280
|
-
}, actorId);
|
|
2281
|
-
if (!input.expectationId) {
|
|
2282
|
-
return requirement;
|
|
2283
|
-
}
|
|
2284
|
-
return linkRecords(runtime.db, {
|
|
2285
|
-
workspaceId: input.workspaceId,
|
|
2286
|
-
fromType: "requirements",
|
|
2287
|
-
fromId: requirement._id,
|
|
2288
|
-
toType: "expectations",
|
|
2289
|
-
toId: input.expectationId,
|
|
2290
|
-
relationship: "satisfies"
|
|
2291
|
-
}, actorId);
|
|
2292
|
-
}
|
|
2293
|
-
async function createTask(runtime, input, actorId) {
|
|
2294
|
-
assertNoReservedFields(input.fields, ["workspaceId", "requirementId"]);
|
|
2295
|
-
assertNoTypedFields(input.fields, "create_task", TASK_TYPED_FIELDS);
|
|
2296
|
-
if (input.requirementId) {
|
|
2297
|
-
const requirement = await getRecord(runtime.db, "requirements", input.requirementId, {
|
|
2298
|
-
workspaceId: input.workspaceId
|
|
2299
|
-
});
|
|
2300
|
-
if (!requirement) {
|
|
2301
|
-
throw new Error(`Requirement not found: requirements/${input.requirementId}`);
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
const now = new Date().toISOString();
|
|
2305
|
-
const initialStatus = input.initialStatus ?? "open";
|
|
2306
|
-
const initialStatusEntry = {
|
|
2307
|
-
id: randomUUID(),
|
|
2308
|
-
entryType: "status_change",
|
|
2309
|
-
body: `Initial status: ${initialStatus}.`,
|
|
2310
|
-
status: initialStatus,
|
|
2311
|
-
createdAt: now,
|
|
2312
|
-
createdBy: actorId
|
|
2313
|
-
};
|
|
2314
|
-
const task = await createRecord(runtime.db, "tasks", {
|
|
2315
|
-
workspaceId: input.workspaceId,
|
|
2316
|
-
title: input.title,
|
|
2317
|
-
summary: input.description,
|
|
2318
|
-
allowManagedFields: true,
|
|
2319
|
-
fields: {
|
|
2320
|
-
...(input.fields ?? {}),
|
|
2321
|
-
description: input.description,
|
|
2322
|
-
...(input.assignee !== undefined ? { assignee: input.assignee } : {}),
|
|
2323
|
-
...(input.assignor !== undefined ? { assignor: input.assignor } : {}),
|
|
2324
|
-
entries: [initialStatusEntry],
|
|
2325
|
-
currentStatus: taskEntryToCurrentStatus(initialStatusEntry)
|
|
2326
|
-
}
|
|
2327
|
-
}, actorId);
|
|
2328
|
-
if (!input.requirementId) {
|
|
2329
|
-
return task;
|
|
2330
|
-
}
|
|
2331
|
-
return linkRecords(runtime.db, {
|
|
2332
|
-
workspaceId: input.workspaceId,
|
|
2333
|
-
fromType: "tasks",
|
|
2334
|
-
fromId: task._id,
|
|
2335
|
-
toType: "requirements",
|
|
2336
|
-
toId: input.requirementId,
|
|
2337
|
-
relationship: "implements"
|
|
2338
|
-
}, actorId);
|
|
2339
|
-
}
|
|
2340
|
-
async function createDecision(runtime, input, actorId) {
|
|
2341
|
-
assertNoTypedFields(input.fields, "create_decision", DECISION_TYPED_FIELDS);
|
|
2342
|
-
assertNoDecisionInputFields(input.fields);
|
|
2343
|
-
const now = new Date().toISOString();
|
|
2344
|
-
const entries = buildInitialDecisionEntries(input.initialEntries, input.initialDecision, actorId, now);
|
|
2345
|
-
const latestDecisionEntry = [...entries].reverse().find((entry) => entry.entryType === "decision");
|
|
2346
|
-
return createRecord(runtime.db, "decisions", {
|
|
2347
|
-
workspaceId: input.workspaceId,
|
|
2348
|
-
title: input.title,
|
|
2349
|
-
summary: latestDecisionEntry?.body ?? input.matter,
|
|
2350
|
-
allowManagedFields: true,
|
|
2351
|
-
fields: {
|
|
2352
|
-
...(input.fields ?? {}),
|
|
2353
|
-
matter: input.matter,
|
|
2354
|
-
entries,
|
|
2355
|
-
...(latestDecisionEntry ? { currentDecision: decisionEntryToCurrentDecision(latestDecisionEntry) } : {})
|
|
2356
|
-
}
|
|
2357
|
-
}, actorId);
|
|
2358
|
-
}
|
|
2359
|
-
function buildInitialDecisionEntries(initialEntries, initialDecision, actorId, createdAt) {
|
|
2360
|
-
const entries = (initialEntries ?? []).map((entry) => buildDecisionEntry({
|
|
2361
|
-
entryType: entry.entryType,
|
|
2362
|
-
body: entry.body,
|
|
2363
|
-
decidedBy: entry.decidedBy,
|
|
2364
|
-
rationale: entry.rationale
|
|
2365
|
-
}, actorId, createdAt));
|
|
2366
|
-
if (initialDecision) {
|
|
2367
|
-
entries.push(buildDecisionEntry({
|
|
2368
|
-
entryType: "decision",
|
|
2369
|
-
body: initialDecision.body,
|
|
2370
|
-
decidedBy: initialDecision.decidedBy,
|
|
2371
|
-
rationale: initialDecision.rationale
|
|
2372
|
-
}, actorId, createdAt));
|
|
2373
|
-
}
|
|
2374
|
-
return entries;
|
|
2375
|
-
}
|
|
2376
|
-
function buildDecisionEntry(input, actorId, createdAt) {
|
|
2377
|
-
if (input.entryType !== "decision" && (input.decidedBy || input.rationale)) {
|
|
2378
|
-
throw new Error("decidedBy and rationale are only valid on decision entries.");
|
|
2379
|
-
}
|
|
2380
|
-
return {
|
|
2381
|
-
id: randomUUID(),
|
|
2382
|
-
entryType: input.entryType,
|
|
2383
|
-
body: input.body,
|
|
2384
|
-
createdAt,
|
|
2385
|
-
createdBy: actorId,
|
|
2386
|
-
...(input.decidedBy ? { decidedBy: input.decidedBy } : {}),
|
|
2387
|
-
...(input.rationale ? { rationale: input.rationale } : {})
|
|
2388
|
-
};
|
|
2389
|
-
}
|
|
2390
|
-
async function createCommitment(runtime, input, actorId) {
|
|
2391
|
-
assertNoReservedFields(input.fields, ["workspaceId", "requirementIds", "expectationIds", "deferralId"]);
|
|
2392
|
-
assertNoTypedFields(input.fields, "create_commitment", COMMITMENT_TYPED_FIELDS);
|
|
2393
|
-
assertAtLeastOneCommitmentTarget(input.requirementIds, input.expectationIds);
|
|
2394
|
-
await assertRecordsExist(runtime, "requirements", input.requirementIds ?? [], input.workspaceId);
|
|
2395
|
-
await assertRecordsExist(runtime, "expectations", input.expectationIds ?? [], input.workspaceId);
|
|
2396
|
-
if (input.deferralId) {
|
|
2397
|
-
const deferral = await getRecord(runtime.db, "deferrals", input.deferralId, {
|
|
2398
|
-
workspaceId: input.workspaceId
|
|
2399
|
-
});
|
|
2400
|
-
if (!deferral) {
|
|
2401
|
-
throw new Error(`Deferral not found: deferrals/${input.deferralId}`);
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
const now = new Date().toISOString();
|
|
2405
|
-
let commitment = await createRecord(runtime.db, "commitments", {
|
|
2406
|
-
workspaceId: input.workspaceId,
|
|
2407
|
-
title: input.title,
|
|
2408
|
-
summary: input.summary ?? input.commitmentStatement,
|
|
2409
|
-
allowManagedFields: true,
|
|
2410
|
-
fields: {
|
|
2411
|
-
...(input.fields ?? {}),
|
|
2412
|
-
commitmentStatement: input.commitmentStatement,
|
|
2413
|
-
reservations: (input.reservationNotes ?? []).map((note) => ({
|
|
2414
|
-
id: randomUUID(),
|
|
2415
|
-
note,
|
|
2416
|
-
createdAt: now,
|
|
2417
|
-
createdBy: actorId
|
|
2418
|
-
}))
|
|
2419
|
-
}
|
|
2420
|
-
}, actorId);
|
|
2421
|
-
commitment = await linkManyRecords(runtime, commitment, "requirements", input.requirementIds ?? [], "commits", actorId);
|
|
2422
|
-
commitment = await linkManyRecords(runtime, commitment, "expectations", input.expectationIds ?? [], "commits", actorId);
|
|
2423
|
-
if (input.deferralId) {
|
|
2424
|
-
commitment = await ensureLinkRecords(runtime, {
|
|
2425
|
-
workspaceId: input.workspaceId,
|
|
2426
|
-
fromType: "commitments",
|
|
2427
|
-
fromId: commitment._id,
|
|
2428
|
-
toType: "deferrals",
|
|
2429
|
-
toId: input.deferralId,
|
|
2430
|
-
relationship: "resolves_deferral"
|
|
2431
|
-
}, actorId);
|
|
2432
|
-
}
|
|
2433
|
-
return commitment;
|
|
2434
|
-
}
|
|
2435
|
-
async function createDeferral(runtime, input, actorId) {
|
|
2436
|
-
assertNoReservedFields(input.fields, ["workspaceId", "requirementIds", "expectationIds"]);
|
|
2437
|
-
assertNoTypedFields(input.fields, "create_deferral", DEFERRAL_TYPED_FIELDS);
|
|
2438
|
-
await assertRecordsExist(runtime, "requirements", input.requirementIds ?? [], input.workspaceId);
|
|
2439
|
-
await assertRecordsExist(runtime, "expectations", input.expectationIds ?? [], input.workspaceId);
|
|
2440
|
-
const now = new Date().toISOString();
|
|
2441
|
-
let deferral = await createRecord(runtime.db, "deferrals", {
|
|
2442
|
-
workspaceId: input.workspaceId,
|
|
2443
|
-
title: input.title,
|
|
2444
|
-
summary: input.summary ?? input.reason,
|
|
2445
|
-
allowManagedFields: true,
|
|
2446
|
-
fields: {
|
|
2447
|
-
...(input.fields ?? {}),
|
|
2448
|
-
reason: input.reason,
|
|
2449
|
-
status: "open",
|
|
2450
|
-
conditions: input.conditions.map((statement) => ({
|
|
2451
|
-
id: randomUUID(),
|
|
2452
|
-
statement,
|
|
2453
|
-
state: "open",
|
|
2454
|
-
createdAt: now,
|
|
2455
|
-
createdBy: actorId,
|
|
2456
|
-
updatedAt: now,
|
|
2457
|
-
updatedBy: actorId
|
|
2458
|
-
})),
|
|
2459
|
-
conditionEvents: []
|
|
2460
|
-
}
|
|
2461
|
-
}, actorId);
|
|
2462
|
-
deferral = await linkManyRecords(runtime, deferral, "requirements", input.requirementIds ?? [], "defers", actorId);
|
|
2463
|
-
deferral = await linkManyRecords(runtime, deferral, "expectations", input.expectationIds ?? [], "defers", actorId);
|
|
2464
|
-
return deferral;
|
|
2465
|
-
}
|
|
2466
|
-
async function appendDeferralEventForTool(runtime, input, actorId) {
|
|
2467
|
-
const event = buildDeferralEventContent(input);
|
|
2468
|
-
if (input.eventType === "deferral_resolved") {
|
|
2469
|
-
const commitment = await getRecord(runtime.db, "commitments", event.commitmentId, {
|
|
2470
|
-
workspaceId: input.workspaceId
|
|
2471
|
-
});
|
|
2472
|
-
if (!commitment) {
|
|
2473
|
-
throw new Error(`Commitment not found: commitments/${event.commitmentId}`);
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
const deferral = await appendDeferralEvent(runtime.db, {
|
|
2477
|
-
workspaceId: input.workspaceId,
|
|
2478
|
-
deferralId: input.deferralId,
|
|
2479
|
-
eventType: input.eventType,
|
|
2480
|
-
event
|
|
2481
|
-
}, actorId);
|
|
2482
|
-
if (input.eventType !== "deferral_resolved") {
|
|
2483
|
-
return deferral;
|
|
2484
|
-
}
|
|
2485
|
-
await ensureLinkRecords(runtime, {
|
|
2486
|
-
workspaceId: input.workspaceId,
|
|
2487
|
-
fromType: "commitments",
|
|
2488
|
-
fromId: event.commitmentId,
|
|
2489
|
-
toType: "deferrals",
|
|
2490
|
-
toId: deferral._id,
|
|
2491
|
-
relationship: "resolves_deferral"
|
|
2492
|
-
}, actorId);
|
|
2493
|
-
const updated = await getRecord(runtime.db, "deferrals", input.deferralId, { workspaceId: input.workspaceId });
|
|
2494
|
-
if (!updated) {
|
|
2495
|
-
throw new Error(`Deferral not found after resolution link: deferrals/${input.deferralId}`);
|
|
2496
|
-
}
|
|
2497
|
-
return updated;
|
|
2498
|
-
}
|
|
2499
|
-
function buildDeferralEventContent(input) {
|
|
2500
|
-
switch (input.eventType) {
|
|
2501
|
-
case "condition_addressed":
|
|
2502
|
-
case "condition_reopened":
|
|
2503
|
-
return compactObject({
|
|
2504
|
-
conditionId: requireDeferralEventField(input.conditionId, input.eventType, "conditionId"),
|
|
2505
|
-
summary: input.summary
|
|
2506
|
-
});
|
|
2507
|
-
case "condition_note_added":
|
|
2508
|
-
return compactObject({
|
|
2509
|
-
conditionId: requireDeferralEventField(input.conditionId, input.eventType, "conditionId"),
|
|
2510
|
-
note: requireDeferralEventField(input.note, input.eventType, "note")
|
|
2511
|
-
});
|
|
2512
|
-
case "deferral_resolved":
|
|
2513
|
-
return compactObject({
|
|
2514
|
-
commitmentId: requireDeferralEventField(input.commitmentId, input.eventType, "commitmentId"),
|
|
2515
|
-
summary: input.summary
|
|
2516
|
-
});
|
|
2517
|
-
case "deferral_abandoned":
|
|
2518
|
-
return compactObject({
|
|
2519
|
-
reason: requireDeferralEventField(input.reason, input.eventType, "reason"),
|
|
2520
|
-
summary: input.summary
|
|
2521
|
-
});
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
function requireDeferralEventField(value, eventType, fieldName) {
|
|
2525
|
-
if (value === undefined) {
|
|
2526
|
-
throw new Error(`${eventType} requires ${fieldName}.`);
|
|
2527
|
-
}
|
|
2528
|
-
return value;
|
|
2529
|
-
}
|
|
2530
|
-
function assertAtLeastOneCommitmentTarget(requirementIds, expectationIds) {
|
|
2531
|
-
if ((requirementIds?.length ?? 0) > 0 || (expectationIds?.length ?? 0) > 0) {
|
|
2532
|
-
return;
|
|
2533
|
-
}
|
|
2534
|
-
throw new Error("create_commitment requires at least one requirementId or expectationId.");
|
|
2535
|
-
}
|
|
2536
|
-
function assertAtLeastOneEstimateTarget(requirementIds, expectationIds) {
|
|
2537
|
-
if ((requirementIds?.length ?? 0) > 0 || (expectationIds?.length ?? 0) > 0) {
|
|
2538
|
-
return;
|
|
2539
|
-
}
|
|
2540
|
-
throw new Error("create_estimate requires at least one requirementId or expectationId.");
|
|
2541
|
-
}
|
|
2542
|
-
function assertAtLeastOneBenefitsTarget(requirementIds, expectationIds) {
|
|
2543
|
-
if ((requirementIds?.length ?? 0) > 0 || (expectationIds?.length ?? 0) > 0) {
|
|
2544
|
-
return;
|
|
2545
|
-
}
|
|
2546
|
-
throw new Error("create_benefits requires at least one requirementId or expectationId.");
|
|
2547
|
-
}
|
|
2548
|
-
function assertAtLeastOneValueRealizationTarget(requirementIds, expectationIds, commitmentIds) {
|
|
2549
|
-
if ((requirementIds?.length ?? 0) > 0 || (expectationIds?.length ?? 0) > 0 || (commitmentIds?.length ?? 0) > 0) {
|
|
2550
|
-
return;
|
|
2551
|
-
}
|
|
2552
|
-
throw new Error("create_value_realization requires at least one requirementId, expectationId, or commitmentId.");
|
|
2553
|
-
}
|
|
2554
|
-
async function assertRecordsExist(runtime, recordType, ids, workspaceId) {
|
|
2555
|
-
for (const id of new Set(ids)) {
|
|
2556
|
-
const record = await getRecord(runtime.db, recordType, id, { workspaceId });
|
|
2557
|
-
if (!record) {
|
|
2558
|
-
throw new Error(`Record not found: ${recordType}/${id}`);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
async function linkManyRecords(runtime, source, toType, toIds, relationship, actorId) {
|
|
2563
|
-
if (!source) {
|
|
2564
|
-
throw new Error("Source record not found.");
|
|
2565
|
-
}
|
|
2566
|
-
let current = source;
|
|
2567
|
-
for (const toId of new Set(toIds)) {
|
|
2568
|
-
current = await ensureLinkRecords(runtime, {
|
|
2569
|
-
workspaceId: current.workspaceId ?? "",
|
|
2570
|
-
fromType: current.recordType,
|
|
2571
|
-
fromId: current._id,
|
|
2572
|
-
toType,
|
|
2573
|
-
toId,
|
|
2574
|
-
relationship
|
|
2575
|
-
}, actorId);
|
|
2576
|
-
}
|
|
2577
|
-
return current;
|
|
2578
|
-
}
|
|
2579
|
-
async function ensureLinkRecords(runtime, input, actorId) {
|
|
2580
|
-
const source = await getRecord(runtime.db, input.fromType, input.fromId, {
|
|
2581
|
-
workspaceId: input.workspaceId
|
|
2582
|
-
});
|
|
2583
|
-
if (!source) {
|
|
2584
|
-
throw new Error(`Source record not found: ${input.fromType}/${input.fromId}`);
|
|
2585
|
-
}
|
|
2586
|
-
const target = await getRecord(runtime.db, input.toType, input.toId, {
|
|
2587
|
-
workspaceId: input.workspaceId
|
|
2588
|
-
});
|
|
2589
|
-
if (!target) {
|
|
2590
|
-
throw new Error(`Target record not found: ${input.toType}/${input.toId}`);
|
|
2591
|
-
}
|
|
2592
|
-
if (source.links.some((link) => link.toType === input.toType &&
|
|
2593
|
-
link.toId === target._id &&
|
|
2594
|
-
link.relationship === input.relationship)) {
|
|
2595
|
-
return source;
|
|
2596
|
-
}
|
|
2597
|
-
return linkRecords(runtime.db, input, actorId);
|
|
2598
|
-
}
|
|
2599
|
-
async function createRisk(runtime, input, actorId, roles) {
|
|
2600
|
-
assertNoReservedFields(input.fields, ["workspaceId"]);
|
|
2601
|
-
assertNoTypedFields(input.fields, "create_risk", RISK_TYPED_FIELDS);
|
|
2602
|
-
assertRiskAcceptanceAccess(input.treatment, roles);
|
|
2603
|
-
if ((input.likelihood && !input.impact) || (!input.likelihood && input.impact)) {
|
|
2604
|
-
throw new Error("create_risk requires both likelihood and impact when creating an initial assessment.");
|
|
2605
|
-
}
|
|
2606
|
-
const now = new Date().toISOString();
|
|
2607
|
-
const identifiedEntry = {
|
|
2608
|
-
id: randomUUID(),
|
|
2609
|
-
entryType: "identified",
|
|
2610
|
-
body: input.body ?? input.topic,
|
|
2611
|
-
createdAt: now,
|
|
2612
|
-
createdBy: actorId
|
|
2613
|
-
};
|
|
2614
|
-
const entries = [identifiedEntry];
|
|
2615
|
-
const fields = {
|
|
2616
|
-
...(input.fields ?? {}),
|
|
2617
|
-
topic: input.topic,
|
|
2618
|
-
entries,
|
|
2619
|
-
currentStatus: riskEntryToCurrentStatus(identifiedEntry, "open")
|
|
2620
|
-
};
|
|
2621
|
-
if (input.likelihood && input.impact) {
|
|
2622
|
-
const assessmentEntry = {
|
|
2623
|
-
id: randomUUID(),
|
|
2624
|
-
entryType: "assessment",
|
|
2625
|
-
body: "Initial risk assessment.",
|
|
2626
|
-
likelihood: input.likelihood,
|
|
2627
|
-
impact: input.impact,
|
|
2628
|
-
createdAt: now,
|
|
2629
|
-
createdBy: actorId
|
|
2630
|
-
};
|
|
2631
|
-
entries.push(assessmentEntry);
|
|
2632
|
-
fields.currentAssessment = riskEntryToCurrentAssessment(assessmentEntry);
|
|
2633
|
-
}
|
|
2634
|
-
if (input.treatment) {
|
|
2635
|
-
const treatmentEntry = {
|
|
2636
|
-
id: randomUUID(),
|
|
2637
|
-
entryType: "treatment",
|
|
2638
|
-
body: input.treatmentRationale ?? `Initial risk treatment: ${input.treatment}.`,
|
|
2639
|
-
treatment: input.treatment,
|
|
2640
|
-
...(input.treatmentRationale ? { treatmentRationale: input.treatmentRationale } : {}),
|
|
2641
|
-
createdAt: now,
|
|
2642
|
-
createdBy: actorId
|
|
2643
|
-
};
|
|
2644
|
-
entries.push(treatmentEntry);
|
|
2645
|
-
fields.currentTreatment = riskEntryToCurrentTreatment(treatmentEntry);
|
|
2646
|
-
}
|
|
2647
|
-
return createRecord(runtime.db, "risks", {
|
|
2648
|
-
workspaceId: input.workspaceId,
|
|
2649
|
-
title: input.title,
|
|
2650
|
-
summary: input.summary ?? input.topic,
|
|
2651
|
-
allowManagedFields: true,
|
|
2652
|
-
fields
|
|
2653
|
-
}, actorId);
|
|
2654
|
-
}
|
|
2655
|
-
async function createIncident(runtime, input, actorId) {
|
|
2656
|
-
assertNoReservedFields(input.fields, ["workspaceId", "componentIds"]);
|
|
2657
|
-
assertNoTypedFields(input.fields, "create_incident", INCIDENT_TYPED_FIELDS);
|
|
2658
|
-
const componentIds = uniqueIds(input.componentIds ?? []);
|
|
2659
|
-
await assertRuntimeRecordsExist(runtime, input.workspaceId, "components", componentIds);
|
|
2660
|
-
const now = new Date().toISOString();
|
|
2661
|
-
const detectedEntry = {
|
|
2662
|
-
id: randomUUID(),
|
|
2663
|
-
entryType: "detected",
|
|
2664
|
-
body: input.description,
|
|
2665
|
-
createdAt: now,
|
|
2666
|
-
createdBy: actorId
|
|
2667
|
-
};
|
|
2668
|
-
const entries = [detectedEntry];
|
|
2669
|
-
const fields = {
|
|
2670
|
-
...(input.fields ?? {}),
|
|
2671
|
-
description: input.description,
|
|
2672
|
-
entries,
|
|
2673
|
-
currentStatus: incidentEntryToCurrentStatus(detectedEntry, "open")
|
|
2674
|
-
};
|
|
2675
|
-
if (input.severity) {
|
|
2676
|
-
const severityEntry = {
|
|
2677
|
-
id: randomUUID(),
|
|
2678
|
-
entryType: "severity",
|
|
2679
|
-
body: `Initial severity: ${input.severity}.`,
|
|
2680
|
-
severity: input.severity,
|
|
2681
|
-
createdAt: now,
|
|
2682
|
-
createdBy: actorId
|
|
2683
|
-
};
|
|
2684
|
-
entries.push(severityEntry);
|
|
2685
|
-
fields.currentSeverity = incidentEntryToCurrentSeverity(severityEntry);
|
|
2686
|
-
}
|
|
2687
|
-
let incident = await createRecord(runtime.db, "incidents", {
|
|
2688
|
-
workspaceId: input.workspaceId,
|
|
2689
|
-
title: input.title,
|
|
2690
|
-
summary: input.summary ?? input.description,
|
|
2691
|
-
allowManagedFields: true,
|
|
2692
|
-
fields
|
|
2693
|
-
}, actorId);
|
|
2694
|
-
for (const componentId of componentIds) {
|
|
2695
|
-
incident = await ensureLinkRecords(runtime, {
|
|
2696
|
-
workspaceId: input.workspaceId,
|
|
2697
|
-
fromType: "incidents",
|
|
2698
|
-
fromId: incident._id,
|
|
2699
|
-
toType: "components",
|
|
2700
|
-
toId: componentId,
|
|
2701
|
-
relationship: "affects"
|
|
2702
|
-
}, actorId);
|
|
2703
|
-
}
|
|
2704
|
-
return incident;
|
|
2705
|
-
}
|
|
2706
|
-
async function createSupportRequest(runtime, input, actorId) {
|
|
2707
|
-
assertNoReservedFields(input.fields, ["workspaceId"]);
|
|
2708
|
-
assertNoTypedFields(input.fields, "create_support_request", SUPPORT_REQUEST_TYPED_FIELDS);
|
|
2709
|
-
const now = new Date().toISOString();
|
|
2710
|
-
const raisedEntry = {
|
|
2711
|
-
id: randomUUID(),
|
|
2712
|
-
entryType: "raised",
|
|
2713
|
-
body: input.reportedExperience,
|
|
2714
|
-
createdAt: now,
|
|
2715
|
-
createdBy: actorId
|
|
2716
|
-
};
|
|
2717
|
-
return createRecord(runtime.db, "support_requests", {
|
|
2718
|
-
workspaceId: input.workspaceId,
|
|
2719
|
-
title: input.title,
|
|
2720
|
-
summary: input.summary ?? input.reportedExperience,
|
|
2721
|
-
allowManagedFields: true,
|
|
2722
|
-
fields: {
|
|
2723
|
-
...(input.fields ?? {}),
|
|
2724
|
-
reporter: input.reporter,
|
|
2725
|
-
kind: input.kind,
|
|
2726
|
-
reportedExperience: input.reportedExperience,
|
|
2727
|
-
entries: [raisedEntry],
|
|
2728
|
-
currentStatus: supportRequestEntryToCurrentStatus(raisedEntry)
|
|
2729
|
-
}
|
|
2730
|
-
}, actorId);
|
|
2731
|
-
}
|
|
2732
|
-
async function appendSupportRequestEntryForTool(runtime, input, actorId) {
|
|
2733
|
-
if (input.incidentId) {
|
|
2734
|
-
const incident = await getRecord(runtime.db, "incidents", input.incidentId, {
|
|
2735
|
-
workspaceId: input.workspaceId
|
|
2736
|
-
});
|
|
2737
|
-
if (!incident) {
|
|
2738
|
-
throw new Error(`Incident not found: incidents/${input.incidentId}`);
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
const supportRequest = await appendSupportRequestEntry(runtime.db, input, actorId);
|
|
2742
|
-
if (!input.incidentId) {
|
|
2743
|
-
return supportRequest;
|
|
2744
|
-
}
|
|
2745
|
-
return ensureLinkRecords(runtime, {
|
|
2746
|
-
workspaceId: input.workspaceId,
|
|
2747
|
-
fromType: "support_requests",
|
|
2748
|
-
fromId: supportRequest._id,
|
|
2749
|
-
toType: "incidents",
|
|
2750
|
-
toId: input.incidentId,
|
|
2751
|
-
relationship: "spawned_incident"
|
|
2752
|
-
}, actorId);
|
|
2753
|
-
}
|
|
2754
|
-
async function createProblem(runtime, input, actorId) {
|
|
2755
|
-
assertNoReservedFields(input.fields, ["workspaceId", "incidentIds", "componentIds"]);
|
|
2756
|
-
assertNoTypedFields(input.fields, "create_problem", PROBLEM_TYPED_FIELDS);
|
|
2757
|
-
const incidentIds = uniqueIds(input.incidentIds);
|
|
2758
|
-
const componentIds = uniqueIds(input.componentIds ?? []);
|
|
2759
|
-
if (incidentIds.length === 0) {
|
|
2760
|
-
throw new Error("create_problem requires at least one incidentId.");
|
|
2761
|
-
}
|
|
2762
|
-
await assertRuntimeRecordsExist(runtime, input.workspaceId, "incidents", incidentIds);
|
|
2763
|
-
await assertRuntimeRecordsExist(runtime, input.workspaceId, "components", componentIds);
|
|
2764
|
-
const now = new Date().toISOString();
|
|
2765
|
-
const identifiedEntry = {
|
|
2766
|
-
id: randomUUID(),
|
|
2767
|
-
entryType: "identified",
|
|
2768
|
-
body: input.description,
|
|
2769
|
-
createdAt: now,
|
|
2770
|
-
createdBy: actorId
|
|
2771
|
-
};
|
|
2772
|
-
let problem = await createRecord(runtime.db, "problems", {
|
|
2773
|
-
workspaceId: input.workspaceId,
|
|
2774
|
-
title: input.title,
|
|
2775
|
-
summary: input.summary ?? input.description,
|
|
2776
|
-
allowManagedFields: true,
|
|
2777
|
-
fields: {
|
|
2778
|
-
...(input.fields ?? {}),
|
|
2779
|
-
description: input.description,
|
|
2780
|
-
entries: [identifiedEntry],
|
|
2781
|
-
currentStatus: problemEntryToCurrentStatus(identifiedEntry, "open")
|
|
2782
|
-
}
|
|
2783
|
-
}, actorId);
|
|
2784
|
-
for (const incidentId of incidentIds) {
|
|
2785
|
-
problem = await ensureLinkRecords(runtime, {
|
|
2786
|
-
workspaceId: input.workspaceId,
|
|
2787
|
-
fromType: "problems",
|
|
2788
|
-
fromId: problem._id,
|
|
2789
|
-
toType: "incidents",
|
|
2790
|
-
toId: incidentId,
|
|
2791
|
-
relationship: "evidenced_by"
|
|
2792
|
-
}, actorId);
|
|
2793
|
-
}
|
|
2794
|
-
for (const componentId of componentIds) {
|
|
2795
|
-
problem = await ensureLinkRecords(runtime, {
|
|
2796
|
-
workspaceId: input.workspaceId,
|
|
2797
|
-
fromType: "problems",
|
|
2798
|
-
fromId: problem._id,
|
|
2799
|
-
toType: "components",
|
|
2800
|
-
toId: componentId,
|
|
2801
|
-
relationship: "affects"
|
|
2802
|
-
}, actorId);
|
|
2803
|
-
}
|
|
2804
|
-
return problem;
|
|
2805
|
-
}
|
|
2806
|
-
function uniqueIds(ids) {
|
|
2807
|
-
return [...new Set(ids.map((id) => id.trim()).filter(Boolean))];
|
|
2808
|
-
}
|
|
2809
|
-
async function assertRuntimeRecordsExist(runtime, workspaceId, recordType, ids) {
|
|
2810
|
-
for (const id of ids) {
|
|
2811
|
-
const record = await getRecord(runtime.db, recordType, id, { workspaceId });
|
|
2812
|
-
if (!record) {
|
|
2813
|
-
throw new Error(`Record not found: ${recordType}/${id}`);
|
|
2814
|
-
}
|
|
2815
|
-
}
|
|
2816
|
-
}
|
|
2817
|
-
async function createChange(runtime, input, actorId) {
|
|
2818
|
-
assertNoReservedFields(input.fields, ["workspaceId", "initiativeId", "requirementId"]);
|
|
2819
|
-
assertNoTypedFields(input.fields, "create_change", CHANGE_TYPED_FIELDS);
|
|
2820
|
-
assertChangeTypeInput(input);
|
|
2821
|
-
if (input.requirementId) {
|
|
2822
|
-
const requirement = await getRecord(runtime.db, "requirements", input.requirementId, {
|
|
2823
|
-
workspaceId: input.workspaceId
|
|
2824
|
-
});
|
|
2825
|
-
if (!requirement) {
|
|
2826
|
-
throw new Error(`Requirement not found: requirements/${input.requirementId}`);
|
|
2827
|
-
}
|
|
2828
|
-
}
|
|
2829
|
-
let change = await createRecord(runtime.db, "changes", {
|
|
2830
|
-
workspaceId: input.workspaceId,
|
|
2831
|
-
title: input.title,
|
|
2832
|
-
summary: input.summary ?? input.changePlan,
|
|
2833
|
-
allowManagedFields: true,
|
|
2834
|
-
fields: {
|
|
2835
|
-
...(input.fields ?? {}),
|
|
2836
|
-
changeType: input.changeType ?? "normal",
|
|
2837
|
-
...(input.impactGrade !== undefined ? { impactGrade: input.impactGrade } : {}),
|
|
2838
|
-
...(input.emergencyImportance !== undefined ? { emergencyImportance: input.emergencyImportance } : {}),
|
|
2839
|
-
...(input.emergencyImmediacy !== undefined ? { emergencyImmediacy: input.emergencyImmediacy } : {}),
|
|
2840
|
-
...emergencyRationaleGapFields(input),
|
|
2841
|
-
changePlan: input.changePlan,
|
|
2842
|
-
executionSteps: input.executionSteps,
|
|
2843
|
-
rollbackPlan: input.rollbackPlan,
|
|
2844
|
-
riskImpact: input.riskImpact,
|
|
2845
|
-
...(input.plannedFor !== undefined ? { plannedFor: input.plannedFor } : {})
|
|
2846
|
-
}
|
|
2847
|
-
}, actorId);
|
|
2848
|
-
if (input.requirementId) {
|
|
2849
|
-
change = await linkRecords(runtime.db, {
|
|
2850
|
-
workspaceId: input.workspaceId,
|
|
2851
|
-
fromType: "changes",
|
|
2852
|
-
fromId: change._id,
|
|
2853
|
-
toType: "requirements",
|
|
2854
|
-
toId: input.requirementId,
|
|
2855
|
-
relationship: "for_requirement"
|
|
2856
|
-
}, actorId);
|
|
2857
|
-
}
|
|
2858
|
-
return change;
|
|
2859
|
-
}
|
|
2860
|
-
function buildChangeEventContent(input) {
|
|
2861
|
-
if (input.gitCommitReferences && input.eventType !== "result_reported" && input.eventType !== "recovery_recorded") {
|
|
2862
|
-
throw new Error("gitCommitReferences are only valid on result_reported or recovery_recorded Change events.");
|
|
2863
|
-
}
|
|
2864
|
-
switch (input.eventType) {
|
|
2865
|
-
case "notice_given":
|
|
2866
|
-
return compactObject({
|
|
2867
|
-
notice: requireChangeEventField(input.notice, input.eventType, "notice"),
|
|
2868
|
-
noticeTo: input.noticeTo,
|
|
2869
|
-
effectiveAt: input.effectiveAt
|
|
2870
|
-
});
|
|
2871
|
-
case "veto_recorded":
|
|
2872
|
-
return compactObject({
|
|
2873
|
-
vetoByRole: requireChangeEventField(input.vetoByRole, input.eventType, "vetoByRole"),
|
|
2874
|
-
reason: input.reason,
|
|
2875
|
-
summary: input.summary
|
|
2876
|
-
});
|
|
2877
|
-
case "decision_recorded":
|
|
2878
|
-
return compactObject({
|
|
2879
|
-
decision: requireChangeEventField(input.decision, input.eventType, "decision"),
|
|
2880
|
-
reason: input.reason,
|
|
2881
|
-
summary: input.summary
|
|
2882
|
-
});
|
|
2883
|
-
case "result_reported":
|
|
2884
|
-
return compactObject({
|
|
2885
|
-
result: requireChangeEventField(input.result, input.eventType, "result"),
|
|
2886
|
-
gitCommitReferences: input.gitCommitReferences,
|
|
2887
|
-
summary: input.summary
|
|
2888
|
-
});
|
|
2889
|
-
case "recovery_recorded":
|
|
2890
|
-
return compactObject({
|
|
2891
|
-
summary: requireChangeEventField(input.summary, input.eventType, "summary"),
|
|
2892
|
-
gitCommitReferences: input.gitCommitReferences
|
|
2893
|
-
});
|
|
2894
|
-
case "plan_revised": {
|
|
2895
|
-
const event = compactObject({
|
|
2896
|
-
summary: input.summary,
|
|
2897
|
-
revisedChangeType: input.revisedChangeType,
|
|
2898
|
-
revisedImpactGrade: input.revisedImpactGrade,
|
|
2899
|
-
revisedEmergencyImportance: input.revisedEmergencyImportance,
|
|
2900
|
-
revisedEmergencyImmediacy: input.revisedEmergencyImmediacy,
|
|
2901
|
-
revisedChangePlan: input.revisedChangePlan,
|
|
2902
|
-
revisedExecutionSteps: input.revisedExecutionSteps,
|
|
2903
|
-
revisedRollbackPlan: input.revisedRollbackPlan,
|
|
2904
|
-
revisedRiskImpact: input.revisedRiskImpact,
|
|
2905
|
-
revisedPlannedFor: input.revisedPlannedFor
|
|
2906
|
-
});
|
|
2907
|
-
if (Object.keys(event).length === 0) {
|
|
2908
|
-
throw new Error("plan_revised requires summary or at least one revised plan field.");
|
|
2909
|
-
}
|
|
2910
|
-
return event;
|
|
2911
|
-
}
|
|
2912
|
-
case "note_added":
|
|
2913
|
-
return compactObject({
|
|
2914
|
-
note: requireChangeEventField(input.note, input.eventType, "note")
|
|
2915
|
-
});
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
function requireChangeEventField(value, eventType, fieldName) {
|
|
2919
|
-
if (value === undefined) {
|
|
2920
|
-
throw new Error(`${eventType} requires ${fieldName}.`);
|
|
2921
|
-
}
|
|
2922
|
-
return value;
|
|
2923
|
-
}
|
|
2924
|
-
function assertRiskAcceptanceAccess(treatment, roles) {
|
|
2925
|
-
if (treatment !== "accept" || !roles || roles.includes("owner")) {
|
|
2926
|
-
return;
|
|
2927
|
-
}
|
|
2928
|
-
throw new Error("Formal risk acceptance requires the Owner role. Other roles may record non-acceptance treatment or proceed with visible open risk.");
|
|
2929
|
-
}
|
|
2930
|
-
function assertChangeTypeInput(input) {
|
|
2931
|
-
const changeType = input.changeType ?? "normal";
|
|
2932
|
-
if (input.impactGrade && changeType !== "normal") {
|
|
2933
|
-
throw new Error("impactGrade is only valid for normal changes.");
|
|
2934
|
-
}
|
|
2935
|
-
if ((input.emergencyImportance || input.emergencyImmediacy) && changeType !== "emergency") {
|
|
2936
|
-
throw new Error("emergencyImportance and emergencyImmediacy are only valid for emergency changes.");
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
function emergencyRationaleGapFields(input) {
|
|
2940
|
-
if ((input.changeType ?? "normal") !== "emergency") {
|
|
2941
|
-
return {};
|
|
2942
|
-
}
|
|
2943
|
-
const missing = [
|
|
2944
|
-
...(input.emergencyImportance ? [] : ["emergencyImportance"]),
|
|
2945
|
-
...(input.emergencyImmediacy ? [] : ["emergencyImmediacy"])
|
|
2946
|
-
];
|
|
2947
|
-
return missing.length > 0 ? { emergencyRationaleGaps: missing } : {};
|
|
2948
|
-
}
|
|
2949
|
-
function compactObject(input) {
|
|
2950
|
-
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
|
|
2951
|
-
}
|
|
2952
|
-
async function updateExpectation(runtime, input, actorId) {
|
|
2953
|
-
assertNoTypedFields(input.fields, "update_expectation", EXPECTATION_TYPED_FIELDS);
|
|
2954
|
-
assertNoObsoleteExpectationFields(input.fields, "update_expectation");
|
|
2955
|
-
return updateRecord(runtime.db, {
|
|
2956
|
-
recordType: "expectations",
|
|
2957
|
-
workspaceId: input.workspaceId,
|
|
2958
|
-
id: input.id,
|
|
2959
|
-
title: input.title,
|
|
2960
|
-
summary: input.statement,
|
|
2961
|
-
fields: {
|
|
2962
|
-
...(input.fields ?? {}),
|
|
2963
|
-
...(input.statement !== undefined ? { statement: input.statement } : {}),
|
|
2964
|
-
...(input.successRecognition !== undefined ? { successRecognition: input.successRecognition } : {}),
|
|
2965
|
-
...(input.approvalState !== undefined ? { approvalState: input.approvalState } : {}),
|
|
2966
|
-
...(input.approvedBy !== undefined ? { approvedBy: input.approvedBy } : {}),
|
|
2967
|
-
...(input.approvedAt !== undefined ? { approvedAt: input.approvedAt } : {}),
|
|
2968
|
-
...(input.source !== undefined ? { source: input.source } : {})
|
|
2969
|
-
},
|
|
2970
|
-
unsetFields: input.unsetFields,
|
|
2971
|
-
allowManagedFields: true,
|
|
2972
|
-
revisionNote: input.revisionNote
|
|
2973
|
-
}, actorId);
|
|
2974
|
-
}
|
|
2975
|
-
async function updateRequirement(runtime, input, actorId) {
|
|
2976
|
-
assertNoTypedFields(input.fields, "update_requirement", REQUIREMENT_TYPED_FIELDS);
|
|
2977
|
-
return updateRecord(runtime.db, {
|
|
2978
|
-
recordType: "requirements",
|
|
2979
|
-
workspaceId: input.workspaceId,
|
|
2980
|
-
id: input.id,
|
|
2981
|
-
title: input.title,
|
|
2982
|
-
summary: input.statement,
|
|
2983
|
-
fields: {
|
|
2984
|
-
...(input.fields ?? {}),
|
|
2985
|
-
...(input.statement !== undefined ? { statement: input.statement } : {}),
|
|
2986
|
-
...(input.acceptanceCriteria !== undefined ? { acceptanceCriteria: input.acceptanceCriteria } : {}),
|
|
2987
|
-
...(input.priority !== undefined ? { priority: input.priority } : {}),
|
|
2988
|
-
...(input.status !== undefined ? { status: input.status } : {})
|
|
2989
|
-
},
|
|
2990
|
-
unsetFields: input.unsetFields,
|
|
2991
|
-
allowManagedFields: true,
|
|
2992
|
-
revisionNote: input.revisionNote
|
|
2993
|
-
}, actorId);
|
|
2994
|
-
}
|
|
2995
|
-
async function linkDecisionInput(runtime, input, actorId) {
|
|
2996
|
-
if (input.inputRecordType === "decisions" && input.inputId === input.decisionId) {
|
|
2997
|
-
throw new Error("A Decision cannot be linked to itself as a decision input.");
|
|
2998
|
-
}
|
|
2999
|
-
const decision = await getRecord(runtime.db, "decisions", input.decisionId, {
|
|
3000
|
-
workspaceId: input.workspaceId
|
|
3001
|
-
});
|
|
3002
|
-
if (!decision) {
|
|
3003
|
-
throw new Error(`Decision not found: decisions/${input.decisionId}`);
|
|
3004
|
-
}
|
|
3005
|
-
const inputRecord = await getRecord(runtime.db, input.inputRecordType, input.inputId, {
|
|
3006
|
-
workspaceId: input.workspaceId
|
|
3007
|
-
});
|
|
3008
|
-
if (!inputRecord) {
|
|
3009
|
-
throw new Error(`Decision input not found: ${input.inputRecordType}/${input.inputId}`);
|
|
3010
|
-
}
|
|
3011
|
-
if (decision.links.some((link) => link.toType === input.inputRecordType &&
|
|
3012
|
-
link.toId === inputRecord._id &&
|
|
3013
|
-
link.relationship === "informed_by")) {
|
|
3014
|
-
return decision;
|
|
3015
|
-
}
|
|
3016
|
-
return linkRecords(runtime.db, {
|
|
3017
|
-
workspaceId: input.workspaceId,
|
|
3018
|
-
fromType: "decisions",
|
|
3019
|
-
fromId: decision._id,
|
|
3020
|
-
toType: input.inputRecordType,
|
|
3021
|
-
toId: inputRecord._id,
|
|
3022
|
-
relationship: "informed_by"
|
|
3023
|
-
}, actorId);
|
|
3024
|
-
}
|
|
3025
|
-
function assertNoReservedFields(fields, reservedFields) {
|
|
3026
|
-
for (const reservedField of reservedFields) {
|
|
3027
|
-
if (fields && Object.hasOwn(fields, reservedField)) {
|
|
3028
|
-
throw new Error(`${reservedField} is a relationship input on this tool. Use the top-level ${reservedField} argument instead of fields.${reservedField}.`);
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
function assertNoTypedFields(fields, toolName, typedFields) {
|
|
3033
|
-
for (const typedField of typedFields) {
|
|
3034
|
-
if (fields && Object.hasOwn(fields, typedField)) {
|
|
3035
|
-
throw new Error(`${typedField} is a typed input on ${toolName}. Use the top-level ${typedField} argument instead of fields.${typedField}.`);
|
|
3036
|
-
}
|
|
3037
|
-
}
|
|
3038
|
-
}
|
|
3039
|
-
function assertNoTypedUnsetFields(unsetFields, toolName, typedFields) {
|
|
3040
|
-
for (const unsetField of unsetFields ?? []) {
|
|
3041
|
-
if (typedFields.includes(unsetField)) {
|
|
3042
|
-
throw new Error(`${unsetField} is managed on ${toolName}. Use the typed inputs instead of unsetFields.${unsetField}.`);
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
function assertNoDecisionInputFields(fields) {
|
|
3047
|
-
for (const fieldName of DECISION_INPUT_FIELDS) {
|
|
3048
|
-
if (fields && Object.hasOwn(fields, fieldName)) {
|
|
3049
|
-
throw new Error(`${fieldName} is managed on decisions. Use link_decision_input to record decision inputs.`);
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
}
|
|
3053
|
-
function assertNoObsoleteExpectationFields(fields, toolName) {
|
|
3054
|
-
for (const obsoleteField of OBSOLETE_EXPECTATION_FIELDS) {
|
|
3055
|
-
if (fields && Object.hasOwn(fields, obsoleteField)) {
|
|
3056
|
-
throw new Error(`${obsoleteField} is not part of the current Expectation model on ${toolName}. Use approvalState, approvedBy, or approvedAt where approval tracking is needed.`);
|
|
3057
|
-
}
|
|
3058
|
-
}
|
|
3059
|
-
}
|