@llblab/pi-kit 0.24.1 → 0.26.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.
Files changed (162) hide show
  1. package/AGENTS.md +1 -1
  2. package/BACKLOG.md +5 -1
  3. package/CHANGELOG.md +12 -0
  4. package/README.md +11 -8
  5. package/node_modules/@llblab/pi-actors/AGENTS.md +2 -0
  6. package/node_modules/@llblab/pi-actors/CHANGELOG.md +4 -1
  7. package/node_modules/@llblab/pi-actors/LICENSE +21 -0
  8. package/node_modules/@llblab/pi-actors/README.md +1 -1
  9. package/node_modules/@llblab/pi-actors/docs/coordinator-delivery.md +1 -1
  10. package/node_modules/@llblab/pi-actors/package.json +4 -3
  11. package/node_modules/@llblab/pi-claude-usage/AGENTS.md +23 -0
  12. package/node_modules/@llblab/pi-claude-usage/BACKLOG.md +4 -0
  13. package/node_modules/@llblab/pi-claude-usage/CHANGELOG.md +21 -0
  14. package/node_modules/@llblab/pi-claude-usage/LICENSE +22 -0
  15. package/node_modules/@llblab/pi-claude-usage/README.md +155 -0
  16. package/node_modules/@llblab/pi-claude-usage/banner.jpg +0 -0
  17. package/node_modules/@llblab/pi-claude-usage/index.ts +8 -0
  18. package/node_modules/@llblab/pi-claude-usage/lib/extension.ts +30 -0
  19. package/node_modules/@llblab/pi-claude-usage/lib/fast.ts +24 -0
  20. package/node_modules/@llblab/pi-claude-usage/lib/query.ts +146 -0
  21. package/node_modules/@llblab/pi-claude-usage/lib/status-format.ts +297 -0
  22. package/node_modules/@llblab/pi-claude-usage/lib/status.ts +366 -0
  23. package/node_modules/@llblab/pi-claude-usage/lib/telegram.ts +44 -0
  24. package/node_modules/@llblab/pi-claude-usage/lib/usage-store.ts +221 -0
  25. package/node_modules/@llblab/pi-claude-usage/lib/usage.ts +128 -0
  26. package/node_modules/@llblab/pi-claude-usage/package.json +64 -0
  27. package/node_modules/@llblab/pi-clean-room/AGENTS.md +1 -0
  28. package/node_modules/@llblab/pi-clean-room/CHANGELOG.md +5 -0
  29. package/node_modules/@llblab/pi-clean-room/LICENSE +21 -0
  30. package/node_modules/@llblab/pi-clean-room/README.md +1 -1
  31. package/node_modules/@llblab/pi-clean-room/package.json +3 -2
  32. package/node_modules/@llblab/pi-codex-usage/AGENTS.md +9 -6
  33. package/node_modules/@llblab/pi-codex-usage/BACKLOG.md +2 -1
  34. package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +17 -0
  35. package/node_modules/@llblab/pi-codex-usage/README.md +75 -17
  36. package/node_modules/@llblab/pi-codex-usage/index.ts +8 -1602
  37. package/node_modules/@llblab/pi-codex-usage/lib/extension.ts +25 -0
  38. package/node_modules/@llblab/pi-codex-usage/lib/fast.ts +23 -0
  39. package/node_modules/@llblab/pi-codex-usage/lib/query.ts +368 -0
  40. package/node_modules/@llblab/pi-codex-usage/lib/status-format.ts +347 -0
  41. package/node_modules/@llblab/pi-codex-usage/lib/status.ts +435 -0
  42. package/node_modules/@llblab/pi-codex-usage/lib/telegram.ts +45 -0
  43. package/node_modules/@llblab/pi-codex-usage/lib/usage-store.ts +229 -0
  44. package/node_modules/@llblab/pi-codex-usage/lib/usage.ts +425 -0
  45. package/node_modules/@llblab/pi-codex-usage/package.json +11 -6
  46. package/node_modules/@llblab/pi-command-fast/AGENTS.md +7 -0
  47. package/node_modules/@llblab/pi-command-fast/BACKLOG.md +9 -0
  48. package/node_modules/@llblab/pi-command-fast/CHANGELOG.md +7 -0
  49. package/node_modules/@llblab/pi-command-fast/LICENSE +21 -0
  50. package/node_modules/@llblab/pi-command-fast/README.md +42 -0
  51. package/node_modules/@llblab/pi-command-fast/dist/command.d.ts +8 -0
  52. package/node_modules/@llblab/pi-command-fast/dist/command.js +52 -0
  53. package/node_modules/@llblab/pi-command-fast/dist/index.d.ts +3 -0
  54. package/node_modules/@llblab/pi-command-fast/dist/index.js +3 -0
  55. package/node_modules/@llblab/pi-command-fast/dist/models-json.d.ts +10 -0
  56. package/node_modules/@llblab/pi-command-fast/dist/models-json.js +81 -0
  57. package/node_modules/@llblab/pi-command-fast/package.json +49 -0
  58. package/node_modules/@llblab/pi-grow-loop/AGENTS.md +1 -0
  59. package/node_modules/@llblab/pi-grow-loop/CHANGELOG.md +4 -1
  60. package/node_modules/@llblab/pi-grow-loop/LICENSE +21 -0
  61. package/node_modules/@llblab/pi-grow-loop/README.md +1 -1
  62. package/node_modules/@llblab/pi-grow-loop/package.json +3 -2
  63. package/node_modules/@llblab/pi-state-flow/AGENTS.md +43 -56
  64. package/node_modules/@llblab/pi-state-flow/BACKLOG.md +17 -3
  65. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +25 -0
  66. package/node_modules/@llblab/pi-state-flow/LICENSE +21 -0
  67. package/node_modules/@llblab/pi-state-flow/README.md +18 -15
  68. package/node_modules/@llblab/pi-state-flow/dist/index.d.ts +2 -2
  69. package/node_modules/@llblab/pi-state-flow/dist/index.js +2 -2
  70. package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.d.ts +1 -1
  71. package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.js +1 -1
  72. package/node_modules/@llblab/pi-state-flow/dist/lib/config.d.ts +7 -3
  73. package/node_modules/@llblab/pi-state-flow/dist/lib/config.js +16 -7
  74. package/node_modules/@llblab/pi-state-flow/dist/lib/context.d.ts +9 -9
  75. package/node_modules/@llblab/pi-state-flow/dist/lib/context.js +5 -4
  76. package/node_modules/@llblab/pi-state-flow/dist/lib/continuation.js +2 -2
  77. package/node_modules/@llblab/pi-state-flow/dist/lib/durable.d.ts +1 -1
  78. package/node_modules/@llblab/pi-state-flow/dist/lib/durable.js +7 -4
  79. package/node_modules/@llblab/pi-state-flow/dist/lib/episode.d.ts +3 -3
  80. package/node_modules/@llblab/pi-state-flow/dist/lib/episode.js +5 -5
  81. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.d.ts +3 -5
  82. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +503 -235
  83. package/node_modules/@llblab/pi-state-flow/dist/lib/git.d.ts +2 -2
  84. package/node_modules/@llblab/pi-state-flow/dist/lib/git.js +16 -5
  85. package/node_modules/@llblab/pi-state-flow/dist/lib/history.d.ts +11 -4
  86. package/node_modules/@llblab/pi-state-flow/dist/lib/history.js +6 -7
  87. package/node_modules/@llblab/pi-state-flow/dist/lib/logging.d.ts +4 -1
  88. package/node_modules/@llblab/pi-state-flow/dist/lib/logging.js +1 -0
  89. package/node_modules/@llblab/pi-state-flow/dist/lib/query.d.ts +4 -5
  90. package/node_modules/@llblab/pi-state-flow/dist/lib/query.js +13 -13
  91. package/node_modules/@llblab/pi-state-flow/dist/lib/recovery.d.ts +7 -6
  92. package/node_modules/@llblab/pi-state-flow/dist/lib/recovery.js +9 -9
  93. package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.d.ts +3 -2
  94. package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.js +17 -12
  95. package/node_modules/@llblab/pi-state-flow/dist/lib/session.d.ts +13 -1
  96. package/node_modules/@llblab/pi-state-flow/dist/lib/session.js +62 -2
  97. package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.d.ts +23 -8
  98. package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.js +52 -20
  99. package/node_modules/@llblab/pi-state-flow/dist/lib/state.d.ts +22 -3
  100. package/node_modules/@llblab/pi-state-flow/dist/lib/state.js +30 -10
  101. package/node_modules/@llblab/pi-state-flow/dist/lib/status.d.ts +5 -3
  102. package/node_modules/@llblab/pi-state-flow/dist/lib/status.js +19 -28
  103. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.d.ts +17 -15
  104. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.js +52 -52
  105. package/node_modules/@llblab/pi-state-flow/dist/lib/temporal.d.ts +8 -4
  106. package/node_modules/@llblab/pi-state-flow/dist/lib/temporal.js +34 -18
  107. package/node_modules/@llblab/pi-state-flow/dist/lib/transition.d.ts +5 -5
  108. package/node_modules/@llblab/pi-state-flow/dist/lib/transition.js +13 -19
  109. package/node_modules/@llblab/pi-state-flow/dist/package.json +12 -11
  110. package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-guide/SKILL.md +2 -2
  111. package/node_modules/@llblab/pi-state-flow/docs/README.md +2 -1
  112. package/node_modules/@llblab/pi-state-flow/docs/agent-contract-relocation.md +72 -0
  113. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +44 -36
  114. package/node_modules/@llblab/pi-state-flow/docs/compatibility.md +14 -6
  115. package/node_modules/@llblab/pi-state-flow/docs/fork-contract.md +7 -5
  116. package/node_modules/@llblab/pi-state-flow/docs/lazy-state.md +6 -6
  117. package/node_modules/@llblab/pi-state-flow/docs/performance.md +1 -1
  118. package/node_modules/@llblab/pi-state-flow/docs/temporal-acceptance.md +13 -12
  119. package/node_modules/@llblab/pi-state-flow/docs/usage.md +37 -33
  120. package/node_modules/@llblab/pi-state-flow/index.ts +3 -2
  121. package/node_modules/@llblab/pi-state-flow/lib/compaction.ts +2 -2
  122. package/node_modules/@llblab/pi-state-flow/lib/config.ts +20 -10
  123. package/node_modules/@llblab/pi-state-flow/lib/context.ts +15 -14
  124. package/node_modules/@llblab/pi-state-flow/lib/continuation.ts +1 -1
  125. package/node_modules/@llblab/pi-state-flow/lib/durable.ts +8 -6
  126. package/node_modules/@llblab/pi-state-flow/lib/episode.ts +6 -6
  127. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +484 -232
  128. package/node_modules/@llblab/pi-state-flow/lib/git.ts +14 -5
  129. package/node_modules/@llblab/pi-state-flow/lib/history.ts +16 -11
  130. package/node_modules/@llblab/pi-state-flow/lib/logging.ts +5 -1
  131. package/node_modules/@llblab/pi-state-flow/lib/query.ts +16 -16
  132. package/node_modules/@llblab/pi-state-flow/lib/recovery.ts +11 -11
  133. package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +19 -13
  134. package/node_modules/@llblab/pi-state-flow/lib/session.ts +57 -3
  135. package/node_modules/@llblab/pi-state-flow/lib/snapshot.ts +57 -22
  136. package/node_modules/@llblab/pi-state-flow/lib/state.ts +46 -13
  137. package/node_modules/@llblab/pi-state-flow/lib/status.ts +23 -32
  138. package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +66 -65
  139. package/node_modules/@llblab/pi-state-flow/lib/temporal.ts +39 -19
  140. package/node_modules/@llblab/pi-state-flow/lib/transition.ts +19 -27
  141. package/node_modules/@llblab/pi-state-flow/package.json +12 -11
  142. package/node_modules/@llblab/pi-state-flow/skills/state-flow-guide/SKILL.md +2 -2
  143. package/node_modules/jsonc-parser/CHANGELOG.md +76 -0
  144. package/node_modules/jsonc-parser/LICENSE.md +21 -0
  145. package/node_modules/jsonc-parser/README.md +364 -0
  146. package/node_modules/jsonc-parser/SECURITY.md +41 -0
  147. package/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
  148. package/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
  149. package/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
  150. package/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
  151. package/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
  152. package/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
  153. package/node_modules/jsonc-parser/lib/esm/main.js +178 -0
  154. package/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
  155. package/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
  156. package/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
  157. package/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
  158. package/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
  159. package/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
  160. package/node_modules/jsonc-parser/lib/umd/main.js +194 -0
  161. package/node_modules/jsonc-parser/package.json +37 -0
  162. package/package.json +10 -6
