skillar 0.2.1 → 0.3.1

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 (111) hide show
  1. package/NOTICE +280 -0
  2. package/README.md +37 -5
  3. package/dist/analysis/finding.js +8 -190
  4. package/dist/analysis/kernel.js +896 -0
  5. package/dist/analysis/tree.js +7 -154
  6. package/dist/analysis/usage.js +9 -394
  7. package/dist/api/flows.js +42 -212
  8. package/dist/api/report-kernel.js +1063 -0
  9. package/dist/api/routes.js +12 -2
  10. package/dist/catalog/fields.js +138 -146
  11. package/dist/catalog/watcher.js +7 -2
  12. package/dist/cli/init.js +45 -0
  13. package/dist/cli/main.js +76 -3
  14. package/dist/cli/private-skills.js +122 -0
  15. package/dist/cli/serve.js +15 -1
  16. package/dist/cli/sync.js +124 -0
  17. package/dist/dashboard/NOTICE +280 -0
  18. package/dist/dashboard/assets/app.js +737 -275
  19. package/dist/dashboard/assets/astryx-reset.css +407 -0
  20. package/dist/dashboard/assets/astryx.css +1077 -0
  21. package/dist/dashboard/assets/charts.css +54 -0
  22. package/dist/dashboard/assets/chunk-TPGDA2J4.js +1 -0
  23. package/dist/dashboard/assets/chunk-YLWHVDMP.js +36 -0
  24. package/dist/dashboard/assets/controls.css +207 -0
  25. package/dist/dashboard/assets/overlays.css +132 -0
  26. package/dist/dashboard/assets/p1.css +135 -0
  27. package/dist/dashboard/assets/shell.css +71 -0
  28. package/dist/dashboard/assets/skillar-theme.css +692 -0
  29. package/dist/dashboard/assets/styles.css +224 -121
  30. package/dist/dashboard/assets/tokens.css +278 -0
  31. package/dist/dashboard/assets/widgets.css +83 -0
  32. package/dist/dashboard/index.html +11 -2
  33. package/dist/dashboard/viewers/viewers.css +61 -0
  34. package/dist/ingest/attribution.js +5 -1
  35. package/dist/ingest/pipeline.js +2 -0
  36. package/dist/ingest/request-recorder.js +39 -0
  37. package/dist/mcp/dispatch.js +2 -2
  38. package/dist/mcp/http.js +43 -3
  39. package/dist/mcp/skills-extension.js +42 -15
  40. package/dist/mcp/stdio-proxy.js +24 -3
  41. package/dist/mcp/tools.js +38 -24
  42. package/dist/packs/claude-code.js +22 -11
  43. package/dist/packs/cursor.js +9 -4
  44. package/dist/packs/gemini.js +9 -4
  45. package/dist/packs/json-config.js +41 -0
  46. package/dist/packs/omo.js +15 -6
  47. package/dist/request-status.js +81 -0
  48. package/dist/search/fts.js +93 -58
  49. package/dist/search/fusion.js +49 -47
  50. package/dist/search/guidance.js +18 -6
  51. package/dist/search/index.js +291 -70
  52. package/dist/search/lexical.js +71 -63
  53. package/dist/server.js +12 -0
  54. package/dist/skills/apply.js +130 -0
  55. package/dist/skills/capture.js +54 -0
  56. package/dist/skills/cloud-plan.js +57 -0
  57. package/dist/skills/cloud.js +81 -0
  58. package/dist/skills/fs.js +133 -0
  59. package/dist/skills/package.js +734 -0
  60. package/dist/skills/plan.js +83 -0
  61. package/dist/skills/receipt.js +44 -0
  62. package/dist/skills/rollback.js +119 -0
  63. package/dist/skills/transfer.js +51 -0
  64. package/dist/store/db.js +7 -1
  65. package/dist/store/execution.js +2 -34
  66. package/dist/store/export.js +25 -4
  67. package/dist/store/migrations/007_sync.sql +49 -0
  68. package/dist/store/migrations/008_connector_commands.sql +12 -0
  69. package/dist/store/queries.js +33 -7
  70. package/dist/store/writes.js +38 -5
  71. package/dist/sync/cloud-blobs.js +175 -0
  72. package/dist/sync/cloud-commands.js +101 -0
  73. package/dist/sync/cloud-connection.js +105 -0
  74. package/dist/sync/cloud-delivery.js +114 -0
  75. package/dist/sync/cloud-documents.js +103 -0
  76. package/dist/sync/cloud-export.js +67 -0
  77. package/dist/sync/cloud-http.js +150 -0
  78. package/dist/sync/cloud-jobs.js +94 -0
  79. package/dist/sync/cloud-pending.js +143 -0
  80. package/dist/sync/cloud-prepare.js +101 -0
  81. package/dist/sync/cloud-restore.js +136 -0
  82. package/dist/sync/cloud-rollback.js +24 -0
  83. package/dist/sync/cloud-runner.js +86 -0
  84. package/dist/sync/cloud-runtime.js +293 -0
  85. package/dist/sync/cloud-schema.js +32 -0
  86. package/dist/sync/cloud-stage.js +112 -0
  87. package/dist/sync/cloud-wire.js +693 -0
  88. package/dist/sync/cloud-worker.js +57 -0
  89. package/dist/sync/cloud.js +157 -0
  90. package/dist/sync/command-apply.js +140 -0
  91. package/dist/sync/command-control.js +25 -0
  92. package/dist/sync/command-wire.js +437 -0
  93. package/dist/sync/consent.js +130 -0
  94. package/dist/sync/journal.js +43 -0
  95. package/dist/sync/outbox.js +134 -0
  96. package/dist/sync/restore-rows.js +125 -0
  97. package/dist/sync/restore.js +174 -0
  98. package/dist/sync/snapshot.js +78 -0
  99. package/dist/sync/spool-request.js +103 -0
  100. package/dist/sync/tables.js +27 -0
  101. package/dist/sync/triggers.js +34 -0
  102. package/dist/workflow/compare.js +3 -43
  103. package/docs/cloud-sync.md +94 -0
  104. package/docs/private-skills.md +75 -0
  105. package/docs/sync-p4.md +102 -0
  106. package/docs/sync-restore.md +167 -0
  107. package/package.json +18 -5
  108. package/src/store/migrations/007_sync.sql +49 -0
  109. package/src/store/migrations/008_connector_commands.sql +12 -0
  110. package/dist/dashboard/assets/chunk-5DFWNJC2.js +0 -1
  111. package/dist/dashboard/assets/chunk-S6B2HJQA.js +0 -17
