borgmcp-shared 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CONTRIBUTING.md +40 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +2 -0
  4. package/README.md +159 -0
  5. package/SECURITY.md +25 -0
  6. package/dist/conformance/adapter.d.ts +112 -0
  7. package/dist/conformance/adapter.d.ts.map +1 -0
  8. package/dist/conformance/adapter.js +417 -0
  9. package/dist/conformance/adapter.js.map +1 -0
  10. package/dist/conformance/index.d.ts +15 -0
  11. package/dist/conformance/index.d.ts.map +1 -0
  12. package/dist/conformance/index.js +49 -0
  13. package/dist/conformance/index.js.map +1 -0
  14. package/dist/domain/index.d.ts +5 -0
  15. package/dist/domain/index.d.ts.map +1 -0
  16. package/dist/domain/index.js +4 -0
  17. package/dist/domain/index.js.map +1 -0
  18. package/dist/drone-address.d.ts +3 -0
  19. package/dist/drone-address.d.ts.map +1 -0
  20. package/dist/drone-address.js +7 -0
  21. package/dist/drone-address.js.map +1 -0
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +5 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/log-stream-hwm.d.ts +6 -0
  27. package/dist/log-stream-hwm.d.ts.map +1 -0
  28. package/dist/log-stream-hwm.js +12 -0
  29. package/dist/log-stream-hwm.js.map +1 -0
  30. package/dist/protocol/contract.d.ts +127 -0
  31. package/dist/protocol/contract.d.ts.map +1 -0
  32. package/dist/protocol/contract.js +434 -0
  33. package/dist/protocol/contract.js.map +1 -0
  34. package/dist/protocol/coordination.d.ts +38 -0
  35. package/dist/protocol/coordination.d.ts.map +1 -0
  36. package/dist/protocol/coordination.js +176 -0
  37. package/dist/protocol/coordination.js.map +1 -0
  38. package/dist/protocol/errors.d.ts +33 -0
  39. package/dist/protocol/errors.d.ts.map +1 -0
  40. package/dist/protocol/errors.js +26 -0
  41. package/dist/protocol/errors.js.map +1 -0
  42. package/dist/protocol/index.d.ts +8 -0
  43. package/dist/protocol/index.d.ts.map +1 -0
  44. package/dist/protocol/index.js +7 -0
  45. package/dist/protocol/index.js.map +1 -0
  46. package/dist/protocol/sse.d.ts +44 -0
  47. package/dist/protocol/sse.d.ts.map +1 -0
  48. package/dist/protocol/sse.js +246 -0
  49. package/dist/protocol/sse.js.map +1 -0
  50. package/dist/protocol/types.d.ts +174 -0
  51. package/dist/protocol/types.d.ts.map +1 -0
  52. package/dist/protocol/types.js +2 -0
  53. package/dist/protocol/types.js.map +1 -0
  54. package/dist/protocol/version.d.ts +11 -0
  55. package/dist/protocol/version.d.ts.map +1 -0
  56. package/dist/protocol/version.js +14 -0
  57. package/dist/protocol/version.js.map +1 -0
  58. package/dist/role-section.d.ts +24 -0
  59. package/dist/role-section.d.ts.map +1 -0
  60. package/dist/role-section.js +114 -0
  61. package/dist/role-section.js.map +1 -0
  62. package/dist/templates.d.ts +44 -0
  63. package/dist/templates.d.ts.map +1 -0
  64. package/dist/templates.js +771 -0
  65. package/dist/templates.js.map +1 -0
  66. package/docs/compatibility.md +38 -0
  67. package/docs/releasing.md +220 -0
  68. package/package.json +89 -0
  69. package/src/conformance/adapter.ts +717 -0
  70. package/src/conformance/index.ts +68 -0
  71. package/src/domain/index.ts +9 -0
  72. package/src/drone-address.ts +25 -0
  73. package/src/index.ts +4 -0
  74. package/src/log-stream-hwm.ts +16 -0
  75. package/src/protocol/contract.ts +608 -0
  76. package/src/protocol/coordination.ts +249 -0
  77. package/src/protocol/errors.ts +36 -0
  78. package/src/protocol/index.ts +7 -0
  79. package/src/protocol/sse.ts +295 -0
  80. package/src/protocol/types.ts +201 -0
  81. package/src/protocol/version.ts +31 -0
  82. package/src/role-section.ts +270 -0
  83. package/src/templates.ts +953 -0
