@bpmsoftwaresolutions/ai-engine-client 1.1.66 → 1.1.70

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 (3) hide show
  1. package/README.md +29 -0
  2. package/package.json +1 -1
  3. package/src/index.js +279 -0
package/README.md CHANGED
@@ -94,6 +94,34 @@ const continuation = await client.resumeProjectWork({
94
94
 
95
95
  That call resolves the canonical project, active roadmap state, workflow context, tool bindings, and the continuation brief in one governed response. Use the returned `continuation_brief_markdown` as the primary focus surface for LOGA and operator startup flows.
96
96
 
97
+ ### Roadmap Closure Workflow
98
+
99
+ Use `closeRoadmapItemWorkflow(...)` when you want the client to compose the full roadmap-closure path end to end.
100
+
101
+ ```js
102
+ const closure = await client.closeRoadmapItemWorkflow({
103
+ projectIdentifier: charter.project_id,
104
+ claimId: existingClaimId,
105
+ });
106
+ ```
107
+
108
+ The helper:
109
+
110
+ - resumes the project
111
+ - loads the active roadmap item
112
+ - validates a supplied claim with `claimIsValid(claimId)`
113
+ - starts a fresh claim when the supplied claim is missing or inactive
114
+ - loads and verifies acceptance checks
115
+ - verifies the required artifacts
116
+ - records the implementation gate decision
117
+ - advances the item to terminal status
118
+ - attaches closure evidence
119
+ - signs off the claim
120
+ - reloads the active item
121
+ - closes the active project when no open tasks remain
122
+
123
+ The backend still does not expose a project-scoped `getActiveClaim(projectId)` helper. This client records that gap and uses `claimIsValid(claimId)` plus claim creation when it needs a governed fallback path.
124
+
97
125
  ## Integration Notes
98
126
 
99
127
  ### Auth Modes
@@ -604,6 +632,7 @@ Generated scripts are ephemeral helpers, not source-of-truth. The server keeps S
604
632
  | `getProjectRoadmap(projectId)` | Get full roadmap for a project. |
605
633
  | `getProjectRoadmapSummary(projectId)` | Roadmap summary. |
606
634
  | `getProjectRoadmapActiveItem(projectId)` | Current active roadmap item. |
635
+ | `closeRoadmapItemWorkflow({ projectIdentifier, claimId, actorMode, executionIntent, workflowRunLimit, requiredArtifacts, requiredAcceptanceCheckStatus, terminalItemStatus, gateType, gateDecision, closeProjectIfNoRemainingOpenItems })` | Compose roadmap closure end to end: resume, claim fallback, verify checks/artifacts, record a gate decision, sign off, and close the project when nothing remains open. |
607
636
  | `getProjectImplementationRoadmapReport(projectId)` | Get the SQL-backed implementation roadmap report payload. |
608
637
  | `downloadProjectImplementationRoadmapReportMarkdown(projectId)` | Download the implementation roadmap markdown report. |
609
638
  | `ensureProjectRoadmapTaskSurface(projectId, { requestedBy, assignedTo, createAcceptanceSubtasks })` | Materialize the active roadmap item's parent task and acceptance subtasks. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmsoftwaresolutions/ai-engine-client",
3
- "version": "1.1.66",
3
+ "version": "1.1.70",
4
4
  "description": "Thin npm client for the AI Engine operator and retrieval APIs",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -4395,6 +4395,285 @@ export class AIEngineClient {
4395
4395
  });
4396
4396
  }
4397
4397
 
