@zhixuan92/multi-model-agent 4.9.1 → 5.0.1
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 +4 -3
- package/bin/mmagent.mjs +47 -0
- package/package.json +24 -43
- package/postinstall.mjs +8 -0
- package/dist/cli/index.d.ts +0 -62
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -345
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/info.d.ts +0 -22
- package/dist/cli/info.d.ts.map +0 -1
- package/dist/cli/info.js +0 -100
- package/dist/cli/info.js.map +0 -1
- package/dist/cli/logs.d.ts +0 -15
- package/dist/cli/logs.d.ts.map +0 -1
- package/dist/cli/logs.js +0 -102
- package/dist/cli/logs.js.map +0 -1
- package/dist/cli/print-token.d.ts +0 -18
- package/dist/cli/print-token.d.ts.map +0 -1
- package/dist/cli/print-token.js +0 -60
- package/dist/cli/print-token.js.map +0 -1
- package/dist/cli/serve.d.ts +0 -28
- package/dist/cli/serve.d.ts.map +0 -1
- package/dist/cli/serve.js +0 -405
- package/dist/cli/serve.js.map +0 -1
- package/dist/cli/status.d.ts +0 -49
- package/dist/cli/status.d.ts.map +0 -1
- package/dist/cli/status.js +0 -155
- package/dist/cli/status.js.map +0 -1
- package/dist/cli/sync-skills.d.ts +0 -58
- package/dist/cli/sync-skills.d.ts.map +0 -1
- package/dist/cli/sync-skills.js +0 -266
- package/dist/cli/sync-skills.js.map +0 -1
- package/dist/cli/telemetry.d.ts +0 -10
- package/dist/cli/telemetry.d.ts.map +0 -1
- package/dist/cli/telemetry.js +0 -161
- package/dist/cli/telemetry.js.map +0 -1
- package/dist/cli/toggle.d.ts +0 -26
- package/dist/cli/toggle.d.ts.map +0 -1
- package/dist/cli/toggle.js +0 -185
- package/dist/cli/toggle.js.map +0 -1
- package/dist/http/async-dispatch.d.ts +0 -44
- package/dist/http/async-dispatch.d.ts.map +0 -1
- package/dist/http/async-dispatch.js +0 -175
- package/dist/http/async-dispatch.js.map +0 -1
- package/dist/http/auth.d.ts +0 -20
- package/dist/http/auth.d.ts.map +0 -1
- package/dist/http/auth.js +0 -56
- package/dist/http/auth.js.map +0 -1
- package/dist/http/canonicalize-file-paths.d.ts +0 -8
- package/dist/http/canonicalize-file-paths.d.ts.map +0 -1
- package/dist/http/canonicalize-file-paths.js +0 -43
- package/dist/http/canonicalize-file-paths.js.map +0 -1
- package/dist/http/cwd-validator.d.ts +0 -11
- package/dist/http/cwd-validator.d.ts.map +0 -1
- package/dist/http/cwd-validator.js +0 -130
- package/dist/http/cwd-validator.js.map +0 -1
- package/dist/http/errors.d.ts +0 -4
- package/dist/http/errors.d.ts.map +0 -1
- package/dist/http/errors.js +0 -9
- package/dist/http/errors.js.map +0 -1
- package/dist/http/execution-context.d.ts +0 -18
- package/dist/http/execution-context.d.ts.map +0 -1
- package/dist/http/execution-context.js +0 -61
- package/dist/http/execution-context.js.map +0 -1
- package/dist/http/handler-deps.d.ts +0 -19
- package/dist/http/handler-deps.d.ts.map +0 -1
- package/dist/http/handler-deps.js +0 -2
- package/dist/http/handler-deps.js.map +0 -1
- package/dist/http/handlers/control/batch-slice.d.ts +0 -4
- package/dist/http/handlers/control/batch-slice.d.ts.map +0 -1
- package/dist/http/handlers/control/batch-slice.js +0 -40
- package/dist/http/handlers/control/batch-slice.js.map +0 -1
- package/dist/http/handlers/control/batch.d.ts +0 -23
- package/dist/http/handlers/control/batch.d.ts.map +0 -1
- package/dist/http/handlers/control/batch.js +0 -332
- package/dist/http/handlers/control/batch.js.map +0 -1
- package/dist/http/handlers/control/context-blocks.d.ts +0 -22
- package/dist/http/handlers/control/context-blocks.d.ts.map +0 -1
- package/dist/http/handlers/control/context-blocks.js +0 -111
- package/dist/http/handlers/control/context-blocks.js.map +0 -1
- package/dist/http/handlers/introspection/health.d.ts +0 -20
- package/dist/http/handlers/introspection/health.d.ts.map +0 -1
- package/dist/http/handlers/introspection/health.js +0 -18
- package/dist/http/handlers/introspection/health.js.map +0 -1
- package/dist/http/handlers/introspection/status.d.ts +0 -26
- package/dist/http/handlers/introspection/status.d.ts.map +0 -1
- package/dist/http/handlers/introspection/status.js +0 -136
- package/dist/http/handlers/introspection/status.js.map +0 -1
- package/dist/http/handlers/tools/audit.d.ts +0 -4
- package/dist/http/handlers/tools/audit.d.ts.map +0 -1
- package/dist/http/handlers/tools/audit.js +0 -43
- package/dist/http/handlers/tools/audit.js.map +0 -1
- package/dist/http/handlers/tools/debug.d.ts +0 -4
- package/dist/http/handlers/tools/debug.d.ts.map +0 -1
- package/dist/http/handlers/tools/debug.js +0 -43
- package/dist/http/handlers/tools/debug.js.map +0 -1
- package/dist/http/handlers/tools/delegate.d.ts +0 -4
- package/dist/http/handlers/tools/delegate.d.ts.map +0 -1
- package/dist/http/handlers/tools/delegate.js +0 -43
- package/dist/http/handlers/tools/delegate.js.map +0 -1
- package/dist/http/handlers/tools/execute-plan.d.ts +0 -4
- package/dist/http/handlers/tools/execute-plan.d.ts.map +0 -1
- package/dist/http/handlers/tools/execute-plan.js +0 -45
- package/dist/http/handlers/tools/execute-plan.js.map +0 -1
- package/dist/http/handlers/tools/investigate.d.ts +0 -4
- package/dist/http/handlers/tools/investigate.d.ts.map +0 -1
- package/dist/http/handlers/tools/investigate.js +0 -64
- package/dist/http/handlers/tools/investigate.js.map +0 -1
- package/dist/http/handlers/tools/journal-recall.d.ts +0 -4
- package/dist/http/handlers/tools/journal-recall.d.ts.map +0 -1
- package/dist/http/handlers/tools/journal-recall.js +0 -40
- package/dist/http/handlers/tools/journal-recall.js.map +0 -1
- package/dist/http/handlers/tools/journal-record.d.ts +0 -4
- package/dist/http/handlers/tools/journal-record.d.ts.map +0 -1
- package/dist/http/handlers/tools/journal-record.js +0 -35
- package/dist/http/handlers/tools/journal-record.js.map +0 -1
- package/dist/http/handlers/tools/research.d.ts +0 -4
- package/dist/http/handlers/tools/research.d.ts.map +0 -1
- package/dist/http/handlers/tools/research.js +0 -64
- package/dist/http/handlers/tools/research.js.map +0 -1
- package/dist/http/handlers/tools/retry.d.ts +0 -4
- package/dist/http/handlers/tools/retry.d.ts.map +0 -1
- package/dist/http/handlers/tools/retry.js +0 -73
- package/dist/http/handlers/tools/retry.js.map +0 -1
- package/dist/http/handlers/tools/review.d.ts +0 -4
- package/dist/http/handlers/tools/review.d.ts.map +0 -1
- package/dist/http/handlers/tools/review.js +0 -43
- package/dist/http/handlers/tools/review.js.map +0 -1
- package/dist/http/middleware/body-reader.d.ts +0 -16
- package/dist/http/middleware/body-reader.d.ts.map +0 -1
- package/dist/http/middleware/body-reader.js +0 -44
- package/dist/http/middleware/body-reader.js.map +0 -1
- package/dist/http/middleware/caller-identity.d.ts +0 -16
- package/dist/http/middleware/caller-identity.d.ts.map +0 -1
- package/dist/http/middleware/caller-identity.js +0 -16
- package/dist/http/middleware/caller-identity.js.map +0 -1
- package/dist/http/middleware/decompress.d.ts +0 -14
- package/dist/http/middleware/decompress.d.ts.map +0 -1
- package/dist/http/middleware/decompress.js +0 -51
- package/dist/http/middleware/decompress.js.map +0 -1
- package/dist/http/project-registry.d.ts +0 -54
- package/dist/http/project-registry.d.ts.map +0 -1
- package/dist/http/project-registry.js +0 -130
- package/dist/http/project-registry.js.map +0 -1
- package/dist/http/request-observability.d.ts +0 -8
- package/dist/http/request-observability.d.ts.map +0 -1
- package/dist/http/request-observability.js +0 -20
- package/dist/http/request-observability.js.map +0 -1
- package/dist/http/request-pipeline.d.ts +0 -16
- package/dist/http/request-pipeline.d.ts.map +0 -1
- package/dist/http/request-pipeline.js +0 -144
- package/dist/http/request-pipeline.js.map +0 -1
- package/dist/http/server.d.ts +0 -17
- package/dist/http/server.d.ts.map +0 -1
- package/dist/http/server.js +0 -300
- package/dist/http/server.js.map +0 -1
- package/dist/http/types.d.ts +0 -20
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -2
- package/dist/http/types.js.map +0 -1
- package/dist/skill-install/disabled-state.d.ts +0 -35
- package/dist/skill-install/disabled-state.d.ts.map +0 -1
- package/dist/skill-install/disabled-state.js +0 -96
- package/dist/skill-install/disabled-state.js.map +0 -1
- package/dist/skill-install/discover.d.ts +0 -29
- package/dist/skill-install/discover.d.ts.map +0 -1
- package/dist/skill-install/discover.js +0 -104
- package/dist/skill-install/discover.js.map +0 -1
- package/dist/skill-install/include-utils.d.ts +0 -27
- package/dist/skill-install/include-utils.d.ts.map +0 -1
- package/dist/skill-install/include-utils.js +0 -90
- package/dist/skill-install/include-utils.js.map +0 -1
- package/dist/skill-install/manifest.d.ts +0 -82
- package/dist/skill-install/manifest.d.ts.map +0 -1
- package/dist/skill-install/manifest.js +0 -215
- package/dist/skill-install/manifest.js.map +0 -1
- package/dist/skill-install/skill-installer-common.d.ts +0 -26
- package/dist/skill-install/skill-installer-common.d.ts.map +0 -1
- package/dist/skill-install/skill-installer-common.js +0 -139
- package/dist/skill-install/skill-installer-common.js.map +0 -1
- package/dist/skill-install/skill-installers/claude-code.d.ts +0 -43
- package/dist/skill-install/skill-installers/claude-code.d.ts.map +0 -1
- package/dist/skill-install/skill-installers/claude-code.js +0 -65
- package/dist/skill-install/skill-installers/claude-code.js.map +0 -1
- package/dist/skill-install/skill-installers/codex-cli.d.ts +0 -27
- package/dist/skill-install/skill-installers/codex-cli.d.ts.map +0 -1
- package/dist/skill-install/skill-installers/codex-cli.js +0 -84
- package/dist/skill-install/skill-installers/codex-cli.js.map +0 -1
- package/dist/skill-install/skill-installers/cursor.d.ts +0 -72
- package/dist/skill-install/skill-installers/cursor.d.ts.map +0 -1
- package/dist/skill-install/skill-installers/cursor.js +0 -81
- package/dist/skill-install/skill-installers/cursor.js.map +0 -1
- package/dist/skill-install/skill-installers/gemini-cli.d.ts +0 -50
- package/dist/skill-install/skill-installers/gemini-cli.d.ts.map +0 -1
- package/dist/skill-install/skill-installers/gemini-cli.js +0 -72
- package/dist/skill-install/skill-installers/gemini-cli.js.map +0 -1
- package/dist/skill-install/skill-manifest-sync.d.ts +0 -11
- package/dist/skill-install/skill-manifest-sync.d.ts.map +0 -1
- package/dist/skill-install/skill-manifest-sync.js +0 -65
- package/dist/skill-install/skill-manifest-sync.js.map +0 -1
- package/dist/skills/_shared/auth.md +0 -41
- package/dist/skills/_shared/error-handling.md +0 -31
- package/dist/skills/_shared/polling.md +0 -88
- package/dist/skills/_shared/response-shape.md +0 -55
- package/dist/skills/_shared/review-policy.md +0 -15
- package/dist/skills/mma-audit/SKILL.md +0 -270
- package/dist/skills/mma-context-blocks/SKILL.md +0 -148
- package/dist/skills/mma-debug/SKILL.md +0 -208
- package/dist/skills/mma-delegate/SKILL.md +0 -216
- package/dist/skills/mma-execute-plan/SKILL.md +0 -214
- package/dist/skills/mma-explore/SKILL.md +0 -190
- package/dist/skills/mma-investigate/SKILL.md +0 -258
- package/dist/skills/mma-journal-recall/SKILL.md +0 -242
- package/dist/skills/mma-journal-record/SKILL.md +0 -189
- package/dist/skills/mma-research/SKILL.md +0 -223
- package/dist/skills/mma-retry/SKILL.md +0 -221
- package/dist/skills/mma-review/SKILL.md +0 -209
- package/dist/skills/multi-model-agent/SKILL.md +0 -206
- package/dist/telemetry/consent.d.ts +0 -4
- package/dist/telemetry/consent.d.ts.map +0 -1
- package/dist/telemetry/consent.js +0 -40
- package/dist/telemetry/consent.js.map +0 -1
- package/dist/telemetry/flusher.d.ts +0 -19
- package/dist/telemetry/flusher.d.ts.map +0 -1
- package/dist/telemetry/flusher.js +0 -277
- package/dist/telemetry/flusher.js.map +0 -1
- package/dist/telemetry/generation.d.ts +0 -9
- package/dist/telemetry/generation.d.ts.map +0 -1
- package/dist/telemetry/generation.js +0 -33
- package/dist/telemetry/generation.js.map +0 -1
- package/dist/telemetry/identity.d.ts +0 -9
- package/dist/telemetry/identity.d.ts.map +0 -1
- package/dist/telemetry/identity.js +0 -35
- package/dist/telemetry/identity.js.map +0 -1
- package/dist/telemetry/install-id.d.ts +0 -13
- package/dist/telemetry/install-id.d.ts.map +0 -1
- package/dist/telemetry/install-id.js +0 -49
- package/dist/telemetry/install-id.js.map +0 -1
- package/dist/telemetry/install-meta.d.ts +0 -10
- package/dist/telemetry/install-meta.d.ts.map +0 -1
- package/dist/telemetry/install-meta.js +0 -15
- package/dist/telemetry/install-meta.js.map +0 -1
- package/dist/telemetry/queue.d.ts +0 -35
- package/dist/telemetry/queue.d.ts.map +0 -1
- package/dist/telemetry/queue.js +0 -287
- package/dist/telemetry/queue.js.map +0 -1
- package/dist/telemetry/recorder.d.ts +0 -39
- package/dist/telemetry/recorder.d.ts.map +0 -1
- package/dist/telemetry/recorder.js +0 -173
- package/dist/telemetry/recorder.js.map +0 -1
- package/scripts/postinstall.js +0 -36
package/dist/cli/toggle.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* toggle.ts — `mmagent disable` / `mmagent enable` subcommands.
|
|
3
|
-
*
|
|
4
|
-
* disable: remove every shipped skill from the resolved clients, drop their
|
|
5
|
-
* manifest entries, and record a sticky sentinel so a later `npm install`
|
|
6
|
-
* postinstall (which shells out to `sync-skills`) does not silently
|
|
7
|
-
* reinstall them. This is the only "off switch" that survives an upgrade.
|
|
8
|
-
* enable: clear the sentinel for the resolved clients, then run the normal
|
|
9
|
-
* sync-skills upsert to reinstall the skills.
|
|
10
|
-
*
|
|
11
|
-
* Both reuse sync-skills' target resolution so `--target` / `--all-targets`
|
|
12
|
-
* behave identically across all three commands.
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* mmagent disable [--target=<client>] [--all-targets] [--dry-run] [--json]
|
|
16
|
-
* mmagent enable [--target=<client>] [--all-targets] [--dry-run] [--json]
|
|
17
|
-
*
|
|
18
|
-
* Exit codes:
|
|
19
|
-
* 0 — success (or no clients detected)
|
|
20
|
-
* 1 — one or more skills failed to remove
|
|
21
|
-
* 3 — explicit --target was not a known client
|
|
22
|
-
*/
|
|
23
|
-
import * as os from 'node:os';
|
|
24
|
-
import minimist from 'minimist';
|
|
25
|
-
import { removeEntry, ALL_CLIENTS } from '../skill-install/manifest.js';
|
|
26
|
-
import { SUPPORTED_SKILLS } from '../skill-install/discover.js';
|
|
27
|
-
import { removeSkillFromClient, UnknownTargetError, } from '../skill-install/skill-installer-common.js';
|
|
28
|
-
import { addDisabledTargets, clearDisabledTargets, disabledTargets, } from '../skill-install/disabled-state.js';
|
|
29
|
-
import { resolveTargets, runSyncSkills } from './sync-skills.js';
|
|
30
|
-
export const ToggleExitCode = Object.freeze({
|
|
31
|
-
SUCCESS: 0,
|
|
32
|
-
ERR_PARTIAL: 1,
|
|
33
|
-
ERR_UNKNOWN_TARGET: 3,
|
|
34
|
-
});
|
|
35
|
-
function parseToggleArgs(argv) {
|
|
36
|
-
const args = minimist(argv, {
|
|
37
|
-
string: ['target'],
|
|
38
|
-
boolean: ['dry-run', 'json', 'all-targets'],
|
|
39
|
-
alias: { t: 'target', j: 'json' },
|
|
40
|
-
});
|
|
41
|
-
let targets = null;
|
|
42
|
-
if (args.target) {
|
|
43
|
-
const t = Array.isArray(args.target) ? args.target : [args.target];
|
|
44
|
-
targets = t.map((s) => s);
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
targets,
|
|
48
|
-
allTargets: args['all-targets'] === true,
|
|
49
|
-
dryRun: args['dry-run'] === true,
|
|
50
|
-
json: args['json'] === true,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* `mmagent disable` — remove all MMA skills from the resolved clients and
|
|
55
|
-
* record the sticky sentinel.
|
|
56
|
-
*/
|
|
57
|
-
export async function runDisable(deps = {}) {
|
|
58
|
-
const argv = deps.argv ?? process.argv.slice(2);
|
|
59
|
-
const homeDir = deps.homeDir ?? os.homedir();
|
|
60
|
-
const stdout = deps.stdout ?? process.stdout.write.bind(process.stdout);
|
|
61
|
-
const stderr = deps.stderr ?? process.stderr.write.bind(process.stderr);
|
|
62
|
-
const cliVersion = deps.cliVersion ?? 'unknown';
|
|
63
|
-
const parsed = parseToggleArgs(argv);
|
|
64
|
-
let targets;
|
|
65
|
-
try {
|
|
66
|
-
targets = resolveTargets(parsed.targets, parsed.allTargets, homeDir);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
if (err instanceof UnknownTargetError) {
|
|
70
|
-
stderr(`mmagent disable: ${err.message}\n`);
|
|
71
|
-
return ToggleExitCode.ERR_UNKNOWN_TARGET;
|
|
72
|
-
}
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
75
|
-
if (targets.length === 0) {
|
|
76
|
-
if (parsed.json) {
|
|
77
|
-
stdout(JSON.stringify({ action: 'disable', targets: [], outcome: 'no-clients-detected' }) + '\n');
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
stdout('No clients detected. Use --target=<client> or --all-targets.\n');
|
|
81
|
-
}
|
|
82
|
-
return ToggleExitCode.SUCCESS;
|
|
83
|
-
}
|
|
84
|
-
const removed = [];
|
|
85
|
-
const errors = [];
|
|
86
|
-
if (parsed.dryRun) {
|
|
87
|
-
for (const target of targets) {
|
|
88
|
-
for (const skill of SUPPORTED_SKILLS)
|
|
89
|
-
removed.push({ skill, target });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
for (const target of targets) {
|
|
94
|
-
for (const skill of SUPPORTED_SKILLS) {
|
|
95
|
-
try {
|
|
96
|
-
removeSkillFromClient(skill, target, homeDir);
|
|
97
|
-
removed.push({ skill, target });
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
errors.push({
|
|
101
|
-
skill,
|
|
102
|
-
target,
|
|
103
|
-
reason: err instanceof Error ? err.message : String(err),
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
for (const skill of SUPPORTED_SKILLS)
|
|
109
|
-
removeEntry(skill, targets, homeDir);
|
|
110
|
-
addDisabledTargets(homeDir, targets, cliVersion);
|
|
111
|
-
}
|
|
112
|
-
if (parsed.json) {
|
|
113
|
-
stdout(JSON.stringify({
|
|
114
|
-
action: 'disable',
|
|
115
|
-
dryRun: parsed.dryRun,
|
|
116
|
-
targets,
|
|
117
|
-
removed: removed.length,
|
|
118
|
-
errors,
|
|
119
|
-
}) + '\n');
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
const verb = parsed.dryRun ? 'Would disable' : 'Disabled';
|
|
123
|
-
const errClause = errors.length > 0 ? `, ${errors.length} errors` : '';
|
|
124
|
-
stdout(`${verb} MMA skills → ${targets.join(', ')} (${removed.length} removed${errClause}).\n`);
|
|
125
|
-
if (!parsed.dryRun)
|
|
126
|
-
stdout('Run `mmagent enable` to restore.\n');
|
|
127
|
-
for (const e of errors)
|
|
128
|
-
stderr(`error: ${e.skill} → ${e.target}: ${e.reason}\n`);
|
|
129
|
-
}
|
|
130
|
-
return errors.length > 0 ? ToggleExitCode.ERR_PARTIAL : ToggleExitCode.SUCCESS;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* `mmagent enable` — clear the sentinel for the resolved clients, then
|
|
134
|
-
* delegate to sync-skills' idempotent upsert to reinstall the skills.
|
|
135
|
-
*/
|
|
136
|
-
export async function runEnable(deps = {}) {
|
|
137
|
-
const argv = deps.argv ?? process.argv.slice(2);
|
|
138
|
-
const homeDir = deps.homeDir ?? os.homedir();
|
|
139
|
-
const stdout = deps.stdout ?? process.stdout.write.bind(process.stdout);
|
|
140
|
-
const stderr = deps.stderr ?? process.stderr.write.bind(process.stderr);
|
|
141
|
-
const parsed = parseToggleArgs(argv);
|
|
142
|
-
let targets;
|
|
143
|
-
try {
|
|
144
|
-
targets = resolveTargets(parsed.targets, parsed.allTargets, homeDir);
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
if (err instanceof UnknownTargetError) {
|
|
148
|
-
stderr(`mmagent enable: ${err.message}\n`);
|
|
149
|
-
return ToggleExitCode.ERR_UNKNOWN_TARGET;
|
|
150
|
-
}
|
|
151
|
-
throw err;
|
|
152
|
-
}
|
|
153
|
-
const wasDisabled = disabledTargets(homeDir);
|
|
154
|
-
const bare = parsed.targets === null && !parsed.allTargets;
|
|
155
|
-
// Clear the sentinel BEFORE syncing — otherwise sync-skills would see the
|
|
156
|
-
// targets as still-disabled and skip them. On --dry-run, leave it intact.
|
|
157
|
-
if (!parsed.dryRun) {
|
|
158
|
-
// No explicit --target means "re-enable everything", so clear the whole set.
|
|
159
|
-
const toClear = bare ? [...ALL_CLIENTS] : targets;
|
|
160
|
-
clearDisabledTargets(homeDir, toClear);
|
|
161
|
-
}
|
|
162
|
-
if (wasDisabled.length === 0) {
|
|
163
|
-
stdout('MMA skills were not disabled; syncing to ensure they are installed.\n');
|
|
164
|
-
}
|
|
165
|
-
// Reinstall via the canonical upsert. For a bare `enable`, sync-skills would
|
|
166
|
-
// otherwise touch only auto-detected clients (claude-code / codex) and skip
|
|
167
|
-
// a previously `disable --target=cursor` — un-pinning it without restoring
|
|
168
|
-
// it. So when no explicit target is given, sync the union of detected
|
|
169
|
-
// clients and whatever was pinned off, making `enable` actually restore what
|
|
170
|
-
// `disable` removed. Explicit --target / --all-targets pass straight through.
|
|
171
|
-
let syncArgv = argv;
|
|
172
|
-
if (bare && wasDisabled.length > 0) {
|
|
173
|
-
const detected = resolveTargets(null, false, homeDir);
|
|
174
|
-
const union = ALL_CLIENTS.filter((c) => detected.includes(c) || wasDisabled.includes(c));
|
|
175
|
-
syncArgv = [...argv, ...union.map((c) => `--target=${c}`)];
|
|
176
|
-
}
|
|
177
|
-
return runSyncSkills({
|
|
178
|
-
argv: syncArgv,
|
|
179
|
-
homeDir,
|
|
180
|
-
skillsRoot: deps.skillsRoot,
|
|
181
|
-
stdout: deps.stdout,
|
|
182
|
-
stderr: deps.stderr,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
//# sourceMappingURL=toggle.js.map
|
package/dist/cli/toggle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.js","sourceRoot":"","sources":["../../src/cli/to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EAAE,CAAC;QAC7B,MAAM,CAAC,uEAAuE,CAAC,CAAC;IAClF,CAAC;IAED,6EAA6E;IAC7E,4EAA4E;IAC5E,2EAA2E;IAC3E,sEAAsE;IACtE,6EAA6E;IAC7E,8EAA8E;IAC9E,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,IAAI,IAAI,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACzF,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,aAAa,CAAC;QACnB,IAAI,EAAE,QAAQ;QACd,OAAO;QACP,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { BatchRegistry, ProjectContext } from '@zhixuan92/multi-model-agent-core';
|
|
2
|
-
import type { ExecutionContext } from '@zhixuan92/multi-model-agent-core';
|
|
3
|
-
import type { HandlerDeps } from './handler-deps.js';
|
|
4
|
-
export interface AsyncDispatchOptions<TResult> {
|
|
5
|
-
tool: string;
|
|
6
|
-
projectCwd: string;
|
|
7
|
-
blockIds: string[];
|
|
8
|
-
batchRegistry: BatchRegistry;
|
|
9
|
-
projectContext: ProjectContext;
|
|
10
|
-
deps: HandlerDeps;
|
|
11
|
-
/**
|
|
12
|
-
* Caller identity from the x-mma-client request header. Threaded into
|
|
13
|
-
* ExecutionContext so the cloud `task.completed` event carries the client.
|
|
14
|
-
* Without this the wire event has an empty string and the backend rejects
|
|
15
|
-
* the upload (STRICT_ID_REGEX). triggeringSkill was dropped because it's
|
|
16
|
-
* implied by `route` for the 99% case (mma-<route> → /<route>).
|
|
17
|
-
*/
|
|
18
|
-
caller?: {
|
|
19
|
-
client: string;
|
|
20
|
-
mainModel?: string | null;
|
|
21
|
-
};
|
|
22
|
-
reviewPolicy?: 'full' | 'quality_only' | 'diff_only' | 'none';
|
|
23
|
-
/**
|
|
24
|
-
* The async function that does the real work. Receives the ExecutionContext
|
|
25
|
-
* and the pre-allocated batchId.
|
|
26
|
-
*/
|
|
27
|
-
executor: (ctx: ExecutionContext, batchId: string) => Promise<TResult>;
|
|
28
|
-
}
|
|
29
|
-
export interface AsyncDispatchResult {
|
|
30
|
-
batchId: string;
|
|
31
|
-
statusUrl: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Registers a new batch as 'pending', schedules the executor via setImmediate,
|
|
35
|
-
* and returns immediately with { batchId, statusUrl }.
|
|
36
|
-
*
|
|
37
|
-
* On success: calls batchRegistry.complete(batchId, result).
|
|
38
|
-
* On failure: calls batchRegistry.fail(batchId, { code, message, stack }).
|
|
39
|
-
*
|
|
40
|
-
* IMPORTANT: Does NOT maintain a manual activeBatches counter.
|
|
41
|
-
* Use BatchRegistry.countActiveForProject(cwd) as the truth source.
|
|
42
|
-
*/
|
|
43
|
-
export declare function asyncDispatch<TResult>(opts: AsyncDispatchOptions<TResult>): AsyncDispatchResult;
|
|
44
|
-
//# sourceMappingURL=async-dispatch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-dispatch.d.ts","sourceRoot":"","sources":["../../src/http/async-dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAG1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,WAAW,oBAAoB,CAAC,OAAO;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACvD,YAAY,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,WAAW,GAAG,MAAM,CAAC;IAC9D;;;OAGG;IACH,QAAQ,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,EACnC,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,mBAAmB,CA8HrB"}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// packages/server/src/http/async-dispatch.ts
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { TaskEnvelopeStore } from '@zhixuan92/multi-model-agent-core/events/task-envelope';
|
|
4
|
-
import { buildExecutionContext } from './execution-context.js';
|
|
5
|
-
/**
|
|
6
|
-
* Registers a new batch as 'pending', schedules the executor via setImmediate,
|
|
7
|
-
* and returns immediately with { batchId, statusUrl }.
|
|
8
|
-
*
|
|
9
|
-
* On success: calls batchRegistry.complete(batchId, result).
|
|
10
|
-
* On failure: calls batchRegistry.fail(batchId, { code, message, stack }).
|
|
11
|
-
*
|
|
12
|
-
* IMPORTANT: Does NOT maintain a manual activeBatches counter.
|
|
13
|
-
* Use BatchRegistry.countActiveForProject(cwd) as the truth source.
|
|
14
|
-
*/
|
|
15
|
-
export function asyncDispatch(opts) {
|
|
16
|
-
const batchId = randomUUID();
|
|
17
|
-
const { batchRegistry, projectContext, deps, tool, projectCwd, blockIds } = opts;
|
|
18
|
-
// Register entry as 'pending' before scheduling executor
|
|
19
|
-
batchRegistry.register({
|
|
20
|
-
batchId,
|
|
21
|
-
projectCwd,
|
|
22
|
-
tool,
|
|
23
|
-
state: 'pending',
|
|
24
|
-
startedAt: Date.now(),
|
|
25
|
-
stateChangedAt: Date.now(),
|
|
26
|
-
blockIds,
|
|
27
|
-
blocksReleased: false,
|
|
28
|
-
});
|
|
29
|
-
// Create and attach envelope to registry
|
|
30
|
-
const envelope = TaskEnvelopeStore.create({
|
|
31
|
-
taskId: batchId + ':' + 0,
|
|
32
|
-
batchId: batchId, taskIndex: 0,
|
|
33
|
-
route: tool, agentType: 'standard',
|
|
34
|
-
client: opts.caller?.client ?? '', mainModel: opts.caller?.mainModel ?? '', cwd: projectCwd,
|
|
35
|
-
reviewPolicy: opts.reviewPolicy ?? 'full',
|
|
36
|
-
}, deps.bus);
|
|
37
|
-
batchRegistry.attachEnvelope(batchId, 0, envelope);
|
|
38
|
-
// Build execution context for this batch
|
|
39
|
-
const ctx = buildExecutionContext(deps, projectContext, batchId, envelope, tool, opts.caller);
|
|
40
|
-
// Schedule executor asynchronously — do not await here
|
|
41
|
-
const startedAtMs = Date.now();
|
|
42
|
-
setImmediate(() => {
|
|
43
|
-
void (async () => {
|
|
44
|
-
try {
|
|
45
|
-
// Mark the batch as running so /batch/:id polling reports
|
|
46
|
-
// "1/1 running, Xs elapsed" the instant the executor begins.
|
|
47
|
-
// Without bumping the headline snapshot here, the polling endpoint
|
|
48
|
-
// returns the initial "0/N queued" fallback until the runner's first
|
|
49
|
-
// heartbeat arrives — which can be many seconds (or minutes) later
|
|
50
|
-
// because heartbeats fire from inside provider.run. That gap is what
|
|
51
|
-
// made 4.0.1 audits look like the daemon was deadlocked when the
|
|
52
|
-
// only thing actually slow was the LLM call.
|
|
53
|
-
const entry = batchRegistry.get(batchId);
|
|
54
|
-
if (entry) {
|
|
55
|
-
entry.tasksTotal = 1;
|
|
56
|
-
entry.tasksStarted = 1;
|
|
57
|
-
entry.tasksCompleted = 0;
|
|
58
|
-
// Use the route's stage-order denominator (3 for audit, 7 for
|
|
59
|
-
// delegate, etc.) so polling shows "Implementing (1/3)" the
|
|
60
|
-
// instant the executor starts — instead of an opaque
|
|
61
|
-
// "1/1 running" that doesn't tell the main agent how far along
|
|
62
|
-
// the lifecycle has progressed.
|
|
63
|
-
// Headline seeding moved to envelope creation in T7-T11 migration —
|
|
64
|
-
// each TaskEnvelope's headline is derived on every mutation, and
|
|
65
|
-
// BatchRegistry no longer caches snapshot objects.
|
|
66
|
-
}
|
|
67
|
-
// 4.6.0+: always-on verbose breadcrumb so operators tailing the daemon
|
|
68
|
-
// see the executor lifecycle past request_received without grepping the
|
|
69
|
-
// JSONL log.
|
|
70
|
-
process.stderr.write(`[mmagent] event=executor_started ts=${new Date().toISOString()} batch=${batchId} route=${tool}\n`);
|
|
71
|
-
const result = await opts.executor(ctx, batchId);
|
|
72
|
-
const resultObj = result;
|
|
73
|
-
const entryAfter = batchRegistry.get(batchId);
|
|
74
|
-
if (entryAfter) {
|
|
75
|
-
// For multi-task batches the executor bumped tasksTotal from the
|
|
76
|
-
// placeholder of 1 to the real fan-out width. Mark every task as
|
|
77
|
-
// completed so the live/terminal headline reports n/n complete.
|
|
78
|
-
entryAfter.tasksCompleted = Math.max(entryAfter.tasksTotal ?? 1, 1);
|
|
79
|
-
}
|
|
80
|
-
const taskCount = Array.isArray(resultObj?.results) ? resultObj.results.length : 0;
|
|
81
|
-
const durationMs = Date.now() - startedAtMs;
|
|
82
|
-
// Gap 5 fix (4.0.3+): inspect the envelope for structured failure
|
|
83
|
-
// signals. The executor may catch errors and package them into a
|
|
84
|
-
// result envelope (with structuredError or status='error') instead
|
|
85
|
-
// of throwing — without this check, batch_completed fires
|
|
86
|
-
// misleadingly while the verbose log gives operators no signal
|
|
87
|
-
// that anything went wrong. Detection uses STRUCTURED FIELDS ONLY,
|
|
88
|
-
// never string comparisons.
|
|
89
|
-
//
|
|
90
|
-
// Order matters: detect failure FIRST, then call complete() or
|
|
91
|
-
// fail() exactly once. Pre-fix, complete() ran unconditionally
|
|
92
|
-
// before fail() — the fail() then no-op'd because the registry
|
|
93
|
-
// entry was already terminal, leaving the wire error field stuck
|
|
94
|
-
// at "not_applicable" even when detectFailure returned a real
|
|
95
|
-
// failure. Probe I (multi-task /delegate) hit this every time.
|
|
96
|
-
const failure = detectFailure(resultObj);
|
|
97
|
-
if (failure) {
|
|
98
|
-
batchRegistry.fail(batchId, failure);
|
|
99
|
-
deps.bus.emitPlainEntry({ ts: new Date().toISOString(), kind: 'batch_failed', fields: { batch_id: batchId, tool, duration_ms: durationMs, error_code: failure.code, error_message: failure.message } });
|
|
100
|
-
process.stderr.write(`[mmagent] event=batch_failed ts=${new Date().toISOString()} batch=${batchId} route=${tool} duration_ms=${durationMs} error_code=${failure.code} error="${failure.message.replace(/"/g, '\\"')}"\n`);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
batchRegistry.complete(batchId);
|
|
104
|
-
const dispatchMode = resultObj?.dispatchMode;
|
|
105
|
-
deps.bus.emitPlainEntry({ ts: new Date().toISOString(), kind: 'batch_completed', fields: { batch_id: batchId, tool, duration_ms: durationMs, task_count: taskCount, ...(dispatchMode !== undefined ? { dispatch_mode: dispatchMode } : {}) } });
|
|
106
|
-
process.stderr.write(`[mmagent] event=batch_completed ts=${new Date().toISOString()} batch=${batchId} route=${tool} duration_ms=${durationMs}\n`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
111
|
-
const stack = err instanceof Error ? err.stack : undefined;
|
|
112
|
-
const errObj = {
|
|
113
|
-
code: 'runner_crash',
|
|
114
|
-
message,
|
|
115
|
-
...(stack !== undefined && { stack }),
|
|
116
|
-
};
|
|
117
|
-
batchRegistry.fail(batchId, errObj);
|
|
118
|
-
const durationMs = Date.now() - startedAtMs;
|
|
119
|
-
deps.bus.emitPlainEntry({ ts: new Date().toISOString(), kind: 'batch_failed', fields: { batch_id: batchId, tool, duration_ms: durationMs, error_code: errObj.code, error_message: errObj.message } });
|
|
120
|
-
process.stderr.write(`[mmagent] event=batch_failed ts=${new Date().toISOString()} batch=${batchId} route=${tool} duration_ms=${durationMs} error="${message.replace(/"/g, '\\"')}"\n`);
|
|
121
|
-
}
|
|
122
|
-
})();
|
|
123
|
-
});
|
|
124
|
-
return {
|
|
125
|
-
batchId,
|
|
126
|
-
statusUrl: `/batch/${batchId}`,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Inspect an executor return envelope for structured failure signals.
|
|
131
|
-
* Returns { code, message } when the envelope indicates failure, null
|
|
132
|
-
* otherwise.
|
|
133
|
-
*
|
|
134
|
-
* Per the Gap 5 fix design (wire-telemetry-gaps plan): NO string
|
|
135
|
-
* comparison to "batch succeeded". Use only:
|
|
136
|
-
* 1. Any task result with `structuredError` (most authoritative)
|
|
137
|
-
* 2. Any task result with `status` other than 'ok'
|
|
138
|
-
* 3. Envelope-level `error` object whose `kind` is not 'not_applicable'
|
|
139
|
-
* (notApplicable() is the structured "no error" sentinel)
|
|
140
|
-
*/
|
|
141
|
-
function detectFailure(envelope) {
|
|
142
|
-
if (!envelope)
|
|
143
|
-
return null;
|
|
144
|
-
const results = Array.isArray(envelope.results) ? envelope.results : [];
|
|
145
|
-
// Source 1: explicit structuredError on any task result
|
|
146
|
-
for (const r of results) {
|
|
147
|
-
const se = r.structuredError;
|
|
148
|
-
if (se && typeof se.code === 'string') {
|
|
149
|
-
return { code: se.code, message: typeof se.message === 'string' ? se.message : se.code };
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// Source 2: any task result with status === 'error'.
|
|
153
|
-
// 'incomplete' is intentionally NOT treated as failure — review-rework
|
|
154
|
-
// paths can transit through 'incomplete' on intermediate rounds while
|
|
155
|
-
// the eventual envelope still represents a valid (if imperfect) batch.
|
|
156
|
-
// Only 'error' and 'failed' are categorical batch-level failures.
|
|
157
|
-
for (const r of results) {
|
|
158
|
-
const status = r.status;
|
|
159
|
-
if (typeof status === 'string' && (status === 'error' || status === 'failed')) {
|
|
160
|
-
const code = (typeof r.errorCode === 'string' && r.errorCode.length > 0) ? r.errorCode : status;
|
|
161
|
-
const msg = (typeof r.error === 'string' && r.error.length > 0) ? r.error : status;
|
|
162
|
-
return { code, message: msg };
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Source 3: envelope-level error object with kind != 'not_applicable'
|
|
166
|
-
const env = envelope.error;
|
|
167
|
-
if (env && typeof env.kind === 'string' && env.kind !== 'not_applicable') {
|
|
168
|
-
return {
|
|
169
|
-
code: typeof env.code === 'string' ? env.code : 'envelope_error',
|
|
170
|
-
message: typeof env.message === 'string' ? env.message : 'envelope error',
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
//# sourceMappingURL=async-dispatch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-dispatch.js","sourceRoot":"","sources":["../../src/http/async-dispatch.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAE3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AA8B/D;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,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CAAC,EAAE,CAAC;YAC9E,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;YAChG,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;YACnF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAuE,CAAC;IAC7F,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACzE,OAAO;YACL,IAAI,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB;YAChE,OAAO,EAAE,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB;SAC1E,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/http/auth.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load or generate the bearer token from a file path.
|
|
3
|
-
* Respects the MMAGENT_AUTH_TOKEN env override via coreLoadAuthToken when the
|
|
4
|
-
* file already exists. Falls back to generating a new token if the file does not exist.
|
|
5
|
-
*/
|
|
6
|
-
export declare function loadToken(tokenPath: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* Validate an Authorization header value (including "Bearer " prefix).
|
|
9
|
-
* Uses crypto.timingSafeEqual to prevent timing attacks.
|
|
10
|
-
*
|
|
11
|
-
* Returns { ok: true } on success.
|
|
12
|
-
* Returns { ok: false, reason } on failure without leaking which check failed.
|
|
13
|
-
*/
|
|
14
|
-
export declare function validateAuthHeader(header: string | undefined, expected: string): {
|
|
15
|
-
ok: true;
|
|
16
|
-
} | {
|
|
17
|
-
ok: false;
|
|
18
|
-
reason: 'missing' | 'malformed' | 'mismatch';
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=auth.d.ts.map
|
package/dist/http/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/http/auth.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAkBnD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,EAAE,MAAM,GACf;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAA;CAAE,CAU5E"}
|
package/dist/http/auth.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import * as os from 'node:os';
|
|
4
|
-
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
5
|
-
import { loadAuthToken as coreLoadAuthToken } from '@zhixuan92/multi-model-agent-core';
|
|
6
|
-
function expandHome(p) {
|
|
7
|
-
if (p.startsWith('~/'))
|
|
8
|
-
return path.join(os.homedir(), p.slice(2));
|
|
9
|
-
return p;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Load or generate the bearer token from a file path.
|
|
13
|
-
* Respects the MMAGENT_AUTH_TOKEN env override via coreLoadAuthToken when the
|
|
14
|
-
* file already exists. Falls back to generating a new token if the file does not exist.
|
|
15
|
-
*/
|
|
16
|
-
export function loadToken(tokenPath) {
|
|
17
|
-
const resolved = expandHome(tokenPath);
|
|
18
|
-
if (fs.existsSync(resolved)) {
|
|
19
|
-
const stat = fs.statSync(resolved);
|
|
20
|
-
// Warn (do not fail) if the existing file has group/other read/write bits set.
|
|
21
|
-
if ((stat.mode & 0o077) !== 0) {
|
|
22
|
-
process.stderr.write(`[multi-model-agent] warning: token file ${resolved} has insecure permissions (mode ${(stat.mode & 0o777).toString(8)}); recommend 'chmod 0600 ${resolved}'\n`);
|
|
23
|
-
}
|
|
24
|
-
// Use core's loadAuthToken so the MMAGENT_AUTH_TOKEN env override is respected.
|
|
25
|
-
return coreLoadAuthToken({ tokenFile: resolved });
|
|
26
|
-
}
|
|
27
|
-
const dir = path.dirname(resolved);
|
|
28
|
-
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
29
|
-
const token = randomBytes(32).toString('base64url');
|
|
30
|
-
fs.writeFileSync(resolved, token + '\n', { mode: 0o600 });
|
|
31
|
-
return token;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Validate an Authorization header value (including "Bearer " prefix).
|
|
35
|
-
* Uses crypto.timingSafeEqual to prevent timing attacks.
|
|
36
|
-
*
|
|
37
|
-
* Returns { ok: true } on success.
|
|
38
|
-
* Returns { ok: false, reason } on failure without leaking which check failed.
|
|
39
|
-
*/
|
|
40
|
-
export function validateAuthHeader(header, expected) {
|
|
41
|
-
if (!header)
|
|
42
|
-
return { ok: false, reason: 'missing' };
|
|
43
|
-
const parts = header.split(/\s+/);
|
|
44
|
-
if (parts.length !== 2)
|
|
45
|
-
return { ok: false, reason: 'malformed' };
|
|
46
|
-
if (parts[0].toLowerCase() !== 'bearer')
|
|
47
|
-
return { ok: false, reason: 'malformed' };
|
|
48
|
-
const presented = Buffer.from(parts[1]);
|
|
49
|
-
const expectedBuf = Buffer.from(expected);
|
|
50
|
-
if (presented.length !== expectedBuf.length)
|
|
51
|
-
return { ok: false, reason: 'mismatch' };
|
|
52
|
-
if (!timingSafeEqual(presented, expectedBuf))
|
|
53
|
-
return { ok: false, reason: 'mismatch' };
|
|
54
|
-
return { ok: true };
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=auth.js.map
|
package/dist/http/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/http/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEvF,SAAS,UAAU,CAAC,CAAS;IAC3B,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,SAAiB;IACzC,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACvC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnC,+EAA+E;QAC/E,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,MAAM,CAA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ACxC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,SAAS,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IACtF,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,WAAW,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IACvF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type CanonicalizeResult = string[] | {
|
|
2
|
-
error: 'invalid_request';
|
|
3
|
-
fieldErrors: {
|
|
4
|
-
filePaths: string[];
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export declare function canonicalizeFilePaths(rawPaths: string[], cwd: string): CanonicalizeResult;
|
|
8
|
-
//# sourceMappingURL=canonicalize-file-paths.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalize-file-paths.d.ts","sourceRoot":"","sources":["../../src/http/canonicalize-file-paths.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAC1B,MAAM,EAAE,GACR;IAAE,KAAK,EAAE,iBAAiB,CAAC;IAAC,WAAW,EAAE;QAAE,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,CAAC;AAEvE,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAoCzF"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { realpathSync, existsSync } from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
export function canonicalizeFilePaths(rawPaths, cwd) {
|
|
4
|
-
const realCwd = realpathSync(cwd);
|
|
5
|
-
const accepted = [];
|
|
6
|
-
const offenders = [];
|
|
7
|
-
for (const raw of rawPaths) {
|
|
8
|
-
const resolved = path.isAbsolute(raw) ? path.normalize(raw) : path.resolve(realCwd, raw);
|
|
9
|
-
let cursor = resolved;
|
|
10
|
-
while (!existsSync(cursor) && path.dirname(cursor) !== cursor) {
|
|
11
|
-
cursor = path.dirname(cursor);
|
|
12
|
-
}
|
|
13
|
-
let realAncestor;
|
|
14
|
-
try {
|
|
15
|
-
realAncestor = realpathSync(cursor);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
offenders.push(raw);
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const suffix = path.relative(cursor, resolved);
|
|
22
|
-
const candidate = suffix ? path.normalize(path.join(realAncestor, suffix)) : realAncestor;
|
|
23
|
-
const rel = path.relative(realCwd, candidate);
|
|
24
|
-
const inside = rel === '' || (!rel.startsWith('..' + path.sep) && rel !== '..' && !path.isAbsolute(rel));
|
|
25
|
-
if (!inside) {
|
|
26
|
-
offenders.push(raw);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
accepted.push(candidate);
|
|
30
|
-
}
|
|
31
|
-
if (offenders.length > 0) {
|
|
32
|
-
return { error: 'invalid_request', fieldErrors: { filePaths: offenders } };
|
|
33
|
-
}
|
|
34
|
-
const seen = new Set();
|
|
35
|
-
const dedup = [];
|
|
36
|
-
for (const p of accepted)
|
|
37
|
-
if (!seen.has(p)) {
|
|
38
|
-
seen.add(p);
|
|
39
|
-
dedup.push(p);
|
|
40
|
-
}
|
|
41
|
-
return dedup;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=canonicalize-file-paths.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalize-file-paths.js","sourceRoot":"","sources":["../../src/http/canonicalize-file-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,IAAI,M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AAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;QACzG,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpB,SAAS;QACX,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC;IAC7E,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,QAAQ;QAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAAC,CAAC;IAC3E,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type CwdValidationError = 'missing_cwd' | 'invalid_cwd' | 'cwd_not_dir' | 'forbidden_cwd';
|
|
2
|
-
export type CwdValidationResult = {
|
|
3
|
-
ok: true;
|
|
4
|
-
canonicalCwd: string;
|
|
5
|
-
} | {
|
|
6
|
-
ok: false;
|
|
7
|
-
error: CwdValidationError;
|
|
8
|
-
message: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function validateCwd(cwd: string | undefined): CwdValidationResult;
|
|
11
|
-
//# sourceMappingURL=cwd-validator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cwd-validator.d.ts","sourceRoot":"","sources":["../../src/http/cwd-validator.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG,aAAa,GAAG,aAAa,GAAG,eAAe,CAAC;AAEjG,MAAM,MAAM,mBAAmB,GAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAiF9D,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,mBAAmB,CA8CxE"}
|