agent-first-data 0.13.0 → 0.13.2
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 +2 -1
- package/dist/cli.d.ts +13 -0
- package/dist/cli.js +63 -1
- package/dist/format.d.ts +7 -2
- package/dist/format.js +46 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ console.log(outputJson(value));
|
|
|
20
20
|
console.log(outputPlain(value));
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Useful names use TypeScript casing: `outputJson`, `outputYaml`, `outputPlain`, `outputJsonWithOptions`, `redactedValue`, `redactSecretsInPlace`, `redactUrlSecrets`, `parseSize`, `normalizeUtcOffset`, `cliParseOutput`, `cliOutput`, and `
|
|
23
|
+
Useful names use TypeScript casing: `outputJson`, `outputYaml`, `outputPlain`, `outputJsonWithOptions`, `redactedValue`, `redactSecretsInPlace`, `redactUrlSecrets`, `parseSize`, `normalizeUtcOffset`, `isValidRfc3339Date`, `isValidRfc3339Time`, `cliParseOutput`, `cliOutput`, `buildCliError`, `buildCliVersion`, and `cliHandleVersionOrContinue`.
|
|
24
24
|
|
|
25
25
|
Logging is available through `initJson`, `initPlain`, `initYaml`, `span`, and `log`.
|
|
26
26
|
|
|
@@ -37,6 +37,7 @@ initJson({ secretNames: ["authorization"] });
|
|
|
37
37
|
- YAML/plain quote and escape keys as well as values, sort by UTF-16 code unit order, and render nested objects in arrays as canonical JSON.
|
|
38
38
|
- Logging records use `code: "log"` plus a separate `level` field, so error-level logs are not terminal protocol errors.
|
|
39
39
|
- `build_cli_error(message, hint?)` returns `{code:"error", error: message, hint?}` only.
|
|
40
|
+
- Use `cliHandleVersionOrContinue()` before argument parsing so bare `--version` stays conventional and `--version --output json|yaml|plain` stays structured.
|
|
40
41
|
|
|
41
42
|
## Reference
|
|
42
43
|
|
package/dist/cli.d.ts
CHANGED
|
@@ -34,6 +34,19 @@ export declare function cliOutput(value: JsonValue, format: OutputFormat): strin
|
|
|
34
34
|
* JSON ignores OutputStyle and preserves original keys and values after redaction.
|
|
35
35
|
*/
|
|
36
36
|
export declare function cliOutputWithOptions(value: JsonValue, format: OutputFormat, outputOptions: OutputOptions): string;
|
|
37
|
+
/** Build a standard CLI version value. */
|
|
38
|
+
export declare function buildCliVersion(version: string): JsonValue;
|
|
39
|
+
/**
|
|
40
|
+
* Render CLI version output.
|
|
41
|
+
* Pass an OutputFormat for AFDATA JSON/YAML/plain. Pass null to preserve
|
|
42
|
+
* conventional "<name> <version>" text.
|
|
43
|
+
*/
|
|
44
|
+
export declare function cliRenderVersion(name: string, version: string, format?: OutputFormat | null): string;
|
|
45
|
+
/**
|
|
46
|
+
* Render version output if --version/-V is present; otherwise return undefined.
|
|
47
|
+
* Throws for malformed version requests, for example `--version --output xml`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function cliHandleVersionOrContinue(rawArgs: string[], name: string, version: string, defaultOutput?: OutputFormat | null, outputFlag?: string, allowOutputFormat?: boolean): string | undefined;
|
|
37
50
|
/**
|
|
38
51
|
* Build a standard CLI parse error value.
|
|
39
52
|
* Use when flag parsing fails or a flag value is invalid.
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AFDATA CLI helpers — output format parsing, log filter normalization, error building.
|
|
3
3
|
*/
|
|
4
|
-
import { outputJson, outputJsonWithOptions, outputYaml, outputYamlWithOptions, outputPlain, outputPlainWithOptions, } from "./format.js";
|
|
4
|
+
import { buildJson, outputJson, outputJsonWithOptions, outputYaml, outputYamlWithOptions, outputPlain, outputPlainWithOptions, } from "./format.js";
|
|
5
5
|
/**
|
|
6
6
|
* Parse the --output flag value into an OutputFormat.
|
|
7
7
|
* Throws on unknown values; catch and pass message to buildCliError.
|
|
@@ -58,6 +58,68 @@ export function cliOutputWithOptions(value, format, outputOptions) {
|
|
|
58
58
|
return outputPlainWithOptions(value, outputOptions);
|
|
59
59
|
return outputJsonWithOptions(value, outputOptions);
|
|
60
60
|
}
|
|
61
|
+
/** Build a standard CLI version value. */
|
|
62
|
+
export function buildCliVersion(version) {
|
|
63
|
+
return buildJson("version", { version });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Render CLI version output.
|
|
67
|
+
* Pass an OutputFormat for AFDATA JSON/YAML/plain. Pass null to preserve
|
|
68
|
+
* conventional "<name> <version>" text.
|
|
69
|
+
*/
|
|
70
|
+
export function cliRenderVersion(name, version, format = null) {
|
|
71
|
+
const rendered = format === null ? `${name} ${version}` : cliOutput(buildCliVersion(version), format);
|
|
72
|
+
return `${rendered.replace(/\n+$/u, "")}\n`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Render version output if --version/-V is present; otherwise return undefined.
|
|
76
|
+
* Throws for malformed version requests, for example `--version --output xml`.
|
|
77
|
+
*/
|
|
78
|
+
export function cliHandleVersionOrContinue(rawArgs, name, version, defaultOutput = null, outputFlag = "--output", allowOutputFormat = true) {
|
|
79
|
+
let versionRequested = false;
|
|
80
|
+
let outputFormat;
|
|
81
|
+
let outputError;
|
|
82
|
+
for (let i = 0; i < rawArgs.length;) {
|
|
83
|
+
const arg = rawArgs[i];
|
|
84
|
+
if (arg === "--")
|
|
85
|
+
break;
|
|
86
|
+
if (arg === "--version" || arg === "-V") {
|
|
87
|
+
versionRequested = true;
|
|
88
|
+
i += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (allowOutputFormat && (arg === outputFlag || arg.startsWith(`${outputFlag}=`))) {
|
|
92
|
+
let value;
|
|
93
|
+
let step = 1;
|
|
94
|
+
if (arg.startsWith(`${outputFlag}=`)) {
|
|
95
|
+
value = arg.slice(outputFlag.length + 1);
|
|
96
|
+
}
|
|
97
|
+
else if (rawArgs[i + 1] !== undefined && !rawArgs[i + 1].startsWith("-")) {
|
|
98
|
+
value = rawArgs[i + 1];
|
|
99
|
+
step = 2;
|
|
100
|
+
}
|
|
101
|
+
if (value === undefined) {
|
|
102
|
+
outputError = new Error(`missing value for ${outputFlag}: expected json, yaml, or plain`);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
try {
|
|
106
|
+
outputFormat = cliParseOutput(value);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
outputError = e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
i += step;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
i += 1;
|
|
116
|
+
}
|
|
117
|
+
if (!versionRequested)
|
|
118
|
+
return undefined;
|
|
119
|
+
if (outputError !== undefined)
|
|
120
|
+
throw outputError;
|
|
121
|
+
return cliRenderVersion(name, version, allowOutputFormat && outputFormat !== undefined ? outputFormat : defaultOutput);
|
|
122
|
+
}
|
|
61
123
|
/**
|
|
62
124
|
* Build a standard CLI parse error value.
|
|
63
125
|
* Use when flag parsing fails or a flag value is invalid.
|
package/dist/format.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AFDATA output formatting and protocol templates.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 21 public APIs and 4 types: protocol builders, value redactors (copy and
|
|
5
5
|
* in-place; cover _secret and _url fields), output formatters, URL-string
|
|
6
6
|
* redactors (redactUrlSecrets / WithOptions), parseSize, normalizeUtcOffset,
|
|
7
|
-
*
|
|
7
|
+
* isValidRfc3339Date, isValidRfc3339Time, RedactionPolicy, RedactionOptions,
|
|
8
|
+
* OutputStyle, and OutputOptions.
|
|
8
9
|
*/
|
|
9
10
|
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
10
11
|
[key: string]: JsonValue;
|
|
@@ -94,3 +95,7 @@ export declare function parseSize(s: string): number | null;
|
|
|
94
95
|
* are intentionally out of scope.
|
|
95
96
|
*/
|
|
96
97
|
export declare function normalizeUtcOffset(value: string): string | null;
|
|
98
|
+
/** Return true when value is an RFC 3339 full-date (YYYY-MM-DD). */
|
|
99
|
+
export declare function isValidRfc3339Date(value: string): boolean;
|
|
100
|
+
/** Return true when value is an RFC 3339 partial-time (HH:MM:SS[.fraction]). */
|
|
101
|
+
export declare function isValidRfc3339Time(value: string): boolean;
|
package/dist/format.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AFDATA output formatting and protocol templates.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 21 public APIs and 4 types: protocol builders, value redactors (copy and
|
|
5
5
|
* in-place; cover _secret and _url fields), output formatters, URL-string
|
|
6
6
|
* redactors (redactUrlSecrets / WithOptions), parseSize, normalizeUtcOffset,
|
|
7
|
-
*
|
|
7
|
+
* isValidRfc3339Date, isValidRfc3339Time, RedactionPolicy, RedactionOptions,
|
|
8
|
+
* OutputStyle, and OutputOptions.
|
|
8
9
|
*/
|
|
9
10
|
// ═══════════════════════════════════════════
|
|
10
11
|
// Public API: Protocol Builders
|
|
@@ -202,6 +203,32 @@ export function normalizeUtcOffset(value) {
|
|
|
202
203
|
return "UTC";
|
|
203
204
|
return `${s[0]}${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}`;
|
|
204
205
|
}
|
|
206
|
+
/** Return true when value is an RFC 3339 full-date (YYYY-MM-DD). */
|
|
207
|
+
export function isValidRfc3339Date(value) {
|
|
208
|
+
if (value.length !== 10 || value[4] !== "-" || value[7] !== "-")
|
|
209
|
+
return false;
|
|
210
|
+
const year = parseFixedDigits(value.slice(0, 4));
|
|
211
|
+
const month = parseFixedDigits(value.slice(5, 7));
|
|
212
|
+
const day = parseFixedDigits(value.slice(8, 10));
|
|
213
|
+
if (year === null || month === null || day === null)
|
|
214
|
+
return false;
|
|
215
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth(year, month);
|
|
216
|
+
}
|
|
217
|
+
/** Return true when value is an RFC 3339 partial-time (HH:MM:SS[.fraction]). */
|
|
218
|
+
export function isValidRfc3339Time(value) {
|
|
219
|
+
if (value.length < 8 || value[2] !== ":" || value[5] !== ":")
|
|
220
|
+
return false;
|
|
221
|
+
const hour = parseFixedDigits(value.slice(0, 2));
|
|
222
|
+
const minute = parseFixedDigits(value.slice(3, 5));
|
|
223
|
+
const second = parseFixedDigits(value.slice(6, 8));
|
|
224
|
+
if (hour === null || minute === null || second === null)
|
|
225
|
+
return false;
|
|
226
|
+
if (hour > 23 || minute > 59 || second > 59)
|
|
227
|
+
return false;
|
|
228
|
+
if (value.length === 8)
|
|
229
|
+
return true;
|
|
230
|
+
return value[8] === "." && value.length > 9 && /^[0-9]+$/.test(value.slice(9));
|
|
231
|
+
}
|
|
205
232
|
function parseUtcOffsetBody(body) {
|
|
206
233
|
if (!body)
|
|
207
234
|
return null;
|
|
@@ -224,6 +251,23 @@ function parseUtcOffsetBody(body) {
|
|
|
224
251
|
return [Number(body.slice(0, 2)), Number(body.slice(2))];
|
|
225
252
|
return null;
|
|
226
253
|
}
|
|
254
|
+
function parseFixedDigits(value) {
|
|
255
|
+
if (!/^[0-9]+$/.test(value))
|
|
256
|
+
return null;
|
|
257
|
+
return Number(value);
|
|
258
|
+
}
|
|
259
|
+
function daysInMonth(year, month) {
|
|
260
|
+
if ([1, 3, 5, 7, 8, 10, 12].includes(month))
|
|
261
|
+
return 31;
|
|
262
|
+
if ([4, 6, 9, 11].includes(month))
|
|
263
|
+
return 30;
|
|
264
|
+
if (month === 2)
|
|
265
|
+
return isLeapYear(year) ? 29 : 28;
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
function isLeapYear(year) {
|
|
269
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
270
|
+
}
|
|
227
271
|
const DEFAULT_CONTEXT = {
|
|
228
272
|
secretNames: new Set(),
|
|
229
273
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
|
|
3
3
|
*/
|
|
4
|
-
export { buildJsonOk, buildJsonError, buildJson, type JsonValue, RedactionPolicy, type RedactionOptions, OutputStyle, type OutputOptions, outputJson, outputJsonWith, outputJsonWithOptions, outputYaml, outputYamlWithOptions, outputPlain, outputPlainWithOptions, redactSecretsInPlace, redactSecretsInPlaceWithOptions, redactedValue, redactedValueWith, redactedValueWithOptions, redactUrlSecrets, redactUrlSecretsWithOptions, parseSize, normalizeUtcOffset, } from "./format.js";
|
|
4
|
+
export { buildJsonOk, buildJsonError, buildJson, type JsonValue, RedactionPolicy, type RedactionOptions, OutputStyle, type OutputOptions, outputJson, outputJsonWith, outputJsonWithOptions, outputYaml, outputYamlWithOptions, outputPlain, outputPlainWithOptions, redactSecretsInPlace, redactSecretsInPlaceWithOptions, redactedValue, redactedValueWith, redactedValueWithOptions, redactUrlSecrets, redactUrlSecretsWithOptions, parseSize, normalizeUtcOffset, isValidRfc3339Date, isValidRfc3339Time, } from "./format.js";
|
|
5
5
|
export { log, span, initJson, initPlain, initYaml } from "./afdata_logging.js";
|
|
6
|
-
export { type OutputFormat, cliParseOutput, cliParseLogFilters, cliOutput, cliOutputWithOptions, buildCliError, } from "./cli.js";
|
|
6
|
+
export { type OutputFormat, cliParseOutput, cliParseLogFilters, cliOutput, cliOutputWithOptions, buildCliError, buildCliVersion, cliRenderVersion, cliHandleVersionOrContinue, } from "./cli.js";
|
|
7
7
|
export { type SkillSpec, type SkillAction, type SkillScope, type SkillAgentSelection, type SkillAgent, type SkillOptions, type SkillTargetStatus, type SkillUninstallStatus, type SkillReport, SkillError, runSkillAdmin, } from "./skill.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent-First Data (AFDATA) — suffix-driven output formatting and protocol templates.
|
|
3
3
|
*/
|
|
4
|
-
export { buildJsonOk, buildJsonError, buildJson, RedactionPolicy, OutputStyle, outputJson, outputJsonWith, outputJsonWithOptions, outputYaml, outputYamlWithOptions, outputPlain, outputPlainWithOptions, redactSecretsInPlace, redactSecretsInPlaceWithOptions, redactedValue, redactedValueWith, redactedValueWithOptions, redactUrlSecrets, redactUrlSecretsWithOptions, parseSize, normalizeUtcOffset, } from "./format.js";
|
|
4
|
+
export { buildJsonOk, buildJsonError, buildJson, RedactionPolicy, OutputStyle, outputJson, outputJsonWith, outputJsonWithOptions, outputYaml, outputYamlWithOptions, outputPlain, outputPlainWithOptions, redactSecretsInPlace, redactSecretsInPlaceWithOptions, redactedValue, redactedValueWith, redactedValueWithOptions, redactUrlSecrets, redactUrlSecretsWithOptions, parseSize, normalizeUtcOffset, isValidRfc3339Date, isValidRfc3339Time, } from "./format.js";
|
|
5
5
|
export { log, span, initJson, initPlain, initYaml } from "./afdata_logging.js";
|
|
6
|
-
export { cliParseOutput, cliParseLogFilters, cliOutput, cliOutputWithOptions, buildCliError, } from "./cli.js";
|
|
6
|
+
export { cliParseOutput, cliParseLogFilters, cliOutput, cliOutputWithOptions, buildCliError, buildCliVersion, cliRenderVersion, cliHandleVersionOrContinue, } from "./cli.js";
|
|
7
7
|
export { SkillError, runSkillAdmin, } from "./skill.js";
|