4398
+ async closeRoadmapItemWorkflow({
4399
+ projectIdentifier,
4400
+ projectId,
4401
+ claimId,
4402
+ claimName,
4403
+ actorId,
4404
+ actorMode = 'operator',
4405
+ executionIntent = 'close roadmap item workflow',
4406
+ workflowRunLimit = 5,
4407
+ declaredScopeFiles,
4408
+ allowedMutationSurfaces,
4409
+ requiredArtifacts,
4410
+ requiredAcceptanceCheckStatus = 'verified',
4411
+ terminalItemStatus = 'accepted',
4412
+ gateType = 'roadmap_closure',
4413
+ gateDecision = 'pass',
4414
+ gateRationale,
4415
+ gateEvidenceRefs,
4416
+ remediationActions = [],
4417
+ closureEvidenceType = 'roadmap_closure',
4418
+ closureEvidenceRef,
4419
+ closureEvidenceTitle,
4420
+ closeProjectIfNoRemainingOpenItems = true,
4421
+ closeProjectReason,
4422
+ } = {}) {
4423
+ const normalizedProjectReference = cleanText(projectIdentifier) || cleanText(projectId);
4424
+ if (!normalizedProjectReference) {
4425
+ throw new Error('projectIdentifier is required.');
4426
+ }
4427
+
4428
+ const normalizedActorId = cleanText(actorId) || this.actorId;
4429
+ const continuation = await this.resumeProjectWork({
4430
+ projectIdentifier: normalizedProjectReference,
4431
+ projectId: normalizedProjectReference,
4432
+ actorMode,
4433
+ executionIntent,
4434
+ requireClaim: false,
4435
+ workflowRunLimit,
4436
+ });
4437
+
4438
+ const projectSummary = isPlainObject(continuation?.project) ? continuation.project : {};
4439
+ const resolvedProjectId = cleanText(projectSummary.project_id) || cleanText(projectSummary.projectId) || normalizedProjectReference;
4440
+ const resolvedWorkflowId = cleanText(projectSummary.workflow_id) || cleanText(projectSummary.workflowId);
4441
+ const resolvedWorkflowRunId = cleanText(projectSummary.workflow_run_id) || cleanText(projectSummary.workflowRunId) || null;
4442
+ const activeItem = await this.getProjectRoadmapActiveItem(resolvedProjectId);
4443
+ const normalizedActiveItem = isPlainObject(activeItem) ? activeItem : {};
4444
+ const implementationItemId = cleanText(normalizedActiveItem.implementation_item_id) || cleanText(normalizedActiveItem.implementationItemId);
4445
+ const itemKey = cleanText(normalizedActiveItem.item_key) || cleanText(normalizedActiveItem.itemKey) || implementationItemId;
4446
+ const itemStatus = cleanText(normalizedActiveItem.item_status) || cleanText(normalizedActiveItem.status);
4447
+ const packetId = cleanText(normalizedActiveItem.implementation_packet_id) || cleanText(normalizedActiveItem.implementationPacketId);
4448
+
4449
+ if (!implementationItemId || !resolvedWorkflowId || !packetId) {
4450
+ throw new Error('project closure state is ambiguous.');
4451
+ }
4452
+
4453
+ let effectiveClaimId = cleanText(claimId);
4454
+ let claimSource = 'provided';
4455
+ if (effectiveClaimId) {
4456
+ const claimStillValid = await this.claimIsValid(effectiveClaimId).catch(() => false);
4457
+ if (!claimStillValid) {
4458
+ effectiveClaimId = null;
4459
+ claimSource = 'fresh';
4460
+ }
4461
+ } else {
4462
+ claimSource = 'fresh';
4463
+ }
4464
+
4465
+ let freshClaim = null;
4466
+ if (!effectiveClaimId) {
4467
+ const declaredScope = cleanList(declaredScopeFiles);
4468
+ const surfaces = cleanList(allowedMutationSurfaces);
4469
+ const fallbackDeclaredScope = declaredScope.length > 0 ? declaredScope : [
4470
+ `${resolvedProjectId}`,
4471
+ itemKey || implementationItemId,
4472
+ ].filter(Boolean);
4473
+ const fallbackSurfaces = surfaces.length > 0 ? surfaces : [
4474
+ 'project_roadmap_task',
4475
+ 'implementation_acceptance_check',
4476
+ 'implementation_evidence',
4477
+ 'implementation_gate',
4478
+ 'project_close',
4479
+ ];
4480
+ const closureTaskStatus = itemStatus && !new Set(['done', 'completed', 'complete', 'blocked', 'failed', 'rejected', 'cancelled']).has(itemStatus.toLowerCase())
4481
+ ? itemStatus
4482
+ : 'in_progress';
4483
+ const closureTaskBinding = {
4484
+ task_id: implementationItemId || itemKey || resolvedProjectId,
4485
+ roadmap_item_id: implementationItemId || itemKey || resolvedProjectId,
4486
+ task_status: closureTaskStatus,
4487
+ allowed_actions: ['claim_work_item'],
4488
+ substrate_action: 'claim_work_item',
4489
+ task_type: 'roadmap_closure',
4490
+ };
4491
+ try {
4492
+ freshClaim = await this.startClaimedWork({
4493
+ claimName: cleanText(claimName) || `closeRoadmapItemWorkflow:${resolvedProjectId}:${itemKey || implementationItemId}`,
4494
+ actorId: normalizedActorId,
4495
+ intentId: 'code_mutation',
4496
+ declaredScopeFiles: fallbackDeclaredScope,
4497
+ allowedMutationSurfaces: fallbackSurfaces,
4498
+ runtimeSessionId: resolvedWorkflowRunId || resolvedProjectId,
4499
+ executionPurpose: cleanText(executionIntent) || `Close roadmap item ${itemKey || implementationItemId}`,
4500
+ successCriteria: 'Active roadmap item closed with verified acceptance checks, artifacts, gate decision, and claim signoff.',
4501
+ mutationAllowed: true,
4502
+ metadata: {
4503
+ source: 'closeRoadmapItemWorkflow',
4504
+ project_id: resolvedProjectId,
4505
+ workflow_id: resolvedWorkflowId,
4506
+ workflow_run_id: resolvedWorkflowRunId,
4507
+ task_binding: closureTaskBinding,
4508
+ },
4509
+ });
4510
+ } catch (error) {
4511
+ throw new Error(`claim cannot be established: ${error.message}`);
4512
+ }
4513
+ effectiveClaimId = cleanText(freshClaim?.claim_id) || cleanText(freshClaim?.claim?.claim_id);
4514
+ if (!effectiveClaimId) {
4515
+ throw new Error('claim cannot be established.');
4516
+ }
4517
+ }
4518
+
4519
+ const acceptanceCheckResult = await this.getImplementationItemAcceptanceChecks(implementationItemId);
4520
+ const acceptanceChecks = Array.isArray(acceptanceCheckResult?.acceptance_checks)
4521
+ ? acceptanceCheckResult.acceptance_checks.filter((check) => isPlainObject(check))
4522
+ : [];
4523
+ if (acceptanceChecks.length === 0) {
4524
+ throw new Error('acceptance checks are incomplete.');
4525
+ }
4526
+
4527
+ const normalizedAcceptanceStatus = cleanText(requiredAcceptanceCheckStatus) || 'verified';
4528
+ const verifiedAcceptanceChecks = [];
4529
+ for (const check of acceptanceChecks) {
4530
+ const acceptanceCheckId = cleanText(check.acceptance_check_id) || cleanText(check.acceptanceCheckId);
4531
+ if (!acceptanceCheckId) {
4532
+ throw new Error('acceptance checks are incomplete.');
4533
+ }
4534
+ const status = cleanText(check.status).toLowerCase();
4535
+ if (status !== normalizedAcceptanceStatus.toLowerCase()) {
4536
+ try {
4537
+ const verification = await this.updateAcceptanceCheckStatusVerified(
4538
+ implementationItemId,
4539
+ acceptanceCheckId,
4540
+ normalizedAcceptanceStatus,
4541
+ {
4542
+ updated_by: normalizedActorId,
4543
+ workflowId: resolvedWorkflowId,
4544
+ claim_id: effectiveClaimId,
4545
+ status_reason: 'Roadmap closure workflow verified the required acceptance check.',
4546
+ },
4547
+ );
4548
+ verifiedAcceptanceChecks.push({
4549
+ acceptance_check_id: acceptanceCheckId,
4550
+ status: normalizedAcceptanceStatus,
4551
+ verification,
4552
+ });
4553
+ } catch (error) {
4554
+ throw new Error(`acceptance checks are incomplete: ${error.message}`);
4555
+ }
4556
+ continue;
4557
+ }
4558
+ verifiedAcceptanceChecks.push({
4559
+ acceptance_check_id: acceptanceCheckId,
4560
+ status,
4561
+ existing: true,
4562
+ });
4563
+ }
4564
+
4565
+ const artifacts = await this.verifyImplementationItemArtifacts(implementationItemId, {
4566
+ requiredArtifacts: cleanList(requiredArtifacts).length > 0
4567
+ ? cleanList(requiredArtifacts)
4568
+ : ['artifact_manifest', 'decision_packet'],
4569
+ });
4570
+
4571
+ const evidenceRefs = cleanList(gateEvidenceRefs);
4572
+ if (evidenceRefs.length === 0) {
4573
+ evidenceRefs.push(closureEvidenceRef || `roadmap-closure:${resolvedProjectId}:${itemKey || implementationItemId}`);
4574
+ }
4575
+
4576
+ const gateDecisionResult = await this.createImplementationPacketGateDecision(packetId, {
4577
+ gate_type: cleanText(gateType) || 'roadmap_closure',
4578
+ decision: cleanText(gateDecision) || 'pass',
4579
+ rationale: cleanText(gateRationale) || `Roadmap item ${itemKey || implementationItemId} satisfied all closure checks.`,
4580
+ evidence_refs: evidenceRefs,
4581
+ remediation_actions: cleanList(remediationActions),
4582
+ decided_by: normalizedActorId,
4583
+ claim_id: effectiveClaimId,
4584
+ workflow_id: resolvedWorkflowId,
4585
+ workflow_run_id: resolvedWorkflowRunId,
4586
+ });
4587
+
4588
+ const itemStatusResult = await this.updateImplementationItemStatusVerified(
4589
+ implementationItemId,
4590
+ cleanText(terminalItemStatus) || 'accepted',
4591
+ {
4592
+ workflowId: resolvedWorkflowId,
4593
+ updated_by: normalizedActorId,
4594
+ claim_id: effectiveClaimId,
4595
+ status_reason: cleanText(closeProjectReason) || `Roadmap closure workflow advanced ${itemKey || implementationItemId} to terminal status.`,
4596
+ },
4597
+ );
4598
+
4599
+ const closureEvidenceRefValue = cleanText(closureEvidenceRef) || `roadmap-closure:${resolvedProjectId}:${itemKey || implementationItemId}`;
4600
+ const closureEvidence = await this.addImplementationItemEvidence(implementationItemId, {
4601
+ evidence_type: cleanText(closureEvidenceType) || 'roadmap_closure',
4602
+ evidence_ref: closureEvidenceRefValue,
4603
+ title: cleanText(closureEvidenceTitle) || `Closure evidence for ${itemKey || implementationItemId}`,
4604
+ recorded_by: normalizedActorId,
4605
+ metadata: {
4606
+ project_id: resolvedProjectId,
4607
+ workflow_id: resolvedWorkflowId,
4608
+ workflow_run_id: resolvedWorkflowRunId,
4609
+ claim_id: effectiveClaimId,
4610
+ gate_decision_id: cleanText(gateDecisionResult?.implementation_gate_decision_id) || cleanText(gateDecisionResult?.gate_decision_id),
4611
+ gate_type: cleanText(gateType) || 'roadmap_closure',
4612
+ },
4613
+ });
4614
+
4615
+ const signedClaim = await this.signoffClaim(effectiveClaimId, {
4616
+ actor_signature: normalizedActorId,
4617
+ intent_confirmation: cleanText(executionIntent) || 'I confirm this governed roadmap closure workflow.',
4618
+ });
4619
+
4620
+ const reloadedActiveItem = await this.getProjectRoadmapActiveItem(resolvedProjectId);
4621
+ const remainingOpenTasksPayload = await this.listProjectOpenTasks(resolvedProjectId);
4622
+ const remainingOpenTasks = Array.isArray(remainingOpenTasksPayload?.tasks)
4623
+ ? remainingOpenTasksPayload.tasks.filter((task) => isPlainObject(task))
4624
+ : Array.isArray(remainingOpenTasksPayload)
4625
+ ? remainingOpenTasksPayload.filter((task) => isPlainObject(task))
4626
+ : [];
4627
+ const reloadedItemStatus = cleanText(reloadedActiveItem?.item_status) || cleanText(reloadedActiveItem?.status) || null;
4628
+ const terminalStatuses = new Set([
4629
+ cleanText(terminalItemStatus) || 'accepted',
4630
+ 'accepted',
4631
+ 'verified',
4632
+ 'done',
4633
+ 'completed',
4634
+ 'closed',
4635
+ ].map((value) => String(value || '').toLowerCase()));
4636
+ const activeItemClosed = !reloadedActiveItem || terminalStatuses.has(String(reloadedItemStatus || '').toLowerCase());
4637
+ if (!activeItemClosed) {
4638
+ throw new Error('project closure state is ambiguous.');
4639
+ }
4640
+
4641
+ let closeProjectResult = null;
4642
+ if (closeProjectIfNoRemainingOpenItems && remainingOpenTasks.length === 0) {
4643
+ closeProjectResult = await this.closeActiveProject(resolvedProjectId, {
4644
+ workflowId: resolvedWorkflowId,
4645
+ workflowRunIds: resolvedWorkflowRunId ? [resolvedWorkflowRunId] : undefined,
4646
+ reason: cleanText(closeProjectReason) || `Roadmap item ${itemKey || implementationItemId} closed.`,
4647
+ operatorIdentity: normalizedActorId,
4648
+ runTerminalStatus: cleanText(terminalItemStatus) || 'accepted',
4649
+ });
4650
+ }
4651
+
4652
+ return {
4653
+ status: closeProjectResult ? 'closed' : 'item_closed',
4654
+ project_id: resolvedProjectId,
4655
+ workflow_id: resolvedWorkflowId,
4656
+ workflow_run_id: resolvedWorkflowRunId,
4657
+ claim_id: effectiveClaimId,
4658
+ claim_source: claimSource,
4659
+ continuation_brief: continuation,
4660
+ project: projectSummary,
4661
+ active_item_before: normalizedActiveItem,
4662
+ active_item_after: reloadedActiveItem,
4663
+ acceptance_checks: {
4664
+ loaded: acceptanceChecks,
4665
+ verified: verifiedAcceptanceChecks,
4666
+ },
4667
+ artifact_verification: artifacts,
4668
+ gate_decision: gateDecisionResult,
4669
+ implementation_item_status: itemStatusResult,
4670
+ closure_evidence: closureEvidence,
4671
+ claim_signoff: signedClaim,
4672
+ remaining_open_task_count: remainingOpenTasks.length,
4673
+ close_project: closeProjectResult,
4674
+ };
4675
+ }
4676
+
4398
4677
  // LOGA projections are governed runtime documents, not static reports.
4399
4678
 
4400
4679
  async getLogaOperatorHomeProjection() {