@gixcopilot/context 0.1.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/context-compressor.d.ts +28 -0
  4. package/dist/context-compressor.d.ts.map +1 -0
  5. package/dist/context-compressor.js +35 -0
  6. package/dist/context-compressor.js.map +1 -0
  7. package/dist/context-engine.d.ts +36 -0
  8. package/dist/context-engine.d.ts.map +1 -0
  9. package/dist/context-engine.js +191 -0
  10. package/dist/context-engine.js.map +1 -0
  11. package/dist/context-format.d.ts +10 -0
  12. package/dist/context-format.d.ts.map +1 -0
  13. package/dist/context-format.js +16 -0
  14. package/dist/context-format.js.map +1 -0
  15. package/dist/context-item.d.ts +44 -0
  16. package/dist/context-item.d.ts.map +1 -0
  17. package/dist/context-item.js +2 -0
  18. package/dist/context-item.js.map +1 -0
  19. package/dist/context-priority.d.ts +13 -0
  20. package/dist/context-priority.d.ts.map +1 -0
  21. package/dist/context-priority.js +16 -0
  22. package/dist/context-priority.js.map +1 -0
  23. package/dist/context-registry.d.ts +47 -0
  24. package/dist/context-registry.d.ts.map +1 -0
  25. package/dist/context-registry.js +130 -0
  26. package/dist/context-registry.js.map +1 -0
  27. package/dist/context-scope.d.ts +19 -0
  28. package/dist/context-scope.d.ts.map +1 -0
  29. package/dist/context-scope.js +13 -0
  30. package/dist/context-scope.js.map +1 -0
  31. package/dist/context-sensitivity.d.ts +11 -0
  32. package/dist/context-sensitivity.d.ts.map +1 -0
  33. package/dist/context-sensitivity.js +11 -0
  34. package/dist/context-sensitivity.js.map +1 -0
  35. package/dist/context-serializer.d.ts +33 -0
  36. package/dist/context-serializer.d.ts.map +1 -0
  37. package/dist/context-serializer.js +112 -0
  38. package/dist/context-serializer.js.map +1 -0
  39. package/dist/index.d.ts +23 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +11 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/resolved-context.d.ts +64 -0
  44. package/dist/resolved-context.d.ts.map +1 -0
  45. package/dist/resolved-context.js +2 -0
  46. package/dist/resolved-context.js.map +1 -0
  47. package/dist/state-patch.d.ts +35 -0
  48. package/dist/state-patch.d.ts.map +1 -0
  49. package/dist/state-patch.js +2 -0
  50. package/dist/state-patch.js.map +1 -0
  51. package/dist/state-store.d.ts +80 -0
  52. package/dist/state-store.d.ts.map +1 -0
  53. package/dist/state-store.js +129 -0
  54. package/dist/state-store.js.map +1 -0
  55. package/dist/token-estimator.d.ts +17 -0
  56. package/dist/token-estimator.d.ts.map +1 -0
  57. package/dist/token-estimator.js +16 -0
  58. package/dist/token-estimator.js.map +1 -0
  59. package/package.json +51 -0
