@company-semantics/contracts 89.2.0 → 91.0.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.
Files changed (53) hide show
  1. package/package.json +4 -3
  2. package/src/affordances/README.md +65 -0
  3. package/src/affordances/__tests__/README.md +30 -0
  4. package/src/affordances/__tests__/affordances.test.ts +251 -0
  5. package/src/affordances/affordance.ts +124 -0
  6. package/src/affordances/args.ts +59 -0
  7. package/src/affordances/availability.ts +78 -0
  8. package/src/affordances/ids.ts +45 -0
  9. package/src/affordances/index.ts +39 -0
  10. package/src/api/generated-spec-hash.ts +2 -2
  11. package/src/api/generated.ts +142 -2
  12. package/src/generated/openapi-routes.ts +1 -0
  13. package/src/proactive/README.md +26 -4
  14. package/src/proactive/__tests__/README.md +10 -0
  15. package/src/proactive/__tests__/chat-templates.test.ts +8 -0
  16. package/src/proactive/__tests__/vocabulary.test.ts +11 -0
  17. package/src/proactive/__tests__/workflow-attention-fixtures.ts +49 -0
  18. package/src/proactive/__tests__/workflow-attention.test.ts +146 -0
  19. package/src/proactive/composer.ts +8 -0
  20. package/src/proactive/facts.ts +36 -0
  21. package/src/proactive/index.ts +2 -0
  22. package/src/proactive/kinds.ts +29 -0
  23. package/src/proactive/registry.ts +22 -0
  24. package/src/proactive/surfaces.ts +2 -0
  25. package/src/proactive/templates/README.md +9 -1
  26. package/src/proactive/templates/index.ts +2 -0
  27. package/src/proactive/templates/workflow-needs-attention.ts +35 -0
  28. package/src/root-exports/README.md +1 -0
  29. package/src/root-exports/delivery.ts +69 -1
  30. package/src/source-sync/README.md +95 -5
  31. package/src/source-sync/__tests__/attention-evidence.test.ts +96 -0
  32. package/src/source-sync/__tests__/barrel.test.ts +39 -0
  33. package/src/source-sync/__tests__/enumeration.test.ts +160 -0
  34. package/src/source-sync/__tests__/schemas.test.ts +223 -0
  35. package/src/source-sync/__tests__/vocabulary.test.ts +104 -5
  36. package/src/source-sync/attention-evidence.ts +93 -0
  37. package/src/source-sync/candidate-item.ts +25 -0
  38. package/src/source-sync/enumeration.ts +152 -0
  39. package/src/source-sync/index.ts +35 -1
  40. package/src/source-sync/relevance.ts +85 -11
  41. package/src/source-sync/vocabulary.ts +37 -1
  42. package/src/user-notifications/README.md +8 -0
  43. package/src/user-notifications/kinds.ts +13 -0
  44. package/src/user-notifications/lifecycle-registry.ts +10 -0
  45. package/src/workflows/README.md +38 -2
  46. package/src/workflows/__tests__/README.md +21 -2
  47. package/src/workflows/__tests__/affordances-of-outcome.test.ts +99 -0
  48. package/src/workflows/__tests__/deferred-route.test.ts +168 -0
  49. package/src/workflows/__tests__/outcome.test.ts +66 -0
  50. package/src/workflows/affordances-of-outcome.ts +65 -0
  51. package/src/workflows/deferred-route.ts +240 -0
  52. package/src/workflows/index.ts +34 -0
  53. package/src/workflows/outcome.ts +114 -1
@@ -29,13 +29,16 @@ export type {
29
29
  } from "./outcome";
30
30
 