@@ -0,0 +1,68 @@
1
+ import type { BroadcastHwm } from '../log-stream-hwm.js';
2
+
3
+ export * from './adapter.js';
4
+
5
+ /** A portable input/output vector that can be consumed by any test runner. */
6
+ export interface ConformanceVector<Input, Output> {
7
+ name: string;
8
+ input: Input;
9
+ expected: Output;
10
+ }
11
+
12
+ export interface BroadcastHwmComparisonInput {
13
+ a: BroadcastHwm;
14
+ b: BroadcastHwm;
15
+ }
16
+
17
+ export const BROADCAST_HWM_CONFORMANCE: readonly ConformanceVector<
18
+ BroadcastHwmComparisonInput,
19
+ -1 | 0 | 1
20
+ >[] = [
21
+ {
22
+ name: 'orders by timestamp',
23
+ input: {
24
+ a: { id: 'z', created_at: '2026-05-29T09:59:59.000Z' },
25
+ b: { id: 'a', created_at: '2026-05-29T10:00:00.000Z' },
26
+ },
27
+ expected: -1,
28
+ },
29
+ {
30
+ name: 'breaks equal-timestamp ties by id',
31
+ input: {
32
+ a: { id: 'a', created_at: '2026-05-29T10:00:00.000Z' },
33
+ b: { id: 'b', created_at: '2026-05-29T10:00:00.000Z' },
34
+ },
35
+ expected: -1,
36
+ },
37
+ {
38
+ name: 'compares identical tuples as equal',
39
+ input: {
40
+ a: { id: 'a', created_at: '2026-05-29T10:00:00.000Z' },
41
+ b: { id: 'a', created_at: '2026-05-29T10:00:00.000Z' },
42
+ },
43
+ expected: 0,
44
+ },
45
+ {
46
+ name: 'falls back to raw timestamp ordering for invalid dates',
47
+ input: {
48
+ a: { id: 'a', created_at: 'not-a-date-a' },
49
+ b: { id: 'a', created_at: 'not-a-date-b' },
50
+ },
51
+ expected: -1,
52
+ },
53
+ ];
54
+
55
+ export const DRONE_ADDRESS_CONFORMANCE: readonly ConformanceVector<string, string>[] = [
56
+ {
57
+ name: 'formats the stable lowercase eight-character id prefix',
58
+ input: '3336CDE1-a76e-4e89-8bc2-77c149bb6a74',
59
+ expected: '`id:3336cde1`',
60
+ },
61
+ ];
62
+
63
+ export const ROLE_SECTION_ROUND_TRIP_CONFORMANCE: readonly string[] = [
64
+ '',
65
+ 'Preamble only.',
66
+ 'Preamble.\n\nWorkflow:\n- step one\n\nProject conventions:\n- TDD.\n',
67
+ '**Markdown heading:**\nMust remain part of the preamble.\n',
68
+ ];
@@ -0,0 +1,9 @@
1
+ export * from '../drone-address.js';
2
+ export * from '../log-stream-hwm.js';
3
+ export * from '../role-section.js';
4
+ export type {
5
+ MessageTaxonomy,
6
+ MessageTaxonomyClass,
7
+ Template,
8
+ TemplateRole,
9
+ } from '../templates.js';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Shared short-UUID rendering keeps roster and activity-log addresses
3
+ * consistent. A drone label may change as cube membership changes; the ID
4
+ * prefix remains the stable address.
5
+ */
6
+
7
+ /**
8
+ * The stable short-uuid: the first 8 hex of the drone_id (UUID). It is, by
9
+ * construction, a valid `startsWith` prefix of the full drone ID. It is
10
+ * lowercased so case differences cannot create cross-surface drift.
11
+ */
12
+ export function shortDroneId(droneId: string): string {
13
+ return droneId.slice(0, 8).toLowerCase();
14
+ }
15
+
16
+ /**
17
+ * The clearly-LABELED address token shown beside a drone on the roster and on
18
+ * each read-log entry: `` `id:3336cde1` ``. Backticked so it
19
+ * renders monospace — visually distinct from the plain `[entry_id: …]` bracket
20
+ * that sits beside it in read-log, so a weak model never confuses which token
21
+ * to `borg_ack` with (entry_id) versus address a dispatch to (`id:` short-uuid).
22
+ */
23
+ export function formatDroneAddressToken(droneId: string): string {
24
+ return `\`id:${shortDroneId(droneId)}\``;
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './protocol/index.js';
2
+ export * from './domain/index.js';
3
+ export * from './conformance/index.js';
4
+ export * from './templates.js';
@@ -0,0 +1,16 @@
1
+ export interface BroadcastHwm {
2
+ id: string;
3
+ created_at: string;
4
+ }
5
+
6
+ export function compareBroadcastHwm(a: BroadcastHwm, b: BroadcastHwm): number {
7
+ const aTime = Date.parse(a.created_at);
8
+ const bTime = Date.parse(b.created_at);
9
+ if (Number.isFinite(aTime) && Number.isFinite(bTime) && aTime !== bTime) {
10
+ return aTime - bTime;
11
+ }
12
+ if (a.created_at !== b.created_at) {
13
+ return a.created_at < b.created_at ? -1 : 1;
14
+ }
15
+ return a.id.localeCompare(b.id);
16
+ }