@@ -0,0 +1,47 @@
1
+ import type { ContextScope } from './context-scope.js';
2
+ import type { ContextItemInput, ContextItemPatch, CopilotContextItem } from './context-item.js';
3
+ /**
4
+ * A live handle returned by `register()` (Section 17). Prefer this over calling
5
+ * `registry.update(id, ...)`/`registry.remove(id)` directly - it is what a React hook's
6
+ * effect cleanup calls on unmount, and it fails loudly (not silently) once disposed.
7
+ */
8
+ export interface ContextRegistration<T = unknown> {
9
+ readonly id: string;
10
+ /** Replace this item's value only, keeping every other field unchanged. */
11
+ update(value: T): void;
12
+ /** Merge a partial patch (value and/or metadata fields) into this item. */
13
+ patch(next: ContextItemPatch<T>): void;
14
+ /** Idempotent. Removes the item from the registry; safe to call more than once. */
15
+ dispose(): void;
16
+ }
17
+ export interface ContextFilter {
18
+ readonly scope?: ContextScope | readonly ContextScope[];
19
+ /** Defaults to `false` - `list()` returns disabled items too unless this is `true`. */
20
+ readonly enabledOnly?: boolean;
21
+ }
22
+ /**
23
+ * The central, framework-independent context registry (Section 16). One registry is one
24
+ * isolated universe of context items - a host application creates one per independent
25
+ * Copilot instance (Section 65); nothing here requires a global singleton.
26
+ */
27
+ export interface ContextRegistry {
28
+ register<T>(input: ContextItemInput<T>): ContextRegistration<T>;
29
+ update<T>(id: string, value: T): void;
30
+ patch<T>(id: string, next: ContextItemPatch<T>): void;
31
+ remove(id: string): void;
32
+ get(id: string): CopilotContextItem | undefined;
33
+ list(filter?: ContextFilter): readonly CopilotContextItem[];
34
+ subscribe(listener: () => void): () => void;
35
+ /** Removes every item. Primarily for provider teardown/tests. */
36
+ clear(): void;
37
+ }
38
+ /**
39
+ * Identity/deduplication rule (Section 18), chosen and documented deterministically: an
40
+ * explicit `id` is an update-in-place key - registering the same `id` twice replaces the
41
+ * existing item rather than creating a second one. Omitting `id` always creates a new item
42
+ * with a generated id, even if `name` collides with an existing item - registration never
43
+ * merges by name alone, which would be a fuzzy/implicit rule (Section 24 makes the same
44
+ * choice for near-duplicate *values* found later, at resolve time).
45
+ */
46
+ export declare function createContextRegistry(): ContextRegistry;
47
+ //# sourceMappingURL=context-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-registry.d.ts","sourceRoot":"","sources":["../src/context-registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,OAAO;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACvB,2EAA2E;IAC3E,KAAK,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvC,mFAAmF;IACnF,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,GAAG,SAAS,YAAY,EAAE,CAAC;IACxD,uFAAuF;IACvF,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACtC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,kBAAkB,EAAE,CAAC;IAC5D,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,iEAAiE;IACjE,KAAK,IAAI,IAAI,CAAC;CACf;AAQD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,CAgHvD"}
@@ -0,0 +1,130 @@
1
+ import { CopilotError } from '@gixcopilot/protocol';
2
+ import { DEFAULT_CONTEXT_PRIORITY } from './context-priority.js';
3
+ import { DEFAULT_CONTEXT_SENSITIVITY } from './context-sensitivity.js';
4
+ function matchesScope(item, filter) {
5
+ if (!filter?.scope)
6
+ return true;
7
+ const scopes = Array.isArray(filter.scope) ? filter.scope : [filter.scope];
8
+ return scopes.includes(item.scope);
9
+ }
10
+ /**
11
+ * Identity/deduplication rule (Section 18), chosen and documented deterministically: an
12
+ * explicit `id` is an update-in-place key - registering the same `id` twice replaces the
13
+ * existing item rather than creating a second one. Omitting `id` always creates a new item
14
+ * with a generated id, even if `name` collides with an existing item - registration never
15
+ * merges by name alone, which would be a fuzzy/implicit rule (Section 24 makes the same
16
+ * choice for near-duplicate *values* found later, at resolve time).
17
+ */
18
+ export function createContextRegistry() {
19
+ const items = new Map();
20
+ const listeners = new Set();
21
+ function notify() {
22
+ for (const listener of listeners)
23
+ listener();
24
+ }
25
+ function requireName(name) {
26
+ if (!name.trim()) {
27
+ throw CopilotError.validation('A context item requires a non-empty name.');
28
+ }
29
+ }
30
+ function store(id, input) {
31
+ requireName(input.name);
32
+ const item = {
33
+ id,
34
+ name: input.name,
35
+ description: input.description,
36
+ scope: input.scope,
37
+ value: input.value,
38
+ priority: input.priority ?? DEFAULT_CONTEXT_PRIORITY,
39
+ sensitivity: input.sensitivity ?? DEFAULT_CONTEXT_SENSITIVITY,
40
+ enabled: input.enabled ?? true,
41
+ owner: input.owner,
42
+ metadata: input.metadata,
43
+ };
44
+ items.set(id, item);
45
+ return item;
46
+ }
47
+ function registerInternal(input) {
48
+ const id = input.id ?? crypto.randomUUID();
49
+ store(id, input);
50
+ notify();
51
+ let disposed = false;
52
+ return {
53
+ id,
54
+ update(value) {
55
+ if (disposed)
56
+ return;
57
+ registryUpdate(id, value);
58
+ },
59
+ patch(next) {
60
+ if (disposed)
61
+ return;
62
+ registryPatch(id, next);
63
+ },
64
+ dispose() {
65
+ if (disposed)
66
+ return;
67
+ disposed = true;
68
+ registryRemove(id);
69
+ },
70
+ };
71
+ }
72
+ function registryUpdate(id, value) {
73
+ const existing = items.get(id);
74
+ if (!existing) {
75
+ throw CopilotError.validation('No context item registered with that id.', { id });
76
+ }
77
+ items.set(id, { ...existing, value });
78
+ notify();
79
+ }
80
+ function registryPatch(id, next) {
81
+ const existing = items.get(id);
82
+ if (!existing) {
83
+ throw CopilotError.validation('No context item registered with that id.', { id });
84
+ }
85
+ if (next.name !== undefined)
86
+ requireName(next.name);
87
+ items.set(id, {
88
+ ...existing,
89
+ ...(next.name !== undefined ? { name: next.name } : {}),
90
+ ...(next.description !== undefined ? { description: next.description } : {}),
91
+ ...(next.scope !== undefined ? { scope: next.scope } : {}),
92
+ ...(next.value !== undefined ? { value: next.value } : {}),
93
+ ...(next.priority !== undefined ? { priority: next.priority } : {}),
94
+ ...(next.sensitivity !== undefined ? { sensitivity: next.sensitivity } : {}),
95
+ ...(next.enabled !== undefined ? { enabled: next.enabled } : {}),
96
+ ...(next.owner !== undefined ? { owner: next.owner } : {}),
97
+ ...(next.metadata !== undefined ? { metadata: next.metadata } : {}),
98
+ });
99
+ notify();
100
+ }
101
+ function registryRemove(id) {
102
+ if (items.delete(id))
103
+ notify();
104
+ }
105
+ return {
106
+ register: registerInternal,
107
+ update: registryUpdate,
108
+ patch: registryPatch,
109
+ remove: registryRemove,
110
+ get: (id) => items.get(id),
111
+ list: (filter) => Array.from(items.values()).filter((item) => {
112
+ if (filter?.enabledOnly && !item.enabled)
113
+ return false;
114
+ return matchesScope(item, filter);
115
+ }),
116
+ subscribe(listener) {
117
+ listeners.add(listener);
118
+ return () => {
119
+ listeners.delete(listener);
120
+ };
121
+ },
122
+ clear() {
123
+ if (items.size === 0)
124
+ return;
125
+ items.clear();
126
+ notify();
127
+ },
128
+ };
129
+ }
130
+ //# sourceMappingURL=context-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-registry.js","sourceRoot":"","sources":["../src/context-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AA8CvE,SAAS,YAAY,CAAC,IAAwB,EAAE,MAAiC;IAC/E,IAAI,CAAC,MAAM,EAAE,KAAK;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3E,OAAQ,MAAkC,CAAC,QAAQ,CAAC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pE,CAAC,CAAC;QACH,MAAM,EAAE,CAAC;IACX,CAAC;IAED,SAAS,cAAc,CAAC,EAAU;QAChC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAAE,MAAM,EAAE,CAAC;IACjC,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,aAAa;QACpB,MAAM,EAAE,cAAc;QACtB,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3D,IAAI,MAAM,EAAE,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO;gBAAE,OAAO,KAAK,CAAC;YACvD,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpC,CAAC,CAAC;QACF,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC;QACD,KAAK;YACH,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC;gBAAE,OAAO;YAC7B,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,MAAM,EAAE,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The lifetime/origin classification of a context item. Each scope carries its own
3
+ * semantics (Sections 8-15) rather than being an implicit convention:
4
+ *
5
+ * - `global` - company/product-wide terminology or instructions. Rare; not a dumping
6
+ * ground for everything an application knows.
7
+ * - `user` - the current authenticated user (id, locale, role names, preferences).
8
+ * Treat as untrusted-for-authorization, not just untrusted-for-injection.
9
+ * - `application` - the hosting application/module/workspace/business domain.
10
+ * - `page` - the current route, page type, current entity, visible filters/dataset.
11
+ * - `component` - focused information a single mounted component chooses to expose.
12
+ * - `session` - short-lived workflow state (current wizard step, current search) - not
13
+ * durable AI memory (that is a later phase's concern).
14
+ * - `temporary` - very short-lived transient state (open modal, hovered/selected object).
15
+ */
16
+ export type ContextScope = 'global' | 'user' | 'application' | 'page' | 'component' | 'session' | 'temporary';
17
+ export declare const CONTEXT_SCOPES: readonly ContextScope[];
18
+ export declare function isContextScope(value: unknown): value is ContextScope;
19
+ //# sourceMappingURL=context-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-scope.d.ts","sourceRoot":"","sources":["../src/context-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,MAAM,GACN,aAAa,GACb,MAAM,GACN,WAAW,GACX,SAAS,GACT,WAAW,CAAC;AAEhB,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAQjD,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE"}
@@ -0,0 +1,13 @@
1
+ export const CONTEXT_SCOPES = [
2
+ 'global',
3
+ 'user',
4
+ 'application',
5
+ 'page',
6
+ 'component',
7
+ 'session',
8
+ 'temporary',
9
+ ];
10
+ export function isContextScope(value) {
11
+ return typeof value === 'string' && CONTEXT_SCOPES.includes(value);
12
+ }
13
+ //# sourceMappingURL=context-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-scope.js","sourceRoot":"","sources":["../src/context-scope.ts"],"names":[],"mappings":"AAwBA,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,QAAQ;IACR,MAAM;IACN,aAAa;IACb,MAAM;IACN,WAAW;IACX,SAAS;IACT,WAAW;CACZ,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,cAAoC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Context sensitivity metadata (Section 30). This is metadata/foundation only - Phase 7
3
+ * owns the full enterprise security/PII policy system (see the security skill). The default
4
+ * engine policy (Section 27, `context-engine.ts`) uses this only to exclude `restricted`
5
+ * items by default; it is not an authorization mechanism and must never be treated as one.
6
+ */
7
+ export type ContextSensitivity = 'public' | 'internal' | 'sensitive' | 'restricted';
8
+ export declare const CONTEXT_SENSITIVITIES: readonly ContextSensitivity[];
9
+ export declare const DEFAULT_CONTEXT_SENSITIVITY: ContextSensitivity;
10
+ export declare function isContextSensitivity(value: unknown): value is ContextSensitivity;
11
+ //# sourceMappingURL=context-sensitivity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-sensitivity.d.ts","sourceRoot":"","sources":["../src/context-sensitivity.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;AAEpF,eAAO,MAAM,qBAAqB,EAAE,SAAS,kBAAkB,EAK9D,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,kBAA+B,CAAC;AAE1E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEhF"}
@@ -0,0 +1,11 @@
1
+ export const CONTEXT_SENSITIVITIES = [
2
+ 'public',
3
+ 'internal',
4
+ 'sensitive',
5
+ 'restricted',
6
+ ];
7
+ export const DEFAULT_CONTEXT_SENSITIVITY = 'internal';
8
+ export function isContextSensitivity(value) {
9
+ return typeof value === 'string' && CONTEXT_SENSITIVITIES.includes(value);
10
+ }
11
+ //# sourceMappingURL=context-sensitivity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-sensitivity.js","sourceRoot":"","sources":["../src/context-sensitivity.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,qBAAqB,GAAkC;IAClE,QAAQ;IACR,UAAU;IACV,WAAW;IACX,YAAY;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAuB,UAAU,CAAC;AAE1E,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,qBAA2C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnG,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The controlled serialization boundary application objects must pass through before
3
+ * reaching a model (Section 21). Never `JSON.stringify` an arbitrary application object
4
+ * directly - this module is the single place that decides what is safe to include and what
5
+ * gets normalized/omitted, with every decision recorded as a warning rather than silently
6
+ * dropped (Section 60, 69).
7
+ */
8
+ export interface ContextSerializerOptions {
9
+ /** Longest a single string value may be before truncation. Default 2000. */
10
+ readonly maxStringLength?: number;
11
+ /** Longest an array may be before truncation. Default 50. */
12
+ readonly maxArrayLength?: number;
13
+ /** Deepest an object/array may nest before being cut off. Default 6. */
14
+ readonly maxDepth?: number;
15
+ }
16
+ export interface SerializedValue {
17
+ /** Stable, pretty-printed JSON text - the model-facing representation of the value. */
18
+ readonly text: string;
19
+ /** True if any string/array/depth limit was applied while producing `text`. */
20
+ readonly truncated: boolean;
21
+ /** Human-readable notes on what was normalized or omitted, e.g. `'function-omitted'`. */
22
+ readonly warnings: readonly string[];
23
+ }
24
+ export interface ContextSerializer {
25
+ serialize(value: unknown): SerializedValue;
26
+ }
27
+ /**
28
+ * The default, dependency-free serializer. Handles `undefined`, `Date`, `bigint`, circular
29
+ * references, functions, DOM-like nodes, class instances, and oversized strings/arrays
30
+ * deterministically (Section 21, 69) rather than throwing or producing invalid JSON.
31
+ */
32
+ export declare function createDefaultContextSerializer(options?: ContextSerializerOptions): ContextSerializer;
33
+ //# sourceMappingURL=context-serializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-serializer.d.ts","sourceRoot":"","sources":["../src/context-serializer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,6DAA6D;IAC7D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC9B,uFAAuF;IACvF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC;CAC5C;AAuGD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,GAAE,wBAA6B,GACrC,iBAAiB,CAoBnB"}
@@ -0,0 +1,112 @@
1
+ const TRUNCATION_MARKER = '…(truncated)';
2
+ function isPlainObject(value) {
3
+ const proto = Object.getPrototypeOf(value);
4
+ return proto === Object.prototype || proto === null;
5
+ }
6
+ function looksLikeDomNode(value) {
7
+ return 'nodeType' in value && typeof value.nodeType === 'number';
8
+ }
9
+ function truncateString(value, state) {
10
+ if (value.length <= state.maxStringLength)
11
+ return value;
12
+ state.truncated = true;
13
+ state.warnings.push('string-truncated');
14
+ return value.slice(0, state.maxStringLength) + TRUNCATION_MARKER;
15
+ }
16
+ function toSafe(value, depth, state) {
17
+ if (value === undefined)
18
+ return undefined;
19
+ if (value === null)
20
+ return null;
21
+ const type = typeof value;
22
+ if (type === 'string')
23
+ return truncateString(value, state);
24
+ if (type === 'number' || type === 'boolean')
25
+ return value;
26
+ if (type === 'bigint')
27
+ return `${value.toString()}n`;
28
+ if (type === 'function') {
29
+ state.warnings.push('function-omitted');
30
+ return '[Function omitted]';
31
+ }
32
+ if (type === 'symbol') {
33
+ state.warnings.push('symbol-omitted');
34
+ return '[Symbol omitted]';
35
+ }
36
+ // type === 'object' from here on - TS narrows `value` via the `type` alias above.
37
+ const obj = value;
38
+ if (value instanceof Date) {
39
+ return value.toISOString();
40
+ }
41
+ if (value instanceof RegExp) {
42
+ return value.toString();
43
+ }
44
+ if (looksLikeDomNode(obj)) {
45
+ state.warnings.push('dom-node-omitted');
46
+ return '[DOM node omitted]';
47
+ }
48
+ if (state.ancestors.includes(value)) {
49
+ state.warnings.push('circular-reference');
50
+ return '[Circular]';
51
+ }
52
+ if (depth >= state.maxDepth) {
53
+ state.truncated = true;
54
+ state.warnings.push('max-depth-exceeded');
55
+ return '[MaxDepthExceeded]';
56
+ }
57
+ state.ancestors.push(value);
58
+ try {
59
+ if (Array.isArray(value)) {
60
+ const limited = value.length > state.maxArrayLength;
61
+ if (limited) {
62
+ state.truncated = true;
63
+ state.warnings.push('array-truncated');
64
+ }
65
+ const items = limited ? value.slice(0, state.maxArrayLength) : value;
66
+ return items.map((item) => toSafe(item, depth + 1, state));
67
+ }
68
+ if (typeof obj.toJSON === 'function') {
69
+ const toJSON = obj.toJSON.bind(obj);
70
+ return toSafe(toJSON(), depth + 1, state);
71
+ }
72
+ if (!isPlainObject(obj)) {
73
+ state.warnings.push('class-instance-normalized');
74
+ }
75
+ const result = {};
76
+ for (const [key, entryValue] of Object.entries(obj)) {
77
+ const safeEntry = toSafe(entryValue, depth + 1, state);
78
+ if (safeEntry !== undefined)
79
+ result[key] = safeEntry;
80
+ }
81
+ return result;
82
+ }
83
+ finally {
84
+ state.ancestors.pop();
85
+ }
86
+ }
87
+ /**
88
+ * The default, dependency-free serializer. Handles `undefined`, `Date`, `bigint`, circular
89
+ * references, functions, DOM-like nodes, class instances, and oversized strings/arrays
90
+ * deterministically (Section 21, 69) rather than throwing or producing invalid JSON.
91
+ */
92
+ export function createDefaultContextSerializer(options = {}) {
93
+ const maxStringLength = options.maxStringLength ?? 2000;
94
+ const maxArrayLength = options.maxArrayLength ?? 50;
95
+ const maxDepth = options.maxDepth ?? 6;
96
+ return {
97
+ serialize(value) {
98
+ const state = {
99
+ maxStringLength,
100
+ maxArrayLength,
101
+ maxDepth,
102
+ warnings: [],
103
+ truncated: false,
104
+ ancestors: [],
105
+ };
106
+ const safe = toSafe(value, 0, state);
107
+ const text = safe === undefined ? 'null' : JSON.stringify(safe, null, 2);
108
+ return { text, truncated: state.truncated, warnings: state.warnings };
109
+ },
110
+ };
111
+ }
112
+ //# sourceMappingURL=context-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-serializer.js","sourceRoot":"","sources":["../src/context-serializer.ts"],"names":[],"mappings":"AA6BA,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAEzC,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAkB,CAAC;IAC5D,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,UAAU,IAAI,KAAK,IAAI,OAAQ,KAAgC,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC/F,CAAC;AAWD,SAAS,cAAc,CAAC,KAAa,EAAE,KAAqB;IAC1D,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,eAAe;QAAE,OAAO,KAAK,CAAC;IACxD,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,iBAAiB,CAAC;AACnE,CAAC;AAED,SAAS,MAAM,CAAC,KAAc,EAAE,KAAa,E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AAQ,EAAE,CAAC;QACxE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ export type { ContextScope } from './context-scope.js';
2
+ export { CONTEXT_SCOPES, isContextScope } from './context-scope.js';
3
+ export type { ContextPriority } from './context-priority.js';
4
+ export { CONTEXT_PRIORITIES, DEFAULT_CONTEXT_PRIORITY, isContextPriority, priorityWeight, } from './context-priority.js';
5
+ export type { ContextSensitivity } from './context-sensitivity.js';
6
+ export { CONTEXT_SENSITIVITIES, DEFAULT_CONTEXT_SENSITIVITY, isContextSensitivity, } from './context-sensitivity.js';
7
+ export type { ContextItemInput, ContextItemMetadata, ContextItemPatch, CopilotContextItem, } from './context-item.js';
8
+ export type { ContextFilter, ContextRegistration, ContextRegistry } from './context-registry.js';
9
+ export { createContextRegistry } from './context-registry.js';
10
+ export type { ContextSerializer, ContextSerializerOptions, SerializedValue } from './context-serializer.js';
11
+ export { createDefaultContextSerializer } from './context-serializer.js';
12
+ export type { TokenEstimator } from './token-estimator.js';
13
+ export { createDefaultTokenEstimator } from './token-estimator.js';
14
+ export type { CompressibleText, ContextCompressor } from './context-compressor.js';
15
+ export { createTruncatingCompressor } from './context-compressor.js';
16
+ export { formatContextItemBlock, joinContextBlocks } from './context-format.js';
17
+ export type { ContextDiagnostics, ContextExclusion, ContextExclusionReason, ContextInspection, ResolvedContext, ResolvedContextItem, } from './resolved-context.js';
18
+ export type { ContextEngine, ContextEngineOptions } from './context-engine.js';
19
+ export { createContextEngine } from './context-engine.js';
20
+ export type { CopilotStateDefinition, CopilotStateStore, StateScope, StateValidationResult, StateValidator, } from './state-store.js';
21
+ export { createCopilotStateStore } from './state-store.js';
22
+ export type { StatePatch, StatePatchOp, StatePatchRejectionReason, StatePatchResult, } from './state-patch.js';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,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mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,YAAY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,qBAAqB,EACrB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,YAAY,EACV,UAAU,EACV,YAAY,EACZ,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { CONTEXT_SCOPES, isContextScope } from './context-scope.js';
2
+ export { CONTEXT_PRIORITIES, DEFAULT_CONTEXT_PRIORITY, isContextPriority, priorityWeight, } from './context-priority.js';
3
+ export { CONTEXT_SENSITIVITIES, DEFAULT_CONTEXT_SENSITIVITY, isContextSensitivity, } from './context-sensitivity.js';
4
+ export { createContextRegistry } from './context-registry.js';
5
+ export { createDefaultContextSerializer } from './context-serializer.js';
6
+ export { createDefaultTokenEstimator } from './token-estimator.js';
7
+ export { createTruncatingCompressor } from './context-compressor.js';
8
+ export { formatContextItemBlock, joinContextBlocks } from './context-format.js';
9
+ export { createContextEngine } from './context-engine.js';
10
+ export { createCopilotStateStore } from './state-store.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpE,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAUlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAGzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAGnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAYhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAS1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { ContextPriority } from './context-priority.js';
2
+ import type { ContextScope } from './context-scope.js';
3
+ import type { ContextSensitivity } from './context-sensitivity.js';
4
+ /**
5
+ * Why an otherwise-registered item did not make it into the resolved context (Section 35).
6
+ * Phase 4 does not implement every policy type this closed set anticipates (e.g. a real
7
+ * `sensitivity-policy` engine is Phase 7's), but the shape is stable so later phases add
8
+ * reasons additively rather than repurposing an existing one.
9
+ */
10
+ export type ContextExclusionReason = 'disabled' | 'budget' | 'duplicate' | 'invalid' | 'sensitivity-policy' | 'serialization-failure';
11
+ export interface ContextExclusion {
12
+ readonly id: string;
13
+ readonly name: string;
14
+ readonly scope: ContextScope;
15
+ readonly reason: ContextExclusionReason;
16
+ readonly detail?: string;
17
+ }
18
+ /** One included item, formatted and budgeted (Section 22, 34). */
19
+ export interface ResolvedContextItem {
20
+ readonly id: string;
21
+ readonly name: string;
22
+ readonly description?: string;
23
+ readonly scope: ContextScope;
24
+ readonly priority: ContextPriority;
25
+ readonly sensitivity: ContextSensitivity;
26
+ readonly estimatedTokens: number;
27
+ readonly truncated: boolean;
28
+ /** The formatted `[Context: name] ...` block for this item alone (Section 22). */
29
+ readonly text: string;
30
+ }
31
+ /** Lightweight observability counters for one resolution pass (Section 62). */
32
+ export interface ContextDiagnostics {
33
+ readonly itemsRegistered: number;
34
+ readonly itemsIncluded: number;
35
+ readonly itemsExcluded: number;
36
+ readonly resolutionMs: number;
37
+ }
38
+ /** The output of `ContextEngine.resolve()` - everything needed to build a model request. */
39
+ export interface ResolvedContext {
40
+ readonly items: readonly ResolvedContextItem[];
41
+ /** All included items' `text`, joined - ready to place into a model request (Section 33). */
42
+ readonly content: string;
43
+ readonly estimatedTokens: number;
44
+ readonly excluded: readonly ContextExclusion[];
45
+ readonly diagnostics: ContextDiagnostics;
46
+ }
47
+ /** The debug-friendly projection `ContextEngine.inspect()` returns (Section 57, 90). */
48
+ export interface ContextInspection {
49
+ readonly estimatedTokens: number;
50
+ readonly included: readonly {
51
+ readonly name: string;
52
+ readonly scope: ContextScope;
53
+ readonly priority: ContextPriority;
54
+ readonly estimatedTokens: number;
55
+ readonly truncated: boolean;
56
+ }[];
57
+ readonly excluded: readonly {
58
+ readonly name: string;
59
+ readonly scope: ContextScope;
60
+ readonly reason: ContextExclusionReason;
61
+ }[];
62
+ readonly diagnostics: ContextDiagnostics;
63
+ }
64
+ //# sourceMappingURL=resolved-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolved-context.d.ts","sourceRoot":"","sources":["../src/resolved-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC9B,UAAU,GACV,QAAQ,GACR,WAAW,GACX,SAAS,GACT,oBAAoB,GACpB,uBAAuB,CAAC;AAE5B,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,kEAAkE;AAClE,MAAM,WAAW,mBAAmB;IAClC,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Ae,EAAE,MAAM,CAAC;QACjC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;KAC7B,EAAE,CAAC;IACJ,QAAQ,CAAC,QAAQ,EAAE,SAAS;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;QAC7B,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;KACzC,EAAE,CAAC;IACJ,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;CAC1C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resolved-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolved-context.js","sourceRoot":"","sources":["../src/resolved-context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The provider-neutral shared-state patch contract (Section 41-42 of the Phase 6 brief).
3
+ * Deliberately smaller than the brief's own illustrative RFC 6902-flavored sample
4
+ * (`{ op: 'replace', path: '/status', value: ... }`): a state slot already holds one typed
5
+ * value, so "replace one field" only ever needs two operations - `'set'` (replace the whole
6
+ * value) and `'merge'` (shallow-merge a partial object into the current value) - not a
7
+ * general JSON-Pointer path language, which Section 42 explicitly warns against
8
+ * ("avoid an excessively powerful expression language"). See
9
+ * `docs/adr/0011-generative-ui-and-state-patch-architecture.md`.
10
+ */
11
+ export type StatePatchOp = 'set' | 'merge';
12
+ export interface StatePatch {
13
+ readonly op: StatePatchOp;
14
+ readonly value: unknown;
15
+ }
16
+ export type StatePatchRejectionReason = 'unknown-state' | 'not-writable' | 'invalid-value' | 'invalid-patch';
17
+ /**
18
+ * The outcome of `CopilotStateStore.applyPatch()` (Section 43, 45-46). A discriminated
19
+ * union so a caller (typically the reserved state-patch tool a writable state slot
20
+ * auto-registers - see `@gixcopilot/generative-ui`) can distinguish "stale revision, safe to
21
+ * retry with the current value" from "rejected outright" without parsing a message string.
22
+ */
23
+ export type StatePatchResult = {
24
+ readonly status: 'applied';
25
+ readonly revision: number;
26
+ readonly value: unknown;
27
+ } | {
28
+ readonly status: 'conflict';
29
+ readonly currentRevision: number;
30
+ } | {
31
+ readonly status: 'rejected';
32
+ readonly reason: StatePatchRejectionReason;
33
+ readonly detail?: string;
34
+ };
35
+ //# sourceMappingURL=state-patch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-patch.d.ts","sourceRoot":"","sources":["../src/state-patch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,MAAM,yBAAyB,GACjC,eAAe,GACf,cAAc,GACd,eAAe,GACf,eAAe,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAClF;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=state-patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-patch.js","sourceRoot":"","sources":["../src/state-patch.ts"],"names":[],"mappings":""}