31
31
  export {
32
+ DISCOVER_AFFORDANCES_OF_REASON,
32
33
  DISCOVER_OUTCOME_KIND_OF_REASON,
33
34
  DiscoverOutcomeFactsSchema,
34
35
  DiscoverWorkflowOutcomeSchema,
35
36
  HrisConnectWorkflowOutcomeSchema,
37
+ ORG_STRUCTURE_AFFORDANCES_OF_REASON,
36
38
  ORG_STRUCTURE_OUTCOME_KIND_OF_REASON,
37
39
  OrgStructureOutcomeFactsSchema,
38
40
  ReanalyzeWorkflowOutcomeSchema,
41
+ SYNTHESIZE_AFFORDANCES_OF_REASON,
39
42
  SYNTHESIZE_OUTCOME_KIND_OF_REASON,
40
43
  SynthesizeOutcomeFactsSchema,
41
44
  SynthesizeWorkflowOutcomeSchema,
@@ -43,3 +46,34 @@ export {
43
46
  WorkflowOutcomeDispositionSchema,
44
47
  WorkflowOutcomeSchema,
45
48
  } from "./outcome";
49
+
50
+ export {
51
+ WORKFLOW_AFFORDANCES_OF_REASON,
52
+ affordancesOfOutcome,
53
+ affordancesOfReason,
54
+ } from "./affordances-of-outcome";
55
+
56
+ export type {
57
+ DeferredRoute,
58
+ DeferredRouteKind,
59
+ ExplainedDiscoverReason,
60
+ ExplainedOrgStructureReason,
61
+ ExplainedSynthesizeReason,
62
+ ExplainedWorkflowOutcome,
63
+ SettlementAudiencePolicy,
64
+ SettlementCoveringKind,
65
+ } from "./deferred-route";
66
+
67
+ export {
68
+ DEFERRED_ROUTES,
69
+ DISCOVER_DEFERRED_ROUTE_OF_REASON,
70
+ DeferredRouteSchema,
71
+ ORG_STRUCTURE_DEFERRED_ROUTE_OF_REASON,
72
+ SETTLEMENT_AUDIENCE_POLICIES,
73
+ SETTLEMENT_COVERING_KINDS,
74
+ SETTLEMENT_SILENT_REASONS,
75
+ SYNTHESIZE_DEFERRED_ROUTE_OF_REASON,
76
+ WORKFLOW_DEFERRED_ROUTE_OF_REASON,
77
+ deferredRouteOf,
78
+ toExplainedOutcome,
79
+ } from "./deferred-route";
@@ -22,6 +22,11 @@
22
22
  * on; `narrate` means the ending is told, not reviewed. `produced` does not
23
23
  * imply a review surface, and only a `produced` or `partial` outcome may carry
24
24
  * `review`.
25
+ * - THE OFFER IS A FUNCTION OF REASON. `affordances` is the ordered list of
26
+ * next steps the ending offers (control ADR affordance-system), fixed by the
27
+ * per-type `*_AFFORDANCES_OF_REASON` table and frozen with the outcome. The
28
+ * schema refuses any other list. A projected affordance (`review.open`) is
29
+ * never stored here: it is derived from the `review` disposition.
25
30
  * - `unknown` IS A SAFETY VALVE for a terminal transition the classifier did not
26
31
  * recognize. It is never used for a failure to OBSERVE a workflow: a workflow
27
32
  * whose state cannot be read has no outcome yet.
@@ -32,6 +37,12 @@
32
37
  */
33
38
  import { z } from "zod";
34
39
 
40
+ import {
41
+ MAX_OFFERED_AFFORDANCES,
42
+ OfferedAffordanceSchema,
43
+ sameAffordances,
44
+ type OfferedAffordance,
45
+ } from "../affordances/affordance";
35
46
  import { INPUT_REQUEST_TYPES } from "../input-requests/types";
36
47
 
37
48
  /** The shape of an ending, shared by every workflow type. */
@@ -74,6 +85,14 @@ export type WorkflowOutcomeDisposition = z.infer<
74
85
 
75
86
  const Count = z.number().int().nonnegative();
76
87
 
88
+ // The affordances an ending may offer, named once for the tables below.
89
+ const FIND_FILES = { id: "sourceSync.findFiles" } as const;
90
+ const CONNECT_GOOGLE_DRIVE = { id: "integrations.connectGoogleDrive" } as const;
91
+ const ENABLE_SOURCE_SYNC = { id: "sourceSync.enable" } as const;
92
+ const OPEN_BILLING = { id: "billing.open" } as const;
93
+ const REANALYZE_STRUCTURE = { id: "orgStructure.reanalyze" } as const;
94
+ const RESYNC_DIRECTORY = { id: "hris.resyncDirectory" } as const;
95
+
77
96
  // ---------------------------------------------------------------------------
78
97
  // source-sync/discover
79
98
  // ---------------------------------------------------------------------------
@@ -100,6 +119,32 @@ export const DISCOVER_OUTCOME_KIND_OF_REASON = {
100
119
  export type DiscoverOutcomeReason =
101
120
  keyof typeof DISCOVER_OUTCOME_KIND_OF_REASON;
102
121
 
122
+ /**
123
+ * What each discovery ending offers (control ADR affordance-system). TOTAL: an
124
+ * empty list is a decision that no grounded action changes that ending — a
125
+ * re-run of the same search is not "broadening" it, and nothing raises a budget.
126
+ */
127
+ export const DISCOVER_AFFORDANCES_OF_REASON = {
128
+ candidates_found: [],
129
+ nothing_found: [],
130
+ nothing_relevant: [],
131
+ budget_exhausted: [],
132
+ file_ceiling: [],
133
+ stopped_by_user: [],
134
+ plan_coverage_refused: [],
135
+ billing_refused: [OPEN_BILLING],
136
+ drive_auth: [CONNECT_GOOGLE_DRIVE],
137
+ drive_unavailable: [FIND_FILES],
138
+ no_connection: [CONNECT_GOOGLE_DRIVE],
139
+ source_sync_off: [ENABLE_SOURCE_SYNC],
140
+ internal_error: [FIND_FILES],
141
+ abandoned: [FIND_FILES],
142
+ unrecognized_terminal_state: [],
143
+ } as const satisfies Record<
144
+ DiscoverOutcomeReason,
145
+ readonly OfferedAffordance[]
146
+ >;
147
+
103
148
  /** The counts a discovery run reports at its end. */
104
149
  export const DiscoverOutcomeFactsSchema = z
105
150
  .object({
@@ -139,6 +184,26 @@ export const SYNTHESIZE_OUTCOME_KIND_OF_REASON = {
139
184
  export type SynthesizeOutcomeReason =
140
185
  keyof typeof SYNTHESIZE_OUTCOME_KIND_OF_REASON;
141
186
 
187
+ /** What each synthesis ending offers. TOTAL; an empty list is explicit. */
188
+ export const SYNTHESIZE_AFFORDANCES_OF_REASON = {
189
+ updates_ready: [],
190
+ updates_applied: [],
191
+ stopped_by_user: [],
192
+ paused_billing: [OPEN_BILLING],
193
+ synthesis_incomplete: [],
194
+ approval_mismatch: [],
195
+ landing_refused: [],
196
+ standing_order_refused: [],
197
+ no_connection: [CONNECT_GOOGLE_DRIVE],
198
+ source_sync_off: [ENABLE_SOURCE_SYNC],
199
+ internal_error: [],
200
+ abandoned: [],
201
+ unrecognized_terminal_state: [],
202
+ } as const satisfies Record<
203
+ SynthesizeOutcomeReason,
204
+ readonly OfferedAffordance[]
205
+ >;
206
+
142
207
  /** The counts a synthesis run reports at its end. */
143
208
  export const SynthesizeOutcomeFactsSchema = z
144
209
  .object({
@@ -185,6 +250,32 @@ export const ORG_STRUCTURE_OUTCOME_KIND_OF_REASON = {
185
250
  export type OrgStructureOutcomeReason =
186
251
  keyof typeof ORG_STRUCTURE_OUTCOME_KIND_OF_REASON;
187
252
 
253
+ /**
254
+ * What each org-structure ending offers; shared by both org-structure workflow
255
+ * types, like the kind table. TOTAL; an empty list is explicit.
256
+ */
257
+ export const ORG_STRUCTURE_AFFORDANCES_OF_REASON = {
258
+ proposal_ready: [],
259
+ directory_synced: [],
260
+ analysis_already_running: [],
261
+ proposal_blocked: [],
262
+ no_sync_run: [RESYNC_DIRECTORY],
263
+ no_persons: [],
264
+ reporting_not_keyed: [],
265
+ stopped_by_user: [],
266
+ sync_failed: [RESYNC_DIRECTORY],
267
+ snapshot_too_large: [],
268
+ model_failed: [REANALYZE_STRUCTURE],
269
+ run_too_large: [],
270
+ placement_failed: [REANALYZE_STRUCTURE],
271
+ internal_error: [REANALYZE_STRUCTURE],
272
+ abandoned: [REANALYZE_STRUCTURE],
273
+ unrecognized_terminal_state: [],
274
+ } as const satisfies Record<
275
+ OrgStructureOutcomeReason,
276
+ readonly OfferedAffordance[]
277
+ >;
278
+
188
279
  /** The counts a finished org-structure proposal carries. */
189
280
  export const OrgStructureOutcomeFactsSchema = z
190
281
  .object({
@@ -207,7 +298,12 @@ function memberSchema<
207
298
  T extends string,
208
299
  R extends Record<string, WorkflowOutcomeKind>,
209
300
  F extends z.ZodTypeAny,
210
- >(workflowType: T, kindOfReason: R, facts: F) {
301
+ >(
302
+ workflowType: T,
303
+ kindOfReason: R,
304
+ facts: F,
305
+ affordancesOfReason: Record<keyof R, readonly OfferedAffordance[]>,
306
+ ) {
211
307
  const reasons = Object.keys(kindOfReason) as [
212
308
  keyof R & string,
213
309
  ...(keyof R & string)[],
@@ -221,6 +317,10 @@ function memberSchema<
221
317
  reason: z.enum(reasons),
222
318
  facts: facts.nullable(),
223
319
  disposition: WorkflowOutcomeDispositionSchema,
320
+ /** The next steps this ending offers, frozen with it (see the table). */
321
+ affordances: z
322
+ .array(OfferedAffordanceSchema)
323
+ .max(MAX_OFFERED_AFFORDANCES),
224
324
  })
225
325
  .strict()
226
326
  .superRefine((outcome, ctx) => {
@@ -243,6 +343,15 @@ function memberSchema<
243
343
  message: "only a produced or partial outcome may hand off to review",
244
344
  });
245
345
  }
346
+ const offered = affordancesOfReason[outcome.reason as keyof R];
347
+ if (!sameAffordances(outcome.affordances, offered)) {
348
+ ctx.addIssue({
349
+ code: z.ZodIssueCode.custom,
350
+ path: ["affordances"],
351
+ message:
352
+ "an outcome offers exactly its reason's affordances, in order",
353
+ });
354
+ }
246
355
  });
247
356
  }
248
357
 
@@ -250,21 +359,25 @@ export const DiscoverWorkflowOutcomeSchema = memberSchema(
250
359
  "source-sync/discover",
251
360
  DISCOVER_OUTCOME_KIND_OF_REASON,
252
361
  DiscoverOutcomeFactsSchema,
362
+ DISCOVER_AFFORDANCES_OF_REASON,
253
363
  );
254
364
  export const SynthesizeWorkflowOutcomeSchema = memberSchema(
255
365
  "source-sync/synthesize",
256
366
  SYNTHESIZE_OUTCOME_KIND_OF_REASON,
257
367
  SynthesizeOutcomeFactsSchema,
368
+ SYNTHESIZE_AFFORDANCES_OF_REASON,
258
369
  );
259
370
  export const HrisConnectWorkflowOutcomeSchema = memberSchema(
260
371
  "org-structure/hris-connect",
261
372
  ORG_STRUCTURE_OUTCOME_KIND_OF_REASON,
262
373
  OrgStructureOutcomeFactsSchema,
374
+ ORG_STRUCTURE_AFFORDANCES_OF_REASON,
263
375
  );
264
376
  export const ReanalyzeWorkflowOutcomeSchema = memberSchema(
265
377
  "org-structure/reanalyze",
266
378
  ORG_STRUCTURE_OUTCOME_KIND_OF_REASON,
267
379
  OrgStructureOutcomeFactsSchema,
380
+ ORG_STRUCTURE_AFFORDANCES_OF_REASON,
268
381
  );
269
382
 
270
383
  export type DiscoverWorkflowOutcome = z.infer<