@agentproto/agencies 0.1.0-alpha.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 (35) hide show
  1. package/AGENTAGENCIES.md +39 -0
  2. package/LICENSE +21 -0
  3. package/README.md +90 -0
  4. package/dist/capacity-98VwY285.d.ts +862 -0
  5. package/dist/chunk-DYQ4A5HV.mjs +649 -0
  6. package/dist/chunk-DYQ4A5HV.mjs.map +1 -0
  7. package/dist/chunk-GAJQ5ZC2.mjs +149 -0
  8. package/dist/chunk-GAJQ5ZC2.mjs.map +1 -0
  9. package/dist/chunk-SOJ4GQR7.mjs +3 -0
  10. package/dist/chunk-SOJ4GQR7.mjs.map +1 -0
  11. package/dist/composition/index.d.ts +61 -0
  12. package/dist/composition/index.mjs +75 -0
  13. package/dist/composition/index.mjs.map +1 -0
  14. package/dist/doctypes/index.d.ts +61 -0
  15. package/dist/doctypes/index.mjs +4 -0
  16. package/dist/doctypes/index.mjs.map +1 -0
  17. package/dist/index.d.ts +32 -0
  18. package/dist/index.mjs +17 -0
  19. package/dist/index.mjs.map +1 -0
  20. package/dist/renderers/index.d.ts +288 -0
  21. package/dist/renderers/index.mjs +321 -0
  22. package/dist/renderers/index.mjs.map +1 -0
  23. package/dist/validators/index.d.ts +70 -0
  24. package/dist/validators/index.mjs +4 -0
  25. package/dist/validators/index.mjs.map +1 -0
  26. package/package.json +94 -0
  27. package/src/spec/canvakit-templates/agency.agency-overview/template.canvakit.html +173 -0
  28. package/src/spec/canvakit-templates/agency.agency-profile/template.canvakit.html +121 -0
  29. package/src/spec/canvakit-templates/agency.agreement-signing/template.canvakit.html +164 -0
  30. package/src/spec/canvakit-templates/agency.deliverable-review/template.canvakit.html +148 -0
  31. package/src/spec/canvakit-templates/agency.engagement-dashboard/template.canvakit.html +191 -0
  32. package/src/spec/canvakit-templates/agency.invoice-pdf/template.canvakit.html +142 -0
  33. package/src/spec/canvakit-templates/agency.procedure-card/template.canvakit.html +93 -0
  34. package/src/spec/snippets/agency-overview-rollup/procedures/compute-agency-overview/PROCEDURE.md +88 -0
  35. package/src/spec/snippets/agency-overview-rollup/routines/agency-overview-rollup/ROUTINE.md +58 -0