@@ -12,12 +12,13 @@ import { createAcceptedTransition, type AcceptedTransition } from "./history.ts"
12
12
  import { applyPatch, containsNull, hashJson, isObject, validatePatch, type JsonObject } from "./json.ts";
13
13
  import { hasCompiledSkillArtifact, SKILL_ARTIFACT_COMPILER, type SuccessfulSkillRead } from "./skills.ts";
14
14
  import type { Snapshot } from "./snapshot.ts";
15
+ import { emptyState } from "./state.ts";
15
16
  import type {
16
17
  AtomicScopePatches,
17
- MaterializedState,
18
+ SemanticState,
18
19
  ScopePatch,
19
20
  ScopedPatch,
20
- ScopedStates,
21
+ ScopedSemanticStates,
21
22
  SemanticTransition,
22
23
  StateDocument,
23
24
  StatePatch,
@@ -26,7 +27,7 @@ import type {
26
27
  } from "./state.ts";
27
28
 
28
29
  export interface StagedScopedTransition {
29
- nextStates: ScopedStates;
30
+ nextStates: ScopedSemanticStates;
30
31
  stateHashes: Record<StateScope, string>;
31
32
  /** Fresh runtime-owned provenance for artifacts compiled in this transition. */
32
33
  provenanceUpdates: Record<StateScope, Record<string, ArtifactProvenance>>;
@@ -126,7 +127,7 @@ function compileReadSkills(
126
127
  }
127
128
 
128
129
  function validateMaterializedTransition(nextState: StateDocument, scope: StateScope): void {
129
- if (containsNull(nextState)) {
130
+ if (Object.keys(emptyState()).some((key) => containsNull(nextState[key]))) {
130
131
  throw new Error("Materialized state cannot contain null; use null only as an object-key deletion marker");
131
132
  }
132
133
  validateArtifactRegistry(nextState.artifacts, `${scope}.artifacts`);
@@ -156,20 +157,9 @@ function validateScopePatch(scope: unknown, patch: unknown): asserts patch is Sc
156
157
  if (isObject(patch.artifacts)) validateModelArtifactPatch(patch.artifacts, `${scope}.artifacts`);
157
158
  }
158
159
 
159
- function completePatch(patch: ScopePatch, response: string): StatePatch {
160
- return {
161
- artifacts: patch.artifacts ?? {},
162
- contract: patch.contract ?? {},
163
- working: patch.working ?? {},
164
- intents: patch.intents ?? {},
165
- response,
166
- lazy: structuredClone(patch.lazy ?? {}),
167
- };
168
- }
169
-
170
160
  /** Stage all scope updates against one immutable basis before any state is published. */
171
161
  function stageScopedSemanticTransition(
172
- currentStates: ScopedStates,
162
+ currentStates: ScopedSemanticStates,
173
163
  transition: SemanticTransition,
174
164
  successfulSkillReads: Iterable<SuccessfulSkillRead>,
175
165
  causalBasis: string,
@@ -197,19 +187,21 @@ function stageScopedSemanticTransition(
197
187
  const provenanceUpdates: Record<StateScope, Record<string, ArtifactProvenance>> = { global: {}, cwd: {}, session: {} };
198
188
  for (const scope of SCOPES) {
199
189
  const authored = patches.get(scope) ?? {};
200
- const response = scope === "session" && acceptedResponse !== undefined
201
- ? acceptedResponse
202
- : currentStates[scope].response;
203
- const patch = completePatch(authored, response);
204
- const nextState = applyPatch(currentStates[scope], patch) as MaterializedState;
190
+ const patch = { ...authored, ...(scope === "session" && acceptedResponse !== undefined ? { response: acceptedResponse } : {}) };
191
+ const materialized = applyPatch({ ...emptyState(), ...currentStates[scope] }, patch) as StateDocument;
205
192
  compileReadArtifacts(
206
- nextState,
193
+ materialized,
207
194
  { artifacts: authored.artifacts ?? {} },
208
195
  artifactReads.filter((read) => (read.scope ?? "global") === scope),
209
196
  provenanceUpdates[scope],
210
197
  );
211
- compileReadSkills(scope, nextState, { artifacts: authored.artifacts ?? {} }, skillReads.filter((read) => read.scope === scope), provenanceUpdates[scope]);
212
- validateMaterializedTransition(nextState, scope);
198
+ compileReadSkills(scope, materialized, { artifacts: authored.artifacts ?? {} }, skillReads.filter((read) => read.scope === scope), provenanceUpdates[scope]);
199
+ validateMaterializedTransition(materialized, scope);
200
+ const nextState: SemanticState = materialized;
201
+ for (const key of Object.keys(emptyState())) {
202
+ if (!Object.hasOwn(currentStates[scope], key) && !Object.hasOwn(patch, key)
203
+ && !(key === "artifacts" && Object.keys(provenanceUpdates[scope]).length > 0)) delete nextState[key];
204
+ }
213
205
  nextStates[scope] = nextState;
214
206
  }
215
207
  return {
@@ -227,7 +219,7 @@ function stageScopedSemanticTransition(
227
219
 
228
220
  /** Stage one canonical atomic scope cohort without changing the finalized response. */
229
221
  export function stageAtomicScopePatches(
230
- currentStates: ScopedStates,
222
+ currentStates: ScopedSemanticStates,
231
223
  patches: AtomicScopePatches,
232
224
  successfulSkillReads: Iterable<SuccessfulSkillRead>,
233
225
  causalBasis: string,
@@ -251,7 +243,7 @@ export function stageAtomicScopePatches(
251
243
  }
252
244
 
253
245
  export function stageScopedTransition(
254
- currentStates: ScopedStates,
246
+ currentStates: ScopedSemanticStates,
255
247
  transition: TerminalTransition,
256
248
  successfulSkillReads: Iterable<SuccessfulSkillRead>,
257
249
  causalBasis: string,
@@ -278,7 +270,7 @@ export interface CommitScopedTransitionOptions {
278
270
 
279
271
  export function commitScopedTransition(
280
272
  snapshot: Snapshot,
281
- states: ScopedStates,
273
+ states: ScopedSemanticStates,
282
274
  stage: StagedScopedTransition,
283
275
  publishDurable: (accepted: AcceptedTransition | undefined, nextSnapshot: Snapshot) => void,
284
276
  causalBasis: string,
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@llblab/pi-state-flow",
3
- "version": "0.21.0",
3
+ "version": "0.24.0",
4
+ "license": "MIT",
4
5
  "private": false,
5
6
  "description": "Incremental scoped state/context/memory compiler for Pi, inspired by SKILL.state",
6
7
  "keywords": [
@@ -66,17 +67,17 @@
66
67
  "node": ">=22.19.0"
67
68
  },
68
69
  "peerDependencies": {
69
- "@earendil-works/pi-agent-core": ">=0.87.0",
70
- "@earendil-works/pi-ai": ">=0.87.0",
71
- "@earendil-works/pi-coding-agent": ">=0.87.0",
72
- "@earendil-works/pi-tui": ">=0.87.0"
70
+ "@earendil-works/pi-agent-core": ">=1.0.0",
71
+ "@earendil-works/pi-ai": ">=1.0.0",
72
+ "@earendil-works/pi-coding-agent": ">=1.0.0",
73
+ "@earendil-works/pi-tui": ">=1.0.0"
73
74
  },
74
75
  "devDependencies": {
75
- "@earendil-works/pi-agent-core": "0.87.0",
76
- "@earendil-works/pi-ai": "0.87.0",
77
- "@earendil-works/pi-coding-agent": "0.87.0",
78
- "@earendil-works/pi-tui": "0.87.0",
79
- "@types/node": "latest",
80
- "typescript": "latest"
76
+ "@earendil-works/pi-agent-core": "1.0.0",
77
+ "@earendil-works/pi-ai": "1.0.0",
78
+ "@earendil-works/pi-coding-agent": "1.0.0",
79
+ "@earendil-works/pi-tui": "1.0.0",
80
+ "@types/node": "^26.4.0",
81
+ "typescript": "^7.0.2"
81
82
  }
82
83
  }
@@ -15,7 +15,7 @@ State Flow's on-demand operational reference. Resolve the usage question or iden
15
15
 
16
16
  Passive tools access memory without starting an episode. Missing tools or storage are blockers, not permission to enable an episode or bypass storage; explanation alone remains possible.
17
17
 
18
- Operator commands: `/state-flow-status` inspects; `/state-flow-start` enables the current branch; `/state-flow-stop` ends active semantics without erasing memory or necessarily disabling passive tools.
18
+ Operator commands: `/state-flow-status` inspects; `/state-flow-active` selects state-driven episodes; `/state-flow-passive` selects ordinary conversation with both memory tools and existing-state projection; `/state-flow-off` removes both tools and all State Flow context, including frozen handoffs, without deleting memory. Commands and Telegram change only the current session's `mode`. Global `mode` defaults to Off for new sessions and never overrides retained choices. Do not change mode without operator authorization.
19
19
 
20
20
  ## Map
21
21
 
@@ -56,7 +56,7 @@ Call `patch_state` alone per assistant response; await acceptance before depende
56
56
 
57
57
  The runtime waits cancelably for publication ownership, then applies authored Global/CWD operations to current canonical values. Untouched fields survive; overlapping targets follow successful acceptance order. Correct repeats succeed as `State already current.` without another semantic revision. Do not repeat external actions during a memory wait, or rebuild an entire scope from an older snapshot. Session ownership/history fences remain private, not a universal merge.
58
58
 
59
- Semantic planes `intents`, `contract`, `working`, `artifacts`, and the required `lazy` root are objects; nested lazy values may contain ordinary JSON without stored nulls. Objects merge, arrays/scalars replace, omitted fields persist. Nested `null` removes an owned object key; inherited content may reappear. Canonical `"[N]"` keys patch array elements; indexed deletion is forbidden.
59
+ When present, semantic planes `intents`, `contract`, `working`, `artifacts`, and `lazy` are objects; nested lazy values may contain ordinary JSON without stored nulls. Stored checkpoints and patches may omit any documented plane. Current and historical views assemble only known fields present in the selected scopes. Absent fields and empty responses are omitted from views. Checkpoint/tail readers ignore unknown top-level fields, and writers emit only known fields. Nested data within known planes remains intact. Explicit value reads of an absent documented top-level field return `null`. Authored `patch_state` keeps its documented field grammar. Objects merge, arrays/scalars replace, omitted fields persist. Nested `null` removes an owned object key; inherited content may reappear. Canonical `"[N]"` keys patch array elements; indexed deletion is forbidden.
60
60
 
61
61
  Illustrative deletion, only for an actually completed intent and after satisfying pending acquisitions:
62
62
 
@@ -0,0 +1,76 @@
1
+ 3.3.0 2022-06-24
2
+ =================
3
+ - `JSONVisitor.onObjectBegin` and `JSONVisitor.onArrayBegin` can now return `false` to instruct the visitor that no children should be visited.
4
+
5
+
6
+ 3.2.0 2022-08-30
7
+ =================
8
+ - update the version of the bundled Javascript files to `es2020`.
9
+ - include all `const enum` values in the bundled JavaScript files (`ScanError`, `SyntaxKind`, `ParseErrorCode`).
10
+
11
+ 3.1.0 2022-07-07
12
+ ==================
13
+ * added new API `FormattingOptions.keepLines` : It leaves the initial line positions in the formatting.
14
+
15
+ 3.0.0 2020-11-13
16
+ ==================
17
+ * fixed API spec for `parseTree`. Can return `undefine` for empty input.
18
+ * added new API `FormattingOptions.insertFinalNewline`.
19
+
20
+
21
+ 2.3.0 2020-07-03
22
+ ==================
23
+ * new API `ModificationOptions.isArrayInsertion`: If `JSONPath` refers to an index of an array and `isArrayInsertion` is `true`, then `modify` will insert a new item at that location instead of overwriting its contents.
24
+ * `ModificationOptions.formattingOptions` is now optional. If not set, newly inserted content will not be formatted.
25
+
26
+
27
+ 2.2.0 2019-10-25
28
+ ==================
29
+ * added `ParseOptions.allowEmptyContent`. Default is `false`.
30
+ * new API `getNodeType`: Returns the type of a value returned by parse.
31
+ * `parse`: Fix issue with empty property name
32
+
33
+ 2.1.0 2019-03-29
34
+ ==================
35
+ * `JSONScanner` and `JSONVisitor` return lineNumber / character.
36
+
37
+ 2.0.0 2018-04-12
38
+ ==================
39
+ * renamed `Node.columnOffset` to `Node.colonOffset`
40
+ * new API `getNodePath`: Gets the JSON path of the given JSON DOM node
41
+ * new API `findNodeAtOffset`: Finds the most inner node at the given offset. If `includeRightBound` is set, also finds nodes that end at the given offset.
42
+
43
+ 1.0.3 2018-03-07
44
+ ==================
45
+ * provide ems modules
46
+
47
+ 1.0.2 2018-03-05
48
+ ==================
49
+ * added the `visit.onComment` API, reported when comments are allowed.
50
+ * added the `ParseErrorCode.InvalidCommentToken` enum value, reported when comments are disallowed.
51
+
52
+ 1.0.1
53
+ ==================
54
+ * added the `format` API: computes edits to format a JSON document.
55
+ * added the `modify` API: computes edits to insert, remove or replace a property or value in a JSON document.
56
+ * added the `allyEdits` API: applies edits to a document
57
+
58
+ 1.0.0
59
+ ==================
60
+ * remove nls dependency (remove `getParseErrorMessage`)
61
+
62
+ 0.4.2 / 2017-05-05
63
+ ==================
64
+ * added `ParseError.offset` & `ParseError.length`
65
+
66
+ 0.4.1 / 2017-04-02
67
+ ==================
68
+ * added `ParseOptions.allowTrailingComma`
69
+
70
+ 0.4.0 / 2017-02-23
71
+ ==================
72
+ * fix for `getLocation`. Now `getLocation` inside an object will always return a property from inside that property. Can be empty string if the object has no properties or if the offset is before a actual property `{ "a": { | }} will return location ['a', ' ']`
73
+
74
+ 0.3.0 / 2017-01-17
75
+ ==================
76
+ * Updating to typescript 2.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Microsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,364 @@
1
+ # jsonc-parser
2
+ Scanner and parser for JSON with comments.
3
+
4
+ [![npm Package](https://img.shields.io/npm/v/jsonc-parser.svg?style=flat-square)](https://www.npmjs.org/package/jsonc-parser)
5
+ [![NPM Downloads](https://img.shields.io/npm/dm/jsonc-parser.svg)](https://npmjs.org/package/jsonc-parser)
6
+ [![Build Status](https://github.com/microsoft/node-jsonc-parser/workflows/Tests/badge.svg)](https://github.com/microsoft/node-jsonc-parser/workflows/Tests)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ Why?
10
+ ----
11
+ JSONC is JSON with JavaScript style comments. This node module provides a scanner and fault tolerant parser that can process JSONC but is also useful for standard JSON.
12
+ - the *scanner* tokenizes the input string into tokens and token offsets
13
+ - the *visit* function implements a 'SAX' style parser with callbacks for the encountered properties and values.
14
+ - the *parseTree* function computes a hierarchical DOM with offsets representing the encountered properties and values.
15
+ - the *parse* function evaluates the JavaScript object represented by JSON string in a fault tolerant fashion.
16
+ - the *getLocation* API returns a location object that describes the property or value located at a given offset in a JSON document.
17
+ - the *findNodeAtLocation* API finds the node at a given location path in a JSON DOM.
18
+ - the *format* API computes edits to format a JSON document.
19
+ - the *modify* API computes edits to insert, remove or replace a property or value in a JSON document.
20
+ - the *applyEdits* API applies edits to a document.
21
+
22
+ Installation
23
+ ------------
24
+
25
+ ```
26
+ npm install --save jsonc-parser
27
+ ```
28
+
29
+ API
30
+ ---
31
+
32
+ ### Scanner:
33
+ ```typescript
34
+
35
+ /**
36
+ * Creates a JSON scanner on the given text.
37
+ * If ignoreTrivia is set, whitespaces or comments are ignored.
38
+ */
39
+ export function createScanner(text: string, ignoreTrivia: boolean = false): JSONScanner;
40
+
41
+ /**
42
+ * The scanner object, representing a JSON scanner at a position in the input string.
43
+ */
44
+ export interface JSONScanner {
45
+ /**
46
+ * Sets the scan position to a new offset. A call to 'scan' is needed to get the first token.
47
+ */
48
+ setPosition(pos: number): any;
49
+ /**
50
+ * Read the next token. Returns the token code.
51
+ */
52
+ scan(): SyntaxKind;
53
+ /**
54
+ * Returns the zero-based current scan position, which is after the last read token.
55
+ */
56
+ getPosition(): number;
57
+ /**
58
+ * Returns the last read token.
59
+ */
60
+ getToken(): SyntaxKind;
61
+ /**
62
+ * Returns the last read token value. The value for strings is the decoded string content. For numbers it's of type number, for boolean it's true or false.
63
+ */
64
+ getTokenValue(): string;
65
+ /**
66
+ * The zero-based start offset of the last read token.
67
+ */
68
+ getTokenOffset(): number;
69
+ /**
70
+ * The length of the last read token.
71
+ */
72
+ getTokenLength(): number;
73
+ /**
74
+ * The zero-based start line number of the last read token.
75
+ */
76
+ getTokenStartLine(): number;
77
+ /**
78
+ * The zero-based start character (column) of the last read token.
79
+ */
80
+ getTokenStartCharacter(): number;
81
+ /**
82
+ * An error code of the last scan.
83
+ */
84
+ getTokenError(): ScanError;
85
+ }
86
+ ```
87
+
88
+ ### Parser:
89
+ ```typescript
90
+
91
+ export interface ParseOptions {
92
+ disallowComments?: boolean;
93
+ allowTrailingComma?: boolean;
94
+ allowEmptyContent?: boolean;
95
+ }
96
+ /**
97
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
98
+ * Therefore always check the errors list to find out if the input was valid.
99
+ */
100
+ export declare function parse(text: string, errors?: {error: ParseErrorCode;}[], options?: ParseOptions): any;
101
+
102
+ /**
103
+ * Parses the given text and invokes the visitor functions for each object, array and literal reached.
104
+ */
105
+ export declare function visit(text: string, visitor: JSONVisitor, options?: ParseOptions): any;
106
+
107
+ /**
108
+ * Visitor called by {@linkcode visit} when parsing JSON.
109
+ *
110
+ * The visitor functions have the following common parameters:
111
+ * - `offset`: Global offset within the JSON document, starting at 0
112
+ * - `startLine`: Line number, starting at 0
113
+ * - `startCharacter`: Start character (column) within the current line, starting at 0
114
+ *
115
+ * Additionally some functions have a `pathSupplier` parameter which can be used to obtain the
116
+ * current `JSONPath` within the document.
117
+ */
118
+ export interface JSONVisitor {
119
+ /**
120
+ * Invoked when an open brace is encountered and an object is started. The offset and length represent the location of the open brace.
121
+ * When `false` is returned, the array items will not be visited.
122
+ */
123
+ onObjectBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void | boolean;
124
+
125
+ /**
126
+ * Invoked when a property is encountered. The offset and length represent the location of the property name.
127
+ * The `JSONPath` created by the `pathSupplier` refers to the enclosing JSON object, it does not include the
128
+ * property name yet.
129
+ */
130
+ onObjectProperty?: (property: string, offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
131
+ /**
132
+ * Invoked when a closing brace is encountered and an object is completed. The offset and length represent the location of the closing brace.
133
+ */
134
+ onObjectEnd?: (offset: number, length: number, startLine: number, startCharacter: number) => void;
135
+ /**
136
+ * Invoked when an open bracket is encountered. The offset and length represent the location of the open bracket.
137
+ * When `false` is returned, the array items will not be visited.*
138
+ */
139
+ onArrayBegin?: (offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void | boolean;
140
+ /**
141
+ * Invoked when a closing bracket is encountered. The offset and length represent the location of the closing bracket.
142
+ */
143
+ onArrayEnd?: (offset: number, length: number, startLine: number, startCharacter: number) => void;
144
+ /**
145
+ * Invoked when a literal value is encountered. The offset and length represent the location of the literal value.
146
+ */
147
+ onLiteralValue?: (value: any, offset: number, length: number, startLine: number, startCharacter: number, pathSupplier: () => JSONPath) => void;
148
+ /**
149
+ * Invoked when a comma or colon separator is encountered. The offset and length represent the location of the separator.
150
+ */
151
+ onSeparator?: (character: string, offset: number, length: number, startLine: number, startCharacter: number) => void;
152
+ /**
153
+ * When comments are allowed, invoked when a line or block comment is encountered. The offset and length represent the location of the comment.
154
+ */
155
+ onComment?: (offset: number, length: number, startLine: number, startCharacter: number) => void;
156
+ /**
157
+ * Invoked on an error.
158
+ */
159
+ onError?: (error: ParseErrorCode, offset: number, length: number, startLine: number, startCharacter: number) => void;
160
+ }
161
+
162
+ /**
163
+ * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
164
+ */
165
+ export declare function parseTree(text: string, errors?: ParseError[], options?: ParseOptions): Node | undefined;
166
+
167
+ export declare type NodeType = "object" | "array" | "property" | "string" | "number" | "boolean" | "null";
168
+ export interface Node {
169
+ type: NodeType;
170
+ value?: any;
171
+ offset: number;
172
+ length: number;
173
+ colonOffset?: number;
174
+ parent?: Node;
175
+ children?: Node[];
176
+ }
177
+
178
+ ```
179
+
180
+ ### Utilities:
181
+ ```typescript
182
+ /**
183
+ * Takes JSON with JavaScript-style comments and remove
184
+ * them. Optionally replaces every none-newline character
185
+ * of comments with a replaceCharacter
186
+ */
187
+ export declare function stripComments(text: string, replaceCh?: string): string;
188
+
189
+ /**
190
+ * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
191
+ */
192
+ export declare function getLocation(text: string, position: number): Location;
193
+
194
+ /**
195
+ * A {@linkcode JSONPath} segment. Either a string representing an object property name
196
+ * or a number (starting at 0) for array indices.
197
+ */
198
+ export declare type Segment = string | number;
199
+ export declare type JSONPath = Segment[];
200
+ export interface Location {
201
+ /**
202
+ * The previous property key or literal value (string, number, boolean or null) or undefined.
203
+ */
204
+ previousNode?: Node;
205
+ /**
206
+ * The path describing the location in the JSON document. The path consists of a sequence strings
207
+ * representing an object property or numbers for array indices.
208
+ */
209
+ path: JSONPath;
210
+ /**
211
+ * Matches the locations path against a pattern consisting of strings (for properties) and numbers (for array indices).
212
+ * '*' will match a single segment, of any property name or index.
213
+ * '**' will match a sequence of segments or no segment, of any property name or index.
214
+ */
215
+ matches: (patterns: JSONPath) => boolean;
216
+ /**
217
+ * If set, the location's offset is at a property key.
218
+ */
219
+ isAtPropertyKey: boolean;
220
+ }
221
+
222
+ /**
223
+ * Finds the node at the given path in a JSON DOM.
224
+ */
225
+ export function findNodeAtLocation(root: Node, path: JSONPath): Node | undefined;
226
+
227
+ /**
228
+ * Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
229
+ */
230
+ export function findNodeAtOffset(root: Node, offset: number, includeRightBound?: boolean) : Node | undefined;
231
+
232
+ /**
233
+ * Gets the JSON path of the given JSON DOM node
234
+ */
235
+ export function getNodePath(node: Node): JSONPath;
236
+
237
+ /**
238
+ * Evaluates the JavaScript object of the given JSON DOM node
239
+ */
240
+ export function getNodeValue(node: Node): any;
241
+
242
+ /**
243
+ * Computes the edit operations needed to format a JSON document.
244
+ *
245
+ * @param documentText The input text
246
+ * @param range The range to format or `undefined` to format the full content
247
+ * @param options The formatting options
248
+ * @returns The edit operations describing the formatting changes to the original document following the format described in {@linkcode EditResult}.
249
+ * To apply the edit operations to the input, use {@linkcode applyEdits}.
250
+ */
251
+ export function format(documentText: string, range: Range, options: FormattingOptions): EditResult;
252
+
253
+ /**
254
+ * Computes the edit operations needed to modify a value in the JSON document.
255
+ *
256
+ * @param documentText The input text
257
+ * @param path The path of the value to change. The path represents either to the document root, a property or an array item.
258
+ * If the path points to an non-existing property or item, it will be created.
259
+ * @param value The new value for the specified property or item. If the value is undefined,
260
+ * the property or item will be removed.
261
+ * @param options Options
262
+ * @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.
263
+ * To apply the edit operations to the input, use {@linkcode applyEdits}.
264
+ */
265
+ export function modify(text: string, path: JSONPath, value: any, options: ModificationOptions): EditResult;
266
+
267
+ /**
268
+ * Applies edits to an input string.
269
+ * @param text The input text
270
+ * @param edits Edit operations following the format described in {@linkcode EditResult}.
271
+ * @returns The text with the applied edits.
272
+ * @throws An error if the edit operations are not well-formed as described in {@linkcode EditResult}.
273
+ */
274
+ export function applyEdits(text: string, edits: EditResult): string;
275
+
276
+ /**
277
+ * An edit result describes a textual edit operation. It is the result of a {@linkcode format} and {@linkcode modify} operation.
278
+ * It consist of one or more edits describing insertions, replacements or removals of text segments.
279
+ * * The offsets of the edits refer to the original state of the document.
280
+ * * No two edits change or remove the same range of text in the original document.
281
+ * * Multiple edits can have the same offset if they are multiple inserts, or an insert followed by a remove or replace.
282
+ * * The order in the array defines which edit is applied first.
283
+ * To apply an edit result use {@linkcode applyEdits}.
284
+ * In general multiple EditResults must not be concatenated because they might impact each other, producing incorrect or malformed JSON data.
285
+ */
286
+ export type EditResult = Edit[];
287
+
288
+ /**
289
+ * Represents a text modification
290
+ */
291
+ export interface Edit {
292
+ /**
293
+ * The start offset of the modification.
294
+ */
295
+ offset: number;
296
+ /**
297
+ * The length of the modification. Must not be negative. Empty length represents an *insert*.
298
+ */
299
+ length: number;
300
+ /**
301
+ * The new content. Empty content represents a *remove*.
302
+ */
303
+ content: string;
304
+ }
305
+
306
+ /**
307
+ * A text range in the document
308
+ */
309
+ export interface Range {
310
+ /**
311
+ * The start offset of the range.
312
+ */
313
+ offset: number;
314
+ /**
315
+ * The length of the range. Must not be negative.
316
+ */
317
+ length: number;
318
+ }
319
+
320
+ /**
321
+ * Options used by {@linkcode format} when computing the formatting edit operations
322
+ */
323
+ export interface FormattingOptions {
324
+ /**
325
+ * If indentation is based on spaces (`insertSpaces` = true), then what is the number of spaces that make an indent?
326
+ */
327
+ tabSize: number;
328
+ /**
329
+ * Is indentation based on spaces?
330
+ */
331
+ insertSpaces: boolean;
332
+ /**
333
+ * The default 'end of line' character
334
+ */
335
+ eol: string;
336
+ }
337
+
338
+ /**
339
+ * Options used by {@linkcode modify} when computing the modification edit operations
340
+ */
341
+ export interface ModificationOptions {
342
+ /**
343
+ * Formatting options. If undefined, the newly inserted code will be inserted unformatted.
344
+ */
345
+ formattingOptions?: FormattingOptions;
346
+ /**
347
+ * Default false. If `JSONPath` refers to an index of an array and `isArrayInsertion` is `true`, then
348
+ * {@linkcode modify} will insert a new item at that location instead of overwriting its contents.
349
+ */
350
+ isArrayInsertion?: boolean;
351
+ /**
352
+ * Optional function to define the insertion index given an existing list of properties.
353
+ */
354
+ getInsertionIndex?: (properties: string[]) => number;
355
+ }
356
+ ```
357
+
358
+
359
+ License
360
+ -------
361
+
362
+ (MIT License)
363
+
364
+ Copyright 2018, Microsoft
@@ -0,0 +1,41 @@
1
+ <!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6
+
7
+ If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8
+
9
+ ## Reporting Security Issues
10
+
11
+ **Please do not report security vulnerabilities through public GitHub issues.**
12
+
13
+ Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14
+
15
+ If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
16
+
17
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
+
19
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
+
21
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
+ * Full paths of source file(s) related to the manifestation of the issue
23
+ * The location of the affected source code (tag/branch/commit or direct URL)
24
+ * Any special configuration required to reproduce the issue
25
+ * Step-by-step instructions to reproduce the issue
26
+ * Proof-of-concept or exploit code (if possible)
27
+ * Impact of the issue, including how an attacker might exploit the issue
28
+
29
+ This information will help us triage your report more quickly.
30
+
31
+ If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.
32
+
33
+ ## Preferred Languages
34
+
35
+ We prefer all communications to be in English.
36
+
37
+ ## Policy
38
+
39
+ Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
40
+
41
+ <!-- END MICROSOFT SECURITY.MD BLOCK -->