@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
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/CHANGELOG.md +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sideeffect
|
|
3
|
+
* @package @hop-top/kit
|
|
4
|
+
*
|
|
5
|
+
* The `kit/side-effect` vocabulary and the one name-inference table every
|
|
6
|
+
* kit gate and projection reads. Mirrors Go's `cli.SideEffect` tiers and
|
|
7
|
+
* `cmdmeta.InferredDestructive`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Annotation key a command declares its side-effect tier under. */
|
|
11
|
+
export const SIDE_EFFECT_ANNOTATION = 'kit/side-effect';
|
|
12
|
+
|
|
13
|
+
/** The closed set of declarable tiers (legacy 4-tier plus the 6-tier ladder). */
|
|
14
|
+
export const SIDE_EFFECT_TIERS = [
|
|
15
|
+
'read',
|
|
16
|
+
'write',
|
|
17
|
+
'write-local',
|
|
18
|
+
'write-shared',
|
|
19
|
+
'destructive',
|
|
20
|
+
'destructive-local',
|
|
21
|
+
'destructive-shared',
|
|
22
|
+
'interactive',
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
export type SideEffect = (typeof SIDE_EFFECT_TIERS)[number];
|
|
26
|
+
|
|
27
|
+
/** The tier an unannotated command with a destructive leaf name is gated as. */
|
|
28
|
+
export const INFERRED_TIER: SideEffect = 'destructive-shared';
|
|
29
|
+
|
|
30
|
+
const WRITE_LIKE = new Set<string>(['write', 'write-local', 'write-shared']);
|
|
31
|
+
const DESTRUCTIVE_LIKE = new Set<string>([
|
|
32
|
+
'destructive',
|
|
33
|
+
'destructive-local',
|
|
34
|
+
'destructive-shared',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/** True for any tier that mutates state without irreversible loss. */
|
|
38
|
+
export function isWriteLike(tier: string): boolean {
|
|
39
|
+
return WRITE_LIKE.has(tier);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** True for any tier that performs an irreversible mutation. */
|
|
43
|
+
export function isDestructiveLike(tier: string): boolean {
|
|
44
|
+
return DESTRUCTIVE_LIKE.has(tier);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** True when `tier` names a declarable side-effect tier. */
|
|
48
|
+
export function isValidSideEffect(tier: string): boolean {
|
|
49
|
+
return (SIDE_EFFECT_TIERS as readonly string[]).includes(tier);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The one table of leaf names kit treats as destructive when a command
|
|
54
|
+
* carries no `kit/side-effect` annotation. Every gate and projection in
|
|
55
|
+
* this SDK reads it through {@link isDestructiveName} or
|
|
56
|
+
* {@link inferredDestructive}; none keeps its own copy.
|
|
57
|
+
*/
|
|
58
|
+
const DESTRUCTIVE_NAMES: ReadonlySet<string> = new Set([
|
|
59
|
+
'delete',
|
|
60
|
+
'remove',
|
|
61
|
+
'rm',
|
|
62
|
+
'destroy',
|
|
63
|
+
'purge',
|
|
64
|
+
'drop',
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
/** True when `name` is in the destructive-name table. */
|
|
68
|
+
export function isDestructiveName(name: string): boolean {
|
|
69
|
+
return DESTRUCTIVE_NAMES.has(name);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The table's names, sorted. */
|
|
73
|
+
export function destructiveNames(): string[] {
|
|
74
|
+
return [...DESTRUCTIVE_NAMES].sort();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* True when a command is destructive by name alone: its annotation is
|
|
79
|
+
* absent or empty and its leaf name is in the table. An explicit
|
|
80
|
+
* annotation, valid or not, always wins: a malformed value is a
|
|
81
|
+
* declaration defect, never inferred over.
|
|
82
|
+
*/
|
|
83
|
+
export function inferredDestructive(
|
|
84
|
+
name: string,
|
|
85
|
+
annotations: Readonly<Record<string, string>> | undefined,
|
|
86
|
+
): boolean {
|
|
87
|
+
const declared = annotations?.[SIDE_EFFECT_ANNOTATION];
|
|
88
|
+
if (declared !== undefined && declared !== '') return false;
|
|
89
|
+
return isDestructiveName(name);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The tier the delegation gates act on: the declared `kit/side-effect`,
|
|
94
|
+
* else {@link INFERRED_TIER} for a destructive-named command. Undefined
|
|
95
|
+
* when neither says anything. A declared value, valid or malformed, is
|
|
96
|
+
* never replaced.
|
|
97
|
+
*/
|
|
98
|
+
export function gateSideEffect(
|
|
99
|
+
name: string,
|
|
100
|
+
annotations: Readonly<Record<string, string>> | undefined,
|
|
101
|
+
): string | undefined {
|
|
102
|
+
if (inferredDestructive(name, annotations)) return INFERRED_TIER;
|
|
103
|
+
const declared = annotations?.[SIDE_EFFECT_ANNOTATION];
|
|
104
|
+
return declared === undefined ? undefined : declared;
|
|
105
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# telemetry
|
|
2
|
+
|
|
3
|
+
## What it answers
|
|
4
|
+
|
|
5
|
+
What a TS adopter needs before emitting usage telemetry: the mode gate (`off`, `anon`, `full`), the anonymous rotatable install id, the consent reader, the redactor, and a non-blocking `Client` with jsonl and https sinks. Default-denied: a fresh install never emits. Wrong module for Factor 11 provenance metadata on payloads (`@hop-top/kit/provenance`) and for the compliance checker (`@hop-top/kit/compliance`).
|
|
6
|
+
|
|
7
|
+
## Use it when
|
|
8
|
+
|
|
9
|
+
- record an event: `new Client(opts)`, `client.record(event, attrs)`, `await client.shutdown(ms)`
|
|
10
|
+
- know which tier applies: `resolveMode(process.env)`
|
|
11
|
+
- read or rotate the install id: `getInstallId()`, `rotate()`
|
|
12
|
+
- check the operator's decision: `loadConsent()`
|
|
13
|
+
- scrub before your own sink: `redact(value)`, `redactString(s)`
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Client } from '@hop-top/kit/telemetry';
|
|
19
|
+
|
|
20
|
+
const client = new Client({ sink: 'jsonl', sinkFile: '/tmp/kit-events.jsonl', sdkVersion: '0.0.0' });
|
|
21
|
+
client.record('cmd.invoked', { command: 'launch', exit_code: 0 });
|
|
22
|
+
await client.shutdown(5_000);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`record` is a no-op until consent is granted and `KIT_TELEMETRY_MODE` is `anon` or `full`.
|
|
26
|
+
|
|
27
|
+
## Contract
|
|
28
|
+
|
|
29
|
+
- Envelope shape is [`sdk/docs/telemetry-event-schema.md`](../../../docs/telemetry-event-schema.md); keys are wire snake_case.
|
|
30
|
+
- `record` returns synchronously and never throws; the queue is bounded and drops count.
|
|
31
|
+
- Consent and mode are consulted on each `record`, so a live consent flip takes effect without restart.
|
|
32
|
+
- Redactor placeholders are `<redacted:email>`, `<redacted:ipv4>`, `<redacted:ipv6>`, `<redacted:token>`, and `$HOME` for home-path prefixes.
|
|
33
|
+
- The envelope carries a free-form `event` plus `attrs` where Go carries `CommandPath`; this is a documented divergence.
|
|
34
|
+
- Parity: [`sdk/tests/cross-lang/expected/envelope.json`](../../../tests/cross-lang/expected/envelope.json), driven by `sdk/tests/cross-lang/run.sh` from [`fixtures/consent.yaml`](../../../tests/cross-lang/fixtures/consent.yaml) and [`fixtures/install_id.bytes`](../../../tests/cross-lang/fixtures/install_id.bytes).
|
|
35
|
+
|
|
36
|
+
## Neighbours
|
|
37
|
+
|
|
38
|
+
- `@hop-top/kit/provenance`: `_meta` on output payloads
|
|
39
|
+
- `@hop-top/kit/compliance`: 12-factor checks, including the telemetry consent factor
|
|
40
|
+
- `@hop-top/kit/xdg`: state and config paths the install id and consent file live under
|
|
41
|
+
- Go reference: [`go/runtime/telemetry`](../../../../go/runtime/telemetry/README.md); Python port: [`hop_top_kit/telemetry`](../../../py/hop_top_kit/telemetry/README.md)
|
|
42
|
+
|
|
43
|
+
## See also
|
|
44
|
+
|
|
45
|
+
- [`sdk/ts/README.md`](../../README.md), section "Telemetry": env vars, redactor, envelope
|
|
46
|
+
- [`docs/adopters/guides/telemetry.md`](../../../../docs/adopters/guides/telemetry.md)
|
|
47
|
+
- [`docs/adopters/reference/telemetry-compliance.md`](../../../../docs/adopters/reference/telemetry-compliance.md)
|
|
48
|
+
- [`sdk/tests/cross-lang/README.md`](../../../tests/cross-lang/README.md)
|
|
@@ -232,6 +232,37 @@ describe('Client.https sink', () => {
|
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
+
// Telemetry is logging-class egress: --offline stops traffic the user
|
|
236
|
+
// asked for, it is not a second consent gate on diagnostics. The sink
|
|
237
|
+
// must therefore still ship while the process is marked offline.
|
|
238
|
+
//
|
|
239
|
+
// The endpoint is deliberately remote: loopback is exempt from the
|
|
240
|
+
// guard by design, so a 127.0.0.1 target could never fail this test.
|
|
241
|
+
it('ships while offline: --offline must not mute telemetry', async () => {
|
|
242
|
+
const { install, setProcessOffline } = await import('../netpolicy');
|
|
243
|
+
await grantConsent();
|
|
244
|
+
process.env.KIT_TELEMETRY_MODE = 'anon';
|
|
245
|
+
|
|
246
|
+
const mockFetch = vi.fn(async () => new Response(null, { status: 202 }));
|
|
247
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
248
|
+
// Guard the global exactly as createCLI does at start-up.
|
|
249
|
+
install();
|
|
250
|
+
setProcessOffline(true);
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
const c = new Client({
|
|
254
|
+
sink: 'https',
|
|
255
|
+
endpoint: 'https://telemetry.example.com/v1/events',
|
|
256
|
+
});
|
|
257
|
+
c.record('probe', { i: 1 });
|
|
258
|
+
await c.shutdown(2_000);
|
|
259
|
+
|
|
260
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
261
|
+
} finally {
|
|
262
|
+
setProcessOffline(false);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
235
266
|
it('retries once on 5xx, then drops', async () => {
|
|
236
267
|
await grantConsent();
|
|
237
268
|
process.env.KIT_TELEMETRY_MODE = 'anon';
|
package/src/telemetry/client.ts
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
* a fail-closed posture.
|
|
19
19
|
* - **Default Mode is Off**: `resolveMode()` is consulted at the same
|
|
20
20
|
* gating step. Anything other than `anon` / `full` no-ops.
|
|
21
|
-
* - **Envelope shape**: matches the cross-language event
|
|
22
|
-
* for the common fields. NOTE:
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* - **Envelope shape**: matches the cross-language event schema
|
|
22
|
+
* for the common fields. NOTE: the TS+Py SDKs diverge from Go by
|
|
23
|
+
* carrying free-form `event` (string) + `attrs` (object) at the
|
|
24
|
+
* envelope root.
|
|
25
25
|
* - **install_id caching**: `getInstallId()` does file I/O; we resolve
|
|
26
26
|
* it lazily and cache the resolved promise.
|
|
27
27
|
*
|
|
@@ -36,6 +36,7 @@ import * as yaml from 'js-yaml';
|
|
|
36
36
|
|
|
37
37
|
import { Mode, resolveMode } from './mode';
|
|
38
38
|
import { getInstallId } from './installId';
|
|
39
|
+
import { observabilityFetch } from '../netpolicy';
|
|
39
40
|
import { consentPath, legacyConsentPath } from './consent';
|
|
40
41
|
import { redact } from './redact';
|
|
41
42
|
|
|
@@ -68,7 +69,7 @@ const DEFAULT_QUEUE_SIZE = 1024;
|
|
|
68
69
|
const FLUSH_INTERVAL_MS = 5_000;
|
|
69
70
|
/** Threshold that triggers an early flush before the interval fires. */
|
|
70
71
|
const FLUSH_BATCH_TRIGGER = 64;
|
|
71
|
-
/** HTTPS connect timeout (
|
|
72
|
+
/** HTTPS connect timeout (telemetry must never block the caller). */
|
|
72
73
|
const HTTPS_CONNECT_TIMEOUT_MS = 5_000;
|
|
73
74
|
/** HTTPS overall timeout. */
|
|
74
75
|
const HTTPS_TOTAL_TIMEOUT_MS = 10_000;
|
|
@@ -412,7 +413,12 @@ export class Client {
|
|
|
412
413
|
HTTPS_CONNECT_TIMEOUT_MS,
|
|
413
414
|
);
|
|
414
415
|
try {
|
|
415
|
-
|
|
416
|
+
// Telemetry is logging-class egress: --offline stops traffic
|
|
417
|
+
// the user asked for, not diagnostics. Consent and mode already
|
|
418
|
+
// govern whether anything is emitted, so this sink deliberately
|
|
419
|
+
// uses the unguarded fetch captured before install() patched the
|
|
420
|
+
// global.
|
|
421
|
+
const res = await observabilityFetch()(this.endpoint, {
|
|
416
422
|
method: 'POST',
|
|
417
423
|
headers,
|
|
418
424
|
body,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, expect, it, afterEach, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
install,
|
|
5
|
+
observabilityFetch,
|
|
6
|
+
setProcessOffline,
|
|
7
|
+
isOfflineError,
|
|
8
|
+
} from '../netpolicy';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Telemetry is logging-class egress: `--offline` stops traffic the user
|
|
12
|
+
* asked for, it is not a second consent gate on diagnostics. Consent and
|
|
13
|
+
* telemetry mode already govern whether anything is emitted at all.
|
|
14
|
+
*
|
|
15
|
+
* Destinations here are deliberately remote. Loopback is exempt from the
|
|
16
|
+
* guard by design, so a 127.0.0.1 target would pass with or without the
|
|
17
|
+
* carve-out and could never fail.
|
|
18
|
+
*/
|
|
19
|
+
describe('telemetry exemption from --offline', () => {
|
|
20
|
+
const REMOTE = 'https://telemetry.example.com/v1/events';
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
setProcessOffline(false);
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('observability fetch reaches a remote endpoint while offline', async () => {
|
|
28
|
+
const base = vi.fn(async () => new Response('', { status: 200 }));
|
|
29
|
+
globalThis.fetch = base as unknown as typeof globalThis.fetch;
|
|
30
|
+
|
|
31
|
+
// Re-import so the pristine reference is captured from the stub.
|
|
32
|
+
vi.resetModules();
|
|
33
|
+
const fresh = await import('../netpolicy');
|
|
34
|
+
fresh.install();
|
|
35
|
+
fresh.setProcessOffline(true);
|
|
36
|
+
|
|
37
|
+
const res = await fresh.observabilityFetch()(REMOTE, { method: 'POST' });
|
|
38
|
+
expect(res.status).toBe(200);
|
|
39
|
+
expect(base).toHaveBeenCalledTimes(1);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('keeps the carve-out narrow: ordinary fetch is still refused', async () => {
|
|
43
|
+
const base = vi.fn(async () => new Response('', { status: 200 }));
|
|
44
|
+
globalThis.fetch = base as unknown as typeof globalThis.fetch;
|
|
45
|
+
|
|
46
|
+
install();
|
|
47
|
+
setProcessOffline(true);
|
|
48
|
+
|
|
49
|
+
let caught: unknown;
|
|
50
|
+
try {
|
|
51
|
+
await globalThis.fetch(REMOTE, { method: 'GET' });
|
|
52
|
+
} catch (err) {
|
|
53
|
+
caught = err;
|
|
54
|
+
}
|
|
55
|
+
expect(isOfflineError(caught)).toBe(true);
|
|
56
|
+
expect(base).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('observability fetch is not the guarded global', () => {
|
|
60
|
+
install();
|
|
61
|
+
expect(observabilityFetch()).not.toBe(globalThis.fetch);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal helpers shared by the toolspec modules. Not re-exported
|
|
3
|
+
* from the package's `toolspec` entry.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
Command as CommanderCommand,
|
|
8
|
+
Option as CommanderOption,
|
|
9
|
+
} from "commander";
|
|
10
|
+
|
|
11
|
+
export type Annotations = Record<string, string>;
|
|
12
|
+
|
|
13
|
+
export function annotationsOf(cmd: CommanderCommand): Annotations {
|
|
14
|
+
return (cmd as { annotations?: Annotations }).annotations ?? {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function splitCSV(s: string | undefined): string[] | undefined {
|
|
18
|
+
if (!s) return undefined;
|
|
19
|
+
const out = s.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
20
|
+
return out.length > 0 ? out : undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// --- commander facts ---
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* cmd's declared positional arguments (commander registeredArguments),
|
|
27
|
+
* in order, `required` set only on required ones and `variadic` only
|
|
28
|
+
* on a `<name...>` / `[name...]` one. Shared by the toolspec
|
|
29
|
+
* projection and the MCP bridge so both read positionals the same
|
|
30
|
+
* way.
|
|
31
|
+
*/
|
|
32
|
+
export function declaredArgs(
|
|
33
|
+
cmd: CommanderCommand,
|
|
34
|
+
): Array<{ name: string; required?: boolean; variadic?: boolean }> {
|
|
35
|
+
return cmd.registeredArguments.map((a) => {
|
|
36
|
+
const out: { name: string; required?: boolean; variadic?: boolean } = { name: a.name() };
|
|
37
|
+
if (a.required) out.required = true;
|
|
38
|
+
if (a.variadic) out.variadic = true;
|
|
39
|
+
return out;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parse a kit/args annotation the way Go's cmdmeta.ParseArgs does: a
|
|
45
|
+
* comma list, whitespace trimmed, empties dropped; `name?` optional,
|
|
46
|
+
* `name...` variadic (one or more), `name...?` optional variadic
|
|
47
|
+
* (zero or more); the dots come before the `?`, any other suffix is
|
|
48
|
+
* part of the name. Undefined when the annotation is absent or blank.
|
|
49
|
+
*/
|
|
50
|
+
export function parseKitArgs(
|
|
51
|
+
raw: string | undefined,
|
|
52
|
+
): Array<{ name: string; optional: boolean; variadic: boolean }> | undefined {
|
|
53
|
+
const entries = splitCSV(raw);
|
|
54
|
+
if (!entries) return undefined;
|
|
55
|
+
return entries.map((entry) => {
|
|
56
|
+
let name = entry;
|
|
57
|
+
let optional = false;
|
|
58
|
+
let variadic = false;
|
|
59
|
+
if (name.endsWith("?")) {
|
|
60
|
+
optional = true;
|
|
61
|
+
name = name.slice(0, -1);
|
|
62
|
+
}
|
|
63
|
+
if (name.endsWith("...")) {
|
|
64
|
+
variadic = true;
|
|
65
|
+
name = name.slice(0, -3);
|
|
66
|
+
}
|
|
67
|
+
return { name, optional, variadic };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Map a commander option onto pflag's Type() and DefValue spelling,
|
|
73
|
+
* which is what the Go manifest and ToolSpec carry: a bool is
|
|
74
|
+
* "false", a slice "[a,b]", a value flag its default or "".
|
|
75
|
+
*/
|
|
76
|
+
export function flagTypeAndDefault(opt: CommanderOption): [string, string] {
|
|
77
|
+
const def = opt.defaultValue;
|
|
78
|
+
const declared = pflagTypes.get(opt);
|
|
79
|
+
if (declared) return [declared, def === undefined ? "" : String(def)];
|
|
80
|
+
if (opt.variadic) {
|
|
81
|
+
const items = def === undefined ? [] : Array.isArray(def) ? def : [def];
|
|
82
|
+
return ["stringSlice", `[${items.map(String).join(",")}]`];
|
|
83
|
+
}
|
|
84
|
+
// A negated --no-x is its own pflag bool, unset (false) by default;
|
|
85
|
+
// commander's default for it belongs to the x attribute, not the flag.
|
|
86
|
+
if (opt.negate) return ["bool", "false"];
|
|
87
|
+
if (takesNoValue(opt)) return ["bool", def === undefined ? "false" : String(def)];
|
|
88
|
+
return ["string", def === undefined ? "" : String(def)];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The closed value set a commander option declares (`.choices()`), or undefined. */
|
|
92
|
+
export function flagChoices(opt: CommanderOption): string[] | undefined {
|
|
93
|
+
const choices = (opt as { argChoices?: string[] }).argChoices;
|
|
94
|
+
return choices && choices.length > 0 ? [...choices] : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether opt takes no value: a plain boolean flag or a negated one
|
|
99
|
+
* (`--no-x`). commander's isBoolean() is false for negated options,
|
|
100
|
+
* yet they are value-less all the same, so pflag-shaped projections
|
|
101
|
+
* (a `no-x` bool) must not rely on isBoolean() alone.
|
|
102
|
+
*/
|
|
103
|
+
export function takesNoValue(opt: CommanderOption): boolean {
|
|
104
|
+
return !opt.required && !opt.optional;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Whether cmd has an action handler (cobra Runnable). commander 15
|
|
109
|
+
* exposes no public accessor, so this reads the private field.
|
|
110
|
+
*/
|
|
111
|
+
export function isRunnable(cmd: CommanderCommand): boolean {
|
|
112
|
+
return (cmd as unknown as { _actionHandler?: unknown })._actionHandler != null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Hidden per the parent's help (public API; no private _hidden read). */
|
|
116
|
+
export function isHidden(cmd: CommanderCommand, parent: CommanderCommand): boolean {
|
|
117
|
+
return !parent.createHelp().visibleCommands(parent).includes(cmd);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const BUILTIN_NAMES = new Set([
|
|
121
|
+
"help",
|
|
122
|
+
"completion",
|
|
123
|
+
"man",
|
|
124
|
+
"__complete",
|
|
125
|
+
"__completeNoDesc",
|
|
126
|
+
]);
|
|
127
|
+
|
|
128
|
+
export function isBuiltin(cmd: CommanderCommand, parent: CommanderCommand): boolean {
|
|
129
|
+
return BUILTIN_NAMES.has(cmd.name()) || parent.name() === "completion";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function byName(a: { name(): string }, b: { name(): string }): number {
|
|
133
|
+
const x = a.name();
|
|
134
|
+
const y = b.name();
|
|
135
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// --- Go encoding/json byte parity ---
|
|
139
|
+
|
|
140
|
+
/** Go's json string escaping (HTML-safe, U+2028/2029 escaped). */
|
|
141
|
+
export function goQuote(s: string): string {
|
|
142
|
+
return JSON.stringify(s)
|
|
143
|
+
.replace(/</g, "\\u003c")
|
|
144
|
+
.replace(/>/g, "\\u003e")
|
|
145
|
+
.replace(/&/g, "\\u0026")
|
|
146
|
+
.replace(/\u2028/g, "\\u2028")
|
|
147
|
+
.replace(/\u2029/g, "\\u2029");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Re-emit raw JSON text the way Go's Encoder.SetIndent("", " ")
|
|
152
|
+
* does for an embedded RawJSON: tokens verbatim (numbers keep their
|
|
153
|
+
* spelling), insignificant whitespace dropped, strings HTML-escaped,
|
|
154
|
+
* structure re-indented at the given depth. Throws on invalid JSON,
|
|
155
|
+
* as Go's encoder errors.
|
|
156
|
+
*/
|
|
157
|
+
export function reindentRaw(raw: string, depth: number): string {
|
|
158
|
+
JSON.parse(raw); // validity gate
|
|
159
|
+
let out = "";
|
|
160
|
+
let level = depth;
|
|
161
|
+
let needIndent = false;
|
|
162
|
+
const nl = (lvl: number) => "\n" + " ".repeat(lvl);
|
|
163
|
+
for (let i = 0; i < raw.length; i++) {
|
|
164
|
+
const c = raw[i];
|
|
165
|
+
if (c === " " || c === "\t" || c === "\n" || c === "\r") continue;
|
|
166
|
+
if (needIndent && c !== "]" && c !== "}") {
|
|
167
|
+
out += nl(level);
|
|
168
|
+
needIndent = false;
|
|
169
|
+
}
|
|
170
|
+
if (c === '"') {
|
|
171
|
+
let j = i + 1;
|
|
172
|
+
while (raw[j] !== '"') j += raw[j] === "\\" ? 2 : 1;
|
|
173
|
+
out += goQuote(JSON.parse(raw.slice(i, j + 1)) as string);
|
|
174
|
+
i = j;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
switch (c) {
|
|
178
|
+
case "{":
|
|
179
|
+
case "[":
|
|
180
|
+
out += c;
|
|
181
|
+
level++;
|
|
182
|
+
needIndent = true;
|
|
183
|
+
break;
|
|
184
|
+
case "}":
|
|
185
|
+
case "]":
|
|
186
|
+
level--;
|
|
187
|
+
if (needIndent) needIndent = false;
|
|
188
|
+
else out += nl(level);
|
|
189
|
+
out += c;
|
|
190
|
+
break;
|
|
191
|
+
case ",":
|
|
192
|
+
out += c + nl(level);
|
|
193
|
+
break;
|
|
194
|
+
case ":":
|
|
195
|
+
out += ": ";
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
out += c;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Go encoding/json (Encoder.SetIndent("", " ")) bytes for v; keys in rawKeys hold raw JSON text. */
|
|
205
|
+
export function encodeGoJSON(v: unknown, depth: number, rawKeys: Set<string>, key?: string): string {
|
|
206
|
+
if (key !== undefined && rawKeys.has(key) && typeof v === "string") {
|
|
207
|
+
return reindentRaw(v, depth);
|
|
208
|
+
}
|
|
209
|
+
if (typeof v === "string") return goQuote(v);
|
|
210
|
+
if (typeof v === "boolean" || typeof v === "number") return JSON.stringify(v);
|
|
211
|
+
if (Array.isArray(v)) {
|
|
212
|
+
if (v.length === 0) return "[]";
|
|
213
|
+
const pad = " ".repeat(depth + 1);
|
|
214
|
+
const items = v.map((x) => pad + encodeGoJSON(x, depth + 1, rawKeys));
|
|
215
|
+
return "[\n" + items.join(",\n") + "\n" + " ".repeat(depth) + "]";
|
|
216
|
+
}
|
|
217
|
+
if (v && typeof v === "object") {
|
|
218
|
+
const entries = Object.entries(v).filter(([, x]) => x !== undefined);
|
|
219
|
+
if (entries.length === 0) return "{}";
|
|
220
|
+
const pad = " ".repeat(depth + 1);
|
|
221
|
+
const items = entries.map(
|
|
222
|
+
([k, x]) => pad + goQuote(k) + ": " + encodeGoJSON(x, depth + 1, rawKeys, k),
|
|
223
|
+
);
|
|
224
|
+
return "{\n" + items.join(",\n") + "\n" + " ".repeat(depth) + "}";
|
|
225
|
+
}
|
|
226
|
+
return "null";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Visit every command below program depth-first, children in name
|
|
231
|
+
* order (cobra's default sorting), with its Go-style path (root name
|
|
232
|
+
* first) and whether it is reserved: its depth-1 verb is in
|
|
233
|
+
* `reserved`, or it or an ancestor carries kit/reserved=true.
|
|
234
|
+
*/
|
|
235
|
+
export function walkCommands(
|
|
236
|
+
program: CommanderCommand,
|
|
237
|
+
reserved: Iterable<string> | undefined,
|
|
238
|
+
visit: (
|
|
239
|
+
cmd: CommanderCommand,
|
|
240
|
+
parent: CommanderCommand,
|
|
241
|
+
path: string[],
|
|
242
|
+
reserved: boolean,
|
|
243
|
+
) => void,
|
|
244
|
+
): void {
|
|
245
|
+
const reservedSet = new Set(reserved ?? []);
|
|
246
|
+
const walk = (
|
|
247
|
+
cmd: CommanderCommand,
|
|
248
|
+
parent: CommanderCommand,
|
|
249
|
+
path: string[],
|
|
250
|
+
depthOne: string,
|
|
251
|
+
reservedTree: boolean,
|
|
252
|
+
): void => {
|
|
253
|
+
const inReserved = reservedTree || annotationsOf(cmd)["kit/reserved"] === "true";
|
|
254
|
+
visit(cmd, parent, path, inReserved || reservedSet.has(depthOne));
|
|
255
|
+
for (const child of [...cmd.commands].sort(byName)) {
|
|
256
|
+
if (child.name() === "") continue;
|
|
257
|
+
walk(child, cmd, [...path, child.name()], depthOne, inReserved);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
for (const child of [...program.commands].sort(byName)) {
|
|
261
|
+
if (child.name() === "") continue;
|
|
262
|
+
walk(child, program, [program.name(), child.name()], child.name(), false);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* pflag type names for options whose commander shape cannot say
|
|
268
|
+
* (commander has no typed options), e.g. a float --min.
|
|
269
|
+
*/
|
|
270
|
+
export const pflagTypes = new WeakMap<CommanderOption, string>();
|
|
271
|
+
|
|
272
|
+
/** Go fmt "%.0f": round half to even. */
|
|
273
|
+
export function goFormat0(x: number): string {
|
|
274
|
+
const floor = Math.floor(x);
|
|
275
|
+
const diff = x - floor;
|
|
276
|
+
let r = diff > 0.5 ? floor + 1 : diff < 0.5 ? floor : floor % 2 === 0 ? floor : floor + 1;
|
|
277
|
+
if (Object.is(r, -0)) r = 0;
|
|
278
|
+
return String(r);
|
|
279
|
+
}
|