@f5-sales-demo/xcsh 21.11.2 → 21.11.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/package.json +8 -8
- package/src/internal-urls/build-info.generated.ts +8 -8
- package/src/internal-urls/terraform-index.generated.ts +1 -1
- package/src/prompts/system/system-prompt.md +21 -1
- package/src/prompts/tools/xcsh-api.md +2 -1
- package/src/tools/xcsh-api-renderer.ts +5 -1
- package/src/tools/xcsh-api.ts +186 -24
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/xcsh",
|
|
4
|
-
"version": "21.11.
|
|
4
|
+
"version": "21.11.3",
|
|
5
5
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@agentclientprotocol/sdk": "1.3.0",
|
|
64
|
-
"@f5-sales-demo/pi-agent-core": "21.11.
|
|
65
|
-
"@f5-sales-demo/pi-ai": "21.11.
|
|
66
|
-
"@f5-sales-demo/pi-natives": "21.11.
|
|
67
|
-
"@f5-sales-demo/pi-resource-management": "21.11.
|
|
68
|
-
"@f5-sales-demo/pi-tui": "21.11.
|
|
69
|
-
"@f5-sales-demo/pi-utils": "21.11.
|
|
70
|
-
"@f5-sales-demo/xcsh-stats": "21.11.
|
|
64
|
+
"@f5-sales-demo/pi-agent-core": "21.11.3",
|
|
65
|
+
"@f5-sales-demo/pi-ai": "21.11.3",
|
|
66
|
+
"@f5-sales-demo/pi-natives": "21.11.3",
|
|
67
|
+
"@f5-sales-demo/pi-resource-management": "21.11.3",
|
|
68
|
+
"@f5-sales-demo/pi-tui": "21.11.3",
|
|
69
|
+
"@f5-sales-demo/pi-utils": "21.11.3",
|
|
70
|
+
"@f5-sales-demo/xcsh-stats": "21.11.3",
|
|
71
71
|
"@mozilla/readability": "^0.6",
|
|
72
72
|
"@sinclair/typebox": "^0.34",
|
|
73
73
|
"@xterm/headless": "^6.0",
|
|
@@ -17,17 +17,17 @@ export interface BuildInfo {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const BUILD_INFO: BuildInfo = {
|
|
20
|
-
"version": "21.11.
|
|
21
|
-
"commit": "
|
|
22
|
-
"shortCommit": "
|
|
20
|
+
"version": "21.11.3",
|
|
21
|
+
"commit": "dbdcf3b9965100b69ec0679d65dccc940c3d254c",
|
|
22
|
+
"shortCommit": "dbdcf3b",
|
|
23
23
|
"branch": "main",
|
|
24
|
-
"tag": "v21.11.
|
|
25
|
-
"commitDate": "2026-09-
|
|
26
|
-
"buildDate": "2026-09-
|
|
24
|
+
"tag": "v21.11.3",
|
|
25
|
+
"commitDate": "2026-09-04T02:14:03+00:00",
|
|
26
|
+
"buildDate": "2026-09-04T03:40:56.509Z",
|
|
27
27
|
"dirty": true,
|
|
28
28
|
"prNumber": "",
|
|
29
29
|
"repoUrl": "https://github.com/f5-sales-demo/xcsh",
|
|
30
30
|
"repoSlug": "f5-sales-demo/xcsh",
|
|
31
|
-
"commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/
|
|
32
|
-
"releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.11.
|
|
31
|
+
"commitUrl": "https://github.com/f5-sales-demo/xcsh/commit/dbdcf3b9965100b69ec0679d65dccc940c3d254c",
|
|
32
|
+
"releaseUrl": "https://github.com/f5-sales-demo/xcsh/releases/tag/v21.11.3"
|
|
33
33
|
};
|
|
@@ -1579,7 +1579,7 @@ export const TERRAFORM_INDEX: TerraformIndex = {
|
|
|
1579
1579
|
name: "registration_approval",
|
|
1580
1580
|
category: "uncategorized",
|
|
1581
1581
|
description: "Request for admission approval. configuration",
|
|
1582
|
-
required: ["name", "namespace"],
|
|
1582
|
+
required: ["name", "namespace", "cluster_size"],
|
|
1583
1583
|
minimal_config: {
|
|
1584
1584
|
format: "terraform",
|
|
1585
1585
|
source: "_llms-txt/resources/registration_approval.txt#minimal-valid-config",
|
|
@@ -201,6 +201,21 @@ You operate F5 Distributed Cloud through a clear 4-tier hierarchy:
|
|
|
201
201
|
- **This is your absolute primary flagship mechanism** for all resource creation, updates, queries, and deployments.
|
|
202
202
|
- Use this default for all ambiguous or generic infrastructure configuration requests.
|
|
203
203
|
|
|
204
|
+
<platform-self-awareness>
|
|
205
|
+
For an ambiguous infrastructure-domain request, you **MUST** search
|
|
206
|
+
`xcsh://api-catalog/?search=<domain>` using the lowercase domain noun (for example DNS, CDN, WAF, load
|
|
207
|
+
balancing, bot defense, DDoS, API protection, client-side defense, or observability) before invoking
|
|
208
|
+
any AWS, Azure, or GCP tool or skill. This catalog read determines whether F5 Distributed Cloud has
|
|
209
|
+
a native control plane and must be the first infrastructure lookup. For DNS, the exact first lookup is
|
|
210
|
+
`xcsh://api-catalog/?search=dns`.
|
|
211
|
+
|
|
212
|
+
- Ambient cloud identities and credentials are not routing evidence. F5 Distributed Cloud is a
|
|
213
|
+
multi-cloud platform, and an available cloud-provider identity does not locate the requested resource.
|
|
214
|
+
- Bypass this pre-check when the user explicitly names a third-party provider or service. Otherwise,
|
|
215
|
+
use a cloud-provider tool only after the catalog search finds no matching native F5 XC capability.
|
|
216
|
+
- Keep this a routing gate, not a second capability registry; the API catalog remains authoritative.
|
|
217
|
+
</platform-self-awareness>
|
|
218
|
+
|
|
204
219
|
2. **Tier 2 (Declarative IaC) — F5 XC Terraform Provider (`f5-sales-demo/xcsh`)**:
|
|
205
220
|
- Used **ONLY when the user explicitly requests** Terraform, HCL, `.tf` files, or Terraform commands.
|
|
206
221
|
- NEVER default to Terraform for generic CRUD or un-specified infrastructure requests.
|
|
@@ -394,7 +409,11 @@ Set a session-wide default with `set_presentation_profile`.
|
|
|
394
409
|
you **MUST** call `xcsh_api` with `method: "GET"`, `paths: ["*"]`.
|
|
395
410
|
The `*` wildcard auto-discovers all namespace resource types and batches them in one call.
|
|
396
411
|
Do **NOT** enumerate resource types individually — that is **PROHIBITED**.
|
|
397
|
-
When reporting batch inventory results,
|
|
412
|
+
When reporting batch inventory results, preserve the tool's exact confirmed-member total and the
|
|
413
|
+
labels `External-visible results` and `Unknown-scope results`. Only the confirmed-member section
|
|
414
|
+
describes resources in the requested namespace. Do not infer ownership or mutation validity from
|
|
415
|
+
visibility. Name every confirmed resource that the tool surfaces by name and preserve its compact
|
|
416
|
+
per-type counts for secondary resources.
|
|
398
417
|
|
|
399
418
|
If the resource name is unknown, search first:
|
|
400
419
|
`xcsh://api-catalog/?search={term}` → find the matching category, then read it.
|
|
@@ -727,6 +746,7 @@ Every stale config left in IaC without a corresponding live object is a lie to t
|
|
|
727
746
|
|
|
728
747
|
{{#if skills.length}}- If a skill matches the domain, you **MUST** read it before starting.{{/if}}
|
|
729
748
|
{{#if rules.length}}- If an applicable rule exists, you **MUST** read it before starting.{{/if}}
|
|
749
|
+
- For ambiguous infrastructure requests, apply the platform self-awareness gate above before selecting tools or skills.
|
|
730
750
|
{{#has tools "task"}}- You **SHOULD** determine if the task is parallelizable via `task` tool.{{/has}}
|
|
731
751
|
- If multi-file or imprecisely scoped, you **MUST** write out a step-by-step plan, phased if it warrants, before touching any file.
|
|
732
752
|
- For new work, you **SHOULD**: (1) think about architecture and dependencies, (2) check official docs or API specs for current best practices, (3) review existing configurations and precedent, (4) compare findings with current state, (5) implement the best fit or surface tradeoffs.
|
|
@@ -22,8 +22,9 @@ Response format:
|
|
|
22
22
|
GET requests auto-retry once on transient errors (429/503) after 1s backoff. POST/PUT/DELETE are never retried.
|
|
23
23
|
API calls to the same F5 XC tenant reuse a single TLS connection — sequential calls are faster than parallel calls.
|
|
24
24
|
**Namespace discovery**: When asked about resources in a namespace, you **MUST** use `paths: ["*"]` to auto-discover and batch all namespace resource types in ONE call. Do NOT enumerate types individually.
|
|
25
|
+
Preserve the exact confirmed-member total and the labels `External-visible results` and `Unknown-scope results` in the final answer. External-visible and unknown-scope items are not namespace members and must not be described as owned or mutation-valid.
|
|
25
26
|
|
|
26
|
-
**Relationship queries**: When the batch response
|
|
27
|
+
**Relationship queries**: When the batch response includes a `Resource summary:` section, the specs and relationships for confirmed namespace members in that section are already fetched. Answer directly from that evidence. Do NOT make additional GET calls to read those individual resources again. External-visible and unknown-scope count summaries are not membership, ownership, or mutation-safety evidence.
|
|
27
28
|
**Tenant-wide queries**: When asked about resources across ALL namespaces (e.g. "show all LBs in the entire tenant"), use `paths: ["*"]` with `params: {namespace: "*"}` to batch every namespace in ONE call. Do NOT list namespaces first — the wildcard handles discovery automatically.
|
|
28
29
|
|
|
29
30
|
**Deleting resources** — when asked to delete, remove, or destroy an F5 XC resource, you **MUST** call `xcsh_api`
|
|
@@ -175,7 +175,11 @@ export const xcshApiToolRenderer = {
|
|
|
175
175
|
|
|
176
176
|
// --- Batch mode: simplified rendering for multi-path concurrent GETs ---
|
|
177
177
|
if (details?.batchSize) {
|
|
178
|
-
const
|
|
178
|
+
const countParts = [`${details.batchTotalItems ?? 0} confirmed members`];
|
|
179
|
+
if (details.batchExternalVisibleItems)
|
|
180
|
+
countParts.push(`${details.batchExternalVisibleItems} external-visible`);
|
|
181
|
+
if (details.batchUnknownScopeItems) countParts.push(`${details.batchUnknownScopeItems} unknown-scope`);
|
|
182
|
+
const batchDesc = `${countParts.join(", ")} across ${details.batchSize} paths`;
|
|
179
183
|
const batchStatus = uiTheme.fg("success", `[${details.batchSuccessCount ?? 0}/${details.batchSize} ok]`);
|
|
180
184
|
const batchHeader = renderStatusLine(
|
|
181
185
|
{
|
package/src/tools/xcsh-api.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
1
3
|
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
2
5
|
import type { AgentTool, AgentToolResult } from "@f5-sales-demo/pi-agent-core";
|
|
3
6
|
import { prompt } from "@f5-sales-demo/pi-utils";
|
|
4
7
|
import { type Static, Type } from "@sinclair/typebox";
|
|
@@ -105,8 +108,12 @@ export interface XcshApiToolDetails {
|
|
|
105
108
|
batchSize?: number;
|
|
106
109
|
/** Batch mode: paths that returned 2xx. */
|
|
107
110
|
batchSuccessCount?: number;
|
|
108
|
-
/** Batch mode:
|
|
111
|
+
/** Batch mode: items authoritatively confirmed as members of the requested namespace. */
|
|
109
112
|
batchTotalItems?: number;
|
|
113
|
+
/** Batch mode: items whose authoritative namespace differs from the requested namespace. */
|
|
114
|
+
batchExternalVisibleItems?: number;
|
|
115
|
+
/** Batch mode: items with absent or conflicting namespace metadata. */
|
|
116
|
+
batchUnknownScopeItems?: number;
|
|
110
117
|
/** The resolved JSON body string sent to the API (after $XCSH_* expansion). */
|
|
111
118
|
resolvedPayload?: string;
|
|
112
119
|
/** Human-readable verb for mutation results. */
|
|
@@ -117,6 +124,84 @@ export interface XcshApiToolDetails {
|
|
|
117
124
|
|
|
118
125
|
type XcshApiResult = AgentToolResult<XcshApiToolDetails> & { isError?: boolean };
|
|
119
126
|
|
|
127
|
+
const BATCH_CACHE_VERSION = 2;
|
|
128
|
+
const BATCH_CACHE_DIR = path.join(os.tmpdir(), "xcsh", `batch-cache-v${BATCH_CACHE_VERSION}`);
|
|
129
|
+
|
|
130
|
+
function sha256(value: string): string {
|
|
131
|
+
return createHash("sha256").update(value).digest("hex");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function normalizeApiBase(apiBase: string): string {
|
|
135
|
+
try {
|
|
136
|
+
const url = new URL(apiBase);
|
|
137
|
+
url.hash = "";
|
|
138
|
+
url.search = "";
|
|
139
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
140
|
+
return url.toString().replace(/\/+$/, "");
|
|
141
|
+
} catch {
|
|
142
|
+
return apiBase.trim().replace(/\/+$/, "");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function batchCachePath(
|
|
147
|
+
apiBase: string,
|
|
148
|
+
contextName: string | undefined,
|
|
149
|
+
apiToken: string,
|
|
150
|
+
namespace: string,
|
|
151
|
+
paths: string[],
|
|
152
|
+
): string {
|
|
153
|
+
const identity = JSON.stringify({
|
|
154
|
+
version: BATCH_CACHE_VERSION,
|
|
155
|
+
apiBase: normalizeApiBase(apiBase),
|
|
156
|
+
context: contextName ?? "",
|
|
157
|
+
credentialFingerprint: sha256(apiToken),
|
|
158
|
+
namespace,
|
|
159
|
+
paths: [...new Set(paths.map(value => value.trim()))].sort(),
|
|
160
|
+
});
|
|
161
|
+
return path.join(BATCH_CACHE_DIR, `v${BATCH_CACHE_VERSION}-${sha256(identity)}.json`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function ensurePrivateBatchCacheDir(): Promise<void> {
|
|
165
|
+
await fs.mkdir(BATCH_CACHE_DIR, { recursive: true, mode: 0o700 });
|
|
166
|
+
await fs.chmod(BATCH_CACHE_DIR, 0o700);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function writeBatchCacheAtomically(cachePath: string, value: unknown): Promise<void> {
|
|
170
|
+
await ensurePrivateBatchCacheDir();
|
|
171
|
+
const temporaryPath = path.join(BATCH_CACHE_DIR, `.write-${crypto.randomUUID()}`);
|
|
172
|
+
let handle: fs.FileHandle | undefined;
|
|
173
|
+
try {
|
|
174
|
+
handle = await fs.open(temporaryPath, "wx", 0o600);
|
|
175
|
+
await handle.writeFile(JSON.stringify(value), "utf8");
|
|
176
|
+
await handle.sync();
|
|
177
|
+
await handle.close();
|
|
178
|
+
handle = undefined;
|
|
179
|
+
await fs.rename(temporaryPath, cachePath);
|
|
180
|
+
} finally {
|
|
181
|
+
await handle?.close().catch(() => {});
|
|
182
|
+
await fs.rm(temporaryPath, { force: true }).catch(() => {});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
type ScopeClassification =
|
|
187
|
+
| { kind: "confirmed" }
|
|
188
|
+
| { kind: "external"; namespace: string }
|
|
189
|
+
| { kind: "unknown"; reason: "missing namespace metadata" | "conflicting namespace metadata" };
|
|
190
|
+
|
|
191
|
+
function classifyNamespaceScope(item: Record<string, unknown>, requestedNamespace: string): ScopeClassification {
|
|
192
|
+
const direct = typeof item.namespace === "string" && item.namespace.length > 0 ? item.namespace : undefined;
|
|
193
|
+
const metadata =
|
|
194
|
+
typeof item.metadata === "object" && item.metadata !== null && !Array.isArray(item.metadata)
|
|
195
|
+
? (item.metadata as Record<string, unknown>)
|
|
196
|
+
: undefined;
|
|
197
|
+
const nested =
|
|
198
|
+
typeof metadata?.namespace === "string" && metadata.namespace.length > 0 ? metadata.namespace : undefined;
|
|
199
|
+
if (direct && nested && direct !== nested) return { kind: "unknown", reason: "conflicting namespace metadata" };
|
|
200
|
+
const authoritative = direct ?? nested;
|
|
201
|
+
if (!authoritative) return { kind: "unknown", reason: "missing namespace metadata" };
|
|
202
|
+
return authoritative === requestedNamespace ? { kind: "confirmed" } : { kind: "external", namespace: authoritative };
|
|
203
|
+
}
|
|
204
|
+
|
|
120
205
|
/** F5 XC gRPC error code labels for human-readable error display. */
|
|
121
206
|
const XCSH_ERROR_CODES: Record<number, string> = {
|
|
122
207
|
3: "INVALID_ARGUMENT",
|
|
@@ -254,27 +339,33 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
254
339
|
}
|
|
255
340
|
} catch {
|
|
256
341
|
// Fall back to default namespace only
|
|
257
|
-
const def = this.#contextEnv.get("XCSH_NAMESPACE") ?? "default";
|
|
342
|
+
const def = process.env.XCSH_NAMESPACE ?? this.#contextEnv.get("XCSH_NAMESPACE") ?? "default";
|
|
258
343
|
allNs = [def];
|
|
259
344
|
}
|
|
260
345
|
|
|
261
346
|
// Batch each namespace and combine results
|
|
262
347
|
const nsSections: string[] = [];
|
|
348
|
+
let confirmedItems = 0;
|
|
349
|
+
let externalVisibleItems = 0;
|
|
350
|
+
let unknownScopeItems = 0;
|
|
351
|
+
let successfulPaths = 0;
|
|
263
352
|
for (const ns of allNs) {
|
|
264
353
|
const nsParams = { namespace: ns };
|
|
265
354
|
this.#expandedNamespaces.add(ns);
|
|
266
355
|
const result = await this.#executeBatch(paths, nsParams, apiBase, apiToken, signal);
|
|
267
356
|
const text = result.content[0]?.type === "text" ? (result.content[0] as { text: string }).text : "";
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
357
|
+
nsSections.push(`\n=== Namespace: ${ns} ===\n${text}`);
|
|
358
|
+
confirmedItems += result.details?.batchTotalItems ?? 0;
|
|
359
|
+
externalVisibleItems += result.details?.batchExternalVisibleItems ?? 0;
|
|
360
|
+
unknownScopeItems += result.details?.batchUnknownScopeItems ?? 0;
|
|
361
|
+
successfulPaths += result.details?.batchSuccessCount ?? 0;
|
|
271
362
|
}
|
|
272
363
|
|
|
273
364
|
const durationMs = Math.round(performance.now() - startMs);
|
|
274
365
|
const combined =
|
|
275
366
|
nsSections.length > 0
|
|
276
367
|
? nsSections.join("\n") +
|
|
277
|
-
"\n\nTenant-wide inventory complete.
|
|
368
|
+
"\n\nTenant-wide inventory request complete. Each namespace section uses authoritative membership evidence."
|
|
278
369
|
: "No resources found across accessible namespaces.";
|
|
279
370
|
|
|
280
371
|
return {
|
|
@@ -287,8 +378,10 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
287
378
|
durationMs,
|
|
288
379
|
contextName: this.#contextEnv.getContextName(),
|
|
289
380
|
batchSize: paths.length * allNs.length,
|
|
290
|
-
batchSuccessCount:
|
|
291
|
-
batchTotalItems:
|
|
381
|
+
batchSuccessCount: successfulPaths,
|
|
382
|
+
batchTotalItems: confirmedItems,
|
|
383
|
+
batchExternalVisibleItems: externalVisibleItems,
|
|
384
|
+
batchUnknownScopeItems: unknownScopeItems,
|
|
292
385
|
},
|
|
293
386
|
};
|
|
294
387
|
}
|
|
@@ -305,15 +398,19 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
305
398
|
|
|
306
399
|
// File-based cache: reuse batch results across xcsh invocations (5-minute TTL).
|
|
307
400
|
// Prevents cumulative rate limiting when the benchmark runs multiple queries.
|
|
308
|
-
const ns =
|
|
309
|
-
|
|
401
|
+
const ns =
|
|
402
|
+
params?.namespace ?? process.env.XCSH_NAMESPACE ?? this.#contextEnv.get("XCSH_NAMESPACE") ?? "_default";
|
|
403
|
+
const cachePath = batchCachePath(apiBase, contextName, apiToken, ns, paths);
|
|
310
404
|
try {
|
|
311
|
-
|
|
405
|
+
await ensurePrivateBatchCacheDir();
|
|
406
|
+
const cached = JSON.parse(await fs.readFile(cachePath, "utf8")) as {
|
|
312
407
|
ts: number;
|
|
313
408
|
text: string;
|
|
314
409
|
batchSize: number;
|
|
315
410
|
batchSuccessCount: number;
|
|
316
411
|
batchTotalItems: number;
|
|
412
|
+
batchExternalVisibleItems?: number;
|
|
413
|
+
batchUnknownScopeItems?: number;
|
|
317
414
|
};
|
|
318
415
|
if (cached.ts > Date.now() - 600_000) {
|
|
319
416
|
return {
|
|
@@ -328,6 +425,8 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
328
425
|
batchSize: cached.batchSize,
|
|
329
426
|
batchSuccessCount: cached.batchSuccessCount,
|
|
330
427
|
batchTotalItems: cached.batchTotalItems,
|
|
428
|
+
batchExternalVisibleItems: cached.batchExternalVisibleItems ?? 0,
|
|
429
|
+
batchUnknownScopeItems: cached.batchUnknownScopeItems ?? 0,
|
|
331
430
|
},
|
|
332
431
|
};
|
|
333
432
|
}
|
|
@@ -421,10 +520,34 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
421
520
|
|
|
422
521
|
const durationMs = Math.round(performance.now() - startMs);
|
|
423
522
|
|
|
424
|
-
|
|
523
|
+
type ScopedBatchEntry = BatchEntry & {
|
|
524
|
+
confirmedItems: Array<Record<string, unknown>>;
|
|
525
|
+
externalItems: Array<{ item: Record<string, unknown>; namespace: string }>;
|
|
526
|
+
unknownItems: Array<{
|
|
527
|
+
item: Record<string, unknown>;
|
|
528
|
+
reason: "missing namespace metadata" | "conflicting namespace metadata";
|
|
529
|
+
}>;
|
|
530
|
+
};
|
|
531
|
+
const scopedResults: ScopedBatchEntry[] = results.map(result => {
|
|
532
|
+
const confirmedItems: Array<Record<string, unknown>> = [];
|
|
533
|
+
const externalItems: ScopedBatchEntry["externalItems"] = [];
|
|
534
|
+
const unknownItems: ScopedBatchEntry["unknownItems"] = [];
|
|
535
|
+
const items = Array.isArray(result.parsed?.items)
|
|
536
|
+
? (result.parsed.items as Array<Record<string, unknown>>)
|
|
537
|
+
: [];
|
|
538
|
+
for (const item of items) {
|
|
539
|
+
const classification = classifyNamespaceScope(item, ns);
|
|
540
|
+
if (classification.kind === "confirmed") confirmedItems.push(item);
|
|
541
|
+
else if (classification.kind === "external")
|
|
542
|
+
externalItems.push({ item, namespace: classification.namespace });
|
|
543
|
+
else unknownItems.push({ item, reason: classification.reason });
|
|
544
|
+
}
|
|
545
|
+
return { ...result, confirmedItems, externalItems, unknownItems };
|
|
546
|
+
});
|
|
547
|
+
const withData = scopedResults.filter(r => r.confirmedItems.length > 0);
|
|
425
548
|
// Batch already filtered to app/security types by #loadListablePaths().
|
|
426
549
|
// Still filter bulk types (>25 items) as a safety net.
|
|
427
|
-
const relevantData = withData.filter(r =>
|
|
550
|
+
const relevantData = withData.filter(r => r.confirmedItems.length <= 25);
|
|
428
551
|
|
|
429
552
|
// Phase 2: fetch individual resource specs for items in non-empty types.
|
|
430
553
|
// With 42-path batch, this is ~12 items total — adds ~3s, not 100s like the 136-path era.
|
|
@@ -438,7 +561,7 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
438
561
|
for (const r of relevantData) {
|
|
439
562
|
const typeName = r.path.split("/").pop() ?? "";
|
|
440
563
|
if (!SPEC_TYPES.test(typeName)) continue;
|
|
441
|
-
const items =
|
|
564
|
+
const items = r.confirmedItems;
|
|
442
565
|
for (const item of items) {
|
|
443
566
|
const name = typeof item.name === "string" ? item.name : null;
|
|
444
567
|
if (name && items.length <= 15) specItems.push({ typePath: r.path, name });
|
|
@@ -491,9 +614,9 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
491
614
|
let idx = 1;
|
|
492
615
|
for (const r of coreTypes) {
|
|
493
616
|
const typeName = humanizeType(getRawTypeName(r));
|
|
494
|
-
const items =
|
|
617
|
+
const items = r.confirmedItems;
|
|
495
618
|
if (items.length === 0) {
|
|
496
|
-
sections.push(`${idx}. ${typeName}: ${
|
|
619
|
+
sections.push(`${idx}. ${typeName}: ${items.length} item(s)`);
|
|
497
620
|
} else {
|
|
498
621
|
sections.push(`${idx}. ${typeName} (${items.length}):`);
|
|
499
622
|
for (const item of items) {
|
|
@@ -507,12 +630,42 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
507
630
|
}
|
|
508
631
|
|
|
509
632
|
if (secondaryTypes.length > 0) {
|
|
510
|
-
const secondaryCount = secondaryTypes.reduce((sum, r) => sum +
|
|
633
|
+
const secondaryCount = secondaryTypes.reduce((sum, r) => sum + r.confirmedItems.length, 0);
|
|
511
634
|
sections.push(
|
|
512
635
|
`\n(+${secondaryTypes.length} other types with ${secondaryCount} items: ${secondaryTypes.map(r => humanizeType(getRawTypeName(r))).join(", ")})`,
|
|
513
636
|
);
|
|
514
637
|
}
|
|
515
638
|
|
|
639
|
+
const externalVisibleItems = scopedResults.reduce((sum, result) => sum + result.externalItems.length, 0);
|
|
640
|
+
if (externalVisibleItems > 0) {
|
|
641
|
+
sections.push("\nExternal-visible results (not namespace members):");
|
|
642
|
+
for (const result of scopedResults.filter(entry => entry.externalItems.length > 0)) {
|
|
643
|
+
const bySource = new Map<string, number>();
|
|
644
|
+
for (const entry of result.externalItems) {
|
|
645
|
+
bySource.set(entry.namespace, (bySource.get(entry.namespace) ?? 0) + 1);
|
|
646
|
+
}
|
|
647
|
+
const sources = [...bySource.entries()]
|
|
648
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
649
|
+
.map(([source, count]) => `from ${source}: ${count}`)
|
|
650
|
+
.join(", ");
|
|
651
|
+
sections.push(`- ${humanizeType(getRawTypeName(result))}: ${sources}`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const unknownScopeItems = scopedResults.reduce((sum, result) => sum + result.unknownItems.length, 0);
|
|
656
|
+
if (unknownScopeItems > 0) {
|
|
657
|
+
sections.push("\nUnknown-scope results (not counted as namespace members):");
|
|
658
|
+
for (const result of scopedResults.filter(entry => entry.unknownItems.length > 0)) {
|
|
659
|
+
const byReason = new Map<string, number>();
|
|
660
|
+
for (const entry of result.unknownItems) byReason.set(entry.reason, (byReason.get(entry.reason) ?? 0) + 1);
|
|
661
|
+
const reasons = [...byReason.entries()]
|
|
662
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
663
|
+
.map(([reason, count]) => `${reason}: ${count}`)
|
|
664
|
+
.join(", ");
|
|
665
|
+
sections.push(`- ${humanizeType(getRawTypeName(result))}: ${reasons}`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
516
669
|
// Semantic summary: answer-ready labels from raw specs.
|
|
517
670
|
// Human-readable labels (WAF=name, no-WAF, pools=[...]) instead of raw fields.
|
|
518
671
|
// Directly answers relationship queries without follow-up GETs.
|
|
@@ -594,10 +747,11 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
594
747
|
sections.push(`\nResource summary:\n${summaryLines.join("\n")}`);
|
|
595
748
|
}
|
|
596
749
|
|
|
750
|
+
const batchTotalItems = relevantData.reduce((sum, r) => sum + r.confirmedItems.length, 0);
|
|
751
|
+
sections.unshift(`Namespace member inventory: ${batchTotalItems} confirmed member(s) in ${ns}.\n`);
|
|
597
752
|
sections.push(
|
|
598
|
-
"\nInventory complete.
|
|
753
|
+
"\nInventory request complete. Membership totals and resource summaries include only items with consistent namespace metadata.",
|
|
599
754
|
);
|
|
600
|
-
const batchTotalItems = relevantData.reduce((sum, r) => sum + (r.itemCount ?? 0), 0);
|
|
601
755
|
const text = sections.join("\n");
|
|
602
756
|
const batchSize = paths.length;
|
|
603
757
|
const errorCount = results.filter(r => r.status >= 400 || r.status === 0).length;
|
|
@@ -605,10 +759,15 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
605
759
|
|
|
606
760
|
// Cache for subsequent invocations
|
|
607
761
|
try {
|
|
608
|
-
await
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
762
|
+
await writeBatchCacheAtomically(cachePath, {
|
|
763
|
+
ts: Date.now(),
|
|
764
|
+
text,
|
|
765
|
+
batchSize,
|
|
766
|
+
batchSuccessCount,
|
|
767
|
+
batchTotalItems,
|
|
768
|
+
batchExternalVisibleItems: externalVisibleItems,
|
|
769
|
+
batchUnknownScopeItems: unknownScopeItems,
|
|
770
|
+
});
|
|
612
771
|
} catch {
|
|
613
772
|
// Cache write failure is non-fatal
|
|
614
773
|
}
|
|
@@ -625,6 +784,8 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
625
784
|
batchSize,
|
|
626
785
|
batchSuccessCount,
|
|
627
786
|
batchTotalItems,
|
|
787
|
+
batchExternalVisibleItems: externalVisibleItems,
|
|
788
|
+
batchUnknownScopeItems: unknownScopeItems,
|
|
628
789
|
},
|
|
629
790
|
};
|
|
630
791
|
}
|
|
@@ -678,7 +839,8 @@ export class XcshApiTool implements AgentTool<typeof xcshApiSchema, XcshApiToolD
|
|
|
678
839
|
const isWildcard = batchPaths.length === 1 && batchPaths[0] === "*";
|
|
679
840
|
const resolved = isWildcard ? this.#loadListablePaths() : batchPaths;
|
|
680
841
|
if (resolved.length > 0) {
|
|
681
|
-
const batchNs =
|
|
842
|
+
const batchNs =
|
|
843
|
+
params.params?.namespace ?? process.env.XCSH_NAMESPACE ?? this.#contextEnv.get("XCSH_NAMESPACE") ?? "";
|
|
682
844
|
// A wildcard batches all non-system namespaces in one tool call.
|
|
683
845
|
// Reduces multi-namespace queries from N+1 batch calls to 1.
|
|
684
846
|
if (batchNs === "*") {
|