@@ -0,0 +1,112 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { DatabaseSync } from "node:sqlite";
5
+ import { CloudSyncError } from "./cloud-blobs.js";
6
+ import { cloudHome } from "./cloud-connection.js";
7
+ import { coveredRows, snapshotRecords } from "./cloud-documents.js";
8
+ import { liveStream, stageCdcJob, stageMigrationJob } from "./cloud-jobs.js";
9
+ import { preparedPath, preparedSchema } from "./cloud-prepare.js";
10
+ import { journalHead, readJournal } from "./journal.js";
11
+ import { MAX_SNAPSHOT_ROWS } from "./cloud-wire.js";
12
+ export const CLOUD_TIME_END = 8_640_000_000_000_000;
13
+ export function migrationPrefix(connection, sourceDomain) {
14
+ return `cloud-migration:${connection.instanceId}:${sourceDomain}:`;
15
+ }
16
+ /** Whole-device transport requires its explicit browser scope, not an arbitrary project. */
17
+ export function cloudScope(connection, consent, historical) {
18
+ if (consent.mode !== "managed-content")
19
+ throw new CloudSyncError("content_consent_required");
20
+ const projectId = `device:${connection.deviceId}`;
21
+ if (consent.scope.deviceId !== connection.deviceId ||
22
+ !consent.scope.projectIds.includes(projectId) || consent.scope.rootIds.length !== 0) {
23
+ throw new CloudSyncError("whole_device_consent_required");
24
+ }
25
+ if (historical && consent.backfill === undefined)
26
+ throw new CloudSyncError("backfill_consent_required");
27
+ const history = historical ? consent.backfill : undefined;
28
+ return {
29
+ deviceId: connection.deviceId, projectId, rootId: null,
30
+ consentVersion: consent.version, contentKinds: consent.contentKinds,
31
+ fromMs: history?.range.fromMs ?? consent.grantedAtMs,
32
+ toMs: history?.range.toMs ?? CLOUD_TIME_END,
33
+ backfill: history === undefined ? null : {
34
+ version: history.version, snapshotId: history.snapshotId, journalCut: history.journalCut,
35
+ },
36
+ };
37
+ }
38
+ export async function stageBaseline(home, source, blobs, connection, consent, purpose) {
39
+ const head = journalHead(source);
40
+ const historical = consent.mode === "managed-content" && consent.backfill !== undefined;
41
+ const scope = cloudScope(connection, consent, historical);
42
+ let snapshotId = randomUUID();
43
+ let cut = head.cut;
44
+ let records = [];
45
+ if (historical) {
46
+ const prepared = preparedSchema.parse(JSON.parse(readFileSync(join(cloudHome(home), "prepared.json"), "utf8")));
47
+ if (prepared.instanceId !== connection.instanceId || prepared.deviceId !== connection.deviceId ||
48
+ prepared.generation !== connection.generation || prepared.sourceDomain !== head.sourceDomain ||
49
+ prepared.snapshotId !== scope.backfill?.snapshotId || prepared.cut !== scope.backfill.journalCut ||
50
+ prepared.expiresAtMs <= Date.now())
51
+ throw new CloudSyncError("prepared_snapshot_mismatch");
52
+ snapshotId = prepared.snapshotId;
53
+ cut = prepared.cut;
54
+ const frozen = new DatabaseSync(preparedPath(home, snapshotId), { readOnly: true });
55
+ try {
56
+ const frozenHead = journalHead(frozen);
57
+ if (frozenHead.cut !== cut || frozenHead.sourceDomain !== head.sourceDomain) {
58
+ throw new CloudSyncError("prepared_snapshot_mismatch");
59
+ }
60
+ records = snapshotRecords(frozen, cut);
61
+ }
62
+ finally {
63
+ frozen.close();
64
+ }
65
+ }
66
+ else if (purpose === "backfill") {
67
+ throw new CloudSyncError("backfill_consent_required");
68
+ }
69
+ const streamId = `${migrationPrefix(connection, head.sourceDomain)}${snapshotId}`;
70
+ if ((blobs.cursor(streamId)?.ack_sequence ?? 0) > 0)
71
+ return null;
72
+ const transformed = await coveredRows(consent, scope, records);
73
+ return stageMigrationJob(blobs, {
74
+ streamId,
75
+ reference: {
76
+ deviceId: connection.deviceId, generation: connection.generation,
77
+ sourceDomain: head.sourceDomain, snapshotId, cut, purpose,
78
+ },
79
+ consent, scope, rows: transformed.rows, excluded: transformed.excluded,
80
+ });
81
+ }
82
+ export async function stageLive(source, blobs, connection, consent) {
83
+ const head = journalHead(source), streamId = liveStream(connection.instanceId, head.sourceDomain);
84
+ const cursor = blobs.cursor(streamId);
85
+ if (cursor === null)
86
+ throw new CloudSyncError("baseline_required");
87
+ if (head.cut < cursor.ack_cut)
88
+ throw new CloudSyncError("source_history_rewound");
89
+ if (head.cut === cursor.ack_cut)
90
+ return null;
91
+ const rows = [];
92
+ let after = cursor.ack_cut;
93
+ for (;;) {
94
+ const page = readJournal(source, { after, through: head.cut });
95
+ if (page.length === 0)
96
+ break;
97
+ rows.push(...page);
98
+ if (rows.length > MAX_SNAPSHOT_ROWS)
99
+ throw new CloudSyncError("journal_pressure");
100
+ after = page[page.length - 1].revision;
101
+ }
102
+ // A grant that covers history AND future can carry both in the same fixed cut.
103
+ const historical = consent.mode === "managed-content" && consent.backfill !== undefined &&
104
+ consent.backfill.range.toMs === CLOUD_TIME_END;
105
+ const scope = cloudScope(connection, consent, historical);
106
+ const transformed = await coveredRows(consent, scope, rows);
107
+ return stageCdcJob(blobs, {
108
+ streamId, deviceId: connection.deviceId, sourceDomain: head.sourceDomain,
109
+ generation: connection.generation, consent, scope, after: cursor.ack_cut,
110
+ cut: head.cut, rows: transformed.rows, excluded: transformed.excluded,
111
+ });
112
+ }