@mcoda/mswarm 0.1.89 → 0.1.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codali-executor.d.ts +107 -6
- package/dist/codali-executor.d.ts.map +1 -1
- package/dist/codali-executor.js +500 -26
- package/dist/codali-executor.js.map +1 -1
- package/dist/runtime.d.ts +6 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +18 -5
- package/dist/runtime.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +18 -3
- package/dist/server.js.map +1 -1
- package/dist/vendor/codali/cli/DatasetCommand.d.ts +38 -0
- package/dist/vendor/codali/cli/DatasetCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/DatasetCommand.js +959 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts +3 -0
- package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -1
- package/dist/vendor/codali/cli/EvalCommand.js +55 -1
- package/dist/vendor/codali/cli/ImprovementCommand.d.ts +97 -0
- package/dist/vendor/codali/cli/ImprovementCommand.d.ts.map +1 -0
- package/dist/vendor/codali/cli/ImprovementCommand.js +1879 -0
- package/dist/vendor/codali/cli.d.ts.map +1 -1
- package/dist/vendor/codali/cli.js +15 -0
- package/dist/vendor/codali/dataset-cli.d.ts +3 -0
- package/dist/vendor/codali/dataset-cli.d.ts.map +1 -0
- package/dist/vendor/codali/dataset-cli.js +30 -0
- package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts +90 -1
- package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts.map +1 -1
- package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.js +443 -9
- package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts +70 -0
- package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts.map +1 -0
- package/dist/vendor/codali/eval/GatewayDatasetEval.js +477 -0
- package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts +52 -0
- package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts.map +1 -1
- package/dist/vendor/codali/eval/GatewayEvalSuite.js +135 -1
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts +4 -0
- package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGateway.js +37 -1
- package/dist/vendor/codali/gateway/CodaliGatewaySchemas.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGatewaySchemas.js +0 -4
- package/dist/vendor/codali/gateway/CodaliGatewayStore.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/CodaliGatewayStore.js +1 -0
- package/dist/vendor/codali/gateway/GatewayPlanner.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GatewayPlanner.js +355 -41
- package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts +1 -0
- package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts.map +1 -1
- package/dist/vendor/codali/gateway/GatewayStateMachine.js +221 -5
- package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts +201 -0
- package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/CandidateReleaseBuilder.js +1175 -0
- package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts +75 -0
- package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/DatasetEligibilityGate.js +497 -0
- package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts +88 -0
- package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/DatasetExportManifestReader.js +333 -0
- package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts +192 -0
- package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.js +625 -0
- package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts +173 -0
- package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.js +363 -0
- package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts +281 -0
- package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/FineTuneJobPlanner.js +823 -0
- package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts +50 -0
- package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ImprovementEvalRunner.js +648 -0
- package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts +272 -0
- package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ImprovementPolicy.js +1450 -0
- package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts +186 -0
- package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.js +880 -0
- package/dist/vendor/codali/improvement/OperatorInspector.d.ts +182 -0
- package/dist/vendor/codali/improvement/OperatorInspector.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/OperatorInspector.js +604 -0
- package/dist/vendor/codali/improvement/ProductionGovernance.d.ts +91 -0
- package/dist/vendor/codali/improvement/ProductionGovernance.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ProductionGovernance.js +329 -0
- package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts +152 -0
- package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.js +480 -0
- package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts +113 -0
- package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/PublishOrchestrator.js +590 -0
- package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts +133 -0
- package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.js +501 -0
- package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts +71 -0
- package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts.map +1 -0
- package/dist/vendor/codali/improvement/StorageServiceImprovementClient.js +245 -0
- package/dist/vendor/codali/index.d.ts +43 -0
- package/dist/vendor/codali/index.d.ts.map +1 -1
- package/dist/vendor/codali/index.js +21 -0
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +0 -2
- package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CodaliRuntime.js +0 -5
- package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts +138 -0
- package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts.map +1 -0
- package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.js +417 -0
- package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts +50 -0
- package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts.map +1 -0
- package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.js +141 -0
- package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts +337 -0
- package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts.map +1 -0
- package/dist/vendor/codali/storage/CodaliStorageContracts.js +1555 -0
- package/dist/vendor/codali/storage/DatasetExportJob.d.ts +51 -0
- package/dist/vendor/codali/storage/DatasetExportJob.d.ts.map +1 -0
- package/dist/vendor/codali/storage/DatasetExportJob.js +358 -0
- package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts +98 -0
- package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts.map +1 -0
- package/dist/vendor/codali/storage/DatasetReviewQueue.js +426 -0
- package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts +233 -0
- package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts.map +1 -0
- package/dist/vendor/codali/storage/GatewayDatasetStore.js +2070 -0
- package/package.json +3 -3
|
@@ -0,0 +1,1879 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { CODALI_IMPROVEMENT_CONTRACT_SCHEMA_VERSION, CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS, DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS, buildCodaliImprovementCliJsonOutput, createCodaliImprovementPolicy, evaluateCodaliImprovementPolicy, validateCodaliImprovementCliJsonOutput, validateCodaliImprovementPolicy, } from "../improvement/ImprovementPolicy.js";
|
|
3
|
+
import { DEFAULT_CODALI_CANDIDATE_RELEASE_APPROVED_PATHS, buildCodaliCandidateRelease, buildCodaliCandidateReleasePlan, } from "../improvement/CandidateReleaseBuilder.js";
|
|
4
|
+
import { DEFAULT_CODALI_PUBLISH_NPM_REGISTRY, runCodaliPublishOrchestrator, writeCodaliPublishToStorageService, } from "../improvement/PublishOrchestrator.js";
|
|
5
|
+
import { CODALI_RELEASE_RUNTIME_PACKAGE_KINDS, runCodaliReleaseOutcomeReporter, writeCodaliReleaseOutcomeReportToStorageService, } from "../improvement/ReleaseOutcomeReporter.js";
|
|
6
|
+
import { buildCodaliImprovementEvalScorecard, } from "../improvement/ImprovementEvalRunner.js";
|
|
7
|
+
import { inspectDatasetExportManifestForImprovement, } from "../improvement/DatasetExportManifestReader.js";
|
|
8
|
+
import { formatCodaliReleaseOperatorInspectionText, inspectCodaliReleaseForOperators, } from "../improvement/OperatorInspector.js";
|
|
9
|
+
import { buildCodaliEvalReplayCandidateBundle, } from "../improvement/EvalReplayCandidateBuilder.js";
|
|
10
|
+
import { CODALI_PATCH_PROPOSAL_ARTIFACTS, buildCodaliPatchCandidateBundle, } from "../improvement/PromptSchemaToolMetadataCandidateBuilder.js";
|
|
11
|
+
import { CODALI_DOCDEX_RETRIEVAL_SOURCE_ARTIFACT_TYPES, buildCodaliDocdexRetrievalCandidateBundle, } from "../improvement/DocdexRetrievalCandidateBuilder.js";
|
|
12
|
+
import { CODALI_FINE_TUNE_PROPOSAL_ARTIFACT, buildCodaliFineTuneJobPlannerBundle, fineTuneArtifactTypesForRole, normalizeCodaliFineTuneWorkerRole, } from "../improvement/FineTuneJobPlanner.js";
|
|
13
|
+
import { CODALI_MODEL_ROUTER_PROPOSAL_ARTIFACT, CODALI_MODEL_ROUTER_SOURCE_ARTIFACT_TYPES, buildCodaliModelRouterCandidateBundle, } from "../improvement/ModelRouterCandidateBuilder.js";
|
|
14
|
+
import { StorageServiceImprovementClient, } from "../improvement/StorageServiceImprovementClient.js";
|
|
15
|
+
import { createCodaliProductionGovernanceImprovementOverrides, evaluateCodaliProductionGovernanceAction, resolveCodaliProductionGovernance, } from "../improvement/ProductionGovernance.js";
|
|
16
|
+
import { defaultCodaliGatewayLiveCommandRunner, parseCodaliGatewayLiveInventory, } from "../eval/CodaliGatewayLiveHarness.js";
|
|
17
|
+
export const IMPROVEMENT_EXIT_CODES = {
|
|
18
|
+
usage_error: 64,
|
|
19
|
+
validation_error: 65,
|
|
20
|
+
};
|
|
21
|
+
export class ImprovementCommandError extends Error {
|
|
22
|
+
constructor(message, exitCode = IMPROVEMENT_EXIT_CODES.usage_error) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "ImprovementCommandError";
|
|
25
|
+
this.exitCode = exitCode;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const HELP_TEXT = "Usage: codali improvement <policy|levels|inspect|propose|build-release|eval|publish|monitor> [options]\n" +
|
|
29
|
+
" or: codali improve inspect --export-id <id> --dry-run [options]\n" +
|
|
30
|
+
" or: codali improve inspect --release <release-id> --output json [options]\n" +
|
|
31
|
+
" or: codali improve propose --artifact <eval|prompt|schema|tool-metadata|docdex-retrieval|fine-tune|model-router> --export-id <id> --dry-run [options]\n" +
|
|
32
|
+
" or: codali improve build-release --candidate <id> --dry-run [options]\n" +
|
|
33
|
+
" or: codali improve eval --candidate <candidate-id> --output json [options]\n" +
|
|
34
|
+
" or: codali improve publish --candidate <candidate-id> --mode <branch_only|auto_tag> --dry-run [options]\n" +
|
|
35
|
+
" or: codali improve monitor --release <release-id> --output json [options]\n" +
|
|
36
|
+
"\n" +
|
|
37
|
+
"Commands:\n" +
|
|
38
|
+
" policy Build and validate an improvement policy contract.\n" +
|
|
39
|
+
" levels Print the explicit improvement release levels.\n" +
|
|
40
|
+
" inspect Verify a dataset export manifest or inspect release lineage for operators.\n" +
|
|
41
|
+
" propose Build deterministic improvement candidates from an export.\n" +
|
|
42
|
+
" build-release Build a guarded candidate branch workspace and release plan.\n" +
|
|
43
|
+
" eval Build release scorecards and security-gate approval decisions.\n" +
|
|
44
|
+
" publish Orchestrate branch-only or policy-gated auto-tag release publishing.\n" +
|
|
45
|
+
" monitor Report canary, shadow rollout, rollback, and runtime flag outcomes.\n" +
|
|
46
|
+
"\n" +
|
|
47
|
+
"Options:\n" +
|
|
48
|
+
" --output <text|json> Output mode (default: text).\n" +
|
|
49
|
+
" --level <0|1|2|3|4> Maximum release level (default: 0).\n" +
|
|
50
|
+
" --tenant-hash <hash> Tenant scope hash.\n" +
|
|
51
|
+
" --tenant-id <id> Storage-service tenant scope id.\n" +
|
|
52
|
+
" --product-id <id> Product scope id.\n" +
|
|
53
|
+
" --deployment-id <id> Optional deployment scope id.\n" +
|
|
54
|
+
" --run-id <id> Optional storage-service run scope id.\n" +
|
|
55
|
+
" --artifact-type <type> Allowed artifact type; can repeat.\n" +
|
|
56
|
+
" --max-examples <count> Maximum examples for a run.\n" +
|
|
57
|
+
" --max-object-bytes <bytes> Maximum artifact/object bytes.\n" +
|
|
58
|
+
" --storage-mode <mode> local_only|storage_service|hybrid.\n" +
|
|
59
|
+
" --artifact <type> Proposal artifact: eval|prompt|schema|tool-metadata|docdex-retrieval|fine-tune|model-router.\n" +
|
|
60
|
+
" --role <role> Fine-tune worker role (default: extractor).\n" +
|
|
61
|
+
" --export-id <id> Dataset export manifest id to inspect.\n" +
|
|
62
|
+
" --manifest <path> Dataset export manifest file path.\n" +
|
|
63
|
+
" --directory <path> Directory to search for export manifests or release artifacts.\n" +
|
|
64
|
+
" --repo-root <path> Repository root for candidate workspace checks.\n" +
|
|
65
|
+
" --candidate-date <yyyy-mm-dd> Candidate branch date (default: manifest date).\n" +
|
|
66
|
+
" --candidate-output <path> Candidate release artifact path.\n" +
|
|
67
|
+
" --candidate <id> Candidate id, manifest id, or candidate JSON path for eval.\n" +
|
|
68
|
+
" --candidate-path <path> Candidate JSON or manifest file path for eval.\n" +
|
|
69
|
+
" --mode <branch_only|auto_tag> Publish orchestration mode (default: branch_only).\n" +
|
|
70
|
+
" --commit-sha <sha> Candidate commit sha for publish status ingestion.\n" +
|
|
71
|
+
" --workflow-run-id <id> Ingest GitHub Actions release workflow run id.\n" +
|
|
72
|
+
" --workflow-status <status> Ingest GitHub Actions run status.\n" +
|
|
73
|
+
" --workflow-conclusion <c> Ingest GitHub Actions run conclusion.\n" +
|
|
74
|
+
" --workflow-url <url> Ingest GitHub Actions run URL.\n" +
|
|
75
|
+
" --poll-actions Poll GitHub Actions release workflow status with gh.\n" +
|
|
76
|
+
" --verify-npm Verify published versions with npm view.\n" +
|
|
77
|
+
" --npm-package <name> Package to verify with npm view; can repeat.\n" +
|
|
78
|
+
" --npm-version <name=version> Ingest observed npm version; can repeat.\n" +
|
|
79
|
+
" --npm-registry <url> npm registry for version verification.\n" +
|
|
80
|
+
" --release <id> Release id for post-release monitoring.\n" +
|
|
81
|
+
" --monitor-window-minutes <m> Monitor window duration (default: 60).\n" +
|
|
82
|
+
" --monitor-started-at <iso> Monitor window start timestamp.\n" +
|
|
83
|
+
" --monitor-ended-at <iso> Monitor window end timestamp.\n" +
|
|
84
|
+
" --prompt-package-version <v> Runtime prompt package version.\n" +
|
|
85
|
+
" --router-policy-version <v> Runtime router policy version.\n" +
|
|
86
|
+
" --retrieval-policy-version <v> Runtime retrieval policy version.\n" +
|
|
87
|
+
" --schema-version <v> Runtime schema package version.\n" +
|
|
88
|
+
" --fine-tune-adapter-version <v> Runtime fine-tune adapter version.\n" +
|
|
89
|
+
" --disable-runtime-package <k> Runtime package kind to disable; can repeat.\n" +
|
|
90
|
+
" --eligible-requests <n> Eligible request count for shadow monitoring.\n" +
|
|
91
|
+
" --shadow-requests <n> Shadow request count; shadow remains non-blocking.\n" +
|
|
92
|
+
" --schema-failures <n> Observed schema failure count.\n" +
|
|
93
|
+
" --accepted-answer-rate <r> Current accepted-answer rate from 0 to 1.\n" +
|
|
94
|
+
" --baseline-accepted-answer-rate <r> Baseline accepted-answer rate.\n" +
|
|
95
|
+
" --verifier-contradictions <n> Observed verifier contradiction count.\n" +
|
|
96
|
+
" --tool-failures <n> Observed tool failure count.\n" +
|
|
97
|
+
" --p95-latency-ms <n> Current p95 latency in milliseconds.\n" +
|
|
98
|
+
" --baseline-p95-latency-ms <n> Baseline p95 latency in milliseconds.\n" +
|
|
99
|
+
" --cost-usd <n> Current monitor-window cost.\n" +
|
|
100
|
+
" --baseline-cost-usd <n> Baseline monitor-window cost.\n" +
|
|
101
|
+
" --privacy-security-warnings <n> Observed privacy/security warning count.\n" +
|
|
102
|
+
" --rollback-applied Mark runtime-package rollback as applied.\n" +
|
|
103
|
+
" --approved-path <path> Approved write file/directory; can repeat.\n" +
|
|
104
|
+
" --inventory-json <json> Use a provided mcoda agent inventory JSON payload.\n" +
|
|
105
|
+
" --inventory-file <path> Use a provided mcoda agent inventory JSON file.\n" +
|
|
106
|
+
" --no-inventory-refresh Do not run mcoda agent list for fine-tune targets.\n" +
|
|
107
|
+
" --inventory-timeout-ms <ms> Timeout for mcoda agent inventory refresh.\n" +
|
|
108
|
+
" --example-artifact-type <t> Restrict curated examples by artifact type; can repeat.\n" +
|
|
109
|
+
" --revoked-deletion-group <id> Treat a deletion group as revoked during inspection.\n" +
|
|
110
|
+
" --dry-run Verify locally without storage-service writes.\n" +
|
|
111
|
+
" --no-dry-run, --write Send inspected runs/candidates to storage service.\n" +
|
|
112
|
+
" --storage-service-url <url> Storage service base URL for writes.\n" +
|
|
113
|
+
" --storage-service-token <tok> Storage service bearer token for writes.\n" +
|
|
114
|
+
" --hmac-secret <secret> Optional signing secret; defaults to service token.\n" +
|
|
115
|
+
" --enable-export Allow export actions.\n" +
|
|
116
|
+
" --enable-training Allow training actions.\n" +
|
|
117
|
+
" --auto-tag Allow automatic tag actions.\n" +
|
|
118
|
+
" --auto-publish Allow automatic publish actions.\n" +
|
|
119
|
+
" --check-action <action> Evaluate an action against the policy.\n" +
|
|
120
|
+
" --check-artifact-type <type> Evaluate an artifact type.\n" +
|
|
121
|
+
" --check-examples <count> Evaluate an example count.\n" +
|
|
122
|
+
" --check-object-bytes <bytes> Evaluate an object byte count.\n" +
|
|
123
|
+
" --help, -h Show help.\n";
|
|
124
|
+
const DEFAULT_TENANT_HASH = "local_tenant";
|
|
125
|
+
const DEFAULT_PRODUCT_ID = "local_product";
|
|
126
|
+
const DEFAULT_STORAGE_TENANT_ID = "local";
|
|
127
|
+
const DEFAULT_STORAGE_DEPLOYMENT_ID = "local";
|
|
128
|
+
const DEFAULT_FINE_TUNE_INVENTORY_TIMEOUT_MS = 120000;
|
|
129
|
+
const DEFAULT_FINE_TUNE_INVENTORY_MAX_BUFFER = 4 * 1024 * 1024;
|
|
130
|
+
export const parseImprovementArgs = (argv) => {
|
|
131
|
+
const parsed = {
|
|
132
|
+
command: "policy",
|
|
133
|
+
help: false,
|
|
134
|
+
output: "text",
|
|
135
|
+
releaseLevel: 0,
|
|
136
|
+
tenantHash: DEFAULT_TENANT_HASH,
|
|
137
|
+
productId: DEFAULT_PRODUCT_ID,
|
|
138
|
+
dryRun: true,
|
|
139
|
+
inventoryRefresh: true,
|
|
140
|
+
inventoryTimeoutMs: DEFAULT_FINE_TUNE_INVENTORY_TIMEOUT_MS,
|
|
141
|
+
artifactTypes: [...DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.allowedArtifactTypes],
|
|
142
|
+
exampleArtifactTypes: [],
|
|
143
|
+
revokedDeletionGroupIds: [],
|
|
144
|
+
approvedWritePaths: [],
|
|
145
|
+
publishMode: "branch_only",
|
|
146
|
+
pollActions: false,
|
|
147
|
+
npmRegistry: DEFAULT_CODALI_PUBLISH_NPM_REGISTRY,
|
|
148
|
+
npmPackages: [],
|
|
149
|
+
npmVersionResults: [],
|
|
150
|
+
monitorWindowMinutes: 60,
|
|
151
|
+
monitorThresholds: {},
|
|
152
|
+
monitorMetrics: {},
|
|
153
|
+
runtimeVersions: {},
|
|
154
|
+
disabledRuntimePackages: [],
|
|
155
|
+
rollbackApplied: false,
|
|
156
|
+
published: false,
|
|
157
|
+
tagged: false,
|
|
158
|
+
trainingUsed: false,
|
|
159
|
+
exportUsed: false,
|
|
160
|
+
maxExamples: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.maxExamples,
|
|
161
|
+
maxObjectBytes: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.maxObjectBytes,
|
|
162
|
+
storageMode: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.storageMode,
|
|
163
|
+
exportEnabled: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.exportEnabled,
|
|
164
|
+
trainingEnabled: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.trainingEnabled,
|
|
165
|
+
autoTagEnabled: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.autoTagEnabled,
|
|
166
|
+
autoPublishEnabled: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.autoPublishEnabled,
|
|
167
|
+
productionGovernance: resolveCodaliProductionGovernance(),
|
|
168
|
+
};
|
|
169
|
+
const args = [...argv];
|
|
170
|
+
const first = args[0];
|
|
171
|
+
if (first === "policy" ||
|
|
172
|
+
first === "levels" ||
|
|
173
|
+
first === "inspect" ||
|
|
174
|
+
first === "propose" ||
|
|
175
|
+
first === "build-release" ||
|
|
176
|
+
first === "eval" ||
|
|
177
|
+
first === "publish" ||
|
|
178
|
+
first === "monitor") {
|
|
179
|
+
parsed.command = first;
|
|
180
|
+
args.shift();
|
|
181
|
+
}
|
|
182
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
183
|
+
const arg = args[index];
|
|
184
|
+
const next = args[index + 1];
|
|
185
|
+
if (arg === "--help" || arg === "-h") {
|
|
186
|
+
parsed.help = true;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (arg === "--output" && next) {
|
|
190
|
+
if (next !== "text" && next !== "json") {
|
|
191
|
+
throw new ImprovementCommandError("Invalid --output value. Expected text|json.");
|
|
192
|
+
}
|
|
193
|
+
parsed.output = next;
|
|
194
|
+
index += 1;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (arg === "--level" && next) {
|
|
198
|
+
parsed.releaseLevel = parseReleaseLevel(next, "--level");
|
|
199
|
+
parsed.artifactTypes = [
|
|
200
|
+
...CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS[parsed.releaseLevel]
|
|
201
|
+
.allowedArtifactTypes,
|
|
202
|
+
];
|
|
203
|
+
index += 1;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (arg === "--tenant-hash" && next) {
|
|
207
|
+
parsed.tenantHash = next;
|
|
208
|
+
index += 1;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if ((arg === "--tenant-id" || arg === "--tenant") && next) {
|
|
212
|
+
parsed.tenantId = next;
|
|
213
|
+
index += 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (arg === "--product-id" && next) {
|
|
217
|
+
parsed.productId = next;
|
|
218
|
+
index += 1;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (arg === "--deployment-id" && next) {
|
|
222
|
+
parsed.deploymentId = next;
|
|
223
|
+
index += 1;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (arg === "--run-id" && next) {
|
|
227
|
+
parsed.runId = next;
|
|
228
|
+
index += 1;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (arg === "--export-id" && next) {
|
|
232
|
+
parsed.exportId = next;
|
|
233
|
+
index += 1;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if ((arg === "--candidate" || arg === "--candidate-id") && next) {
|
|
237
|
+
parsed.candidateId = next;
|
|
238
|
+
index += 1;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if ((arg === "--candidate-path" || arg === "--candidate-file") && next) {
|
|
242
|
+
parsed.candidatePath = next;
|
|
243
|
+
index += 1;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (arg === "--artifact" && next) {
|
|
247
|
+
parsed.proposalArtifact = parseProposalArtifact(next, "--artifact");
|
|
248
|
+
index += 1;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (arg === "--role" && next) {
|
|
252
|
+
parsed.role = parseFineTuneRole(next, "--role");
|
|
253
|
+
index += 1;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (arg === "--inventory-json" && next) {
|
|
257
|
+
parsed.inventoryJson = next;
|
|
258
|
+
index += 1;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if ((arg === "--inventory-file" || arg === "--inventory") && next) {
|
|
262
|
+
parsed.inventoryPath = next;
|
|
263
|
+
index += 1;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (arg === "--no-inventory-refresh") {
|
|
267
|
+
parsed.inventoryRefresh = false;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (arg === "--inventory-timeout-ms" && next) {
|
|
271
|
+
parsed.inventoryTimeoutMs = parsePositiveInteger(next, "--inventory-timeout-ms");
|
|
272
|
+
index += 1;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if ((arg === "--manifest" || arg === "--manifest-path") && next) {
|
|
276
|
+
parsed.manifestPath = next;
|
|
277
|
+
index += 1;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (arg === "--directory" && next) {
|
|
281
|
+
parsed.directory = next;
|
|
282
|
+
index += 1;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (arg === "--repo-root" && next) {
|
|
286
|
+
parsed.repoRoot = next;
|
|
287
|
+
index += 1;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (arg === "--candidate-date" && next) {
|
|
291
|
+
parsed.candidateDate = next;
|
|
292
|
+
index += 1;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if ((arg === "--candidate-output" || arg === "--candidate-output-path") && next) {
|
|
296
|
+
parsed.candidateOutputPath = next;
|
|
297
|
+
index += 1;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (arg === "--mode" && next) {
|
|
301
|
+
parsed.publishMode = parsePublishMode(next, "--mode");
|
|
302
|
+
index += 1;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (arg === "--commit-sha" && next) {
|
|
306
|
+
parsed.commitSha = next;
|
|
307
|
+
index += 1;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (arg === "--workflow-run-id" && next) {
|
|
311
|
+
parsed.workflowRunId = next;
|
|
312
|
+
index += 1;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (arg === "--workflow-status" && next) {
|
|
316
|
+
parsed.workflowStatus = parseWorkflowStatus(next, "--workflow-status");
|
|
317
|
+
index += 1;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (arg === "--workflow-conclusion" && next) {
|
|
321
|
+
parsed.workflowConclusion = parseWorkflowConclusion(next, "--workflow-conclusion");
|
|
322
|
+
index += 1;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (arg === "--workflow-url" && next) {
|
|
326
|
+
parsed.workflowUrl = next;
|
|
327
|
+
index += 1;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (arg === "--poll-actions") {
|
|
331
|
+
parsed.pollActions = true;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (arg === "--verify-npm") {
|
|
335
|
+
parsed.verifyNpm = true;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (arg === "--no-npm-verify") {
|
|
339
|
+
parsed.verifyNpm = false;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (arg === "--npm-registry" && next) {
|
|
343
|
+
parsed.npmRegistry = next;
|
|
344
|
+
index += 1;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (arg === "--npm-package" && next) {
|
|
348
|
+
parsed.npmPackages.push(next);
|
|
349
|
+
index += 1;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (arg === "--npm-version" && next) {
|
|
353
|
+
parsed.npmVersionResults.push(parseNpmVersionResult(next, "--npm-version"));
|
|
354
|
+
index += 1;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if ((arg === "--release" || arg === "--release-id") && next) {
|
|
358
|
+
parsed.releaseId = next;
|
|
359
|
+
index += 1;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (arg === "--monitor-window-minutes" && next) {
|
|
363
|
+
parsed.monitorWindowMinutes = parsePositiveInteger(next, "--monitor-window-minutes");
|
|
364
|
+
index += 1;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (arg === "--monitor-started-at" && next) {
|
|
368
|
+
parsed.monitorWindowStartedAt = parseIsoTimestamp(next, "--monitor-started-at");
|
|
369
|
+
index += 1;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (arg === "--monitor-ended-at" && next) {
|
|
373
|
+
parsed.monitorWindowEndedAt = parseIsoTimestamp(next, "--monitor-ended-at");
|
|
374
|
+
index += 1;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (arg === "--prompt-package-version" && next) {
|
|
378
|
+
parsed.runtimeVersions.prompt_package = next;
|
|
379
|
+
index += 1;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (arg === "--router-policy-version" && next) {
|
|
383
|
+
parsed.runtimeVersions.router_policy = next;
|
|
384
|
+
index += 1;
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (arg === "--retrieval-policy-version" && next) {
|
|
388
|
+
parsed.runtimeVersions.retrieval_policy = next;
|
|
389
|
+
index += 1;
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
if (arg === "--schema-version" && next) {
|
|
393
|
+
parsed.runtimeVersions.schema = next;
|
|
394
|
+
index += 1;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (arg === "--fine-tune-adapter-version" && next) {
|
|
398
|
+
parsed.runtimeVersions.fine_tune_adapter = next;
|
|
399
|
+
index += 1;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (arg === "--disable-runtime-package" && next) {
|
|
403
|
+
const packageKind = parseRuntimePackageKind(next, "--disable-runtime-package");
|
|
404
|
+
if (!parsed.disabledRuntimePackages.includes(packageKind)) {
|
|
405
|
+
parsed.disabledRuntimePackages.push(packageKind);
|
|
406
|
+
}
|
|
407
|
+
index += 1;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (arg === "--eligible-requests" && next) {
|
|
411
|
+
parsed.monitorMetrics.eligibleRequestCount =
|
|
412
|
+
parseNonNegativeInteger(next, "--eligible-requests");
|
|
413
|
+
index += 1;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (arg === "--shadow-requests" && next) {
|
|
417
|
+
parsed.monitorMetrics.shadowRequestCount =
|
|
418
|
+
parseNonNegativeInteger(next, "--shadow-requests");
|
|
419
|
+
index += 1;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (arg === "--schema-failures" && next) {
|
|
423
|
+
parsed.monitorMetrics.schemaFailures =
|
|
424
|
+
parseNonNegativeInteger(next, "--schema-failures");
|
|
425
|
+
index += 1;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (arg === "--accepted-answer-rate" && next) {
|
|
429
|
+
parsed.monitorMetrics.acceptedAnswerRate = parseRate(next, "--accepted-answer-rate");
|
|
430
|
+
index += 1;
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (arg === "--baseline-accepted-answer-rate" && next) {
|
|
434
|
+
parsed.monitorMetrics.baselineAcceptedAnswerRate =
|
|
435
|
+
parseRate(next, "--baseline-accepted-answer-rate");
|
|
436
|
+
index += 1;
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (arg === "--verifier-contradictions" && next) {
|
|
440
|
+
parsed.monitorMetrics.verifierContradictions =
|
|
441
|
+
parseNonNegativeInteger(next, "--verifier-contradictions");
|
|
442
|
+
index += 1;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (arg === "--tool-failures" && next) {
|
|
446
|
+
parsed.monitorMetrics.toolFailures = parseNonNegativeInteger(next, "--tool-failures");
|
|
447
|
+
index += 1;
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (arg === "--p95-latency-ms" && next) {
|
|
451
|
+
parsed.monitorMetrics.p95LatencyMs =
|
|
452
|
+
parseNonNegativeNumber(next, "--p95-latency-ms");
|
|
453
|
+
index += 1;
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (arg === "--baseline-p95-latency-ms" && next) {
|
|
457
|
+
parsed.monitorMetrics.baselineP95LatencyMs =
|
|
458
|
+
parseNonNegativeNumber(next, "--baseline-p95-latency-ms");
|
|
459
|
+
index += 1;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (arg === "--cost-usd" && next) {
|
|
463
|
+
parsed.monitorMetrics.costUsd = parseNonNegativeNumber(next, "--cost-usd");
|
|
464
|
+
index += 1;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (arg === "--baseline-cost-usd" && next) {
|
|
468
|
+
parsed.monitorMetrics.baselineCostUsd =
|
|
469
|
+
parseNonNegativeNumber(next, "--baseline-cost-usd");
|
|
470
|
+
index += 1;
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (arg === "--privacy-security-warnings" && next) {
|
|
474
|
+
parsed.monitorMetrics.privacySecurityWarnings =
|
|
475
|
+
parseNonNegativeInteger(next, "--privacy-security-warnings");
|
|
476
|
+
index += 1;
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
if (arg === "--threshold-schema-failures" && next) {
|
|
480
|
+
parsed.monitorThresholds.maxSchemaFailures =
|
|
481
|
+
parseNonNegativeInteger(next, "--threshold-schema-failures");
|
|
482
|
+
index += 1;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (arg === "--min-accepted-answer-rate" && next) {
|
|
486
|
+
parsed.monitorThresholds.minAcceptedAnswerRate =
|
|
487
|
+
parseRate(next, "--min-accepted-answer-rate");
|
|
488
|
+
index += 1;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (arg === "--threshold-accepted-answer-rate-drop" && next) {
|
|
492
|
+
parsed.monitorThresholds.maxAcceptedAnswerRateDrop =
|
|
493
|
+
parseRate(next, "--threshold-accepted-answer-rate-drop");
|
|
494
|
+
index += 1;
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
if (arg === "--threshold-verifier-contradictions" && next) {
|
|
498
|
+
parsed.monitorThresholds.maxVerifierContradictions =
|
|
499
|
+
parseNonNegativeInteger(next, "--threshold-verifier-contradictions");
|
|
500
|
+
index += 1;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (arg === "--threshold-tool-failures" && next) {
|
|
504
|
+
parsed.monitorThresholds.maxToolFailures =
|
|
505
|
+
parseNonNegativeInteger(next, "--threshold-tool-failures");
|
|
506
|
+
index += 1;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (arg === "--threshold-latency-increase-ratio" && next) {
|
|
510
|
+
parsed.monitorThresholds.maxP95LatencyIncreaseRatio =
|
|
511
|
+
parseNonNegativeNumber(next, "--threshold-latency-increase-ratio");
|
|
512
|
+
index += 1;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (arg === "--threshold-cost-increase-ratio" && next) {
|
|
516
|
+
parsed.monitorThresholds.maxCostIncreaseRatio =
|
|
517
|
+
parseNonNegativeNumber(next, "--threshold-cost-increase-ratio");
|
|
518
|
+
index += 1;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (arg === "--threshold-privacy-security-warnings" && next) {
|
|
522
|
+
parsed.monitorThresholds.maxPrivacySecurityWarnings =
|
|
523
|
+
parseNonNegativeInteger(next, "--threshold-privacy-security-warnings");
|
|
524
|
+
index += 1;
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (arg === "--rollback-applied") {
|
|
528
|
+
parsed.rollbackApplied = true;
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (arg === "--published") {
|
|
532
|
+
parsed.published = true;
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
if (arg === "--tagged") {
|
|
536
|
+
parsed.tagged = true;
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (arg === "--training-used") {
|
|
540
|
+
parsed.trainingUsed = true;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (arg === "--export-used") {
|
|
544
|
+
parsed.exportUsed = true;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
if ((arg === "--approved-path" || arg === "--allow-write-path") && next) {
|
|
548
|
+
parsed.approvedWritePaths.push(next);
|
|
549
|
+
index += 1;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (arg === "--example-artifact-type" && next) {
|
|
553
|
+
parsed.exampleArtifactTypes.push(next);
|
|
554
|
+
index += 1;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (arg === "--revoked-deletion-group" && next) {
|
|
558
|
+
parsed.revokedDeletionGroupIds.push(next);
|
|
559
|
+
index += 1;
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
if (arg === "--dry-run") {
|
|
563
|
+
parsed.dryRun = true;
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
if (arg === "--no-dry-run" || arg === "--write") {
|
|
567
|
+
parsed.dryRun = false;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
if ((arg === "--storage-service-url" || arg === "--service-url") && next) {
|
|
571
|
+
parsed.storageServiceUrl = next;
|
|
572
|
+
index += 1;
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if ((arg === "--storage-service-token" || arg === "--service-token") && next) {
|
|
576
|
+
parsed.storageServiceToken = next;
|
|
577
|
+
index += 1;
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
if (arg === "--hmac-secret" && next) {
|
|
581
|
+
parsed.hmacSecret = next;
|
|
582
|
+
index += 1;
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (arg === "--artifact-type" && next) {
|
|
586
|
+
const artifactType = parseArtifactType(next, "--artifact-type");
|
|
587
|
+
if (!parsed.artifactTypes.includes(artifactType)) {
|
|
588
|
+
parsed.artifactTypes.push(artifactType);
|
|
589
|
+
}
|
|
590
|
+
index += 1;
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
if (arg === "--max-examples" && next) {
|
|
594
|
+
parsed.maxExamples = parseNonNegativeInteger(next, "--max-examples");
|
|
595
|
+
index += 1;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (arg === "--max-object-bytes" && next) {
|
|
599
|
+
parsed.maxObjectBytes = parsePositiveInteger(next, "--max-object-bytes");
|
|
600
|
+
index += 1;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (arg === "--storage-mode" && next) {
|
|
604
|
+
parsed.storageMode = parseStorageMode(next, "--storage-mode");
|
|
605
|
+
index += 1;
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
if (arg === "--enable-export") {
|
|
609
|
+
parsed.exportEnabled = true;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (arg === "--enable-training") {
|
|
613
|
+
parsed.trainingEnabled = true;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (arg === "--auto-tag") {
|
|
617
|
+
parsed.autoTagEnabled = true;
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
if (arg === "--auto-publish") {
|
|
621
|
+
parsed.autoPublishEnabled = true;
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
if (arg === "--check-action" && next) {
|
|
625
|
+
parsed.checkAction = parseAction(next, "--check-action");
|
|
626
|
+
index += 1;
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (arg === "--check-artifact-type" && next) {
|
|
630
|
+
parsed.checkArtifactType = parseArtifactType(next, "--check-artifact-type");
|
|
631
|
+
index += 1;
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (arg === "--check-examples" && next) {
|
|
635
|
+
parsed.checkExamples = parseNonNegativeInteger(next, "--check-examples");
|
|
636
|
+
index += 1;
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
if (arg === "--check-object-bytes" && next) {
|
|
640
|
+
parsed.checkObjectBytes = parseNonNegativeInteger(next, "--check-object-bytes");
|
|
641
|
+
index += 1;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
throw new ImprovementCommandError(`Unknown improvement option: ${arg ?? ""}`);
|
|
645
|
+
}
|
|
646
|
+
parsed.productionGovernance = resolveCodaliProductionGovernance({
|
|
647
|
+
releaseLevel: parsed.releaseLevel,
|
|
648
|
+
});
|
|
649
|
+
const governanceOverrides = createCodaliProductionGovernanceImprovementOverrides(parsed.productionGovernance);
|
|
650
|
+
if (governanceOverrides.storageMode) {
|
|
651
|
+
parsed.storageMode = governanceOverrides.storageMode;
|
|
652
|
+
}
|
|
653
|
+
if (governanceOverrides.exportEnabled !== undefined) {
|
|
654
|
+
parsed.exportEnabled = governanceOverrides.exportEnabled;
|
|
655
|
+
}
|
|
656
|
+
if (governanceOverrides.trainingEnabled !== undefined) {
|
|
657
|
+
parsed.trainingEnabled = governanceOverrides.trainingEnabled;
|
|
658
|
+
}
|
|
659
|
+
if (governanceOverrides.autoTagEnabled !== undefined) {
|
|
660
|
+
parsed.autoTagEnabled = governanceOverrides.autoTagEnabled;
|
|
661
|
+
}
|
|
662
|
+
if (governanceOverrides.autoPublishEnabled !== undefined) {
|
|
663
|
+
parsed.autoPublishEnabled = governanceOverrides.autoPublishEnabled;
|
|
664
|
+
}
|
|
665
|
+
if (governanceOverrides.dryRun) {
|
|
666
|
+
parsed.dryRun = true;
|
|
667
|
+
}
|
|
668
|
+
return parsed;
|
|
669
|
+
};
|
|
670
|
+
export class ImprovementCommand {
|
|
671
|
+
static async run(argv) {
|
|
672
|
+
const parsed = parseImprovementArgs(argv);
|
|
673
|
+
if (parsed.help) {
|
|
674
|
+
// eslint-disable-next-line no-console
|
|
675
|
+
console.log(HELP_TEXT);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (parsed.command === "inspect") {
|
|
679
|
+
await runInspect(parsed);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
if (parsed.command === "propose") {
|
|
683
|
+
await runPropose(parsed);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
if (parsed.command === "build-release") {
|
|
687
|
+
await runBuildRelease(parsed);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (parsed.command === "eval") {
|
|
691
|
+
await runEval(parsed);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
if (parsed.command === "publish") {
|
|
695
|
+
await runPublish(parsed);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (parsed.command === "monitor") {
|
|
699
|
+
await runMonitor(parsed);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (parsed.command === "levels") {
|
|
703
|
+
const data = Object.values(CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS);
|
|
704
|
+
// eslint-disable-next-line no-console
|
|
705
|
+
console.log(parsed.output === "json"
|
|
706
|
+
? JSON.stringify(buildCodaliImprovementCliJsonOutput({
|
|
707
|
+
outputType: "improvement.release_levels",
|
|
708
|
+
status: "ok",
|
|
709
|
+
data,
|
|
710
|
+
}), null, 2)
|
|
711
|
+
: data
|
|
712
|
+
.map((level) => `level ${level.level}: ${level.description}`)
|
|
713
|
+
.join("\n"));
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const scope = parsed.deploymentId
|
|
717
|
+
? {
|
|
718
|
+
tenantHash: parsed.tenantHash,
|
|
719
|
+
productId: parsed.productId,
|
|
720
|
+
deploymentId: parsed.deploymentId,
|
|
721
|
+
}
|
|
722
|
+
: {
|
|
723
|
+
tenantHash: parsed.tenantHash,
|
|
724
|
+
productId: parsed.productId,
|
|
725
|
+
};
|
|
726
|
+
const policy = createCodaliImprovementPolicy({
|
|
727
|
+
policyId: `policy-level-${parsed.releaseLevel}`,
|
|
728
|
+
releaseLevel: parsed.releaseLevel,
|
|
729
|
+
scope,
|
|
730
|
+
allowedArtifactTypes: parsed.artifactTypes,
|
|
731
|
+
maxExamples: parsed.maxExamples,
|
|
732
|
+
maxObjectBytes: parsed.maxObjectBytes,
|
|
733
|
+
storageMode: parsed.storageMode,
|
|
734
|
+
exportEnabled: parsed.exportEnabled,
|
|
735
|
+
trainingEnabled: parsed.trainingEnabled,
|
|
736
|
+
autoTagEnabled: parsed.autoTagEnabled,
|
|
737
|
+
autoPublishEnabled: parsed.autoPublishEnabled,
|
|
738
|
+
metadata: {
|
|
739
|
+
source: "codali improvement policy cli",
|
|
740
|
+
productionGovernance: parsed.productionGovernance,
|
|
741
|
+
},
|
|
742
|
+
});
|
|
743
|
+
const validation = validateCodaliImprovementPolicy(policy);
|
|
744
|
+
const decision = parsed.checkAction
|
|
745
|
+
? evaluateCodaliImprovementPolicy(policy, {
|
|
746
|
+
action: parsed.checkAction,
|
|
747
|
+
scope: policy.scope,
|
|
748
|
+
releaseLevel: parsed.releaseLevel,
|
|
749
|
+
artifactType: parsed.checkArtifactType,
|
|
750
|
+
exampleCount: parsed.checkExamples,
|
|
751
|
+
objectBytes: parsed.checkObjectBytes,
|
|
752
|
+
})
|
|
753
|
+
: undefined;
|
|
754
|
+
const status = !validation.ok
|
|
755
|
+
? "error"
|
|
756
|
+
: decision && !decision.allowed
|
|
757
|
+
? "blocked"
|
|
758
|
+
: "ok";
|
|
759
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
760
|
+
outputType: decision ? "improvement.policy_decision" : "improvement.policy",
|
|
761
|
+
status,
|
|
762
|
+
policy,
|
|
763
|
+
decision,
|
|
764
|
+
issues: validation.ok ? [] : validation.issues,
|
|
765
|
+
});
|
|
766
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
767
|
+
if (parsed.output === "json") {
|
|
768
|
+
// eslint-disable-next-line no-console
|
|
769
|
+
console.log(JSON.stringify(output, null, 2));
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
// eslint-disable-next-line no-console
|
|
773
|
+
console.log(formatPolicyText(output));
|
|
774
|
+
}
|
|
775
|
+
if (!validation.ok || !outputValidation.ok) {
|
|
776
|
+
throw new ImprovementCommandError("Improvement policy JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
const storageScopeFromParsed = (parsed, inspection) => ({
|
|
781
|
+
tenantId: parsed.tenantId ?? DEFAULT_STORAGE_TENANT_ID,
|
|
782
|
+
productId: parsed.productId,
|
|
783
|
+
deploymentId: parsed.deploymentId ?? DEFAULT_STORAGE_DEPLOYMENT_ID,
|
|
784
|
+
runId: parsed.runId ?? `improvement-inspect-${inspection.manifest.manifestId}`,
|
|
785
|
+
});
|
|
786
|
+
const isRecord = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
787
|
+
const storageScopeFromEval = (parsed, result) => {
|
|
788
|
+
const releaseScope = isRecord(result.storagePayload.releaseScope)
|
|
789
|
+
? result.storagePayload.releaseScope
|
|
790
|
+
: {};
|
|
791
|
+
const releaseTenantHash = typeof releaseScope.tenantHash === "string"
|
|
792
|
+
? releaseScope.tenantHash
|
|
793
|
+
: undefined;
|
|
794
|
+
const releaseProductId = typeof releaseScope.productId === "string"
|
|
795
|
+
? releaseScope.productId
|
|
796
|
+
: undefined;
|
|
797
|
+
const releaseDeploymentId = typeof releaseScope.deploymentId === "string"
|
|
798
|
+
? releaseScope.deploymentId
|
|
799
|
+
: undefined;
|
|
800
|
+
return {
|
|
801
|
+
tenantId: parsed.tenantId ?? releaseTenantHash ?? DEFAULT_STORAGE_TENANT_ID,
|
|
802
|
+
productId: parsed.productId === DEFAULT_PRODUCT_ID && releaseProductId
|
|
803
|
+
? releaseProductId
|
|
804
|
+
: parsed.productId,
|
|
805
|
+
deploymentId: parsed.deploymentId ?? releaseDeploymentId ?? DEFAULT_STORAGE_DEPLOYMENT_ID,
|
|
806
|
+
runId: parsed.runId ?? `improvement-eval-${result.candidateId}`,
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
const storageScopeFromPublish = (parsed, result) => ({
|
|
810
|
+
tenantId: parsed.tenantId ?? result.outcome.scope.tenantHash ?? DEFAULT_STORAGE_TENANT_ID,
|
|
811
|
+
productId: parsed.productId === DEFAULT_PRODUCT_ID && result.outcome.scope.productId
|
|
812
|
+
? result.outcome.scope.productId
|
|
813
|
+
: parsed.productId,
|
|
814
|
+
deploymentId: parsed.deploymentId ?? result.outcome.scope.deploymentId ?? DEFAULT_STORAGE_DEPLOYMENT_ID,
|
|
815
|
+
runId: parsed.runId ?? `improvement-publish-${result.candidateId}`,
|
|
816
|
+
});
|
|
817
|
+
const storageScopeFromMonitor = (parsed, report) => ({
|
|
818
|
+
tenantId: parsed.tenantId ?? report.outcome.scope.tenantHash ?? DEFAULT_STORAGE_TENANT_ID,
|
|
819
|
+
productId: parsed.productId === DEFAULT_PRODUCT_ID && report.outcome.scope.productId
|
|
820
|
+
? report.outcome.scope.productId
|
|
821
|
+
: parsed.productId,
|
|
822
|
+
deploymentId: parsed.deploymentId ?? report.outcome.scope.deploymentId ?? DEFAULT_STORAGE_DEPLOYMENT_ID,
|
|
823
|
+
runId: parsed.runId ?? `improvement-monitor-${report.releaseId}`,
|
|
824
|
+
});
|
|
825
|
+
const hasHardEvalBlocks = (result) => result.releaseApproval.failedHardGateIds.length > 0 ||
|
|
826
|
+
result.releaseApproval.skippedHardGateIds.length > 0;
|
|
827
|
+
const assertProductionGovernanceAllows = (parsed, action) => {
|
|
828
|
+
const decision = evaluateCodaliProductionGovernanceAction(parsed.productionGovernance, action);
|
|
829
|
+
if (!decision.allowed) {
|
|
830
|
+
throw new ImprovementCommandError(`Production governance blocked ${action}: ${decision.reasons.join(", ")}.`);
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
const buildEvalOutputScorecard = (result, storageWrites) => ({
|
|
834
|
+
...result.scorecard,
|
|
835
|
+
metadata: {
|
|
836
|
+
...(result.scorecard.metadata ?? {}),
|
|
837
|
+
storageWrites: storageWrites.map((write) => ({
|
|
838
|
+
accepted: write.accepted,
|
|
839
|
+
status: write.status,
|
|
840
|
+
scope: write.scope,
|
|
841
|
+
})),
|
|
842
|
+
},
|
|
843
|
+
});
|
|
844
|
+
const buildInspectData = (parsed, inspection, storageWrites) => ({
|
|
845
|
+
dryRun: parsed.dryRun,
|
|
846
|
+
exportId: inspection.exportId,
|
|
847
|
+
manifest: {
|
|
848
|
+
manifestId: inspection.manifest.manifestId,
|
|
849
|
+
manifestPath: inspection.manifestPath,
|
|
850
|
+
exportKind: inspection.manifest.exportKind,
|
|
851
|
+
exportFormat: inspection.manifest.exportFormat,
|
|
852
|
+
recordCount: inspection.manifest.recordCount,
|
|
853
|
+
checksum: inspection.manifest.checksum,
|
|
854
|
+
createdAt: inspection.manifest.createdAt,
|
|
855
|
+
},
|
|
856
|
+
primaryArtifact: inspection.primaryArtifact
|
|
857
|
+
? {
|
|
858
|
+
refId: inspection.primaryArtifact.ref.refId,
|
|
859
|
+
path: inspection.primaryArtifact.path,
|
|
860
|
+
contentHash: inspection.primaryArtifact.contentHash,
|
|
861
|
+
byteSize: inspection.primaryArtifact.byteSize,
|
|
862
|
+
payloadSummary: inspection.primaryArtifact.payloadSummary,
|
|
863
|
+
}
|
|
864
|
+
: undefined,
|
|
865
|
+
provenance: inspection.provenance,
|
|
866
|
+
candidates: inspection.candidates,
|
|
867
|
+
warnings: inspection.warnings,
|
|
868
|
+
curationReport: inspection.curationReport,
|
|
869
|
+
storageWrites: storageWrites.map((write) => ({
|
|
870
|
+
accepted: write.accepted,
|
|
871
|
+
status: write.status,
|
|
872
|
+
scope: write.scope,
|
|
873
|
+
})),
|
|
874
|
+
});
|
|
875
|
+
const proposalArtifactTypesFor = (artifact, role = "extractor") => {
|
|
876
|
+
if (artifact === "eval")
|
|
877
|
+
return ["eval", "eval_replay", "replay"];
|
|
878
|
+
if (artifact === "prompt")
|
|
879
|
+
return ["prompt", "prompt_patch", "prompt_regression"];
|
|
880
|
+
if (artifact === "schema")
|
|
881
|
+
return ["schema", "schema_patch"];
|
|
882
|
+
if (artifact === "tool-metadata") {
|
|
883
|
+
return ["tool_metadata", "tool_metadata_patch", "tool_contract"];
|
|
884
|
+
}
|
|
885
|
+
if (artifact === "docdex-retrieval") {
|
|
886
|
+
return [...CODALI_DOCDEX_RETRIEVAL_SOURCE_ARTIFACT_TYPES];
|
|
887
|
+
}
|
|
888
|
+
if (artifact === CODALI_MODEL_ROUTER_PROPOSAL_ARTIFACT) {
|
|
889
|
+
return [...CODALI_MODEL_ROUTER_SOURCE_ARTIFACT_TYPES];
|
|
890
|
+
}
|
|
891
|
+
if (artifact === CODALI_FINE_TUNE_PROPOSAL_ARTIFACT) {
|
|
892
|
+
return fineTuneArtifactTypesForRole(role);
|
|
893
|
+
}
|
|
894
|
+
return [artifact];
|
|
895
|
+
};
|
|
896
|
+
const buildProposeData = (parsed, proposal) => ({
|
|
897
|
+
dryRun: parsed.dryRun,
|
|
898
|
+
artifact: proposal.artifact,
|
|
899
|
+
exportId: proposal.source.exportId,
|
|
900
|
+
manifestId: proposal.source.manifestId,
|
|
901
|
+
proposal,
|
|
902
|
+
});
|
|
903
|
+
const improvementScopeFromParsed = (parsed) => parsed.deploymentId
|
|
904
|
+
? {
|
|
905
|
+
tenantHash: parsed.tenantHash,
|
|
906
|
+
productId: parsed.productId,
|
|
907
|
+
deploymentId: parsed.deploymentId,
|
|
908
|
+
}
|
|
909
|
+
: {
|
|
910
|
+
tenantHash: parsed.tenantHash,
|
|
911
|
+
productId: parsed.productId,
|
|
912
|
+
};
|
|
913
|
+
const isPatchProposalArtifact = (artifact) => artifact === "prompt" || artifact === "schema" || artifact === "tool-metadata";
|
|
914
|
+
const runInspect = async (parsed) => {
|
|
915
|
+
if (parsed.releaseId) {
|
|
916
|
+
const inspection = await inspectCodaliReleaseForOperators({
|
|
917
|
+
releaseId: parsed.releaseId,
|
|
918
|
+
directory: parsed.directory,
|
|
919
|
+
});
|
|
920
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
921
|
+
outputType: "improvement.inspect",
|
|
922
|
+
status: "ok",
|
|
923
|
+
data: inspection,
|
|
924
|
+
});
|
|
925
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
926
|
+
if (!outputValidation.ok) {
|
|
927
|
+
throw new ImprovementCommandError("Improvement release inspect JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
928
|
+
}
|
|
929
|
+
// eslint-disable-next-line no-console
|
|
930
|
+
console.log(parsed.output === "json"
|
|
931
|
+
? JSON.stringify(output, null, 2)
|
|
932
|
+
: formatCodaliReleaseOperatorInspectionText(inspection));
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (!parsed.exportId && !parsed.manifestPath) {
|
|
936
|
+
throw new ImprovementCommandError("improvement inspect requires --export-id <id>, --manifest <path>, or --release <id>.");
|
|
937
|
+
}
|
|
938
|
+
const inspection = await inspectDatasetExportManifestForImprovement({
|
|
939
|
+
exportId: parsed.exportId,
|
|
940
|
+
manifestPath: parsed.manifestPath,
|
|
941
|
+
directory: parsed.directory,
|
|
942
|
+
allowedExampleArtifactTypes: parsed.exampleArtifactTypes,
|
|
943
|
+
revokedDeletionGroupIds: parsed.revokedDeletionGroupIds,
|
|
944
|
+
});
|
|
945
|
+
const storageWrites = parsed.dryRun
|
|
946
|
+
? []
|
|
947
|
+
: await writeInspectionToStorageService(parsed, inspection);
|
|
948
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
949
|
+
outputType: "improvement.inspect",
|
|
950
|
+
status: "ok",
|
|
951
|
+
data: buildInspectData(parsed, inspection, storageWrites),
|
|
952
|
+
});
|
|
953
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
954
|
+
if (!outputValidation.ok) {
|
|
955
|
+
throw new ImprovementCommandError("Improvement inspect JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
956
|
+
}
|
|
957
|
+
// eslint-disable-next-line no-console
|
|
958
|
+
console.log(parsed.output === "json"
|
|
959
|
+
? JSON.stringify(output, null, 2)
|
|
960
|
+
: formatInspectText(output.data));
|
|
961
|
+
};
|
|
962
|
+
const runBuildRelease = async (parsed) => {
|
|
963
|
+
assertProductionGovernanceAllows(parsed, parsed.dryRun ? "improvement_analyze" : "candidate_branch");
|
|
964
|
+
const buildFromCandidate = parsed.candidateId || parsed.candidatePath;
|
|
965
|
+
if (!buildFromCandidate && !parsed.exportId && !parsed.manifestPath) {
|
|
966
|
+
throw new ImprovementCommandError("improvement build-release requires --candidate <id>, --export-id <id>, or --manifest <path>.");
|
|
967
|
+
}
|
|
968
|
+
if (parsed.proposalArtifact && !isPatchProposalArtifact(parsed.proposalArtifact)) {
|
|
969
|
+
throw new ImprovementCommandError("improvement build-release supports --artifact prompt|schema|tool-metadata.");
|
|
970
|
+
}
|
|
971
|
+
if (buildFromCandidate) {
|
|
972
|
+
const candidateId = parsed.candidateId ?? parsed.candidatePath;
|
|
973
|
+
if (!candidateId) {
|
|
974
|
+
throw new ImprovementCommandError("improvement build-release requires --candidate <id> when using candidate mode.");
|
|
975
|
+
}
|
|
976
|
+
const build = await buildCodaliCandidateReleasePlan({
|
|
977
|
+
candidateId,
|
|
978
|
+
candidatePath: parsed.candidatePath,
|
|
979
|
+
candidateDirectories: parsed.directory ? [parsed.directory] : undefined,
|
|
980
|
+
repoRoot: parsed.repoRoot,
|
|
981
|
+
scope: improvementScopeFromParsed(parsed),
|
|
982
|
+
releaseLevel: parsed.releaseLevel || 2,
|
|
983
|
+
dryRun: parsed.dryRun,
|
|
984
|
+
runId: parsed.runId,
|
|
985
|
+
candidateDate: parsed.candidateDate,
|
|
986
|
+
});
|
|
987
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
988
|
+
outputType: "improvement.release",
|
|
989
|
+
status: build.release.status === "blocked" ? "blocked" : "ok",
|
|
990
|
+
data: build.release,
|
|
991
|
+
});
|
|
992
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
993
|
+
if (!outputValidation.ok) {
|
|
994
|
+
throw new ImprovementCommandError("Improvement build-release JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
995
|
+
}
|
|
996
|
+
// eslint-disable-next-line no-console
|
|
997
|
+
console.log(parsed.output === "json"
|
|
998
|
+
? JSON.stringify(output, null, 2)
|
|
999
|
+
: formatBuildReleaseText(build));
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
const artifacts = parsed.proposalArtifact
|
|
1003
|
+
? [parsed.proposalArtifact]
|
|
1004
|
+
: [...CODALI_PATCH_PROPOSAL_ARTIFACTS];
|
|
1005
|
+
const allowedExampleArtifactTypes = parsed.exampleArtifactTypes.length
|
|
1006
|
+
? parsed.exampleArtifactTypes
|
|
1007
|
+
: Array.from(new Set(artifacts.flatMap((artifact) => proposalArtifactTypesFor(artifact))));
|
|
1008
|
+
const inspection = await inspectDatasetExportManifestForImprovement({
|
|
1009
|
+
exportId: parsed.exportId,
|
|
1010
|
+
manifestPath: parsed.manifestPath,
|
|
1011
|
+
directory: parsed.directory,
|
|
1012
|
+
allowedExampleArtifactTypes,
|
|
1013
|
+
revokedDeletionGroupIds: parsed.revokedDeletionGroupIds,
|
|
1014
|
+
});
|
|
1015
|
+
const build = await buildCodaliCandidateRelease({
|
|
1016
|
+
inspection,
|
|
1017
|
+
artifacts,
|
|
1018
|
+
repoRoot: parsed.repoRoot,
|
|
1019
|
+
scope: improvementScopeFromParsed(parsed),
|
|
1020
|
+
releaseLevel: parsed.releaseLevel || 2,
|
|
1021
|
+
dryRun: parsed.dryRun,
|
|
1022
|
+
runId: parsed.runId,
|
|
1023
|
+
candidateDate: parsed.candidateDate,
|
|
1024
|
+
outputPath: parsed.candidateOutputPath,
|
|
1025
|
+
approvedPaths: parsed.approvedWritePaths.length
|
|
1026
|
+
? parsed.approvedWritePaths
|
|
1027
|
+
: DEFAULT_CODALI_CANDIDATE_RELEASE_APPROVED_PATHS,
|
|
1028
|
+
});
|
|
1029
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
1030
|
+
outputType: "improvement.release",
|
|
1031
|
+
status: "ok",
|
|
1032
|
+
data: build.release,
|
|
1033
|
+
});
|
|
1034
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
1035
|
+
if (!outputValidation.ok) {
|
|
1036
|
+
throw new ImprovementCommandError("Improvement build-release JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
1037
|
+
}
|
|
1038
|
+
// eslint-disable-next-line no-console
|
|
1039
|
+
console.log(parsed.output === "json"
|
|
1040
|
+
? JSON.stringify(output, null, 2)
|
|
1041
|
+
: formatBuildReleaseText(build));
|
|
1042
|
+
};
|
|
1043
|
+
const runEval = async (parsed) => {
|
|
1044
|
+
assertProductionGovernanceAllows(parsed, "improvement_analyze");
|
|
1045
|
+
const candidateId = parsed.candidateId ?? parsed.candidatePath ?? parsed.manifestPath;
|
|
1046
|
+
if (!candidateId) {
|
|
1047
|
+
throw new ImprovementCommandError("improvement eval requires --candidate <candidate-id> or --candidate-path <path>.");
|
|
1048
|
+
}
|
|
1049
|
+
const result = await buildCodaliImprovementEvalScorecard({
|
|
1050
|
+
candidateId,
|
|
1051
|
+
candidatePath: parsed.candidatePath ?? parsed.manifestPath,
|
|
1052
|
+
candidateDirectories: parsed.directory ? [parsed.directory] : undefined,
|
|
1053
|
+
approvedPaths: parsed.approvedWritePaths.length ? parsed.approvedWritePaths : undefined,
|
|
1054
|
+
});
|
|
1055
|
+
const storageWrites = parsed.dryRun
|
|
1056
|
+
? []
|
|
1057
|
+
: await writeEvalToStorageService(parsed, result);
|
|
1058
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
1059
|
+
outputType: "improvement.scorecard",
|
|
1060
|
+
status: hasHardEvalBlocks(result) ? "blocked" : "ok",
|
|
1061
|
+
data: buildEvalOutputScorecard(result, storageWrites),
|
|
1062
|
+
});
|
|
1063
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
1064
|
+
if (!outputValidation.ok) {
|
|
1065
|
+
throw new ImprovementCommandError("Improvement eval JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
1066
|
+
}
|
|
1067
|
+
// eslint-disable-next-line no-console
|
|
1068
|
+
console.log(parsed.output === "json"
|
|
1069
|
+
? JSON.stringify(output, null, 2)
|
|
1070
|
+
: formatEvalText(result, storageWrites));
|
|
1071
|
+
};
|
|
1072
|
+
const runPublish = async (parsed) => {
|
|
1073
|
+
assertProductionGovernanceAllows(parsed, "improvement_analyze");
|
|
1074
|
+
if (!parsed.dryRun && parsed.publishMode === "auto_tag") {
|
|
1075
|
+
assertProductionGovernanceAllows(parsed, "stable_publish");
|
|
1076
|
+
}
|
|
1077
|
+
const candidateId = parsed.candidateId ?? parsed.candidatePath ?? parsed.manifestPath;
|
|
1078
|
+
if (!candidateId) {
|
|
1079
|
+
throw new ImprovementCommandError("improvement publish requires --candidate <candidate-id> or --candidate-path <path>.");
|
|
1080
|
+
}
|
|
1081
|
+
const workflowRun = parsed.workflowRunId ||
|
|
1082
|
+
parsed.workflowStatus ||
|
|
1083
|
+
parsed.workflowConclusion ||
|
|
1084
|
+
parsed.workflowUrl
|
|
1085
|
+
? {
|
|
1086
|
+
runId: parsed.workflowRunId,
|
|
1087
|
+
status: parsed.workflowStatus,
|
|
1088
|
+
conclusion: parsed.workflowConclusion,
|
|
1089
|
+
url: parsed.workflowUrl,
|
|
1090
|
+
headSha: parsed.commitSha,
|
|
1091
|
+
}
|
|
1092
|
+
: undefined;
|
|
1093
|
+
const result = await runCodaliPublishOrchestrator({
|
|
1094
|
+
candidateId,
|
|
1095
|
+
candidatePath: parsed.candidatePath ?? parsed.manifestPath,
|
|
1096
|
+
candidateDirectories: parsed.directory ? [parsed.directory] : undefined,
|
|
1097
|
+
repoRoot: parsed.repoRoot,
|
|
1098
|
+
mode: parsed.publishMode,
|
|
1099
|
+
dryRun: parsed.dryRun,
|
|
1100
|
+
releaseLevel: parsed.releaseLevel === 0 ? undefined : parsed.releaseLevel,
|
|
1101
|
+
scope: improvementScopeFromParsed(parsed),
|
|
1102
|
+
autoTagEnabled: parsed.autoTagEnabled,
|
|
1103
|
+
autoPublishEnabled: parsed.autoPublishEnabled,
|
|
1104
|
+
runId: parsed.runId,
|
|
1105
|
+
candidateDate: parsed.candidateDate,
|
|
1106
|
+
commitSha: parsed.commitSha,
|
|
1107
|
+
workflowRun,
|
|
1108
|
+
pollActions: parsed.pollActions,
|
|
1109
|
+
verifyNpm: parsed.verifyNpm,
|
|
1110
|
+
npmRegistry: parsed.npmRegistry,
|
|
1111
|
+
npmPackages: parsed.npmPackages,
|
|
1112
|
+
npmVersions: parsed.npmVersionResults,
|
|
1113
|
+
});
|
|
1114
|
+
const storageWrites = parsed.dryRun
|
|
1115
|
+
? []
|
|
1116
|
+
: await writePublishToStorageService(parsed, result);
|
|
1117
|
+
const outcome = {
|
|
1118
|
+
...result.outcome,
|
|
1119
|
+
metadata: {
|
|
1120
|
+
...(result.outcome.metadata ?? {}),
|
|
1121
|
+
storageWrites: storageWrites.map((write) => ({
|
|
1122
|
+
accepted: write.accepted,
|
|
1123
|
+
status: write.status,
|
|
1124
|
+
scope: write.scope,
|
|
1125
|
+
})),
|
|
1126
|
+
},
|
|
1127
|
+
};
|
|
1128
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
1129
|
+
outputType: "improvement.outcome",
|
|
1130
|
+
status: publishCliStatus(result),
|
|
1131
|
+
data: outcome,
|
|
1132
|
+
});
|
|
1133
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
1134
|
+
if (!outputValidation.ok) {
|
|
1135
|
+
throw new ImprovementCommandError("Improvement publish JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
1136
|
+
}
|
|
1137
|
+
// eslint-disable-next-line no-console
|
|
1138
|
+
console.log(parsed.output === "json"
|
|
1139
|
+
? JSON.stringify(output, null, 2)
|
|
1140
|
+
: formatPublishText(result, storageWrites));
|
|
1141
|
+
};
|
|
1142
|
+
const runMonitor = async (parsed) => {
|
|
1143
|
+
assertProductionGovernanceAllows(parsed, "improvement_analyze");
|
|
1144
|
+
if (!parsed.releaseId) {
|
|
1145
|
+
throw new ImprovementCommandError("improvement monitor requires --release <release-id>.");
|
|
1146
|
+
}
|
|
1147
|
+
const report = runCodaliReleaseOutcomeReporter({
|
|
1148
|
+
releaseId: parsed.releaseId,
|
|
1149
|
+
scope: improvementScopeFromParsed(parsed),
|
|
1150
|
+
monitorWindowMinutes: parsed.monitorWindowMinutes,
|
|
1151
|
+
monitorWindowStartedAt: parsed.monitorWindowStartedAt,
|
|
1152
|
+
monitorWindowEndedAt: parsed.monitorWindowEndedAt,
|
|
1153
|
+
thresholds: parsed.monitorThresholds,
|
|
1154
|
+
metrics: parsed.monitorMetrics,
|
|
1155
|
+
runtimeVersions: parsed.runtimeVersions,
|
|
1156
|
+
disabledRuntimePackages: parsed.disabledRuntimePackages,
|
|
1157
|
+
rollbackApplied: parsed.rollbackApplied,
|
|
1158
|
+
published: parsed.published,
|
|
1159
|
+
tagged: parsed.tagged,
|
|
1160
|
+
trainingUsed: parsed.trainingUsed,
|
|
1161
|
+
exportUsed: parsed.exportUsed,
|
|
1162
|
+
});
|
|
1163
|
+
const storageWrites = parsed.dryRun
|
|
1164
|
+
? []
|
|
1165
|
+
: await writeMonitorToStorageService(parsed, report);
|
|
1166
|
+
const data = {
|
|
1167
|
+
...report,
|
|
1168
|
+
storageWrites: storageWrites.map((write) => ({
|
|
1169
|
+
accepted: write.accepted,
|
|
1170
|
+
status: write.status,
|
|
1171
|
+
scope: write.scope,
|
|
1172
|
+
})),
|
|
1173
|
+
};
|
|
1174
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
1175
|
+
outputType: "improvement.monitor",
|
|
1176
|
+
status: report.status === "healthy" || report.status === "watch" ? "ok" : "blocked",
|
|
1177
|
+
data,
|
|
1178
|
+
});
|
|
1179
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
1180
|
+
if (!outputValidation.ok) {
|
|
1181
|
+
throw new ImprovementCommandError("Improvement monitor JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
1182
|
+
}
|
|
1183
|
+
// eslint-disable-next-line no-console
|
|
1184
|
+
console.log(parsed.output === "json"
|
|
1185
|
+
? JSON.stringify(output, null, 2)
|
|
1186
|
+
: formatMonitorText(data));
|
|
1187
|
+
};
|
|
1188
|
+
const runPropose = async (parsed) => {
|
|
1189
|
+
assertProductionGovernanceAllows(parsed, "improvement_analyze");
|
|
1190
|
+
if (!parsed.proposalArtifact) {
|
|
1191
|
+
throw new ImprovementCommandError("improvement propose requires --artifact <eval|prompt|schema|tool-metadata|docdex-retrieval|fine-tune|model-router>.");
|
|
1192
|
+
}
|
|
1193
|
+
if (!parsed.exportId && !parsed.manifestPath) {
|
|
1194
|
+
throw new ImprovementCommandError("improvement propose requires --export-id <id> or --manifest <path>.");
|
|
1195
|
+
}
|
|
1196
|
+
if (!parsed.dryRun) {
|
|
1197
|
+
throw new ImprovementCommandError("improvement propose is dry-run only in this phase; pass --dry-run.");
|
|
1198
|
+
}
|
|
1199
|
+
const fineTuneRole = parsed.role ?? "extractor";
|
|
1200
|
+
const allowedExampleArtifactTypes = parsed.exampleArtifactTypes.length
|
|
1201
|
+
? parsed.exampleArtifactTypes
|
|
1202
|
+
: proposalArtifactTypesFor(parsed.proposalArtifact, fineTuneRole);
|
|
1203
|
+
const inspection = await inspectDatasetExportManifestForImprovement({
|
|
1204
|
+
exportId: parsed.exportId,
|
|
1205
|
+
manifestPath: parsed.manifestPath,
|
|
1206
|
+
directory: parsed.directory,
|
|
1207
|
+
allowedExampleArtifactTypes,
|
|
1208
|
+
revokedDeletionGroupIds: parsed.revokedDeletionGroupIds,
|
|
1209
|
+
});
|
|
1210
|
+
const fineTuneInventory = parsed.proposalArtifact === CODALI_FINE_TUNE_PROPOSAL_ARTIFACT
|
|
1211
|
+
? await resolveFineTuneInventoryForPropose(parsed)
|
|
1212
|
+
: undefined;
|
|
1213
|
+
const proposal = parsed.proposalArtifact === "eval"
|
|
1214
|
+
? buildCodaliEvalReplayCandidateBundle({
|
|
1215
|
+
inspection,
|
|
1216
|
+
artifact: parsed.proposalArtifact,
|
|
1217
|
+
})
|
|
1218
|
+
: parsed.proposalArtifact === "docdex-retrieval"
|
|
1219
|
+
? buildCodaliDocdexRetrievalCandidateBundle({
|
|
1220
|
+
inspection,
|
|
1221
|
+
artifact: parsed.proposalArtifact,
|
|
1222
|
+
})
|
|
1223
|
+
: parsed.proposalArtifact === CODALI_MODEL_ROUTER_PROPOSAL_ARTIFACT
|
|
1224
|
+
? buildCodaliModelRouterCandidateBundle({
|
|
1225
|
+
inspection,
|
|
1226
|
+
artifact: parsed.proposalArtifact,
|
|
1227
|
+
})
|
|
1228
|
+
: parsed.proposalArtifact === CODALI_FINE_TUNE_PROPOSAL_ARTIFACT
|
|
1229
|
+
? buildCodaliFineTuneJobPlannerBundle({
|
|
1230
|
+
inspection,
|
|
1231
|
+
artifact: parsed.proposalArtifact,
|
|
1232
|
+
role: fineTuneRole,
|
|
1233
|
+
inventory: fineTuneInventory?.inventory,
|
|
1234
|
+
inventorySource: fineTuneInventory?.source,
|
|
1235
|
+
inventoryWarnings: fineTuneInventory?.warnings,
|
|
1236
|
+
})
|
|
1237
|
+
: buildCodaliPatchCandidateBundle({
|
|
1238
|
+
inspection,
|
|
1239
|
+
artifact: parsed.proposalArtifact,
|
|
1240
|
+
});
|
|
1241
|
+
const output = buildCodaliImprovementCliJsonOutput({
|
|
1242
|
+
outputType: "improvement.propose",
|
|
1243
|
+
status: "ok",
|
|
1244
|
+
data: buildProposeData(parsed, proposal),
|
|
1245
|
+
});
|
|
1246
|
+
const outputValidation = validateCodaliImprovementCliJsonOutput(output);
|
|
1247
|
+
if (!outputValidation.ok) {
|
|
1248
|
+
throw new ImprovementCommandError("Improvement propose JSON contract validation failed.", IMPROVEMENT_EXIT_CODES.validation_error);
|
|
1249
|
+
}
|
|
1250
|
+
// eslint-disable-next-line no-console
|
|
1251
|
+
console.log(parsed.output === "json"
|
|
1252
|
+
? JSON.stringify(output, null, 2)
|
|
1253
|
+
: formatProposeText(output.data));
|
|
1254
|
+
};
|
|
1255
|
+
const resolveFineTuneInventoryForPropose = async (parsed) => {
|
|
1256
|
+
if (parsed.inventoryJson) {
|
|
1257
|
+
return parseFineTuneInventoryPayload(parsed.inventoryJson, {
|
|
1258
|
+
source: "provided",
|
|
1259
|
+
status: "succeeded",
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
if (parsed.inventoryPath) {
|
|
1263
|
+
try {
|
|
1264
|
+
const payload = await readFile(parsed.inventoryPath, "utf8");
|
|
1265
|
+
return parseFineTuneInventoryPayload(payload, {
|
|
1266
|
+
source: "provided",
|
|
1267
|
+
status: "succeeded",
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
catch (error) {
|
|
1271
|
+
return {
|
|
1272
|
+
inventory: [],
|
|
1273
|
+
source: {
|
|
1274
|
+
source: "provided",
|
|
1275
|
+
status: "failed",
|
|
1276
|
+
inventoryCount: 0,
|
|
1277
|
+
errors: ["inventory_file_read_failed"],
|
|
1278
|
+
},
|
|
1279
|
+
warnings: [{
|
|
1280
|
+
code: "inventory_file_read_failed",
|
|
1281
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1282
|
+
details: {
|
|
1283
|
+
path: parsed.inventoryPath,
|
|
1284
|
+
},
|
|
1285
|
+
}],
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
const command = "mcoda";
|
|
1290
|
+
const args = ["agent", "list", "--json", "--refresh-health"];
|
|
1291
|
+
if (!parsed.inventoryRefresh) {
|
|
1292
|
+
return {
|
|
1293
|
+
inventory: [],
|
|
1294
|
+
source: {
|
|
1295
|
+
source: "not_provided",
|
|
1296
|
+
command,
|
|
1297
|
+
args,
|
|
1298
|
+
status: "not_run",
|
|
1299
|
+
inventoryCount: 0,
|
|
1300
|
+
},
|
|
1301
|
+
warnings: [{
|
|
1302
|
+
code: "inventory_refresh_disabled",
|
|
1303
|
+
message: "Fine-tune target resolution requires mcoda inventory data.",
|
|
1304
|
+
}],
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
try {
|
|
1308
|
+
const result = await defaultCodaliGatewayLiveCommandRunner(command, args, {
|
|
1309
|
+
timeoutMs: parsed.inventoryTimeoutMs,
|
|
1310
|
+
maxBuffer: DEFAULT_FINE_TUNE_INVENTORY_MAX_BUFFER,
|
|
1311
|
+
});
|
|
1312
|
+
if (result.exitCode !== 0) {
|
|
1313
|
+
return {
|
|
1314
|
+
inventory: [],
|
|
1315
|
+
source: {
|
|
1316
|
+
source: "command",
|
|
1317
|
+
command,
|
|
1318
|
+
args,
|
|
1319
|
+
status: "failed",
|
|
1320
|
+
latencyMs: result.latencyMs,
|
|
1321
|
+
inventoryCount: 0,
|
|
1322
|
+
errors: [`inventory_command_exit_${result.exitCode}`],
|
|
1323
|
+
},
|
|
1324
|
+
warnings: [{
|
|
1325
|
+
code: "inventory_command_failed",
|
|
1326
|
+
message: "mcoda agent inventory refresh failed.",
|
|
1327
|
+
details: {
|
|
1328
|
+
exitCode: result.exitCode,
|
|
1329
|
+
timedOut: result.timedOut === true,
|
|
1330
|
+
},
|
|
1331
|
+
}],
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
return parseFineTuneInventoryPayload(result.stdout, {
|
|
1335
|
+
source: "command",
|
|
1336
|
+
command,
|
|
1337
|
+
args,
|
|
1338
|
+
status: "succeeded",
|
|
1339
|
+
latencyMs: result.latencyMs,
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
catch (error) {
|
|
1343
|
+
return {
|
|
1344
|
+
inventory: [],
|
|
1345
|
+
source: {
|
|
1346
|
+
source: "command",
|
|
1347
|
+
command,
|
|
1348
|
+
args,
|
|
1349
|
+
status: "failed",
|
|
1350
|
+
inventoryCount: 0,
|
|
1351
|
+
errors: ["inventory_command_error"],
|
|
1352
|
+
},
|
|
1353
|
+
warnings: [{
|
|
1354
|
+
code: "inventory_command_error",
|
|
1355
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1356
|
+
}],
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
const parseFineTuneInventoryPayload = (payload, source) => {
|
|
1361
|
+
try {
|
|
1362
|
+
const inventory = parseCodaliGatewayLiveInventory(payload);
|
|
1363
|
+
return {
|
|
1364
|
+
inventory,
|
|
1365
|
+
source: {
|
|
1366
|
+
...source,
|
|
1367
|
+
inventoryCount: inventory.length,
|
|
1368
|
+
},
|
|
1369
|
+
warnings: inventory.length === 0
|
|
1370
|
+
? [{
|
|
1371
|
+
code: "inventory_empty",
|
|
1372
|
+
message: "No mcoda agent candidates were found in the inventory payload.",
|
|
1373
|
+
}]
|
|
1374
|
+
: [],
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
catch (error) {
|
|
1378
|
+
return {
|
|
1379
|
+
inventory: [],
|
|
1380
|
+
source: {
|
|
1381
|
+
...source,
|
|
1382
|
+
status: "failed",
|
|
1383
|
+
inventoryCount: 0,
|
|
1384
|
+
errors: ["inventory_parse_failed"],
|
|
1385
|
+
},
|
|
1386
|
+
warnings: [{
|
|
1387
|
+
code: "inventory_parse_failed",
|
|
1388
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1389
|
+
}],
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
const writeInspectionToStorageService = async (parsed, inspection) => {
|
|
1394
|
+
assertProductionGovernanceAllows(parsed, "service_gateway_write");
|
|
1395
|
+
if (!parsed.storageServiceUrl || !parsed.storageServiceToken) {
|
|
1396
|
+
throw new ImprovementCommandError("Non-dry-run improvement inspect requires --storage-service-url and --storage-service-token.");
|
|
1397
|
+
}
|
|
1398
|
+
const scope = storageScopeFromParsed(parsed, inspection);
|
|
1399
|
+
const client = new StorageServiceImprovementClient({
|
|
1400
|
+
baseUrl: parsed.storageServiceUrl,
|
|
1401
|
+
serviceToken: parsed.storageServiceToken,
|
|
1402
|
+
hmacSecret: parsed.hmacSecret,
|
|
1403
|
+
});
|
|
1404
|
+
const runWrite = await client.recordRun({
|
|
1405
|
+
scope,
|
|
1406
|
+
idempotencyKey: `improvement-run:${inspection.manifest.manifestId}`,
|
|
1407
|
+
body: {
|
|
1408
|
+
improvement_run_id: scope.runId,
|
|
1409
|
+
run_kind: "candidate_generation",
|
|
1410
|
+
status: "completed",
|
|
1411
|
+
source_export_id: inspection.manifest.manifestId,
|
|
1412
|
+
metadata: {
|
|
1413
|
+
source: "codali improvement inspect",
|
|
1414
|
+
exportId: inspection.exportId,
|
|
1415
|
+
exportKind: inspection.manifest.exportKind,
|
|
1416
|
+
manifestPath: inspection.manifestPath,
|
|
1417
|
+
warningCodes: inspection.warnings.map((warning) => warning.code),
|
|
1418
|
+
curation: {
|
|
1419
|
+
acceptedCount: inspection.curationReport.acceptedCount,
|
|
1420
|
+
rejectedCount: inspection.curationReport.rejectedCount,
|
|
1421
|
+
warningCount: inspection.curationReport.warningCount,
|
|
1422
|
+
reasonCounts: inspection.curationReport.reasonCounts,
|
|
1423
|
+
lineageValid: inspection.curationReport.lineageValid,
|
|
1424
|
+
},
|
|
1425
|
+
},
|
|
1426
|
+
},
|
|
1427
|
+
});
|
|
1428
|
+
const candidateWrites = [];
|
|
1429
|
+
for (const candidate of inspection.candidates) {
|
|
1430
|
+
candidateWrites.push(await client.recordCandidate({
|
|
1431
|
+
scope,
|
|
1432
|
+
idempotencyKey: `improvement-candidate:${candidate.candidateId}`,
|
|
1433
|
+
body: {
|
|
1434
|
+
candidate_id: candidate.candidateId,
|
|
1435
|
+
improvement_run_id: scope.runId,
|
|
1436
|
+
source_export_id: inspection.manifest.manifestId,
|
|
1437
|
+
source_record_ids: candidate.sourceRecordIds,
|
|
1438
|
+
candidate_kind: candidate.candidateKind,
|
|
1439
|
+
candidate_ref: inspection.primaryArtifact?.ref.uri ??
|
|
1440
|
+
inspection.primaryArtifact?.ref.refId ??
|
|
1441
|
+
inspection.manifest.checksum,
|
|
1442
|
+
status: candidate.status,
|
|
1443
|
+
metadata: {
|
|
1444
|
+
artifactIds: candidate.artifactIds,
|
|
1445
|
+
exampleCount: candidate.exampleCount,
|
|
1446
|
+
objectBytes: candidate.objectBytes,
|
|
1447
|
+
provenance: candidate.provenance,
|
|
1448
|
+
},
|
|
1449
|
+
},
|
|
1450
|
+
}));
|
|
1451
|
+
}
|
|
1452
|
+
return [runWrite, ...candidateWrites];
|
|
1453
|
+
};
|
|
1454
|
+
const writeEvalToStorageService = async (parsed, result) => {
|
|
1455
|
+
assertProductionGovernanceAllows(parsed, "service_gateway_write");
|
|
1456
|
+
if (!parsed.storageServiceUrl || !parsed.storageServiceToken) {
|
|
1457
|
+
throw new ImprovementCommandError("Non-dry-run improvement eval requires --storage-service-url and --storage-service-token.");
|
|
1458
|
+
}
|
|
1459
|
+
const scope = storageScopeFromEval(parsed, result);
|
|
1460
|
+
const client = new StorageServiceImprovementClient({
|
|
1461
|
+
baseUrl: parsed.storageServiceUrl,
|
|
1462
|
+
serviceToken: parsed.storageServiceToken,
|
|
1463
|
+
hmacSecret: parsed.hmacSecret,
|
|
1464
|
+
});
|
|
1465
|
+
const manifestId = isRecord(result.scorecard.metadata) &&
|
|
1466
|
+
typeof result.scorecard.metadata.manifestId === "string"
|
|
1467
|
+
? result.scorecard.metadata.manifestId
|
|
1468
|
+
: undefined;
|
|
1469
|
+
const gateStatuses = Object.fromEntries(result.gates.map((gateResult) => [gateResult.gateId, gateResult.status]));
|
|
1470
|
+
const runWrite = await client.recordRun({
|
|
1471
|
+
scope,
|
|
1472
|
+
idempotencyKey: `improvement-eval-run:${result.scorecard.scorecardId}`,
|
|
1473
|
+
body: {
|
|
1474
|
+
scope,
|
|
1475
|
+
improvement_run_id: scope.runId,
|
|
1476
|
+
run_kind: "release_approval_eval",
|
|
1477
|
+
status: hasHardEvalBlocks(result) ? "blocked" : "completed",
|
|
1478
|
+
source_export_id: manifestId ?? result.candidateId,
|
|
1479
|
+
metadata: {
|
|
1480
|
+
source: "codali improvement eval",
|
|
1481
|
+
candidateId: result.candidateId,
|
|
1482
|
+
scorecardId: result.scorecard.scorecardId,
|
|
1483
|
+
scorecardStatus: result.scorecard.status,
|
|
1484
|
+
releaseApproval: result.releaseApproval,
|
|
1485
|
+
blockedReasons: result.blockedReasons,
|
|
1486
|
+
warnings: result.warnings,
|
|
1487
|
+
gateStatuses,
|
|
1488
|
+
},
|
|
1489
|
+
},
|
|
1490
|
+
});
|
|
1491
|
+
const candidateWrite = await client.recordCandidate({
|
|
1492
|
+
scope,
|
|
1493
|
+
idempotencyKey: `improvement-scorecard:${result.scorecard.scorecardId}`,
|
|
1494
|
+
body: {
|
|
1495
|
+
scope,
|
|
1496
|
+
candidate_id: result.candidateId,
|
|
1497
|
+
improvement_run_id: scope.runId,
|
|
1498
|
+
source_export_id: manifestId ?? result.candidateId,
|
|
1499
|
+
source_record_ids: [],
|
|
1500
|
+
candidate_kind: "release",
|
|
1501
|
+
candidate_ref: result.scorecard.scorecardId,
|
|
1502
|
+
status: result.scorecard.status,
|
|
1503
|
+
metadata: {
|
|
1504
|
+
source: "codali improvement eval",
|
|
1505
|
+
scorecard: result.scorecard,
|
|
1506
|
+
releaseApproval: result.releaseApproval,
|
|
1507
|
+
blockedReasons: result.blockedReasons,
|
|
1508
|
+
warnings: result.warnings,
|
|
1509
|
+
storagePayload: result.storagePayload,
|
|
1510
|
+
},
|
|
1511
|
+
},
|
|
1512
|
+
});
|
|
1513
|
+
return [runWrite, candidateWrite];
|
|
1514
|
+
};
|
|
1515
|
+
const writePublishToStorageService = async (parsed, result) => {
|
|
1516
|
+
assertProductionGovernanceAllows(parsed, "service_gateway_write");
|
|
1517
|
+
if (!parsed.storageServiceUrl || !parsed.storageServiceToken) {
|
|
1518
|
+
throw new ImprovementCommandError("Non-dry-run improvement publish requires --storage-service-url and --storage-service-token.");
|
|
1519
|
+
}
|
|
1520
|
+
const scope = storageScopeFromPublish(parsed, result);
|
|
1521
|
+
const client = new StorageServiceImprovementClient({
|
|
1522
|
+
baseUrl: parsed.storageServiceUrl,
|
|
1523
|
+
serviceToken: parsed.storageServiceToken,
|
|
1524
|
+
hmacSecret: parsed.hmacSecret,
|
|
1525
|
+
});
|
|
1526
|
+
return writeCodaliPublishToStorageService({
|
|
1527
|
+
result,
|
|
1528
|
+
scope,
|
|
1529
|
+
client,
|
|
1530
|
+
});
|
|
1531
|
+
};
|
|
1532
|
+
const writeMonitorToStorageService = async (parsed, report) => {
|
|
1533
|
+
assertProductionGovernanceAllows(parsed, "service_gateway_write");
|
|
1534
|
+
if (!parsed.storageServiceUrl || !parsed.storageServiceToken) {
|
|
1535
|
+
throw new ImprovementCommandError("Non-dry-run improvement monitor requires --storage-service-url and --storage-service-token.");
|
|
1536
|
+
}
|
|
1537
|
+
const scope = storageScopeFromMonitor(parsed, report);
|
|
1538
|
+
const client = new StorageServiceImprovementClient({
|
|
1539
|
+
baseUrl: parsed.storageServiceUrl,
|
|
1540
|
+
serviceToken: parsed.storageServiceToken,
|
|
1541
|
+
hmacSecret: parsed.hmacSecret,
|
|
1542
|
+
});
|
|
1543
|
+
return writeCodaliReleaseOutcomeReportToStorageService({
|
|
1544
|
+
report,
|
|
1545
|
+
scope,
|
|
1546
|
+
client,
|
|
1547
|
+
});
|
|
1548
|
+
};
|
|
1549
|
+
const formatInspectText = (data) => {
|
|
1550
|
+
const lines = [
|
|
1551
|
+
`improvement inspect: ${data.dryRun ? "dry_run" : "written"}`,
|
|
1552
|
+
`manifest: ${data.manifest.manifestId}`,
|
|
1553
|
+
`kind: ${data.manifest.exportKind}`,
|
|
1554
|
+
`checksum: ${data.manifest.checksum}`,
|
|
1555
|
+
`candidates: ${data.candidates.length}`,
|
|
1556
|
+
`curation: accepted=${data.curationReport.acceptedCount} rejected=${data.curationReport.rejectedCount} warnings=${data.curationReport.warningCount}`,
|
|
1557
|
+
];
|
|
1558
|
+
if (data.warnings.length) {
|
|
1559
|
+
lines.push(`warnings: ${data.warnings.map((warning) => warning.code).join(", ")}`);
|
|
1560
|
+
}
|
|
1561
|
+
return lines.join("\n");
|
|
1562
|
+
};
|
|
1563
|
+
const formatProposeText = (data) => {
|
|
1564
|
+
const candidate = data.proposal.candidates[0];
|
|
1565
|
+
const lines = [
|
|
1566
|
+
`improvement propose: ${data.dryRun ? "dry_run" : "written"}`,
|
|
1567
|
+
`artifact: ${data.artifact}`,
|
|
1568
|
+
`manifest: ${data.manifestId}`,
|
|
1569
|
+
`candidates: ${data.proposal.candidates.length}`,
|
|
1570
|
+
`status: ${candidate?.status ?? "blocked"}`,
|
|
1571
|
+
];
|
|
1572
|
+
if ("fixtureIds" in data.proposal) {
|
|
1573
|
+
lines.splice(3, 0, `eval fixture: ${data.proposal.fixtureIds.evalFixtureId}`);
|
|
1574
|
+
lines.splice(4, 0, `replay fixture: ${data.proposal.fixtureIds.replayFixtureId}`);
|
|
1575
|
+
}
|
|
1576
|
+
if ("patchPlan" in data.proposal) {
|
|
1577
|
+
lines.splice(3, 0, `patch plan: ${data.proposal.patchPlan.planId}`);
|
|
1578
|
+
lines.push(`operations: ${data.proposal.patchPlan.operations.length}`);
|
|
1579
|
+
}
|
|
1580
|
+
if ("jobSpecs" in data.proposal) {
|
|
1581
|
+
lines.splice(3, 0, `job specs: ${data.proposal.jobSpecs.length}`);
|
|
1582
|
+
if (data.proposal.jobSpecs[0]) {
|
|
1583
|
+
lines.push(`job plan: ${data.proposal.jobSpecs[0].jobPlanId}`);
|
|
1584
|
+
lines.push(`target: ${data.proposal.jobSpecs[0].targetResolution.status}`);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
if ("routerPlan" in data.proposal) {
|
|
1588
|
+
lines.splice(3, 0, `router plan: ${data.proposal.routerPlan.planId}`);
|
|
1589
|
+
lines.push(`router action: ${data.proposal.routerPlan.action}`);
|
|
1590
|
+
lines.push(`routes proposed: ${data.proposal.routerPlan.proposedRouteCount}`);
|
|
1591
|
+
}
|
|
1592
|
+
if ("failureLabels" in data.proposal && data.proposal.failureLabels.length) {
|
|
1593
|
+
lines.push(`failure labels: ${data.proposal.failureLabels.join(", ")}`);
|
|
1594
|
+
}
|
|
1595
|
+
if ("failureClasses" in data.proposal && data.proposal.failureClasses.length) {
|
|
1596
|
+
lines.push(`failure classes: ${data.proposal.failureClasses.join(", ")}`);
|
|
1597
|
+
}
|
|
1598
|
+
return lines.join("\n");
|
|
1599
|
+
};
|
|
1600
|
+
const formatBuildReleaseText = (build) => {
|
|
1601
|
+
const lines = [
|
|
1602
|
+
`improvement build-release: ${build.dryRun ? "dry_run" : build.release.status}`,
|
|
1603
|
+
`branch: ${build.candidateWorkspace.branchName}`,
|
|
1604
|
+
`manifest: ${build.release.metadata?.sourceExportIds instanceof Array
|
|
1605
|
+
? build.release.metadata.sourceExportIds.join(",")
|
|
1606
|
+
: "unavailable"}`,
|
|
1607
|
+
`write plan: ${build.writePlan.status}`,
|
|
1608
|
+
`artifacts: ${build.generatedArtifacts.length}`,
|
|
1609
|
+
`patch lines: ${build.patchOutput.split("\n").filter(Boolean).length}`,
|
|
1610
|
+
];
|
|
1611
|
+
if (build.blockedReasons.length) {
|
|
1612
|
+
lines.push(`blocked: ${build.blockedReasons.join(", ")}`);
|
|
1613
|
+
}
|
|
1614
|
+
if (build.dirtyWorktree.status === "dirty") {
|
|
1615
|
+
lines.push(`dirty unrelated files: ${build.dirtyWorktree.unrelatedDirtyFileCount}`);
|
|
1616
|
+
}
|
|
1617
|
+
return lines.join("\n");
|
|
1618
|
+
};
|
|
1619
|
+
const formatEvalText = (result, storageWrites) => {
|
|
1620
|
+
const counts = {
|
|
1621
|
+
passed: result.gates.filter((item) => item.status === "passed").length,
|
|
1622
|
+
failed: result.gates.filter((item) => item.status === "failed").length,
|
|
1623
|
+
skipped: result.gates.filter((item) => item.status === "skipped").length,
|
|
1624
|
+
warning: result.gates.filter((item) => item.status === "warning").length,
|
|
1625
|
+
};
|
|
1626
|
+
const lines = [
|
|
1627
|
+
`improvement eval: ${result.scorecard.status}`,
|
|
1628
|
+
`candidate: ${result.candidateId}`,
|
|
1629
|
+
`scorecard: ${result.scorecard.scorecardId}`,
|
|
1630
|
+
`gates: passed=${counts.passed} failed=${counts.failed} skipped=${counts.skipped} warning=${counts.warning}`,
|
|
1631
|
+
`tag allowed: ${result.releaseApproval.tagAllowed ? "yes" : "no"}`,
|
|
1632
|
+
`publish allowed: ${result.releaseApproval.publishAllowed ? "yes" : "no"}`,
|
|
1633
|
+
];
|
|
1634
|
+
if (result.blockedReasons.length) {
|
|
1635
|
+
lines.push(`blocked: ${result.blockedReasons.join(", ")}`);
|
|
1636
|
+
}
|
|
1637
|
+
if (result.warnings.length) {
|
|
1638
|
+
lines.push(`warnings: ${result.warnings.join(", ")}`);
|
|
1639
|
+
}
|
|
1640
|
+
if (storageWrites.length) {
|
|
1641
|
+
lines.push(`storage writes: ${storageWrites.length}`);
|
|
1642
|
+
}
|
|
1643
|
+
return lines.join("\n");
|
|
1644
|
+
};
|
|
1645
|
+
const publishCliStatus = (result) => {
|
|
1646
|
+
if (result.status === "blocked")
|
|
1647
|
+
return "blocked";
|
|
1648
|
+
if (result.status === "failed" || result.status === "workflow_failed")
|
|
1649
|
+
return "error";
|
|
1650
|
+
return "ok";
|
|
1651
|
+
};
|
|
1652
|
+
const formatNpmVersionSummary = (versions) => {
|
|
1653
|
+
if (!versions.length)
|
|
1654
|
+
return "none";
|
|
1655
|
+
return versions
|
|
1656
|
+
.map((version) => `${version.packageName}:${version.status}`)
|
|
1657
|
+
.join(", ");
|
|
1658
|
+
};
|
|
1659
|
+
const formatPublishText = (result, storageWrites) => {
|
|
1660
|
+
const lines = [
|
|
1661
|
+
`improvement publish: ${result.status}`,
|
|
1662
|
+
`mode: ${result.mode}`,
|
|
1663
|
+
`candidate: ${result.candidateId}`,
|
|
1664
|
+
`tag: ${result.releaseBuild.releasePlan.futureTag}`,
|
|
1665
|
+
`commit: ${result.commitGuard.commitSha ?? "unavailable"}`,
|
|
1666
|
+
`publisher: ${result.publisher.workflowFile}`,
|
|
1667
|
+
`workflow: ${result.workflowRun.status}${result.workflowRun.runId ? `#${result.workflowRun.runId}` : ""}`,
|
|
1668
|
+
`npm versions: ${formatNpmVersionSummary(result.npmVersions)}`,
|
|
1669
|
+
];
|
|
1670
|
+
if (result.blockedReasons.length) {
|
|
1671
|
+
lines.push(`blocked: ${result.blockedReasons.join(", ")}`);
|
|
1672
|
+
}
|
|
1673
|
+
if (storageWrites.length) {
|
|
1674
|
+
lines.push(`storage writes: ${storageWrites.length}`);
|
|
1675
|
+
}
|
|
1676
|
+
return lines.join("\n");
|
|
1677
|
+
};
|
|
1678
|
+
const formatMonitorText = (report) => {
|
|
1679
|
+
const triggered = report.rollbackTriggers
|
|
1680
|
+
.filter((trigger) => trigger.triggered)
|
|
1681
|
+
.map((trigger) => trigger.code);
|
|
1682
|
+
const disabledRuntimePackages = report.runtimeFlags
|
|
1683
|
+
.filter((flag) => !flag.enabled)
|
|
1684
|
+
.map((flag) => `${flag.packageKind}:${flag.version}`);
|
|
1685
|
+
const lines = [
|
|
1686
|
+
`improvement monitor: ${report.status}`,
|
|
1687
|
+
`release: ${report.releaseId}`,
|
|
1688
|
+
`window: ${report.monitorWindow.startedAt}..${report.monitorWindow.endedAt}`,
|
|
1689
|
+
`shadow: ${report.shadowTraffic.status} ${report.shadowTraffic.shadowRequestCount}/${report.shadowTraffic.eligibleRequestCount}`,
|
|
1690
|
+
`rollback triggers: ${triggered.length ? triggered.join(", ") : "none"}`,
|
|
1691
|
+
`runtime disabled: ${disabledRuntimePackages.length ? disabledRuntimePackages.join(", ") : "none"}`,
|
|
1692
|
+
];
|
|
1693
|
+
if (report.storageWrites.length) {
|
|
1694
|
+
lines.push(`storage writes: ${report.storageWrites.length}`);
|
|
1695
|
+
}
|
|
1696
|
+
return lines.join("\n");
|
|
1697
|
+
};
|
|
1698
|
+
const formatPolicyText = (output) => {
|
|
1699
|
+
const policy = output.policy;
|
|
1700
|
+
const lines = [
|
|
1701
|
+
`improvement policy: ${output.status}`,
|
|
1702
|
+
policy
|
|
1703
|
+
? `level ${policy.releaseLevel}: ${CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS[policy.releaseLevel].description}`
|
|
1704
|
+
: "level: unavailable",
|
|
1705
|
+
];
|
|
1706
|
+
if (output.decision) {
|
|
1707
|
+
lines.push(`action ${output.decision.action}: ${output.decision.allowed ? "allowed" : "blocked"}`);
|
|
1708
|
+
if (output.decision.reasons.length) {
|
|
1709
|
+
lines.push(`reasons: ${output.decision.reasons.join(", ")}`);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
if (output.issues.length) {
|
|
1713
|
+
lines.push(`issues: ${output.issues.map((issue) => issue.code).join(", ")}`);
|
|
1714
|
+
}
|
|
1715
|
+
return lines.join("\n");
|
|
1716
|
+
};
|
|
1717
|
+
const parseReleaseLevel = (value, flag) => {
|
|
1718
|
+
const numberValue = Number(value);
|
|
1719
|
+
if (!Number.isInteger(numberValue) ||
|
|
1720
|
+
!(numberValue in CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS)) {
|
|
1721
|
+
throw new ImprovementCommandError(`${flag} must be one of 0, 1, 2, 3, 4.`);
|
|
1722
|
+
}
|
|
1723
|
+
return numberValue;
|
|
1724
|
+
};
|
|
1725
|
+
const parseNonNegativeInteger = (value, flag) => {
|
|
1726
|
+
const numberValue = Number(value);
|
|
1727
|
+
if (!Number.isInteger(numberValue) || numberValue < 0) {
|
|
1728
|
+
throw new ImprovementCommandError(`${flag} must be a non-negative integer.`);
|
|
1729
|
+
}
|
|
1730
|
+
return numberValue;
|
|
1731
|
+
};
|
|
1732
|
+
const parsePositiveInteger = (value, flag) => {
|
|
1733
|
+
const numberValue = Number(value);
|
|
1734
|
+
if (!Number.isInteger(numberValue) || numberValue <= 0) {
|
|
1735
|
+
throw new ImprovementCommandError(`${flag} must be a positive integer.`);
|
|
1736
|
+
}
|
|
1737
|
+
return numberValue;
|
|
1738
|
+
};
|
|
1739
|
+
const parseNonNegativeNumber = (value, flag) => {
|
|
1740
|
+
const numberValue = Number(value);
|
|
1741
|
+
if (!Number.isFinite(numberValue) || numberValue < 0) {
|
|
1742
|
+
throw new ImprovementCommandError(`${flag} must be a non-negative number.`);
|
|
1743
|
+
}
|
|
1744
|
+
return numberValue;
|
|
1745
|
+
};
|
|
1746
|
+
const parseRate = (value, flag) => {
|
|
1747
|
+
const numberValue = parseNonNegativeNumber(value, flag);
|
|
1748
|
+
if (numberValue > 1) {
|
|
1749
|
+
throw new ImprovementCommandError(`${flag} must be a rate from 0 to 1.`);
|
|
1750
|
+
}
|
|
1751
|
+
return numberValue;
|
|
1752
|
+
};
|
|
1753
|
+
const parseIsoTimestamp = (value, flag) => {
|
|
1754
|
+
const parsed = Date.parse(value);
|
|
1755
|
+
if (!Number.isFinite(parsed)) {
|
|
1756
|
+
throw new ImprovementCommandError(`${flag} must be an ISO timestamp.`);
|
|
1757
|
+
}
|
|
1758
|
+
return value;
|
|
1759
|
+
};
|
|
1760
|
+
const parseRuntimePackageKind = (value, flag) => {
|
|
1761
|
+
if (CODALI_RELEASE_RUNTIME_PACKAGE_KINDS.includes(value)) {
|
|
1762
|
+
return value;
|
|
1763
|
+
}
|
|
1764
|
+
throw new ImprovementCommandError(`${flag} must be prompt_package|router_policy|retrieval_policy|schema|fine_tune_adapter.`);
|
|
1765
|
+
};
|
|
1766
|
+
const parseStorageMode = (value, flag) => {
|
|
1767
|
+
if (value === "local_only" || value === "storage_service" || value === "hybrid") {
|
|
1768
|
+
return value;
|
|
1769
|
+
}
|
|
1770
|
+
throw new ImprovementCommandError(`${flag} must be local_only|storage_service|hybrid.`);
|
|
1771
|
+
};
|
|
1772
|
+
const parsePublishMode = (value, flag) => {
|
|
1773
|
+
if (value === "branch_only" || value === "auto_tag")
|
|
1774
|
+
return value;
|
|
1775
|
+
throw new ImprovementCommandError(`${flag} must be branch_only|auto_tag.`);
|
|
1776
|
+
};
|
|
1777
|
+
const parseWorkflowStatus = (value, flag) => {
|
|
1778
|
+
if (value === "not_requested" ||
|
|
1779
|
+
value === "queued" ||
|
|
1780
|
+
value === "in_progress" ||
|
|
1781
|
+
value === "completed" ||
|
|
1782
|
+
value === "unknown") {
|
|
1783
|
+
return value;
|
|
1784
|
+
}
|
|
1785
|
+
throw new ImprovementCommandError(`${flag} must be not_requested|queued|in_progress|completed|unknown.`);
|
|
1786
|
+
};
|
|
1787
|
+
const parseWorkflowConclusion = (value, flag) => {
|
|
1788
|
+
if (value === "success" ||
|
|
1789
|
+
value === "failure" ||
|
|
1790
|
+
value === "cancelled" ||
|
|
1791
|
+
value === "skipped" ||
|
|
1792
|
+
value === "timed_out" ||
|
|
1793
|
+
value === "action_required" ||
|
|
1794
|
+
value === "neutral" ||
|
|
1795
|
+
value === "unknown") {
|
|
1796
|
+
return value;
|
|
1797
|
+
}
|
|
1798
|
+
throw new ImprovementCommandError(`${flag} must be success|failure|cancelled|skipped|timed_out|action_required|neutral|unknown.`);
|
|
1799
|
+
};
|
|
1800
|
+
const parseNpmVersionResult = (value, flag) => {
|
|
1801
|
+
const separator = value.indexOf("=");
|
|
1802
|
+
const packageName = separator > 0 ? value.slice(0, separator).trim() : "";
|
|
1803
|
+
const version = separator > 0 ? value.slice(separator + 1).trim() : "";
|
|
1804
|
+
if (!packageName || !version) {
|
|
1805
|
+
throw new ImprovementCommandError(`${flag} must use <package=version>.`);
|
|
1806
|
+
}
|
|
1807
|
+
return { packageName, version };
|
|
1808
|
+
};
|
|
1809
|
+
const parseArtifactType = (value, flag) => {
|
|
1810
|
+
const allTypes = Object.values(CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS[4]
|
|
1811
|
+
.allowedArtifactTypes);
|
|
1812
|
+
if (allTypes.includes(value)) {
|
|
1813
|
+
return value;
|
|
1814
|
+
}
|
|
1815
|
+
throw new ImprovementCommandError(`${flag} contains an unsupported artifact type.`);
|
|
1816
|
+
};
|
|
1817
|
+
const parseProposalArtifact = (value, flag) => {
|
|
1818
|
+
if (value === "eval")
|
|
1819
|
+
return value;
|
|
1820
|
+
if (value === "prompt" || value === "schema" || value === "tool-metadata") {
|
|
1821
|
+
return value;
|
|
1822
|
+
}
|
|
1823
|
+
if (value === "docdex-retrieval")
|
|
1824
|
+
return value;
|
|
1825
|
+
if (value === CODALI_FINE_TUNE_PROPOSAL_ARTIFACT)
|
|
1826
|
+
return value;
|
|
1827
|
+
if (value === CODALI_MODEL_ROUTER_PROPOSAL_ARTIFACT)
|
|
1828
|
+
return value;
|
|
1829
|
+
throw new ImprovementCommandError(`${flag} must be eval|prompt|schema|tool-metadata|docdex-retrieval|fine-tune|model-router.`);
|
|
1830
|
+
};
|
|
1831
|
+
const parseFineTuneRole = (value, flag) => {
|
|
1832
|
+
const role = normalizeCodaliFineTuneWorkerRole(value);
|
|
1833
|
+
if (role)
|
|
1834
|
+
return role;
|
|
1835
|
+
throw new ImprovementCommandError(`${flag} must be extractor|tool-router|planner|verifier|query-expander|repair|context-refiner|final-synthesizer.`);
|
|
1836
|
+
};
|
|
1837
|
+
const parseAction = (value, flag) => {
|
|
1838
|
+
const actions = [
|
|
1839
|
+
"analyze",
|
|
1840
|
+
"add_eval_replay",
|
|
1841
|
+
"branch_metadata",
|
|
1842
|
+
"create_prerelease_tag",
|
|
1843
|
+
"publish_stable",
|
|
1844
|
+
"export",
|
|
1845
|
+
"training",
|
|
1846
|
+
"auto_tag",
|
|
1847
|
+
"auto_publish",
|
|
1848
|
+
];
|
|
1849
|
+
if (actions.includes(value)) {
|
|
1850
|
+
return value;
|
|
1851
|
+
}
|
|
1852
|
+
throw new ImprovementCommandError(`${flag} contains an unsupported action.`);
|
|
1853
|
+
};
|
|
1854
|
+
export const createDefaultImprovementPolicyJson = () => JSON.stringify(buildCodaliImprovementCliJsonOutput({
|
|
1855
|
+
outputType: "improvement.policy",
|
|
1856
|
+
status: "ok",
|
|
1857
|
+
policy: createCodaliImprovementPolicy({
|
|
1858
|
+
policyId: "default-local-policy",
|
|
1859
|
+
releaseLevel: 0,
|
|
1860
|
+
scope: {
|
|
1861
|
+
tenantHash: DEFAULT_TENANT_HASH,
|
|
1862
|
+
productId: DEFAULT_PRODUCT_ID,
|
|
1863
|
+
},
|
|
1864
|
+
allowedArtifactTypes: [
|
|
1865
|
+
...CODALI_IMPROVEMENT_RELEASE_LEVEL_CONTRACTS[0].allowedArtifactTypes,
|
|
1866
|
+
],
|
|
1867
|
+
maxExamples: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.maxExamples,
|
|
1868
|
+
maxObjectBytes: DEFAULT_CODALI_IMPROVEMENT_POLICY_LIMITS.maxObjectBytes,
|
|
1869
|
+
storageMode: "local_only",
|
|
1870
|
+
exportEnabled: false,
|
|
1871
|
+
trainingEnabled: false,
|
|
1872
|
+
autoTagEnabled: false,
|
|
1873
|
+
autoPublishEnabled: false,
|
|
1874
|
+
metadata: {
|
|
1875
|
+
schemaVersion: CODALI_IMPROVEMENT_CONTRACT_SCHEMA_VERSION,
|
|
1876
|
+
productionGovernance: resolveCodaliProductionGovernance(),
|
|
1877
|
+
},
|
|
1878
|
+
}),
|
|
1879
|
+
}), null, 2);
|