@@ -0,0 +1,649 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * @agentproto/agencies v0.1.0-alpha
5
+ * agentagencies/v1 — operating layer for entities that exercise agency.
6
+ * Vendor-neutral. Filesystem-first. Extends agentcompanies/v1 + agentgovernance/v1.
7
+ */
8
+
9
+ var SCHEMA_NAME = "agentagencies/v1";
10
+ var kebabSlugSchema = z.string().regex(/^[a-z0-9][a-z0-9-]*$/, {
11
+ message: "Expected kebab-case slug (lowercase, alphanumeric + hyphens, leading alphanumeric)"
12
+ });
13
+ var currencyIsoSchema = z.string().length(3, {
14
+ message: "Expected ISO 4217 3-letter currency code"
15
+ });
16
+ var countryIsoSchema = z.string().length(2, {
17
+ message: "Expected ISO 3166 2-letter country code"
18
+ });
19
+ var timezoneSchema = z.string().min(1);
20
+ var isoDurationSchema = z.string().regex(/^P/, {
21
+ message: "Expected ISO-8601 duration starting with 'P'"
22
+ });
23
+ var isoDateOrDateSchema = z.union([
24
+ z.iso.date(),
25
+ z.date().transform((d) => d.toISOString().slice(0, 10))
26
+ ]);
27
+ var isoDatetimeOrDateSchema = z.union([
28
+ z.iso.datetime(),
29
+ z.date().transform((d) => d.toISOString())
30
+ ]);
31
+ var partyRefSchema = z.string().regex(
32
+ /^(operator|user|counterparty|agent|external|team):([a-z0-9][a-z0-9-]*|\*)$/,
33
+ { message: "Expected '<kind>:<slug>' or '<kind>:*'" }
34
+ );
35
+ var partyRefStrictSchema = z.string().regex(
36
+ /^(operator|user|counterparty|agent|external|team):[a-z0-9][a-z0-9-]*$/,
37
+ { message: "Expected '<kind>:<slug>'" }
38
+ );
39
+ var workspacePathSchema = z.string().min(1).refine((p) => !p.startsWith("/"), {
40
+ message: "Expected relative path (no leading /)"
41
+ }).refine((p) => !p.includes(".."), { message: "Path must not contain '..'" });
42
+ var metadataSchema = z.record(z.string(), z.unknown());
43
+ var sha256HexSchema = z.string().regex(/^[a-f0-9]{64}$/, {
44
+ message: "Expected lowercase hex SHA-256 (64 chars)"
45
+ });
46
+ var authorshipFields = {
47
+ authors: z.array(
48
+ z.object({
49
+ name: z.string().min(1),
50
+ email: z.email().optional(),
51
+ url: z.string().optional()
52
+ })
53
+ ).optional(),
54
+ homepage: z.string().optional(),
55
+ tags: z.array(z.string()).optional()
56
+ };
57
+ function envelope(doctype) {
58
+ return {
59
+ schema: z.literal(SCHEMA_NAME),
60
+ doctype: z.literal(doctype),
61
+ slug: kebabSlugSchema,
62
+ name: z.string().min(1),
63
+ description: z.string().optional(),
64
+ version: z.string().optional(),
65
+ // semver, optional per agentcompanies convention
66
+ metadata: metadataSchema.optional()
67
+ };
68
+ }
69
+ var AUTONOMY_POSTURE = ["full-auto", "hybrid", "manual"];
70
+ var autonomyPostureSchema = z.enum(AUTONOMY_POSTURE);
71
+ var agencyFrontmatterSchema = z.object({
72
+ ...envelope("agency"),
73
+ /** Vertical templates this agency uses (slugs from agencies.sh registry, e.g., "design-project"). */
74
+ verticals: z.array(kebabSlugSchema).default([]),
75
+ /** Slugs of the primary services this agency offers (refs to services/<slug>/SERVICE.md). */
76
+ primaryServices: z.array(kebabSlugSchema).default([]),
77
+ /** Default pricing-model slug applied when a service doesn't specify one. */
78
+ defaultPricingModel: kebabSlugSchema.optional(),
79
+ defaultCurrency: currencyIsoSchema.optional(),
80
+ defaultCountry: countryIsoSchema.optional(),
81
+ billingTimezone: timezoneSchema.optional(),
82
+ /** ISO date marking the start of the fiscal year (e.g., 2026-01-01). */
83
+ fiscalYearStart: isoDateOrDateSchema.optional(),
84
+ autonomyPosture: autonomyPostureSchema.default("hybrid"),
85
+ /** External package paths this AGENCY.md pulls in. Mirrors COMPANY.md.includes[]. */
86
+ includes: z.array(z.string()).default([])
87
+ });
88
+ var AGENCY_FILENAME = "AGENCY.md";
89
+ var operationsFrontmatterSchema = z.object({
90
+ ...envelope("operations"),
91
+ ...authorshipFields,
92
+ /** External package paths or registry shortnames this OPERATIONS.md pulls in. */
93
+ includes: z.array(z.string()).default([]),
94
+ /** License (matches agentcompanies/v1 conventions). */
95
+ license: z.string().optional()
96
+ });
97
+ var OPERATIONS_FILENAME = "OPERATIONS.md";
98
+ var serviceFrontmatterSchema = z.object({
99
+ ...envelope("service"),
100
+ /**
101
+ * Skills required to deliver this service. Refs to companies.sh skills
102
+ * (`SKILL.md` shortnames or paths); resolution per skills.sh / companies.sh rules.
103
+ */
104
+ requiredSkills: z.array(z.string()).default([]),
105
+ /** Default procedure slug to execute when this service is invoked. */
106
+ defaultProcedure: kebabSlugSchema.optional(),
107
+ /** Default pricing-model slug. */
108
+ defaultPricingModel: kebabSlugSchema.optional(),
109
+ /** Estimated duration as ISO-8601 duration (e.g., PT2H, P5D). */
110
+ estimatedDuration: isoDurationSchema.optional(),
111
+ /** Free-form prerequisites for the counterparty (info needed before scoping). */
112
+ prerequisites: z.array(z.string()).default([]),
113
+ /**
114
+ * Scope template — the structure of the engagement scope when this service
115
+ * is sold. Free-form for v1; templates may add their own conventions.
116
+ */
117
+ scopeTemplate: z.unknown().optional(),
118
+ /** Tags for catalog discovery (e.g., ["plumbing", "emergency"]). */
119
+ tags: z.array(z.string()).default([]),
120
+ /** External listing flag — show on agencies.sh registry / public pages. */
121
+ publishable: z.boolean().default(true)
122
+ });
123
+ var SERVICE_FILENAME = "SERVICE.md";
124
+ var procedureTriggerSchema = z.discriminatedUnion("kind", [
125
+ z.object({ kind: z.literal("service"), service: kebabSlugSchema }),
126
+ z.object({ kind: z.literal("routine"), routine: kebabSlugSchema }),
127
+ z.object({ kind: z.literal("manual"), description: z.string().optional() }),
128
+ z.object({ kind: z.literal("event"), eventType: z.string() })
129
+ ]);
130
+ var stepBaseSchema = z.object({
131
+ id: kebabSlugSchema,
132
+ description: z.string().optional(),
133
+ /** Skill required to execute this step (refs companies.sh SKILL.md). */
134
+ requiredSkill: z.string().optional(),
135
+ /** What this step produces (free-form descriptor). */
136
+ output: z.string().optional()
137
+ });
138
+ var procedureSimpleStepSchema = stepBaseSchema.extend({
139
+ branch: z.never().optional()
140
+ });
141
+ var procedureBranchStepSchema = stepBaseSchema.extend({
142
+ branch: z.array(
143
+ z.object({
144
+ if: z.string().optional(),
145
+ // condition expression (free-form for v1)
146
+ else: z.boolean().optional(),
147
+ action: z.string()
148
+ // "proceed_repair", "requestSignaturesTool", "advance_to_step:<id>", etc.
149
+ })
150
+ ).min(1)
151
+ });
152
+ var procedureStepSchema = z.union([
153
+ procedureSimpleStepSchema,
154
+ procedureBranchStepSchema
155
+ ]);
156
+ var procedureFrontmatterSchema = z.object({
157
+ ...envelope("procedure"),
158
+ /** What invokes this procedure. */
159
+ triggers: z.array(procedureTriggerSchema).default([]),
160
+ /** Skills required across the whole procedure (union of step requirements). */
161
+ requiredSkills: z.array(z.string()).default([]),
162
+ /** Estimated total duration (ISO-8601 duration). */
163
+ estimatedDuration: isoDurationSchema.optional(),
164
+ /**
165
+ * Slug of a POLICY.md (agentgovernance/v1) that governs autonomy for this
166
+ * procedure. Steps may individually require signatures via the policy.
167
+ */
168
+ autonomyPolicy: kebabSlugSchema.optional(),
169
+ /** Steps in declared order. */
170
+ steps: z.array(procedureStepSchema).min(1),
171
+ /**
172
+ * Default approvers when a step gates on signature without an explicit
173
+ * policy override (typically refs governance.requiredSignatures).
174
+ */
175
+ defaultApprovers: z.array(partyRefSchema).default([])
176
+ });
177
+ var PROCEDURE_FILENAME = "PROCEDURE.md";
178
+ var PRICING_KIND = [
179
+ "fixed",
180
+ "hourly",
181
+ "retainer",
182
+ "milestone",
183
+ "value",
184
+ "usage_metered"
185
+ ];
186
+ var pricingKindSchema = z.enum(PRICING_KIND);
187
+ var fixedPricingSchema = z.object({
188
+ kind: z.literal("fixed"),
189
+ amount: z.number().positive(),
190
+ currency: currencyIsoSchema
191
+ });
192
+ var hourlyPricingSchema = z.object({
193
+ kind: z.literal("hourly"),
194
+ rate: z.number().positive(),
195
+ currency: currencyIsoSchema,
196
+ /** Optional cap on total hours billable. */
197
+ capHours: z.number().positive().optional()
198
+ });
199
+ var retainerPricingSchema = z.object({
200
+ kind: z.literal("retainer"),
201
+ amount: z.number().positive(),
202
+ currency: currencyIsoSchema,
203
+ /** ISO duration of one billing period (e.g., P1M for monthly). */
204
+ period: isoDurationSchema,
205
+ /** Minimum commitment as ISO duration (e.g., P12M for 12 months). */
206
+ minCommitment: isoDurationSchema.optional()
207
+ });
208
+ var milestonePricingSchema = z.object({
209
+ kind: z.literal("milestone"),
210
+ currency: currencyIsoSchema,
211
+ milestones: z.array(
212
+ z.object({
213
+ slug: z.string(),
214
+ description: z.string().optional(),
215
+ amount: z.number().positive(),
216
+ /** Optional ISO date or duration relative to engagement start. */
217
+ dueAt: z.string().optional()
218
+ })
219
+ ).min(1)
220
+ });
221
+ var valuePricingSchema = z.object({
222
+ kind: z.literal("value"),
223
+ currency: currencyIsoSchema,
224
+ /** Free-form outcome formula description. */
225
+ formula: z.string(),
226
+ baseFee: z.number().nonnegative().optional(),
227
+ capAmount: z.number().positive().optional()
228
+ });
229
+ var usageMeteredPricingSchema = z.object({
230
+ kind: z.literal("usage_metered"),
231
+ currency: currencyIsoSchema,
232
+ unit: z.string(),
233
+ // e.g., "request", "minute", "GB"
234
+ ratePerUnit: z.number().positive(),
235
+ /** Optional included quota before metering kicks in. */
236
+ includedUnits: z.number().nonnegative().optional(),
237
+ /** Stripe-compatible meter id (vendor extension). */
238
+ externalMeterId: z.string().optional()
239
+ });
240
+ var pricingDetailsSchema = z.discriminatedUnion("kind", [
241
+ fixedPricingSchema,
242
+ hourlyPricingSchema,
243
+ retainerPricingSchema,
244
+ milestonePricingSchema,
245
+ valuePricingSchema,
246
+ usageMeteredPricingSchema
247
+ ]);
248
+ var pricingModelFrontmatterSchema = z.object({
249
+ ...envelope("pricing-model"),
250
+ details: pricingDetailsSchema,
251
+ /** Default tax handling (vendor extensions in metadata.<vendor>.tax.*). */
252
+ taxIncluded: z.boolean().optional()
253
+ });
254
+ var PRICING_MODEL_FILENAME = "PRICING-MODEL.md";
255
+ var COUNTERPARTY_KIND = ["individual", "organization"];
256
+ var counterpartyKindSchema = z.enum(COUNTERPARTY_KIND);
257
+ var COUNTERPARTY_SOURCE = [
258
+ "manual",
259
+ "inbound_email",
260
+ "imported",
261
+ "api"
262
+ ];
263
+ var counterpartySourceSchema = z.enum(COUNTERPARTY_SOURCE);
264
+ var counterpartyChannelSchema = z.object({
265
+ kind: z.enum(["email", "whatsapp", "sms"]),
266
+ address: z.string(),
267
+ // normalized: lowercased email / E.164 phone
268
+ isPrimary: z.boolean().default(false),
269
+ verifiedAt: isoDatetimeOrDateSchema.optional(),
270
+ optInAt: isoDatetimeOrDateSchema.optional(),
271
+ optOutAt: isoDatetimeOrDateSchema.optional(),
272
+ optOutReason: z.string().optional(),
273
+ bouncedAt: isoDatetimeOrDateSchema.optional(),
274
+ bounceReason: z.string().optional()
275
+ });
276
+ var counterpartyFrontmatterSchema = z.object({
277
+ ...envelope("counterparty"),
278
+ kind: counterpartyKindSchema,
279
+ /** Display name (NOT the legal name; legal name lives in encrypted PII). */
280
+ displayName: z.string().min(1),
281
+ /** Pre-resolved primary email (denorm of channels[isPrimary, kind=email]). */
282
+ primaryEmail: z.email().optional(),
283
+ /** Pre-resolved primary phone in E.164 (denorm of channels[isPrimary, kind=whatsapp|sms]). */
284
+ primaryPhone: z.string().optional(),
285
+ channels: z.array(counterpartyChannelSchema).default([]),
286
+ country: countryIsoSchema.optional(),
287
+ currency: currencyIsoSchema.optional(),
288
+ timezone: timezoneSchema.optional(),
289
+ source: counterpartySourceSchema.default("manual"),
290
+ /**
291
+ * Path to encrypted PII blob (e.g., legal name, address, taxId, DOB).
292
+ * The blob is encrypted at rest with a workspace-level key; only `displayName`
293
+ * + `primaryEmail` + `primaryPhone` are unencrypted (for inbound channel routing).
294
+ */
295
+ piiBlobRef: z.string().optional(),
296
+ /** Self-FK for dedup: this counterparty is merged into another (canonical) one. */
297
+ mergedIntoId: kebabSlugSchema.optional(),
298
+ /** Free-form tags for segmentation (e.g., ["enterprise", "newsletter-2026"]). */
299
+ tags: z.array(z.string()).default([])
300
+ });
301
+ var COUNTERPARTY_FILENAME = "COUNTERPARTY.md";
302
+ var ENGAGEMENT_KIND = [
303
+ "one_shot",
304
+ "milestone",
305
+ "retainer",
306
+ "usage_metered"
307
+ ];
308
+ var engagementKindSchema = z.enum(ENGAGEMENT_KIND);
309
+ var ENGAGEMENT_STATUS = [
310
+ "scoping",
311
+ "quoted",
312
+ "signed",
313
+ "in_progress",
314
+ "review_requested",
315
+ "revision",
316
+ "validated",
317
+ "invoiced",
318
+ "paid",
319
+ "closed",
320
+ "cancelled",
321
+ "disputed"
322
+ ];
323
+ var engagementStatusSchema = z.enum(ENGAGEMENT_STATUS);
324
+ var engagementPartySchema = z.object({
325
+ /** Role in the engagement (e.g., "client", "primary-contact", "executor"). */
326
+ role: z.string().min(1),
327
+ /** Canonical "<kind>:<slug>" — counterparty:..., operator:..., agent:..., etc. */
328
+ party: partyRefStrictSchema,
329
+ /** Optional revenue-share percentage (0-100). Sum across parties may exceed 100 (multi-step splits). */
330
+ share: z.number().min(0).max(100).optional()
331
+ });
332
+ var engagementFrontmatterSchema = z.object({
333
+ ...envelope("engagement"),
334
+ kind: engagementKindSchema,
335
+ status: engagementStatusSchema,
336
+ /** All parties — roles + canonical refs. */
337
+ parties: z.array(engagementPartySchema).min(1),
338
+ /** Denormalized: primary counterparty for fast queries. */
339
+ primaryCounterpartyId: kebabSlugSchema,
340
+ /** Service slug being delivered. */
341
+ serviceSlug: kebabSlugSchema.optional(),
342
+ /** Active procedure being executed (PROCEDURE.md slug). */
343
+ activeProcedure: kebabSlugSchema.optional(),
344
+ /** Active step within the procedure (step id). */
345
+ activeStep: kebabSlugSchema.optional(),
346
+ /** Path to the AGREEMENT.md (relative to engagement folder). */
347
+ agreementPath: z.string().default("AGREEMENT.md"),
348
+ /** Path to the linked PROJECT.md (companies.sh) — the work. */
349
+ projectPath: workspacePathSchema.optional(),
350
+ /** Pricing model in effect for this engagement. */
351
+ pricingModelSlug: kebabSlugSchema.optional(),
352
+ totalContractValue: z.number().nonnegative().optional(),
353
+ currency: currencyIsoSchema.optional(),
354
+ /** Affiliate referral link (refs core/affiliate domain if present). */
355
+ referredByAffiliateId: kebabSlugSchema.optional(),
356
+ // Lifecycle timestamps (denorm of audit-log + workflow state).
357
+ scopedAt: isoDatetimeOrDateSchema.optional(),
358
+ signedAt: isoDatetimeOrDateSchema.optional(),
359
+ startedAt: isoDatetimeOrDateSchema.optional(),
360
+ validatedAt: isoDatetimeOrDateSchema.optional(),
361
+ paidAt: isoDatetimeOrDateSchema.optional(),
362
+ closedAt: isoDatetimeOrDateSchema.optional()
363
+ });
364
+ var ENGAGEMENT_FILENAME = "ENGAGEMENT.md";
365
+ var AGREEMENT_KIND = ["quote", "agreement"];
366
+ var agreementKindSchema = z.enum(AGREEMENT_KIND);
367
+ var AGREEMENT_STATUS = [
368
+ "draft",
369
+ "proposed",
370
+ "signed",
371
+ "superseded",
372
+ "expired",
373
+ "void",
374
+ "cancelled"
375
+ ];
376
+ var agreementStatusSchema = z.enum(AGREEMENT_STATUS);
377
+ var agreementPartySchema = z.object({
378
+ role: z.string().min(1),
379
+ party: partyRefStrictSchema,
380
+ share: z.number().min(0).max(100).optional()
381
+ });
382
+ var lineItemSchema = z.object({
383
+ /** Stable UUID for the line item — survives revisions. */
384
+ lineItemId: z.uuid(),
385
+ description: z.string().min(1),
386
+ quantity: z.number().positive().default(1),
387
+ unitAmount: z.number().nonnegative(),
388
+ currency: currencyIsoSchema,
389
+ /** When this line item triggers payment (used by milestone pricing). */
390
+ paymentTrigger: z.string().optional()
391
+ });
392
+ var paymentTermsSchema = z.object({
393
+ /** ISO-8601 duration: net payment window after invoice (e.g., PT0H, P15D, P30D). */
394
+ netDuration: isoDurationSchema.default("P30D"),
395
+ /** Schedule kind: at signature, on milestones, monthly retainer, etc. */
396
+ schedule: z.enum(["at_signature", "milestone", "retainer", "on_completion", "custom"]).default("on_completion"),
397
+ /** Late fee terms — free-form for v1. */
398
+ latePolicy: z.string().optional()
399
+ });
400
+ var requiredSignerSchema = z.object({
401
+ signer: partyRefStrictSchema,
402
+ method: z.enum([
403
+ "typed_name",
404
+ "agent_confirm",
405
+ "click_through",
406
+ "esign_external"
407
+ ]),
408
+ weight: z.number().min(0).optional()
409
+ });
410
+ var agreementFrontmatterSchema = z.object({
411
+ ...envelope("agreement"),
412
+ kind: agreementKindSchema,
413
+ status: agreementStatusSchema.default("draft"),
414
+ parties: z.array(agreementPartySchema).min(2),
415
+ /** Denormalized: primary counterparty for fast queries. */
416
+ primaryCounterpartyId: kebabSlugSchema,
417
+ lineItems: z.array(lineItemSchema).default([]),
418
+ currency: currencyIsoSchema,
419
+ // single currency per agreement (multi-currency = separate agreements)
420
+ /** Denormalized total of lineItems[].quantity * unitAmount. */
421
+ totalAmount: z.number().nonnegative().optional(),
422
+ paymentTerms: paymentTermsSchema.default({
423
+ netDuration: "P30D",
424
+ schedule: "on_completion"
425
+ }),
426
+ /** Free-form deliverable spec (refers to DELIVERABLE.md slugs or describes inline). */
427
+ deliverableSpec: z.unknown().optional(),
428
+ /** Required signatures (defers to agentgovernance/v1 contractual approval framework). */
429
+ requiredSignatures: z.array(requiredSignerSchema).default([]),
430
+ /** Legal jurisdiction + governing law. */
431
+ governingLaw: z.string().optional(),
432
+ jurisdiction: z.string().optional(),
433
+ /** Hash of the rendered SoW PDF (or canonical bytes if no PDF). Witness for the signature. */
434
+ documentHash: sha256HexSchema.optional(),
435
+ /** Storage ref for the rendered immutable PDF/document. */
436
+ documentBlobRef: z.string().optional(),
437
+ /** Versioning chain. */
438
+ version: z.string().default("1"),
439
+ /** Self-ref to the previous version's slug (when this agreement supersedes another). */
440
+ parentAgreement: kebabSlugSchema.optional(),
441
+ effectiveAt: isoDatetimeOrDateSchema.optional(),
442
+ expiresAt: isoDatetimeOrDateSchema.optional(),
443
+ signedAt: isoDatetimeOrDateSchema.optional()
444
+ });
445
+ var AGREEMENT_FILENAME = "AGREEMENT.md";
446
+ var DELIVERABLE_STATUS = [
447
+ "draft",
448
+ "submitted",
449
+ "under_review",
450
+ "validated",
451
+ "rejected",
452
+ "revised",
453
+ "superseded"
454
+ ];
455
+ var deliverableStatusSchema = z.enum(DELIVERABLE_STATUS);
456
+ var requiredSignerSchema2 = z.object({
457
+ signer: partyRefStrictSchema,
458
+ method: z.enum([
459
+ "typed_name",
460
+ "agent_confirm",
461
+ "click_through",
462
+ "esign_external"
463
+ ]),
464
+ weight: z.number().min(0).optional()
465
+ });
466
+ var deliverableFrontmatterSchema = z.object({
467
+ ...envelope("deliverable"),
468
+ status: deliverableStatusSchema.default("draft"),
469
+ /** Path to the linked TASK.md (companies.sh) if this deliverable resulted from one. */
470
+ taskPath: workspacePathSchema.optional(),
471
+ /**
472
+ * Workspace-relative paths to attached work products (binary or other artifacts).
473
+ * Each MAY be hashed; the hash anchors what was reviewed.
474
+ */
475
+ attachments: z.array(
476
+ z.object({
477
+ path: workspacePathSchema,
478
+ contentHash: sha256HexSchema.optional(),
479
+ kind: z.string().optional()
480
+ // "image", "pdf", "video", "document", "code", etc.
481
+ })
482
+ ).default([]),
483
+ /** Required signatures for client validation (typically `[counterparty:<id>]`). */
484
+ requiredSignatures: z.array(requiredSignerSchema2).default([]),
485
+ /** Hash of the deliverable.md frontmatter+body — what the signer signs against. */
486
+ documentHash: sha256HexSchema.optional(),
487
+ /** Self-ref for revision chain. */
488
+ parentDeliverable: kebabSlugSchema.optional(),
489
+ version: z.string().default("1"),
490
+ submittedAt: isoDatetimeOrDateSchema.optional(),
491
+ validatedAt: isoDatetimeOrDateSchema.optional(),
492
+ rejectedAt: isoDatetimeOrDateSchema.optional(),
493
+ rejectionReason: z.string().optional()
494
+ });
495
+ var DELIVERABLE_FILENAME = "DELIVERABLE.md";
496
+ var INVOICE_STATUS = [
497
+ "draft",
498
+ "issued",
499
+ "paid",
500
+ "void",
501
+ "uncollectible"
502
+ ];
503
+ var invoiceStatusSchema = z.enum(INVOICE_STATUS);
504
+ var lineItemSchema2 = z.object({
505
+ lineItemId: z.uuid(),
506
+ description: z.string().min(1),
507
+ quantity: z.number().positive().default(1),
508
+ unitAmount: z.number().nonnegative(),
509
+ /** Reference to the originating engagement deliverable / agreement line item. */
510
+ sourceRef: z.string().optional()
511
+ });
512
+ var taxLineSchema = z.object({
513
+ /** Decimal rate (e.g., 0.20 for 20% VAT). */
514
+ rate: z.number().min(0).max(1),
515
+ /** Base amount taxed. */
516
+ base: z.number().nonnegative(),
517
+ /** Computed tax amount. */
518
+ amount: z.number().nonnegative(),
519
+ /** Jurisdiction code (e.g., "FR-VAT", "US-CA-SALES"). */
520
+ jurisdiction: z.string()
521
+ });
522
+ var externalRefsSchema = z.record(
523
+ z.string(),
524
+ z.record(z.string(), z.string()).optional()
525
+ );
526
+ var invoiceFrontmatterSchema = z.object({
527
+ ...envelope("invoice"),
528
+ status: invoiceStatusSchema.default("draft"),
529
+ /** Per-tenant gapless invoice number (e.g., INV-2026-00042). */
530
+ invoiceNumber: z.string().min(1),
531
+ /** Workspace-relative path to the engagement folder. */
532
+ engagementSlug: kebabSlugSchema.optional(),
533
+ agreementSlug: kebabSlugSchema.optional(),
534
+ counterpartyId: kebabSlugSchema,
535
+ billingAccountId: kebabSlugSchema.optional(),
536
+ lineItems: z.array(lineItemSchema2).min(1),
537
+ taxLines: z.array(taxLineSchema).default([]),
538
+ subtotal: z.number().nonnegative(),
539
+ taxTotal: z.number().nonnegative().default(0),
540
+ total: z.number().nonnegative(),
541
+ currency: currencyIsoSchema,
542
+ /** FX snapshot — used when invoice currency != billing-account base currency. */
543
+ fxRate: z.number().positive().optional(),
544
+ fxBaseCurrency: currencyIsoSchema.optional(),
545
+ fxAt: isoDatetimeOrDateSchema.optional(),
546
+ dueAt: isoDatetimeOrDateSchema.optional(),
547
+ issuedAt: isoDatetimeOrDateSchema.optional(),
548
+ paidAt: isoDatetimeOrDateSchema.optional(),
549
+ voidedAt: isoDatetimeOrDateSchema.optional(),
550
+ voidReason: z.string().optional(),
551
+ /** Storage ref for the rendered immutable PDF. */
552
+ pdfBlobRef: z.string().optional(),
553
+ /** SHA-256 of the rendered PDF. */
554
+ pdfHash: sha256HexSchema.optional(),
555
+ /** Provider-specific linkage — Stripe payment intent id, paypal capture id, etc. */
556
+ externalRefs: externalRefsSchema.optional(),
557
+ /** Public payment link (set after `issueInvoiceCheckoutTool` runs). */
558
+ paymentLinkUrl: z.string().optional(),
559
+ /** Dunning state for retainer/late invoices. */
560
+ dunningState: z.enum(["none", "reminder_1", "reminder_2", "final_notice", "collections"]).default("none"),
561
+ nextReminderAt: isoDatetimeOrDateSchema.optional()
562
+ });
563
+ var INVOICE_FILENAME = "INVOICE.md";
564
+ var triggerScheduleSchema = z.object({
565
+ kind: z.literal("schedule"),
566
+ /** Standard 5-field cron (UTC by default unless timezone is set). */
567
+ cronExpression: z.string().min(1),
568
+ timezone: timezoneSchema.optional()
569
+ });
570
+ var triggerEventSchema = z.object({
571
+ kind: z.literal("event"),
572
+ /** Event type to react to (free-form for v1). */
573
+ eventType: z.string()
574
+ });
575
+ var triggerWebhookSchema = z.object({
576
+ kind: z.literal("webhook"),
577
+ webhookSlug: z.string()
578
+ });
579
+ var routineTriggerSchema = z.discriminatedUnion("kind", [
580
+ triggerScheduleSchema,
581
+ triggerEventSchema,
582
+ triggerWebhookSchema
583
+ ]);
584
+ var routineConditionSchema = z.object({
585
+ /** Free-form condition expression (e.g., "engagementStatus == 'pending_signature'"). */
586
+ expression: z.string().optional(),
587
+ /** Pre-defined condition kinds for common cases. */
588
+ engagementStatus: z.string().optional(),
589
+ /** Maximum runs per period (e.g., max 3 nudges per week). */
590
+ maxPerPeriod: z.object({
591
+ count: z.number().positive(),
592
+ period: isoDurationSchema
593
+ }).optional()
594
+ });
595
+ var routineEscalationSchema = z.object({
596
+ /** ISO duration: how long before deadline to escalate. */
597
+ ifPendingAfter: isoDurationSchema,
598
+ escalateTo: z.array(partyRefStrictSchema).min(1)
599
+ });
600
+ var routineFrontmatterSchema = z.object({
601
+ ...envelope("routine"),
602
+ /** Procedure to run on trigger (PROCEDURE.md slug). */
603
+ runs: kebabSlugSchema,
604
+ trigger: routineTriggerSchema,
605
+ conditions: z.array(routineConditionSchema).default([]),
606
+ escalation: routineEscalationSchema.optional(),
607
+ /** Disabled flag for ad-hoc pausing without deletion. */
608
+ enabled: z.boolean().default(true)
609
+ });
610
+ var ROUTINE_FILENAME = "ROUTINE.md";
611
+ var availabilityWindowSchema = z.object({
612
+ /** ISO weekday name or 0-6 (Mon=0..Sun=6). */
613
+ weekday: z.union([
614
+ z.number().min(0).max(6),
615
+ z.enum(["mon", "tue", "wed", "thu", "fri", "sat", "sun"])
616
+ ]),
617
+ /** "HH:MM" 24h start time (in operator's timezone). */
618
+ start: z.string().regex(/^\d{2}:\d{2}$/),
619
+ end: z.string().regex(/^\d{2}:\d{2}$/)
620
+ });
621
+ var capacityFrontmatterSchema = z.object({
622
+ ...envelope("capacity"),
623
+ /** The party this capacity describes (operator, agent, or team). */
624
+ for: partyRefStrictSchema,
625
+ /** Recurring availability windows (in operator's timezone). */
626
+ availability: z.array(availabilityWindowSchema).default([]),
627
+ /** Maximum concurrent engagements. */
628
+ maxConcurrentEngagements: z.number().positive().optional(),
629
+ /** Maximum hours per week of billable work. */
630
+ maxBillableHoursPerWeek: z.number().positive().optional(),
631
+ /** Vertical specializations (slugs of services or templates). */
632
+ specializations: z.array(kebabSlugSchema).default([]),
633
+ /** Current load — denorm of in-flight work (regenerated by runtime). */
634
+ currentEngagementCount: z.number().nonnegative().optional(),
635
+ currentBillableHoursThisWeek: z.number().nonnegative().optional(),
636
+ /** Out-of-office / unavailability windows. */
637
+ blockedWindows: z.array(
638
+ z.object({
639
+ from: isoDatetimeOrDateSchema,
640
+ until: isoDatetimeOrDateSchema,
641
+ reason: z.string().optional()
642
+ })
643
+ ).default([])
644
+ });
645
+ var CAPACITY_FILENAME = "CAPACITY.md";
646
+
647
+ export { AGENCY_FILENAME, AGREEMENT_FILENAME, AGREEMENT_KIND, AGREEMENT_STATUS, AUTONOMY_POSTURE, CAPACITY_FILENAME, COUNTERPARTY_FILENAME, COUNTERPARTY_KIND, COUNTERPARTY_SOURCE, DELIVERABLE_FILENAME, DELIVERABLE_STATUS, ENGAGEMENT_FILENAME, ENGAGEMENT_KIND, ENGAGEMENT_STATUS, INVOICE_FILENAME, INVOICE_STATUS, OPERATIONS_FILENAME, PRICING_KIND, PRICING_MODEL_FILENAME, PROCEDURE_FILENAME, ROUTINE_FILENAME, SCHEMA_NAME, SERVICE_FILENAME, agencyFrontmatterSchema, agreementFrontmatterSchema, agreementKindSchema, agreementStatusSchema, authorshipFields, autonomyPostureSchema, capacityFrontmatterSchema, counterpartyFrontmatterSchema, counterpartyKindSchema, counterpartySourceSchema, countryIsoSchema, currencyIsoSchema, deliverableFrontmatterSchema, deliverableStatusSchema, engagementFrontmatterSchema, engagementKindSchema, engagementStatusSchema, envelope, invoiceFrontmatterSchema, invoiceStatusSchema, isoDateOrDateSchema, isoDatetimeOrDateSchema, isoDurationSchema, kebabSlugSchema, metadataSchema, operationsFrontmatterSchema, partyRefSchema, partyRefStrictSchema, pricingDetailsSchema, pricingKindSchema, pricingModelFrontmatterSchema, procedureBranchStepSchema, procedureFrontmatterSchema, procedureSimpleStepSchema, procedureStepSchema, procedureTriggerSchema, routineFrontmatterSchema, routineTriggerSchema, serviceFrontmatterSchema, sha256HexSchema, timezoneSchema, workspacePathSchema };
648
+ //# sourceMappingURL=chunk-DYQ4A5HV.mjs.map
649
+ //# sourceMappingURL=chunk-DYQ4A5HV.mjs.map