@lumenflow/cli 3.1.2 → 3.1.3
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/README.md +36 -35
- package/dist/agent-issues-query.js +13 -8
- package/dist/agent-log-issue.js +15 -4
- package/dist/agent-session-end.js +15 -4
- package/dist/agent-session.js +18 -6
- package/dist/backlog-prune.js +1 -1
- package/dist/commands/integrate.js +32 -18
- package/dist/config-get.js +27 -15
- package/dist/config-set.js +104 -37
- package/dist/delegation-list.js +1 -1
- package/dist/doctor.js +19 -13
- package/dist/file-delete.js +1 -1
- package/dist/file-edit.js +1 -1
- package/dist/file-read.js +1 -1
- package/dist/file-write.js +1 -1
- package/dist/flow-bottlenecks.js +1 -1
- package/dist/flow-report.js +10 -9
- package/dist/gates.js +3 -2
- package/dist/git-branch.js +1 -1
- package/dist/git-diff.js +1 -1
- package/dist/git-log.js +1 -1
- package/dist/init.js +238 -42
- package/dist/initiative-add-wu.js +1 -1
- package/dist/initiative-bulk-assign-wus.js +1 -1
- package/dist/initiative-create.js +2 -2
- package/dist/initiative-edit.js +1 -1
- package/dist/initiative-list.js +1 -1
- package/dist/initiative-plan.js +1 -3
- package/dist/initiative-status.js +47 -6
- package/dist/lane-edit.js +19 -10
- package/dist/lane-health.js +13 -24
- package/dist/lane-lock.js +4 -5
- package/dist/lane-setup.js +5 -5
- package/dist/lane-status.js +4 -5
- package/dist/lane-suggest.js +9 -7
- package/dist/lane-validate.js +4 -5
- package/dist/lumenflow-upgrade.js +17 -11
- package/dist/mem-checkpoint.js +1 -1
- package/dist/mem-cleanup.js +6 -23
- package/dist/mem-context.js +1 -1
- package/dist/mem-create.js +1 -1
- package/dist/mem-delete.js +1 -1
- package/dist/mem-export.js +1 -1
- package/dist/mem-inbox.js +1 -1
- package/dist/mem-init.js +1 -1
- package/dist/mem-ready.js +1 -1
- package/dist/mem-recover.js +1 -1
- package/dist/mem-signal.js +1 -1
- package/dist/mem-start.js +1 -1
- package/dist/mem-summarize.js +8 -7
- package/dist/mem-triage.js +7 -5
- package/dist/metrics-cli.js +1 -1
- package/dist/metrics-snapshot.js +1 -1
- package/dist/onboard.js +295 -120
- package/dist/orchestrate-init-status.js +12 -7
- package/dist/orchestrate-initiative.js +23 -12
- package/dist/orchestrate-monitor.js +20 -8
- package/dist/pack-scaffold.js +1 -1
- package/dist/plan-create.js +1 -3
- package/dist/plan-edit.js +1 -3
- package/dist/plan-link.js +1 -3
- package/dist/plan-promote.js +1 -3
- package/dist/release.js +1 -3
- package/dist/signal-cleanup.js +4 -18
- package/dist/state-bootstrap.js +11 -8
- package/dist/state-cleanup.js +5 -19
- package/dist/state-doctor.js +213 -9
- package/dist/task-claim.js +1 -1
- package/dist/validate.js +1 -1
- package/dist/workspace-init.js +61 -61
- package/dist/wu-block.js +1 -1
- package/dist/wu-brief.js +1 -1
- package/dist/wu-claim.js +1 -1
- package/dist/wu-cleanup.js +1 -1
- package/dist/wu-create.js +3 -3
- package/dist/wu-delegate.js +1 -1
- package/dist/wu-deps.js +1 -1
- package/dist/wu-done.js +66 -34
- package/dist/wu-edit.js +1 -1
- package/dist/wu-infer-lane.js +1 -1
- package/dist/wu-preflight.js +1 -1
- package/dist/wu-prep.js +1 -1
- package/dist/wu-proto.js +1 -1
- package/dist/wu-prune.js +1 -1
- package/dist/wu-recover.js +1 -1
- package/dist/wu-release.js +1 -1
- package/dist/wu-repair.js +1 -1
- package/dist/wu-sandbox.js +40 -27
- package/dist/wu-status.js +1 -1
- package/dist/wu-unblock.js +1 -1
- package/dist/wu-unlock-lane.js +1 -1
- package/dist/wu-validate.js +1 -1
- package/package.json +12 -8
- package/packs/software-delivery/constants.ts +10 -0
- package/packs/software-delivery/extensions.ts +140 -0
- package/packs/software-delivery/gate-policies.ts +134 -0
- package/packs/software-delivery/index.ts +8 -0
- package/packs/software-delivery/manifest-schema.ts +236 -0
- package/packs/software-delivery/manifest.ts +417 -0
- package/packs/software-delivery/manifest.yaml +711 -0
- package/packs/software-delivery/pack-registration.ts +113 -0
- package/packs/software-delivery/tool-impl/agent-tools.ts +263 -0
- package/packs/software-delivery/tool-impl/delegation-tools.ts +66 -0
- package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +219 -0
- package/packs/software-delivery/tool-impl/git-runner.ts +113 -0
- package/packs/software-delivery/tool-impl/git-tools.ts +316 -0
- package/packs/software-delivery/tool-impl/index.ts +15 -0
- package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +720 -0
- package/packs/software-delivery/tool-impl/lane-lock.ts +246 -0
- package/packs/software-delivery/tool-impl/memory-tools.ts +415 -0
- package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +21 -0
- package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +328 -0
- package/packs/software-delivery/tool-impl/runtime-native-tools.ts +687 -0
- package/packs/software-delivery/tool-impl/worker-loader.ts +52 -0
- package/packs/software-delivery/tool-impl/worktree-tools.ts +46 -0
- package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +759 -0
- package/packs/software-delivery/tools/delegation-tools.ts +23 -0
- package/packs/software-delivery/tools/git-tools.ts +55 -0
- package/packs/software-delivery/tools/index.ts +8 -0
- package/packs/software-delivery/tools/lane-lock-tool.ts +37 -0
- package/packs/software-delivery/tools/types.ts +71 -0
- package/packs/software-delivery/tools/worktree-tools.ts +49 -0
- package/templates/core/LUMENFLOW.md.template +3 -3
- package/templates/core/ai/onboarding/agent-invocation-guide.md.template +1 -1
- package/templates/core/ai/onboarding/lumenflow-force-usage.md.template +1 -1
- package/templates/core/ai/onboarding/quick-ref-commands.md.template +5 -5
- package/templates/core/ai/onboarding/starting-prompt.md.template +3 -3
- package/templates/core/ai/onboarding/vendor-support.md.template +1 -1
- package/templates/core/ai/onboarding/wu-create-checklist.md.template +1 -1
- package/dist/agent-issues-query.js.map +0 -1
- package/dist/agent-log-issue.js.map +0 -1
- package/dist/agent-session-end.js.map +0 -1
- package/dist/agent-session.js.map +0 -1
- package/dist/backlog-prune.js.map +0 -1
- package/dist/cli-entry-point.js +0 -149
- package/dist/cli-entry-point.js.map +0 -1
- package/dist/commands/integrate.js.map +0 -1
- package/dist/commands.js.map +0 -1
- package/dist/config-get.js.map +0 -1
- package/dist/config-set.js.map +0 -1
- package/dist/delegation-list.js.map +0 -1
- package/dist/deps-add.js +0 -259
- package/dist/deps-add.js.map +0 -1
- package/dist/deps-remove.js +0 -105
- package/dist/deps-remove.js.map +0 -1
- package/dist/docs-sync.js.map +0 -1
- package/dist/doctor.js.map +0 -1
- package/dist/file-delete.js.map +0 -1
- package/dist/file-edit.js.map +0 -1
- package/dist/file-read.js.map +0 -1
- package/dist/file-write.js.map +0 -1
- package/dist/flow-bottlenecks.js.map +0 -1
- package/dist/flow-report.js.map +0 -1
- package/dist/formatters.js +0 -151
- package/dist/formatters.js.map +0 -1
- package/dist/gate-defaults.js +0 -131
- package/dist/gate-defaults.js.map +0 -1
- package/dist/gate-registry.js +0 -73
- package/dist/gate-registry.js.map +0 -1
- package/dist/gates-graceful-degradation.js +0 -153
- package/dist/gates-graceful-degradation.js.map +0 -1
- package/dist/gates-plan-resolvers.js +0 -152
- package/dist/gates-plan-resolvers.js.map +0 -1
- package/dist/gates-runners.js +0 -509
- package/dist/gates-runners.js.map +0 -1
- package/dist/gates-types.js +0 -4
- package/dist/gates-types.js.map +0 -1
- package/dist/gates-utils.js +0 -323
- package/dist/gates-utils.js.map +0 -1
- package/dist/gates.js.map +0 -1
- package/dist/git-branch.js.map +0 -1
- package/dist/git-diff.js.map +0 -1
- package/dist/git-log.js.map +0 -1
- package/dist/git-status.js.map +0 -1
- package/dist/guard-locked.js +0 -172
- package/dist/guard-locked.js.map +0 -1
- package/dist/guard-main-branch.js +0 -217
- package/dist/guard-main-branch.js.map +0 -1
- package/dist/guard-worktree-commit.js +0 -163
- package/dist/guard-worktree-commit.js.map +0 -1
- package/dist/hooks/auto-checkpoint-utils.js +0 -54
- package/dist/hooks/auto-checkpoint-utils.js.map +0 -1
- package/dist/hooks/enforcement-checks.js +0 -399
- package/dist/hooks/enforcement-checks.js.map +0 -1
- package/dist/hooks/enforcement-generator.js +0 -139
- package/dist/hooks/enforcement-generator.js.map +0 -1
- package/dist/hooks/enforcement-sync.js +0 -385
- package/dist/hooks/enforcement-sync.js.map +0 -1
- package/dist/hooks/generators/auto-checkpoint.js +0 -125
- package/dist/hooks/generators/auto-checkpoint.js.map +0 -1
- package/dist/hooks/generators/enforce-worktree.js +0 -190
- package/dist/hooks/generators/enforce-worktree.js.map +0 -1
- package/dist/hooks/generators/index.js +0 -18
- package/dist/hooks/generators/index.js.map +0 -1
- package/dist/hooks/generators/pre-compact-checkpoint.js +0 -136
- package/dist/hooks/generators/pre-compact-checkpoint.js.map +0 -1
- package/dist/hooks/generators/require-wu.js +0 -117
- package/dist/hooks/generators/require-wu.js.map +0 -1
- package/dist/hooks/generators/session-start-recovery.js +0 -103
- package/dist/hooks/generators/session-start-recovery.js.map +0 -1
- package/dist/hooks/generators/signal-utils.js +0 -54
- package/dist/hooks/generators/signal-utils.js.map +0 -1
- package/dist/hooks/generators/warn-incomplete.js +0 -67
- package/dist/hooks/generators/warn-incomplete.js.map +0 -1
- package/dist/hooks/index.js +0 -10
- package/dist/hooks/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init-detection.js +0 -232
- package/dist/init-detection.js.map +0 -1
- package/dist/init-lane-validation.js +0 -143
- package/dist/init-lane-validation.js.map +0 -1
- package/dist/init-scaffolding.js +0 -158
- package/dist/init-scaffolding.js.map +0 -1
- package/dist/init-templates.js +0 -1982
- package/dist/init-templates.js.map +0 -1
- package/dist/init.js.map +0 -1
- package/dist/initiative-add-wu.js.map +0 -1
- package/dist/initiative-bulk-assign-wus.js.map +0 -1
- package/dist/initiative-create.js.map +0 -1
- package/dist/initiative-edit.js.map +0 -1
- package/dist/initiative-list.js.map +0 -1
- package/dist/initiative-plan.js.map +0 -1
- package/dist/initiative-remove-wu.js.map +0 -1
- package/dist/initiative-status.js.map +0 -1
- package/dist/lane-edit.js.map +0 -1
- package/dist/lane-health.js.map +0 -1
- package/dist/lane-lifecycle-process.js +0 -366
- package/dist/lane-lifecycle-process.js.map +0 -1
- package/dist/lane-lock.js.map +0 -1
- package/dist/lane-setup.js.map +0 -1
- package/dist/lane-status.js.map +0 -1
- package/dist/lane-suggest.js.map +0 -1
- package/dist/lane-validate.js.map +0 -1
- package/dist/lifecycle-regression-harness.js +0 -181
- package/dist/lifecycle-regression-harness.js.map +0 -1
- package/dist/lumenflow-upgrade.js.map +0 -1
- package/dist/mem-checkpoint.js.map +0 -1
- package/dist/mem-cleanup.js.map +0 -1
- package/dist/mem-context.js.map +0 -1
- package/dist/mem-create.js.map +0 -1
- package/dist/mem-delete.js.map +0 -1
- package/dist/mem-export.js.map +0 -1
- package/dist/mem-inbox.js.map +0 -1
- package/dist/mem-index.js +0 -214
- package/dist/mem-index.js.map +0 -1
- package/dist/mem-init.js.map +0 -1
- package/dist/mem-profile.js +0 -210
- package/dist/mem-profile.js.map +0 -1
- package/dist/mem-promote.js +0 -257
- package/dist/mem-promote.js.map +0 -1
- package/dist/mem-ready.js.map +0 -1
- package/dist/mem-recover.js.map +0 -1
- package/dist/mem-signal.js.map +0 -1
- package/dist/mem-start.js.map +0 -1
- package/dist/mem-summarize.js.map +0 -1
- package/dist/mem-triage.js.map +0 -1
- package/dist/merge-block.js +0 -225
- package/dist/merge-block.js.map +0 -1
- package/dist/metrics-cli.js.map +0 -1
- package/dist/metrics-snapshot.js.map +0 -1
- package/dist/onboard.js.map +0 -1
- package/dist/onboarding-smoke-test.js +0 -418
- package/dist/onboarding-smoke-test.js.map +0 -1
- package/dist/orchestrate-init-status.js.map +0 -1
- package/dist/orchestrate-initiative.js.map +0 -1
- package/dist/orchestrate-monitor.js.map +0 -1
- package/dist/pack-author.js.map +0 -1
- package/dist/pack-hash.js.map +0 -1
- package/dist/pack-install.js.map +0 -1
- package/dist/pack-publish.js.map +0 -1
- package/dist/pack-scaffold.js.map +0 -1
- package/dist/pack-search.js.map +0 -1
- package/dist/pack-validate.js.map +0 -1
- package/dist/plan-create.js.map +0 -1
- package/dist/plan-edit.js.map +0 -1
- package/dist/plan-link.js.map +0 -1
- package/dist/plan-promote.js.map +0 -1
- package/dist/public-manifest.js +0 -920
- package/dist/public-manifest.js.map +0 -1
- package/dist/release.js.map +0 -1
- package/dist/rotate-progress.js +0 -253
- package/dist/rotate-progress.js.map +0 -1
- package/dist/session-coordinator.js +0 -303
- package/dist/session-coordinator.js.map +0 -1
- package/dist/shared-validators.js +0 -81
- package/dist/shared-validators.js.map +0 -1
- package/dist/signal-cleanup.js.map +0 -1
- package/dist/state-bootstrap.js.map +0 -1
- package/dist/state-cleanup.js.map +0 -1
- package/dist/state-doctor-fix.js +0 -226
- package/dist/state-doctor-fix.js.map +0 -1
- package/dist/state-doctor-stamps.js +0 -23
- package/dist/state-doctor-stamps.js.map +0 -1
- package/dist/state-doctor.js.map +0 -1
- package/dist/strict-progress.js +0 -255
- package/dist/strict-progress.js.map +0 -1
- package/dist/sync-templates.js.map +0 -1
- package/dist/task-claim.js.map +0 -1
- package/dist/trace-gen.js +0 -401
- package/dist/trace-gen.js.map +0 -1
- package/dist/validate-agent-skills.js +0 -223
- package/dist/validate-agent-skills.js.map +0 -1
- package/dist/validate-agent-sync.js +0 -151
- package/dist/validate-agent-sync.js.map +0 -1
- package/dist/validate-backlog-sync.js +0 -77
- package/dist/validate-backlog-sync.js.map +0 -1
- package/dist/validate-skills-spec.js +0 -211
- package/dist/validate-skills-spec.js.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/validator-defaults.js +0 -107
- package/dist/validator-defaults.js.map +0 -1
- package/dist/validator-registry.js +0 -71
- package/dist/validator-registry.js.map +0 -1
- package/dist/workspace-init.js.map +0 -1
- package/dist/wu-block.js.map +0 -1
- package/dist/wu-brief.js.map +0 -1
- package/dist/wu-claim-branch.js +0 -123
- package/dist/wu-claim-branch.js.map +0 -1
- package/dist/wu-claim-cloud.js +0 -79
- package/dist/wu-claim-cloud.js.map +0 -1
- package/dist/wu-claim-mode.js +0 -82
- package/dist/wu-claim-mode.js.map +0 -1
- package/dist/wu-claim-output.js +0 -85
- package/dist/wu-claim-output.js.map +0 -1
- package/dist/wu-claim-repair-guidance.js +0 -12
- package/dist/wu-claim-repair-guidance.js.map +0 -1
- package/dist/wu-claim-resume-handler.js +0 -87
- package/dist/wu-claim-resume-handler.js.map +0 -1
- package/dist/wu-claim-state.js +0 -581
- package/dist/wu-claim-state.js.map +0 -1
- package/dist/wu-claim-validation.js +0 -457
- package/dist/wu-claim-validation.js.map +0 -1
- package/dist/wu-claim-worktree.js +0 -223
- package/dist/wu-claim-worktree.js.map +0 -1
- package/dist/wu-claim.js.map +0 -1
- package/dist/wu-cleanup-cloud.js +0 -78
- package/dist/wu-cleanup-cloud.js.map +0 -1
- package/dist/wu-cleanup.js.map +0 -1
- package/dist/wu-code-path-coverage.js +0 -83
- package/dist/wu-code-path-coverage.js.map +0 -1
- package/dist/wu-create-cloud.js +0 -30
- package/dist/wu-create-cloud.js.map +0 -1
- package/dist/wu-create-content.js +0 -264
- package/dist/wu-create-content.js.map +0 -1
- package/dist/wu-create-readiness.js +0 -59
- package/dist/wu-create-readiness.js.map +0 -1
- package/dist/wu-create-validation.js +0 -128
- package/dist/wu-create-validation.js.map +0 -1
- package/dist/wu-create.js.map +0 -1
- package/dist/wu-delegate.js.map +0 -1
- package/dist/wu-delete.js.map +0 -1
- package/dist/wu-deps.js.map +0 -1
- package/dist/wu-done-auto-cleanup.js +0 -203
- package/dist/wu-done-auto-cleanup.js.map +0 -1
- package/dist/wu-done-check.js +0 -38
- package/dist/wu-done-check.js.map +0 -1
- package/dist/wu-done-cloud.js +0 -48
- package/dist/wu-done-cloud.js.map +0 -1
- package/dist/wu-done-decay.js +0 -86
- package/dist/wu-done-decay.js.map +0 -1
- package/dist/wu-done.js.map +0 -1
- package/dist/wu-edit-operations.js +0 -399
- package/dist/wu-edit-operations.js.map +0 -1
- package/dist/wu-edit-validators.js +0 -282
- package/dist/wu-edit-validators.js.map +0 -1
- package/dist/wu-edit.js.map +0 -1
- package/dist/wu-infer-lane.js.map +0 -1
- package/dist/wu-preflight.js.map +0 -1
- package/dist/wu-prep.js.map +0 -1
- package/dist/wu-proto.js.map +0 -1
- package/dist/wu-prune.js.map +0 -1
- package/dist/wu-recover.js.map +0 -1
- package/dist/wu-release.js.map +0 -1
- package/dist/wu-repair.js.map +0 -1
- package/dist/wu-sandbox.js.map +0 -1
- package/dist/wu-spawn-completion.js +0 -33
- package/dist/wu-spawn-completion.js.map +0 -1
- package/dist/wu-spawn-prompt-builders.js +0 -1197
- package/dist/wu-spawn-prompt-builders.js.map +0 -1
- package/dist/wu-spawn-strategy-resolver.js +0 -322
- package/dist/wu-spawn-strategy-resolver.js.map +0 -1
- package/dist/wu-spawn.js +0 -59
- package/dist/wu-spawn.js.map +0 -1
- package/dist/wu-state-cloud.js +0 -41
- package/dist/wu-state-cloud.js.map +0 -1
- package/dist/wu-status.js.map +0 -1
- package/dist/wu-unblock.js.map +0 -1
- package/dist/wu-unlock-lane.js.map +0 -1
- package/dist/wu-validate.js.map +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright (c) 2026 Hellmai Ltd
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import {
|
|
9
|
+
SHA256_ALGORITHM,
|
|
10
|
+
SOFTWARE_DELIVERY_MANIFEST_FILE_NAME,
|
|
11
|
+
UTF8_ENCODING,
|
|
12
|
+
} from './constants.js';
|
|
13
|
+
import { SOFTWARE_DELIVERY_MANIFEST, type SoftwareDeliveryPackManifest } from './manifest.js';
|
|
14
|
+
|
|
15
|
+
const NULL_BYTE_BUFFER = Buffer.from([0]);
|
|
16
|
+
const DEFAULT_EXCLUSIONS = ['node_modules/', '.git/', 'dist/', '.DS_Store'];
|
|
17
|
+
|
|
18
|
+
function getDefaultPackRoot(): string {
|
|
19
|
+
return path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeRelativePath(root: string, absolutePath: string): string {
|
|
23
|
+
return path.relative(root, absolutePath).split(path.sep).join('/');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function shouldExclude(relativePath: string, exclusions: readonly string[]): boolean {
|
|
27
|
+
return exclusions.some((excluded) => {
|
|
28
|
+
if (excluded.endsWith('/')) {
|
|
29
|
+
return relativePath.startsWith(excluded);
|
|
30
|
+
}
|
|
31
|
+
return relativePath === excluded || relativePath.endsWith(`/${excluded}`);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function collectFilesRecursive(root: string, directory: string): Promise<string[]> {
|
|
36
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
37
|
+
const sortedEntries = [...entries].sort((left, right) => left.name.localeCompare(right.name));
|
|
38
|
+
const files: string[] = [];
|
|
39
|
+
|
|
40
|
+
for (const entry of sortedEntries) {
|
|
41
|
+
const absolutePath = path.join(directory, entry.name);
|
|
42
|
+
const relativePath = normalizeRelativePath(root, absolutePath);
|
|
43
|
+
if (entry.isDirectory()) {
|
|
44
|
+
files.push(...(await collectFilesRecursive(root, absolutePath)));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
files.push(relativePath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return files;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function listPackFiles(packRoot: string, exclusions: readonly string[]): Promise<string[]> {
|
|
54
|
+
const absoluteRoot = path.resolve(packRoot);
|
|
55
|
+
const allFiles = await collectFilesRecursive(absoluteRoot, absoluteRoot);
|
|
56
|
+
return allFiles.filter((relativePath) => !shouldExclude(relativePath, exclusions)).sort();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function computeSoftwareDeliveryPackIntegrity(
|
|
60
|
+
packRoot = getDefaultPackRoot(),
|
|
61
|
+
exclusions: readonly string[] = DEFAULT_EXCLUSIONS,
|
|
62
|
+
): Promise<`sha256:${string}`> {
|
|
63
|
+
const absoluteRoot = path.resolve(packRoot);
|
|
64
|
+
const files = await listPackFiles(absoluteRoot, exclusions);
|
|
65
|
+
const digestChunks: Buffer[] = [];
|
|
66
|
+
|
|
67
|
+
for (const relativePath of files) {
|
|
68
|
+
const fileContents = await readFile(path.join(absoluteRoot, relativePath));
|
|
69
|
+
const fileHash = createHash(SHA256_ALGORITHM).update(fileContents).digest('hex');
|
|
70
|
+
digestChunks.push(Buffer.from(relativePath, UTF8_ENCODING));
|
|
71
|
+
digestChunks.push(NULL_BYTE_BUFFER);
|
|
72
|
+
digestChunks.push(Buffer.from(fileHash, UTF8_ENCODING));
|
|
73
|
+
digestChunks.push(NULL_BYTE_BUFFER);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const combinedDigest = createHash(SHA256_ALGORITHM)
|
|
77
|
+
.update(digestChunks.length === 0 ? Buffer.alloc(0) : Buffer.concat(digestChunks))
|
|
78
|
+
.digest('hex');
|
|
79
|
+
|
|
80
|
+
return `sha256:${combinedDigest}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function loadSoftwareDeliveryManifest(
|
|
84
|
+
packRoot = getDefaultPackRoot(),
|
|
85
|
+
): Promise<SoftwareDeliveryPackManifest> {
|
|
86
|
+
const manifestPath = path.join(path.resolve(packRoot), SOFTWARE_DELIVERY_MANIFEST_FILE_NAME);
|
|
87
|
+
await readFile(manifestPath, UTF8_ENCODING);
|
|
88
|
+
return structuredClone(SOFTWARE_DELIVERY_MANIFEST);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface RegisteredSoftwareDeliveryPack {
|
|
92
|
+
manifest: SoftwareDeliveryPackManifest;
|
|
93
|
+
packRoot: string;
|
|
94
|
+
manifestPath: string;
|
|
95
|
+
integrity: `sha256:${string}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function registerSoftwareDeliveryPack(options?: {
|
|
99
|
+
packRoot?: string;
|
|
100
|
+
exclusions?: readonly string[];
|
|
101
|
+
}): Promise<RegisteredSoftwareDeliveryPack> {
|
|
102
|
+
const packRoot = path.resolve(options?.packRoot ?? getDefaultPackRoot());
|
|
103
|
+
const exclusions = options?.exclusions ?? DEFAULT_EXCLUSIONS;
|
|
104
|
+
const manifest = await loadSoftwareDeliveryManifest(packRoot);
|
|
105
|
+
const integrity = await computeSoftwareDeliveryPackIntegrity(packRoot, exclusions);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
manifest,
|
|
109
|
+
packRoot,
|
|
110
|
+
manifestPath: path.join(packRoot, SOFTWARE_DELIVERY_MANIFEST_FILE_NAME),
|
|
111
|
+
integrity,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// Copyright (c) 2026 Hellmai Ltd
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
import type { ToolOutput } from '@lumenflow/kernel';
|
|
5
|
+
import { RUNTIME_CLI_COMMANDS, runtimeCliAdapter } from './runtime-cli-adapter.js';
|
|
6
|
+
|
|
7
|
+
const AGENT_TOOLS = {
|
|
8
|
+
AGENT_SESSION: 'agent:session',
|
|
9
|
+
AGENT_SESSION_END: 'agent:session-end',
|
|
10
|
+
AGENT_LOG_ISSUE: 'agent:log-issue',
|
|
11
|
+
AGENT_ISSUES_QUERY: 'agent:issues-query',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
type AgentToolName = (typeof AGENT_TOOLS)[keyof typeof AGENT_TOOLS];
|
|
15
|
+
|
|
16
|
+
const AGENT_TOOL_ERROR_CODES: Record<AgentToolName, string> = {
|
|
17
|
+
'agent:session': 'AGENT_SESSION_ERROR',
|
|
18
|
+
'agent:session-end': 'AGENT_SESSION_END_ERROR',
|
|
19
|
+
'agent:log-issue': 'AGENT_LOG_ISSUE_ERROR',
|
|
20
|
+
'agent:issues-query': 'AGENT_ISSUES_QUERY_ERROR',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const AGENT_TOOL_COMMANDS: Record<
|
|
24
|
+
AgentToolName,
|
|
25
|
+
(typeof RUNTIME_CLI_COMMANDS)[keyof typeof RUNTIME_CLI_COMMANDS]
|
|
26
|
+
> = {
|
|
27
|
+
'agent:session': RUNTIME_CLI_COMMANDS.AGENT_SESSION,
|
|
28
|
+
'agent:session-end': RUNTIME_CLI_COMMANDS.AGENT_SESSION_END,
|
|
29
|
+
'agent:log-issue': RUNTIME_CLI_COMMANDS.AGENT_LOG_ISSUE,
|
|
30
|
+
'agent:issues-query': RUNTIME_CLI_COMMANDS.AGENT_ISSUES_QUERY,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const MISSING_PARAMETER_MESSAGES = {
|
|
34
|
+
WU_REQUIRED: 'wu is required',
|
|
35
|
+
TIER_REQUIRED: 'tier is required',
|
|
36
|
+
CATEGORY_REQUIRED: 'category is required',
|
|
37
|
+
SEVERITY_REQUIRED: 'severity is required',
|
|
38
|
+
TITLE_REQUIRED: 'title is required',
|
|
39
|
+
DESCRIPTION_REQUIRED: 'description is required',
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
interface CommandExecutionResult {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
status: number;
|
|
45
|
+
stdout: string;
|
|
46
|
+
stderr: string;
|
|
47
|
+
executionError?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function toRecord(input: unknown): Record<string, unknown> {
|
|
51
|
+
if (input && typeof input === 'object') {
|
|
52
|
+
return input as Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function toStringValue(value: unknown): string | null {
|
|
58
|
+
if (typeof value !== 'string') {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const trimmed = value.trim();
|
|
62
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toStringArray(value: unknown): string[] {
|
|
66
|
+
if (!Array.isArray(value)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return value
|
|
70
|
+
.map((entry) => toStringValue(entry))
|
|
71
|
+
.filter((entry): entry is string => entry !== null);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function toIntegerString(value: unknown): string | null {
|
|
75
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
76
|
+
return String(Math.trunc(value));
|
|
77
|
+
}
|
|
78
|
+
if (typeof value === 'string') {
|
|
79
|
+
const trimmed = value.trim();
|
|
80
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function runAgentCommand(
|
|
86
|
+
toolName: AgentToolName,
|
|
87
|
+
args: string[],
|
|
88
|
+
): Promise<CommandExecutionResult> {
|
|
89
|
+
return runtimeCliAdapter.run(AGENT_TOOL_COMMANDS[toolName], args);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function createMissingParameterOutput(message: string): ToolOutput {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
error: {
|
|
96
|
+
code: 'MISSING_PARAMETER',
|
|
97
|
+
message,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function createFailureOutput(
|
|
103
|
+
toolName: AgentToolName,
|
|
104
|
+
execution: CommandExecutionResult,
|
|
105
|
+
): ToolOutput {
|
|
106
|
+
const stderrMessage = execution.stderr.trim();
|
|
107
|
+
const stdoutMessage = execution.stdout.trim();
|
|
108
|
+
const message =
|
|
109
|
+
execution.executionError ??
|
|
110
|
+
(stderrMessage.length > 0
|
|
111
|
+
? stderrMessage
|
|
112
|
+
: stdoutMessage.length > 0
|
|
113
|
+
? stdoutMessage
|
|
114
|
+
: `${toolName} failed`);
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: {
|
|
118
|
+
code: AGENT_TOOL_ERROR_CODES[toolName],
|
|
119
|
+
message,
|
|
120
|
+
details: {
|
|
121
|
+
exit_code: execution.status,
|
|
122
|
+
stdout: execution.stdout,
|
|
123
|
+
stderr: execution.stderr,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function parseJsonOutput(stdout: string): unknown | null {
|
|
130
|
+
const trimmed = stdout.trim();
|
|
131
|
+
if (trimmed.length === 0) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(trimmed) as unknown;
|
|
136
|
+
} catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function createSuccessOutput(
|
|
142
|
+
toolName: AgentToolName,
|
|
143
|
+
execution: CommandExecutionResult,
|
|
144
|
+
): ToolOutput {
|
|
145
|
+
const parsedJson = parseJsonOutput(execution.stdout);
|
|
146
|
+
if (parsedJson !== null) {
|
|
147
|
+
return {
|
|
148
|
+
success: true,
|
|
149
|
+
data: parsedJson,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const message = execution.stdout.trim().length > 0 ? execution.stdout.trim() : `${toolName} ran`;
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
data: {
|
|
157
|
+
message,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function executeAgentTool(toolName: AgentToolName, args: string[]): Promise<ToolOutput> {
|
|
163
|
+
const execution = await runAgentCommand(toolName, args);
|
|
164
|
+
if (!execution.ok) {
|
|
165
|
+
return createFailureOutput(toolName, execution);
|
|
166
|
+
}
|
|
167
|
+
return createSuccessOutput(toolName, execution);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export async function agentSessionTool(input: unknown): Promise<ToolOutput> {
|
|
171
|
+
const parsed = toRecord(input);
|
|
172
|
+
const wu = toStringValue(parsed.wu);
|
|
173
|
+
if (!wu) {
|
|
174
|
+
return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const tier = toIntegerString(parsed.tier);
|
|
178
|
+
if (!tier) {
|
|
179
|
+
return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.TIER_REQUIRED);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const args = ['--wu', wu, '--tier', tier];
|
|
183
|
+
const agentType = toStringValue(parsed.agent_type);
|
|
184
|
+
if (agentType) {
|
|
185
|
+
args.push('--agent-type', agentType);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return executeAgentTool(AGENT_TOOLS.AGENT_SESSION, args);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function agentSessionEndTool(_input: unknown): Promise<ToolOutput> {
|
|
192
|
+
return executeAgentTool(AGENT_TOOLS.AGENT_SESSION_END, []);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function agentLogIssueTool(input: unknown): Promise<ToolOutput> {
|
|
196
|
+
const parsed = toRecord(input);
|
|
197
|
+
const category = toStringValue(parsed.category);
|
|
198
|
+
if (!category) {
|
|
199
|
+
return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.CATEGORY_REQUIRED);
|
|
200
|
+
}
|
|
201
|
+
const severity = toStringValue(parsed.severity);
|
|
202
|
+
if (!severity) {
|
|
203
|
+
return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.SEVERITY_REQUIRED);
|
|
204
|
+
}
|
|
205
|
+
const title = toStringValue(parsed.title);
|
|
206
|
+
if (!title) {
|
|
207
|
+
return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.TITLE_REQUIRED);
|
|
208
|
+
}
|
|
209
|
+
const description = toStringValue(parsed.description);
|
|
210
|
+
if (!description) {
|
|
211
|
+
return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.DESCRIPTION_REQUIRED);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const args = [
|
|
215
|
+
'--category',
|
|
216
|
+
category,
|
|
217
|
+
'--severity',
|
|
218
|
+
severity,
|
|
219
|
+
'--title',
|
|
220
|
+
title,
|
|
221
|
+
'--description',
|
|
222
|
+
description,
|
|
223
|
+
];
|
|
224
|
+
const resolution = toStringValue(parsed.resolution);
|
|
225
|
+
if (resolution) {
|
|
226
|
+
args.push('--resolution', resolution);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for (const tag of toStringArray(parsed.tags)) {
|
|
230
|
+
args.push('--tag', tag);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const step = toStringValue(parsed.step);
|
|
234
|
+
if (step) {
|
|
235
|
+
args.push('--step', step);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
for (const file of toStringArray(parsed.files)) {
|
|
239
|
+
args.push('--file', file);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return executeAgentTool(AGENT_TOOLS.AGENT_LOG_ISSUE, args);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export async function agentIssuesQueryTool(input: unknown): Promise<ToolOutput> {
|
|
246
|
+
const parsed = toRecord(input);
|
|
247
|
+
const args = ['summary'];
|
|
248
|
+
|
|
249
|
+
const since = toIntegerString(parsed.since);
|
|
250
|
+
if (since) {
|
|
251
|
+
args.push('--since', since);
|
|
252
|
+
}
|
|
253
|
+
const category = toStringValue(parsed.category);
|
|
254
|
+
if (category) {
|
|
255
|
+
args.push('--category', category);
|
|
256
|
+
}
|
|
257
|
+
const severity = toStringValue(parsed.severity);
|
|
258
|
+
if (severity) {
|
|
259
|
+
args.push('--severity', severity);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return executeAgentTool(AGENT_TOOLS.AGENT_ISSUES_QUERY, args);
|
|
263
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright (c) 2026 Hellmai Ltd
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
5
|
+
import { appendFile, mkdir } from 'node:fs/promises';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { UTF8_ENCODING } from '../constants.js';
|
|
8
|
+
|
|
9
|
+
export interface RecordDelegationInput {
|
|
10
|
+
parentWuId: string;
|
|
11
|
+
targetWuId: string;
|
|
12
|
+
lane: string;
|
|
13
|
+
registryPath: string;
|
|
14
|
+
lineage?: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RecordDelegationResult {
|
|
18
|
+
success: boolean;
|
|
19
|
+
delegationId: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function migrateLegacyStatePath(registryPath: string): string {
|
|
23
|
+
const normalized = registryPath.replace(/\\/g, '/');
|
|
24
|
+
if (normalized.startsWith('.lumenflow/state/')) {
|
|
25
|
+
return path.join('runtime', 'state', normalized.slice('.lumenflow/state/'.length));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const legacySegment = '/.lumenflow/state/';
|
|
29
|
+
const segmentIndex = normalized.indexOf(legacySegment);
|
|
30
|
+
if (segmentIndex < 0) {
|
|
31
|
+
return registryPath;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [
|
|
35
|
+
normalized.slice(0, segmentIndex),
|
|
36
|
+
'runtime',
|
|
37
|
+
'state',
|
|
38
|
+
normalized.slice(segmentIndex + legacySegment.length),
|
|
39
|
+
]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join('/');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function recordDelegationTool(
|
|
45
|
+
input: RecordDelegationInput,
|
|
46
|
+
): Promise<RecordDelegationResult> {
|
|
47
|
+
const registryPath = migrateLegacyStatePath(input.registryPath);
|
|
48
|
+
const delegationId = `dlg-${input.parentWuId.toLowerCase()}-${input.targetWuId.toLowerCase()}`;
|
|
49
|
+
const entry = {
|
|
50
|
+
id: delegationId,
|
|
51
|
+
parentWuId: input.parentWuId,
|
|
52
|
+
targetWuId: input.targetWuId,
|
|
53
|
+
lane: input.lane,
|
|
54
|
+
lineage: input.lineage ?? [],
|
|
55
|
+
delegatedAt: new Date().toISOString(),
|
|
56
|
+
status: 'pending',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
await mkdir(path.dirname(registryPath), { recursive: true });
|
|
60
|
+
await appendFile(registryPath, `${JSON.stringify(entry)}\n`, UTF8_ENCODING);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
success: true,
|
|
64
|
+
delegationId,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Copyright (c) 2026 Hellmai Ltd
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file flow-metrics-tools.ts
|
|
6
|
+
* @description Software-delivery pack handlers for flow/metrics tools.
|
|
7
|
+
*
|
|
8
|
+
* WU-1905: Migrated from in-process resolver stubs in runtime-tool-resolver.ts
|
|
9
|
+
* to native software-delivery pack handlers.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { ToolOutput } from '@lumenflow/kernel';
|
|
13
|
+
import { RUNTIME_CLI_COMMANDS, runtimeCliAdapter } from './runtime-cli-adapter.js';
|
|
14
|
+
|
|
15
|
+
// --- Tool name constants ---
|
|
16
|
+
|
|
17
|
+
const FLOW_METRICS_TOOLS = {
|
|
18
|
+
FLOW_BOTTLENECKS: 'flow:bottlenecks',
|
|
19
|
+
FLOW_REPORT: 'flow:report',
|
|
20
|
+
METRICS: 'metrics',
|
|
21
|
+
METRICS_SNAPSHOT: 'metrics:snapshot',
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
type FlowMetricsToolName = (typeof FLOW_METRICS_TOOLS)[keyof typeof FLOW_METRICS_TOOLS];
|
|
25
|
+
|
|
26
|
+
// --- Error code mapping ---
|
|
27
|
+
|
|
28
|
+
const FLOW_METRICS_TOOL_ERROR_CODES: Record<FlowMetricsToolName, string> = {
|
|
29
|
+
'flow:bottlenecks': 'FLOW_BOTTLENECKS_ERROR',
|
|
30
|
+
'flow:report': 'FLOW_REPORT_ERROR',
|
|
31
|
+
metrics: 'METRICS_ERROR',
|
|
32
|
+
'metrics:snapshot': 'METRICS_SNAPSHOT_ERROR',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const FLOW_METRICS_TOOL_COMMANDS: Record<
|
|
36
|
+
FlowMetricsToolName,
|
|
37
|
+
(typeof RUNTIME_CLI_COMMANDS)[keyof typeof RUNTIME_CLI_COMMANDS]
|
|
38
|
+
> = {
|
|
39
|
+
'flow:bottlenecks': RUNTIME_CLI_COMMANDS.FLOW_BOTTLENECKS,
|
|
40
|
+
'flow:report': RUNTIME_CLI_COMMANDS.FLOW_REPORT,
|
|
41
|
+
metrics: RUNTIME_CLI_COMMANDS.METRICS,
|
|
42
|
+
'metrics:snapshot': RUNTIME_CLI_COMMANDS.METRICS_SNAPSHOT,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// --- Input helpers ---
|
|
46
|
+
|
|
47
|
+
function toRecord(input: unknown): Record<string, unknown> {
|
|
48
|
+
if (input && typeof input === 'object') {
|
|
49
|
+
return input as Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function toStringValue(value: unknown): string | null {
|
|
55
|
+
if (typeof value !== 'string') {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const trimmed = value.trim();
|
|
59
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function toNumberValue(value: unknown): number | null {
|
|
63
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// --- Command execution ---
|
|
70
|
+
|
|
71
|
+
interface CommandExecutionResult {
|
|
72
|
+
ok: boolean;
|
|
73
|
+
status: number;
|
|
74
|
+
stdout: string;
|
|
75
|
+
stderr: string;
|
|
76
|
+
executionError?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function runFlowMetricsCommand(
|
|
80
|
+
toolName: FlowMetricsToolName,
|
|
81
|
+
args: string[],
|
|
82
|
+
): Promise<CommandExecutionResult> {
|
|
83
|
+
return runtimeCliAdapter.run(FLOW_METRICS_TOOL_COMMANDS[toolName], args);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function createFailureOutput(
|
|
87
|
+
toolName: FlowMetricsToolName,
|
|
88
|
+
execution: CommandExecutionResult,
|
|
89
|
+
): ToolOutput {
|
|
90
|
+
const stderrMessage = execution.stderr.trim();
|
|
91
|
+
const stdoutMessage = execution.stdout.trim();
|
|
92
|
+
const message =
|
|
93
|
+
execution.executionError ??
|
|
94
|
+
(stderrMessage.length > 0
|
|
95
|
+
? stderrMessage
|
|
96
|
+
: stdoutMessage.length > 0
|
|
97
|
+
? stdoutMessage
|
|
98
|
+
: `${toolName} failed`);
|
|
99
|
+
return {
|
|
100
|
+
success: false,
|
|
101
|
+
error: {
|
|
102
|
+
code: FLOW_METRICS_TOOL_ERROR_CODES[toolName],
|
|
103
|
+
message,
|
|
104
|
+
details: {
|
|
105
|
+
exit_code: execution.status,
|
|
106
|
+
stdout: execution.stdout,
|
|
107
|
+
stderr: execution.stderr,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function createSuccessOutput(
|
|
114
|
+
toolName: FlowMetricsToolName,
|
|
115
|
+
execution: CommandExecutionResult,
|
|
116
|
+
): ToolOutput {
|
|
117
|
+
const message = execution.stdout.trim().length > 0 ? execution.stdout.trim() : `${toolName} ran`;
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
data: {
|
|
121
|
+
message,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function executeFlowMetricsTool(
|
|
127
|
+
toolName: FlowMetricsToolName,
|
|
128
|
+
args: string[],
|
|
129
|
+
): Promise<ToolOutput> {
|
|
130
|
+
const execution = await runFlowMetricsCommand(toolName, args);
|
|
131
|
+
if (!execution.ok) {
|
|
132
|
+
return createFailureOutput(toolName, execution);
|
|
133
|
+
}
|
|
134
|
+
return createSuccessOutput(toolName, execution);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// --- Public tool handlers ---
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* flow:bottlenecks handler -- identifies flow bottlenecks via CLI.
|
|
141
|
+
*/
|
|
142
|
+
export async function flowBottlenecksTool(input: unknown): Promise<ToolOutput> {
|
|
143
|
+
const parsed = toRecord(input);
|
|
144
|
+
const args: string[] = [];
|
|
145
|
+
|
|
146
|
+
const limit = toNumberValue(parsed.limit);
|
|
147
|
+
if (limit !== null) {
|
|
148
|
+
args.push('--limit', String(limit));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const format = toStringValue(parsed.format);
|
|
152
|
+
if (format) {
|
|
153
|
+
args.push('--format', format);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return executeFlowMetricsTool(FLOW_METRICS_TOOLS.FLOW_BOTTLENECKS, args);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* flow:report handler -- generates flow metrics report via CLI.
|
|
161
|
+
*/
|
|
162
|
+
export async function flowReportTool(input: unknown): Promise<ToolOutput> {
|
|
163
|
+
const parsed = toRecord(input);
|
|
164
|
+
const args: string[] = [];
|
|
165
|
+
|
|
166
|
+
const start = toStringValue(parsed.start);
|
|
167
|
+
if (start) {
|
|
168
|
+
args.push('--start', start);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const end = toStringValue(parsed.end);
|
|
172
|
+
if (end) {
|
|
173
|
+
args.push('--end', end);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const days = toNumberValue(parsed.days);
|
|
177
|
+
if (days !== null) {
|
|
178
|
+
args.push('--days', String(days));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const format = toStringValue(parsed.format);
|
|
182
|
+
if (format) {
|
|
183
|
+
args.push('--format', format);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return executeFlowMetricsTool(FLOW_METRICS_TOOLS.FLOW_REPORT, args);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* metrics handler -- unified workflow metrics command via CLI.
|
|
191
|
+
*/
|
|
192
|
+
export async function metricsTool(input: unknown): Promise<ToolOutput> {
|
|
193
|
+
const parsed = toRecord(input);
|
|
194
|
+
const args: string[] = [];
|
|
195
|
+
|
|
196
|
+
const subcommand = toStringValue(parsed.subcommand);
|
|
197
|
+
if (subcommand) {
|
|
198
|
+
args.push(subcommand);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const days = toNumberValue(parsed.days);
|
|
202
|
+
if (days !== null) {
|
|
203
|
+
args.push('--days', String(days));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const format = toStringValue(parsed.format);
|
|
207
|
+
if (format) {
|
|
208
|
+
args.push('--format', format);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return executeFlowMetricsTool(FLOW_METRICS_TOOLS.METRICS, args);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* metrics:snapshot handler -- captures metrics snapshot via CLI.
|
|
216
|
+
*/
|
|
217
|
+
export async function metricsSnapshotTool(_input: unknown): Promise<ToolOutput> {
|
|
218
|
+
return executeFlowMetricsTool(FLOW_METRICS_TOOLS.METRICS_SNAPSHOT, []);
|
|
219
|
+
}
|