scoutline 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -5
- package/bin/scoutline.js +36 -15
- package/dist/capabilities/diagnostics.d.ts +97 -0
- package/dist/capabilities/diagnostics.d.ts.map +1 -0
- package/dist/capabilities/diagnostics.js +88 -0
- package/dist/capabilities/diagnostics.js.map +1 -0
- package/dist/capabilities/quota.d.ts +99 -0
- package/dist/capabilities/quota.d.ts.map +1 -0
- package/dist/capabilities/quota.js +129 -0
- package/dist/capabilities/quota.js.map +1 -0
- package/dist/capabilities/search.d.ts +110 -0
- package/dist/capabilities/search.d.ts.map +1 -0
- package/dist/capabilities/search.js +21 -0
- package/dist/capabilities/search.js.map +1 -0
- package/dist/capabilities/vision.d.ts +156 -0
- package/dist/capabilities/vision.d.ts.map +1 -0
- package/dist/capabilities/vision.js +111 -0
- package/dist/capabilities/vision.js.map +1 -0
- package/dist/command-invocation.d.ts +58 -0
- package/dist/command-invocation.d.ts.map +1 -0
- package/dist/command-invocation.js +95 -0
- package/dist/command-invocation.js.map +1 -0
- package/dist/commands/code.d.ts +11 -4
- package/dist/commands/code.d.ts.map +1 -1
- package/dist/commands/code.js +16 -42
- package/dist/commands/code.js.map +1 -1
- package/dist/commands/doctor.d.ts +58 -3
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +154 -52
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/quota.d.ts +45 -3
- package/dist/commands/quota.d.ts.map +1 -1
- package/dist/commands/quota.js +116 -60
- package/dist/commands/quota.js.map +1 -1
- package/dist/commands/read.d.ts +15 -1
- package/dist/commands/read.d.ts.map +1 -1
- package/dist/commands/read.js +53 -54
- package/dist/commands/read.js.map +1 -1
- package/dist/commands/repo.d.ts +8 -3
- package/dist/commands/repo.d.ts.map +1 -1
- package/dist/commands/repo.js +40 -78
- package/dist/commands/repo.js.map +1 -1
- package/dist/commands/search.d.ts +27 -2
- package/dist/commands/search.d.ts.map +1 -1
- package/dist/commands/search.js +95 -103
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/tools.d.ts +9 -3
- package/dist/commands/tools.d.ts.map +1 -1
- package/dist/commands/tools.js +29 -59
- package/dist/commands/tools.js.map +1 -1
- package/dist/commands/vision.d.ts +35 -9
- package/dist/commands/vision.d.ts.map +1 -1
- package/dist/commands/vision.js +184 -131
- package/dist/commands/vision.js.map +1 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +389 -207
- package/dist/index.js.map +1 -1
- package/dist/lib/cache.d.ts +61 -0
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +74 -11
- package/dist/lib/cache.js.map +1 -1
- package/dist/lib/code-mode.d.ts +13 -0
- package/dist/lib/code-mode.d.ts.map +1 -1
- package/dist/lib/code-mode.js +26 -6
- package/dist/lib/code-mode.js.map +1 -1
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +15 -18
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +65 -10
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +135 -19
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/execution.d.ts +76 -0
- package/dist/lib/execution.d.ts.map +1 -0
- package/dist/lib/execution.js +177 -0
- package/dist/lib/execution.js.map +1 -0
- package/dist/lib/index.d.ts +10 -2
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +10 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/mcp-client.d.ts +46 -11
- package/dist/lib/mcp-client.d.ts.map +1 -1
- package/dist/lib/mcp-client.js +92 -27
- package/dist/lib/mcp-client.js.map +1 -1
- package/dist/lib/mcp-config.d.ts +17 -0
- package/dist/lib/mcp-config.d.ts.map +1 -1
- package/dist/lib/mcp-config.js +29 -0
- package/dist/lib/mcp-config.js.map +1 -1
- package/dist/lib/monitor-client.d.ts +17 -3
- package/dist/lib/monitor-client.d.ts.map +1 -1
- package/dist/lib/monitor-client.js +23 -69
- package/dist/lib/monitor-client.js.map +1 -1
- package/dist/lib/output.d.ts +53 -7
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +126 -39
- package/dist/lib/output.js.map +1 -1
- package/dist/lib/redact.d.ts +62 -3
- package/dist/lib/redact.d.ts.map +1 -1
- package/dist/lib/redact.js +165 -31
- package/dist/lib/redact.js.map +1 -1
- package/dist/lib/tty.d.ts +7 -20
- package/dist/lib/tty.d.ts.map +1 -1
- package/dist/lib/tty.js +51 -30
- package/dist/lib/tty.js.map +1 -1
- package/dist/node-command-invocation-adapter.d.ts +28 -0
- package/dist/node-command-invocation-adapter.d.ts.map +1 -0
- package/dist/node-command-invocation-adapter.js +88 -0
- package/dist/node-command-invocation-adapter.js.map +1 -0
- package/dist/providers/minimax/adapter.d.ts +47 -0
- package/dist/providers/minimax/adapter.d.ts.map +1 -0
- package/dist/providers/minimax/adapter.js +443 -0
- package/dist/providers/minimax/adapter.js.map +1 -0
- package/dist/providers/minimax/config.d.ts +32 -0
- package/dist/providers/minimax/config.d.ts.map +1 -0
- package/dist/providers/minimax/config.js +84 -0
- package/dist/providers/minimax/config.js.map +1 -0
- package/dist/providers/minimax/media.d.ts +34 -0
- package/dist/providers/minimax/media.d.ts.map +1 -0
- package/dist/providers/minimax/media.js +92 -0
- package/dist/providers/minimax/media.js.map +1 -0
- package/dist/providers/minimax/quota-client.d.ts +37 -0
- package/dist/providers/minimax/quota-client.d.ts.map +1 -0
- package/dist/providers/minimax/quota-client.js +78 -0
- package/dist/providers/minimax/quota-client.js.map +1 -0
- package/dist/providers/minimax/quota.d.ts +48 -0
- package/dist/providers/minimax/quota.d.ts.map +1 -0
- package/dist/providers/minimax/quota.js +120 -0
- package/dist/providers/minimax/quota.js.map +1 -0
- package/dist/providers/minimax/sdk-client.d.ts +29 -0
- package/dist/providers/minimax/sdk-client.d.ts.map +1 -0
- package/dist/providers/minimax/sdk-client.js +50 -0
- package/dist/providers/minimax/sdk-client.js.map +1 -0
- package/dist/providers/minimax/vision-attestations.d.ts +29 -0
- package/dist/providers/minimax/vision-attestations.d.ts.map +1 -0
- package/dist/providers/minimax/vision-attestations.js +54 -0
- package/dist/providers/minimax/vision-attestations.js.map +1 -0
- package/dist/providers/minimax/vision-conformance.d.ts +184 -0
- package/dist/providers/minimax/vision-conformance.d.ts.map +1 -0
- package/dist/providers/minimax/vision-conformance.js +369 -0
- package/dist/providers/minimax/vision-conformance.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/chart.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/chart.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/chart.js +55 -0
- package/dist/providers/minimax/vision-mappings/chart.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/common.d.ts +60 -0
- package/dist/providers/minimax/vision-mappings/common.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/common.js +75 -0
- package/dist/providers/minimax/vision-mappings/common.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.js +55 -0
- package/dist/providers/minimax/vision-mappings/diagnose-error.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagram.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/diagram.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/diagram.js +55 -0
- package/dist/providers/minimax/vision-mappings/diagram.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/extract-text.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/extract-text.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/extract-text.js +55 -0
- package/dist/providers/minimax/vision-mappings/extract-text.js.map +1 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts +35 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.js +69 -0
- package/dist/providers/minimax/vision-mappings/ui-artifact.js.map +1 -0
- package/dist/providers/minimax/vision-mappings.generated.d.ts +29 -0
- package/dist/providers/minimax/vision-mappings.generated.d.ts.map +1 -0
- package/dist/providers/minimax/vision-mappings.generated.js +29 -0
- package/dist/providers/minimax/vision-mappings.generated.js.map +1 -0
- package/dist/providers/minimax/vision-revisions.d.ts +22 -0
- package/dist/providers/minimax/vision-revisions.d.ts.map +1 -0
- package/dist/providers/minimax/vision-revisions.js +27 -0
- package/dist/providers/minimax/vision-revisions.js.map +1 -0
- package/dist/providers/registry.d.ts +36 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +45 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/selection.d.ts +44 -0
- package/dist/providers/selection.d.ts.map +1 -0
- package/dist/providers/selection.js +85 -0
- package/dist/providers/selection.js.map +1 -0
- package/dist/providers/types.d.ts +247 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +127 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/zai/adapter.d.ts +35 -0
- package/dist/providers/zai/adapter.d.ts.map +1 -0
- package/dist/providers/zai/adapter.js +619 -0
- package/dist/providers/zai/adapter.js.map +1 -0
- package/dist/providers/zai/credentials.d.ts +38 -0
- package/dist/providers/zai/credentials.d.ts.map +1 -0
- package/dist/providers/zai/credentials.js +60 -0
- package/dist/providers/zai/credentials.js.map +1 -0
- package/dist/providers/zai/media.d.ts +38 -0
- package/dist/providers/zai/media.d.ts.map +1 -0
- package/dist/providers/zai/media.js +107 -0
- package/dist/providers/zai/media.js.map +1 -0
- package/dist/providers/zai/monitor-client.d.ts +53 -0
- package/dist/providers/zai/monitor-client.d.ts.map +1 -0
- package/dist/providers/zai/monitor-client.js +117 -0
- package/dist/providers/zai/monitor-client.js.map +1 -0
- package/dist/providers/zai/quota.d.ts +47 -0
- package/dist/providers/zai/quota.d.ts.map +1 -0
- package/dist/providers/zai/quota.js +127 -0
- package/dist/providers/zai/quota.js.map +1 -0
- package/package.json +10 -5
package/dist/commands/quota.js
CHANGED
|
@@ -1,77 +1,133 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Quota command —
|
|
2
|
+
* Quota command — Provider-neutral quota dashboard (P4-03, ADR-0001).
|
|
3
|
+
*
|
|
4
|
+
* The command is presentation-only: it receives a dashboard builder
|
|
5
|
+
* through injected dependencies and wraps the resulting
|
|
6
|
+
* {@link QuotaDashboard} as base data with a TTY presentation override.
|
|
7
|
+
* Provider resolution, capability invocation, settled collection, and
|
|
8
|
+
* failure redaction live in {@link buildQuotaDashboard} so the command
|
|
9
|
+
* never imports a Provider monitor client or maps a Provider response.
|
|
10
|
+
*
|
|
11
|
+
* Default mode (effective Provider) propagates quota failures through
|
|
12
|
+
* the ordinary error path (thrown → invokeCommand). All-provider mode
|
|
13
|
+
* (`--all-providers`) uses settled collection, emits successful and
|
|
14
|
+
* failed entries, and yields exit 1 when any configured Provider fails.
|
|
3
15
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
windowHours: timeLimit.unit,
|
|
22
|
-
resetsAt: timeLimit.nextResetTime
|
|
23
|
-
? new Date(timeLimit.nextResetTime).toISOString()
|
|
24
|
-
: null,
|
|
25
|
-
resetsIn: timeLimit.nextResetTime ? formatResetTime(timeLimit.nextResetTime) : null,
|
|
26
|
-
byTool: timeLimit.usageDetails,
|
|
27
|
-
}
|
|
28
|
-
: null,
|
|
29
|
-
tokens: tokensLimit
|
|
30
|
-
? {
|
|
31
|
-
percentage: tokensLimit.percentage,
|
|
32
|
-
resetsAt: tokensLimit.nextResetTime
|
|
33
|
-
? new Date(tokensLimit.nextResetTime).toISOString()
|
|
34
|
-
: null,
|
|
35
|
-
resetsIn: tokensLimit.nextResetTime ? formatResetTime(tokensLimit.nextResetTime) : null,
|
|
36
|
-
}
|
|
37
|
-
: null,
|
|
38
|
-
};
|
|
39
|
-
const mode = getOutputMode();
|
|
40
|
-
if (mode === "tty") {
|
|
41
|
-
outputSuccess(formatQuotaPretty(formatted));
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
outputSuccess(formatted);
|
|
45
|
-
}
|
|
16
|
+
import { quotaFailureFromError } from "../capabilities/quota.js";
|
|
17
|
+
import { executeProviderOperation } from "../lib/execution.js";
|
|
18
|
+
import { ConfigurationError, UnsupportedCapabilityError } from "../lib/errors.js";
|
|
19
|
+
import { getProviderDescriptor } from "../providers/selection.js";
|
|
20
|
+
import { redactSecrets, configuredSecrets } from "../lib/redact.js";
|
|
21
|
+
import { formatQuotaDashboard } from "../lib/tty.js";
|
|
22
|
+
/**
|
|
23
|
+
* Invoke one Provider's quota Capability through shared execution. The
|
|
24
|
+
* Adapter transport performs a single attempt; the retry policy lives
|
|
25
|
+
* in `executeProviderOperation("quota", ...)`. Quota never uses the
|
|
26
|
+
* response cache.
|
|
27
|
+
*/
|
|
28
|
+
async function invokeProviderQuota(descriptor, env, sleep, random) {
|
|
29
|
+
const adapter = descriptor.create({ env });
|
|
30
|
+
const capability = adapter.quota;
|
|
31
|
+
if (!capability) {
|
|
32
|
+
throw new UnsupportedCapabilityError(descriptor.id, "quota");
|
|
46
33
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
return executeProviderOperation("quota", () => capability.invoke(), { sleep, random });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Default-mode dashboard. Resolves the effective Provider, requires it
|
|
38
|
+
* to be configured (ConfigurationError, exit 3, before transport), then
|
|
39
|
+
* invokes its quota Capability. Failures propagate through the ordinary
|
|
40
|
+
* error path.
|
|
41
|
+
*/
|
|
42
|
+
async function buildDefaultDashboard(deps) {
|
|
43
|
+
const descriptor = getProviderDescriptor(deps.effectiveProvider, deps.descriptors);
|
|
44
|
+
if (!descriptor.isConfigured(deps.env)) {
|
|
45
|
+
throw new ConfigurationError(`Provider "${deps.effectiveProvider}" is not configured. Set Z_AI_API_KEY or MINIMAX_API_KEY.`);
|
|
46
|
+
}
|
|
47
|
+
const success = await invokeProviderQuota(descriptor, deps.env, deps.sleep, deps.random);
|
|
48
|
+
return {
|
|
49
|
+
schemaVersion: 1,
|
|
50
|
+
effectiveProvider: deps.effectiveProvider,
|
|
51
|
+
providers: [success],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* All-provider dashboard. Queries every configured Provider in static
|
|
56
|
+
* registry order using settled collection. No unconfigured Provider is
|
|
57
|
+
* invoked; the effective Provider is dashboard metadata only. Failures
|
|
58
|
+
* are normalized and recursively redacted before joining the dashboard.
|
|
59
|
+
* No configured Provider is a configuration failure, not an empty
|
|
60
|
+
* success.
|
|
61
|
+
*/
|
|
62
|
+
async function buildAllProvidersDashboard(deps) {
|
|
63
|
+
const configured = deps.descriptors.filter((d) => d.isConfigured(deps.env));
|
|
64
|
+
if (configured.length === 0) {
|
|
65
|
+
throw new ConfigurationError("No provider is configured. Set Z_AI_API_KEY and/or MINIMAX_API_KEY.");
|
|
50
66
|
}
|
|
67
|
+
const secrets = configuredSecrets(deps.env);
|
|
68
|
+
const settled = await Promise.allSettled(configured.map((d) => invokeProviderQuota(d, deps.env, deps.sleep, deps.random)));
|
|
69
|
+
const providers = configured.map((d, i) => {
|
|
70
|
+
const result = settled[i];
|
|
71
|
+
if (result.status === "fulfilled") {
|
|
72
|
+
return result.value;
|
|
73
|
+
}
|
|
74
|
+
return redactSecrets(quotaFailureFromError(d.id, result.reason), secrets);
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
schemaVersion: 1,
|
|
78
|
+
effectiveProvider: deps.effectiveProvider,
|
|
79
|
+
providers,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build a {@link QuotaDashboard} for the selected mode. The effective
|
|
84
|
+
* Provider is resolved by the dispatcher (`index.ts`) and passed in as
|
|
85
|
+
* metadata; config validation happens here.
|
|
86
|
+
*/
|
|
87
|
+
export async function buildQuotaDashboard(deps) {
|
|
88
|
+
return deps.allProviders ? buildAllProvidersDashboard(deps) : buildDefaultDashboard(deps);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run the quota command. Returns the dashboard as base data with a TTY
|
|
92
|
+
* presentation override. Exit code is 1 when any dashboard entry failed
|
|
93
|
+
* (all-provider mode); otherwise 0.
|
|
94
|
+
*/
|
|
95
|
+
export async function quota(deps) {
|
|
96
|
+
const dashboard = await deps.buildDashboard();
|
|
97
|
+
const hasFailure = dashboard.providers.some((p) => p.status === "error");
|
|
98
|
+
return {
|
|
99
|
+
kind: "data",
|
|
100
|
+
data: dashboard,
|
|
101
|
+
presentations: { tty: formatQuotaDashboard(dashboard) },
|
|
102
|
+
exitCode: hasFailure ? 1 : 0,
|
|
103
|
+
};
|
|
51
104
|
}
|
|
52
105
|
export const QUOTA_HELP = `
|
|
53
|
-
Quota Command -
|
|
106
|
+
Quota Command - Provider-normalized plan usage dashboard
|
|
54
107
|
|
|
55
108
|
Usage: scoutline quota [options]
|
|
56
109
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- Token budget percentage + reset time
|
|
110
|
+
Reports plan usage for the effective Provider (or every configured
|
|
111
|
+
Provider with --all-providers) as a normalized, schema-version-1
|
|
112
|
+
dashboard (ADR-0001). Each entry carries named quota categories with
|
|
113
|
+
current and optional weekly windows, counts, remaining percentage, and
|
|
114
|
+
ISO reset time. No Provider-specific field crosses the Interface.
|
|
63
115
|
|
|
64
116
|
Options:
|
|
65
|
-
|
|
117
|
+
--all-providers Query every configured Provider in registry order.
|
|
118
|
+
Successful and failed entries both appear; the
|
|
119
|
+
command exits 1 when any Provider fails.
|
|
66
120
|
|
|
67
121
|
Examples:
|
|
68
|
-
scoutline quota
|
|
69
|
-
scoutline quota -
|
|
70
|
-
scoutline quota -O
|
|
122
|
+
scoutline quota # effective Provider usage
|
|
123
|
+
scoutline quota --all-providers # every configured Provider
|
|
124
|
+
scoutline quota -O pretty # human-readable with progress bars
|
|
125
|
+
scoutline quota -O json # envelope-wrapped for scripts
|
|
71
126
|
|
|
72
127
|
Notes:
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
128
|
+
- Quota is never cached by the local response cache.
|
|
129
|
+
- Default-mode failures propagate as ordinary errors (exit 3 for an
|
|
130
|
+
unconfigured effective Provider).
|
|
131
|
+
- All-provider mode never invokes an unconfigured Provider.
|
|
76
132
|
`.trim();
|
|
77
133
|
//# sourceMappingURL=quota.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quota.js","sourceRoot":"","sources":["../../src/commands/quota.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quota.js","sourceRoot":"","sources":["../../src/commands/quota.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAmBrD;;;;;GAKG;AACH,KAAK,UAAU,mBAAmB,CAChC,UAA8B,EAC9B,GAAsB,EACtB,KAAoC,EACpC,MAAoB;IAEpB,MAAM,OAAO,G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AAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC;IACzE,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,SAAS;QACf,aAAa,EAAE,EAAE,GAAG,EAAE,oBAAoB,CAAC,SAAS,CAAC,EAAE;QACvD,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7B,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BzB,CAAC,IAAI,EAAE,CAAC"}
|
package/dist/commands/read.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Web reader command using Z.AI WebReader MCP
|
|
3
|
+
*
|
|
4
|
+
* P1-05: returns a CommandResult instead of writing directly to
|
|
5
|
+
* stdout/stderr. Notices (URL rewrite hint, truncation warning, extract
|
|
6
|
+
* count) flow through the invocation context; errors are thrown and
|
|
7
|
+
* converted by invokeCommand.
|
|
8
|
+
*
|
|
9
|
+
* Behaviour preserved from Phase 0:
|
|
10
|
+
* - By default the data is the page content (string).
|
|
11
|
+
* - With --full-envelope the data is the structured reader envelope.
|
|
12
|
+
* - With -O json/pretty (without --full-envelope) the data is also the
|
|
13
|
+
* envelope so consumers always get the structured object in JSON
|
|
14
|
+
* modes. The `outputMode` parameter is passed by the dispatcher.
|
|
3
15
|
*/
|
|
4
16
|
import { type ExtractMode } from "../lib/extract.js";
|
|
17
|
+
import type { CommandContext, CommandResult } from "../command-invocation.js";
|
|
18
|
+
import type { OutputMode } from "../lib/output.js";
|
|
5
19
|
export interface ReadOptions {
|
|
6
20
|
format?: "markdown" | "text";
|
|
7
21
|
noImages?: boolean;
|
|
@@ -15,6 +29,6 @@ export interface ReadOptions {
|
|
|
15
29
|
fullEnvelope?: boolean;
|
|
16
30
|
extract?: ExtractMode;
|
|
17
31
|
}
|
|
18
|
-
export declare function read(url: string, options?: ReadOptions): Promise<
|
|
32
|
+
export declare function read(url: string, options?: ReadOptions, outputMode?: OutputMode, context?: CommandContext): Promise<CommandResult>;
|
|
19
33
|
export declare const READ_HELP: string;
|
|
20
34
|
//# sourceMappingURL=read.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/commands/read.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/commands/read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAwDD,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,UAAU,CAAC,EAAE,UAAU,EACvB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC,CAkExB;AAGD,eAAO,MAAM,SAAS,QAuCd,CAAC"}
|
package/dist/commands/read.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Web reader command using Z.AI WebReader MCP
|
|
3
|
+
*
|
|
4
|
+
* P1-05: returns a CommandResult instead of writing directly to
|
|
5
|
+
* stdout/stderr. Notices (URL rewrite hint, truncation warning, extract
|
|
6
|
+
* count) flow through the invocation context; errors are thrown and
|
|
7
|
+
* converted by invokeCommand.
|
|
8
|
+
*
|
|
9
|
+
* Behaviour preserved from Phase 0:
|
|
10
|
+
* - By default the data is the page content (string).
|
|
11
|
+
* - With --full-envelope the data is the structured reader envelope.
|
|
12
|
+
* - With -O json/pretty (without --full-envelope) the data is also the
|
|
13
|
+
* envelope so consumers always get the structured object in JSON
|
|
14
|
+
* modes. The `outputMode` parameter is passed by the dispatcher.
|
|
3
15
|
*/
|
|
4
16
|
import { ZaiMcpClient } from "../lib/mcp-client.js";
|
|
5
|
-
import {
|
|
6
|
-
import { formatErrorOutput, ValidationError } from "../lib/errors.js";
|
|
7
|
-
import { silenceConsole, restoreConsole } from "../lib/silence.js";
|
|
17
|
+
import { ValidationError } from "../lib/errors.js";
|
|
8
18
|
import { extract, isExtractMode } from "../lib/extract.js";
|
|
9
19
|
/**
|
|
10
20
|
* Rewrite rendered GitHub gist/file URLs to their raw form so Z.AI's reader
|
|
@@ -57,69 +67,58 @@ function truncate(content, max) {
|
|
|
57
67
|
}
|
|
58
68
|
return { text: content.slice(0, max - 1).trimEnd() + "…", originalLen, truncated: true };
|
|
59
69
|
}
|
|
60
|
-
export async function read(url, options = {}) {
|
|
61
|
-
// Validate URL first (before
|
|
70
|
+
export async function read(url, options = {}, outputMode, context) {
|
|
71
|
+
// Validate URL first (before any client work).
|
|
62
72
|
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
63
|
-
|
|
64
|
-
process.exit(1);
|
|
73
|
+
throw new ValidationError("URL must start with http:// or https://");
|
|
65
74
|
}
|
|
66
75
|
if (options.extract && !isExtractMode(options.extract)) {
|
|
67
|
-
|
|
68
|
-
process.exit(1);
|
|
76
|
+
throw new ValidationError(`Invalid --extract mode: ${options.extract}. Use one of: code, links, tables, headings`);
|
|
69
77
|
}
|
|
70
78
|
const finalUrl = maybeRewriteToRaw(url);
|
|
71
|
-
if (finalUrl !== url) {
|
|
72
|
-
|
|
79
|
+
if (finalUrl !== url && context) {
|
|
80
|
+
context.notice(`ℹ️ rewrote gist URL to raw form: ${finalUrl}`);
|
|
73
81
|
}
|
|
74
|
-
silenceConsole();
|
|
75
82
|
const client = new ZaiMcpClient({ enableVision: false, noCache: options.noCache });
|
|
76
83
|
try {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
outputSuccess(extracted);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const { text, originalLen, truncated } = truncate(rawContent, options.maxChars);
|
|
99
|
-
if (truncated) {
|
|
100
|
-
process.stderr.write(`⚠️ content truncated from ${originalLen.toLocaleString()} to ${text.length.toLocaleString()} chars; use a higher --max-chars or omit it for full content\n`);
|
|
101
|
-
}
|
|
102
|
-
// Default: content-only (drops title/metadata/external envelope).
|
|
103
|
-
// --full-envelope or --output-format json/pretty keeps the structured object.
|
|
104
|
-
const wantEnvelope = options.fullEnvelope || getOutputMode() === "json" || getOutputMode() === "pretty";
|
|
105
|
-
if (wantEnvelope) {
|
|
106
|
-
const envelope = response && typeof response === "object"
|
|
107
|
-
? { ...response, content: text }
|
|
108
|
-
: { content: text };
|
|
109
|
-
outputSuccess(envelope);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
outputSuccess(text);
|
|
84
|
+
const response = await client.webRead({
|
|
85
|
+
url: finalUrl,
|
|
86
|
+
format: options.format || "markdown",
|
|
87
|
+
retainImages: !options.noImages,
|
|
88
|
+
withLinksSummary: options.withLinks,
|
|
89
|
+
timeout: options.timeout,
|
|
90
|
+
noCache: options.noCache,
|
|
91
|
+
noGfm: options.noGfm,
|
|
92
|
+
keepImgDataUrl: options.keepImgDataUrl,
|
|
93
|
+
withImagesSummary: options.withImagesSummary,
|
|
94
|
+
});
|
|
95
|
+
const { content: rawContent } = extractContent(response);
|
|
96
|
+
// --extract short-circuits: returns the extracted slice as a JSON array,
|
|
97
|
+
// bypassing truncation and envelope logic.
|
|
98
|
+
if (options.extract) {
|
|
99
|
+
const extracted = extract(rawContent, options.extract);
|
|
100
|
+
if (context) {
|
|
101
|
+
context.notice(`ℹ️ extracted ${extracted.length} ${options.extract}`);
|
|
113
102
|
}
|
|
103
|
+
return { kind: "data", data: extracted };
|
|
104
|
+
}
|
|
105
|
+
const { text, originalLen, truncated } = truncate(rawContent, options.maxChars);
|
|
106
|
+
if (truncated && context) {
|
|
107
|
+
context.notice(`⚠️ content truncated from ${originalLen.toLocaleString()} to ${text.length.toLocaleString()} chars; use a higher --max-chars or omit it for full content`);
|
|
114
108
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
// Default: content-only (drops title/metadata/external envelope).
|
|
110
|
+
// --full-envelope, json, or pretty keeps the structured object.
|
|
111
|
+
const wantEnvelope = options.fullEnvelope || outputMode === "json" || outputMode === "pretty";
|
|
112
|
+
if (wantEnvelope) {
|
|
113
|
+
const envelope = response && typeof response === "object"
|
|
114
|
+
? { ...response, content: text }
|
|
115
|
+
: { content: text };
|
|
116
|
+
return { kind: "data", data: envelope };
|
|
118
117
|
}
|
|
118
|
+
return { kind: "data", data: text };
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
process.exit(1);
|
|
120
|
+
finally {
|
|
121
|
+
await client.close().catch(() => { });
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
124
|
// Help text
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/commands/read.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/commands/read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAoB,MAAM,mBAAmB,CAAC;AAkB7E;;;;;;;;;GASG;AACH,SAAS,iBAAiB,CAAC,GAAW;IACpC,4BAA4B;IAC5B,IAAI,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC7C,8EAA8E;IAC9E,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAClF,IAAI,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACnB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,oEAAoE;IACpE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,GAAG,IAAI,OAAO,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,QAAiB;IACvC,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACnF,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC7C,MAAM,GAAG,GAAG,QAAgC,CAAC;QAC7C,IAAI,OAAO,GAAG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AAG,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEhF,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,CACZ,8BAA8B,WAAW,CAAC,cAAc,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,8DAA8D,CAC5J,CAAC;QACJ,CAAC;QAED,kEAAkE;QAClE,gEAAgE;QAChE,MAAM,YAAY,GAChB,OAAO,CAAC,YAAY,IAAI,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,QAAQ,CAAC;QAC3E,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,QAAQ,GACZ,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;gBACtC,CAAC,CAAC,EAAE,GAAI,QAAmB,EAAE,OAAO,EAAE,IAAI,EAAE;gBAC5C,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YACxB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC1C,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,YAAY;AACZ,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCxB,CAAC,IAAI,EAAE,CAAC"}
|
package/dist/commands/repo.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Repo commands for GitHub repository exploration (ZRead)
|
|
3
|
+
*
|
|
4
|
+
* P1-05: each command returns a CommandResult instead of writing
|
|
5
|
+
* directly to stdout/stderr. Validation errors are thrown and converted
|
|
6
|
+
* by invokeCommand.
|
|
3
7
|
*/
|
|
8
|
+
import type { CommandContext, CommandResult } from "../command-invocation.js";
|
|
4
9
|
export interface RepoSearchOptions {
|
|
5
10
|
language?: "en" | "zh";
|
|
6
11
|
maxChars?: number;
|
|
@@ -15,8 +20,8 @@ export interface RepoReadOptions {
|
|
|
15
20
|
maxChars?: number;
|
|
16
21
|
noCache?: boolean;
|
|
17
22
|
}
|
|
18
|
-
export declare function repoSearch(repo: string, query: string, options?: RepoSearchOptions): Promise<
|
|
19
|
-
export declare function repoTree(repo: string, options?: RepoTreeOptions): Promise<
|
|
20
|
-
export declare function repoRead(repo: string, path: string, options?: RepoReadOptions): Promise<
|
|
23
|
+
export declare function repoSearch(repo: string, query: string, options?: RepoSearchOptions, _context?: CommandContext): Promise<CommandResult>;
|
|
24
|
+
export declare function repoTree(repo: string, options?: RepoTreeOptions, _context?: CommandContext): Promise<CommandResult>;
|
|
25
|
+
export declare function repoRead(repo: string, path: string, options?: RepoReadOptions, _context?: CommandContext): Promise<CommandResult>;
|
|
21
26
|
export declare const REPO_HELP: string;
|
|
22
27
|
//# sourceMappingURL=repo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../src/commands/repo.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../src/commands/repo.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAW9E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAiFD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,iBAAsB,EAC/B,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,aAAa,CAAC,CAcxB;AAED,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,EAC7B,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,aAAa,CAAC,CA+BxB;AAED,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,EAC7B,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,aAAa,CAAC,CAUxB;AAGD,eAAO,MAAM,SAAS,QA2Cd,CAAC"}
|
package/dist/commands/repo.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Repo commands for GitHub repository exploration (ZRead)
|
|
3
|
+
*
|
|
4
|
+
* P1-05: each command returns a CommandResult instead of writing
|
|
5
|
+
* directly to stdout/stderr. Validation errors are thrown and converted
|
|
6
|
+
* by invokeCommand.
|
|
3
7
|
*/
|
|
4
8
|
import { ZReadMcpClient } from "../lib/mcp-client.js";
|
|
5
|
-
import {
|
|
6
|
-
import { formatErrorOutput, ValidationError } from "../lib/errors.js";
|
|
7
|
-
import { silenceConsole, restoreConsole } from "../lib/silence.js";
|
|
9
|
+
import { ValidationError } from "../lib/errors.js";
|
|
8
10
|
import path from "node:path";
|
|
9
11
|
function validateRepo(repo) {
|
|
10
12
|
if (!repo.includes("/")) {
|
|
@@ -74,101 +76,61 @@ async function collectTreeSnapshots(client, repo, basePath, depth) {
|
|
|
74
76
|
}
|
|
75
77
|
return snapshots;
|
|
76
78
|
}
|
|
77
|
-
export async function repoSearch(repo, query, options = {}) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
throw new ValidationError('Language must be "en" or "zh"');
|
|
82
|
-
}
|
|
79
|
+
export async function repoSearch(repo, query, options = {}, _context) {
|
|
80
|
+
validateRepo(repo);
|
|
81
|
+
if (options.language && options.language !== "en" && options.language !== "zh") {
|
|
82
|
+
throw new ValidationError('Language must be "en" or "zh"');
|
|
83
83
|
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
console.error(formatErrorOutput(error));
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
silenceConsole();
|
|
89
84
|
const client = new ZReadMcpClient({ enableVision: false, noCache: options.noCache });
|
|
90
85
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
outputSuccess(truncateText(results, options.maxChars));
|
|
95
|
-
}
|
|
96
|
-
finally {
|
|
97
|
-
await client.close().catch(() => { });
|
|
98
|
-
restoreConsole();
|
|
99
|
-
}
|
|
86
|
+
const language = options.language || "en";
|
|
87
|
+
const results = await client.searchDoc(repo, query, language);
|
|
88
|
+
return { kind: "data", data: truncateText(results, options.maxChars) };
|
|
100
89
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
process.exit(1);
|
|
90
|
+
finally {
|
|
91
|
+
await client.close().catch(() => { });
|
|
104
92
|
}
|
|
105
93
|
}
|
|
106
|
-
export async function repoTree(repo, options = {}) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
throw new ValidationError("Depth must be a positive integer");
|
|
113
|
-
}
|
|
94
|
+
export async function repoTree(repo, options = {}, _context) {
|
|
95
|
+
validateRepo(repo);
|
|
96
|
+
if (options.depth !== undefined) {
|
|
97
|
+
const depthValue = Number(options.depth);
|
|
98
|
+
if (!Number.isFinite(depthValue) || depthValue < 1) {
|
|
99
|
+
throw new ValidationError("Depth must be a positive integer");
|
|
114
100
|
}
|
|
115
101
|
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
console.error(formatErrorOutput(error));
|
|
118
|
-
process.exit(1);
|
|
119
|
-
}
|
|
120
|
-
silenceConsole();
|
|
121
102
|
const client = new ZReadMcpClient({ enableVision: false, noCache: options.noCache });
|
|
122
103
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
104
|
+
const depth = Math.max(1, Math.floor(options.depth || 1));
|
|
105
|
+
const dirPath = normalizeDirPath(options.path);
|
|
106
|
+
if (depth === 1) {
|
|
107
|
+
const structure = await client.getRepoStructure(repo, dirPath);
|
|
108
|
+
return { kind: "data", data: structure };
|
|
109
|
+
}
|
|
110
|
+
const snapshots = await collectTreeSnapshots(client, repo, dirPath, depth);
|
|
111
|
+
return {
|
|
112
|
+
kind: "data",
|
|
113
|
+
data: {
|
|
133
114
|
repo,
|
|
134
115
|
depth,
|
|
135
116
|
basePath: dirPath || "/",
|
|
136
117
|
snapshots,
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
finally {
|
|
140
|
-
await client.close().catch(() => { });
|
|
141
|
-
restoreConsole();
|
|
142
|
-
}
|
|
118
|
+
},
|
|
119
|
+
};
|
|
143
120
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
process.exit(1);
|
|
121
|
+
finally {
|
|
122
|
+
await client.close().catch(() => { });
|
|
147
123
|
}
|
|
148
124
|
}
|
|
149
|
-
export async function repoRead(repo, path, options = {}) {
|
|
150
|
-
|
|
151
|
-
validateRepo(repo);
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
console.error(formatErrorOutput(error));
|
|
155
|
-
process.exit(1);
|
|
156
|
-
}
|
|
157
|
-
silenceConsole();
|
|
125
|
+
export async function repoRead(repo, path, options = {}, _context) {
|
|
126
|
+
validateRepo(repo);
|
|
158
127
|
const client = new ZReadMcpClient({ enableVision: false, noCache: options.noCache });
|
|
159
128
|
try {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
outputSuccess(truncateText(content, options.maxChars));
|
|
163
|
-
}
|
|
164
|
-
finally {
|
|
165
|
-
await client.close().catch(() => { });
|
|
166
|
-
restoreConsole();
|
|
167
|
-
}
|
|
129
|
+
const content = await client.readFile(repo, path);
|
|
130
|
+
return { kind: "data", data: truncateText(content, options.maxChars) };
|
|
168
131
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
process.exit(1);
|
|
132
|
+
finally {
|
|
133
|
+
await client.close().catch(() => { });
|
|
172
134
|
}
|
|
173
135
|
}
|
|
174
136
|
// Help text
|