create-t2k 0.3.0 → 0.4.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.
package/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  Create a runnable local T2K project with a synthetic ontology, accepted facts,
4
4
  a Decision Context, two executable policies, and disjoint replay evidence.
5
+ The existing decision-loop project remains the default profile.
5
6
 
6
7
  ```bash
7
- npx create-t2k@latest my-decision-loop
8
+ npx create-t2k@0.4.1 my-decision-loop
8
9
  cd my-decision-loop
9
10
  npm start
10
11
  ```
@@ -30,6 +31,10 @@ Stop the local containers without deleting lifecycle data with `npm run
30
31
  db:down`. Use the explicitly destructive `npm run db:reset` only when you
31
32
  intend to delete the disposable local database volume.
32
33
 
34
+ Compose binds PostgreSQL to `127.0.0.1:55432` only. The included `t2k` username
35
+ and `t2k` password are disposable local-only quickstart credentials; never
36
+ reuse them or expose this generated database to another host.
37
+
33
38
  To expose ontology validation, compilation, policy execution, replay, and
34
39
  reward evaluation to an MCP host, add:
35
40
 
@@ -38,7 +43,7 @@ reward evaluation to an MCP host, add:
38
43
  "mcpServers": {
39
44
  "t2k": {
40
45
  "command": "npx",
41
- "args": ["-y", "@t2kai/mcp@latest"]
46
+ "args": ["-y", "@t2kai/mcp@0.3.0"]
42
47
  }
43
48
  }
44
49
  }
@@ -51,10 +56,55 @@ before enabling database access or agent writes.
51
56
  Use `--no-install` to generate files without running `npm install`:
52
57
 
53
58
  ```bash
54
- npx create-t2k@latest my-decision-loop --no-install
59
+ npx create-t2k@0.4.1 my-decision-loop --no-install
55
60
  ```
56
61
 
62
+ The normal command installs dependencies for you. Run `npm install` inside the
63
+ generated project only when you chose `--no-install`.
64
+
57
65
  The command refuses to write into a non-empty directory. Node.js 20.10 or newer
58
66
  is required.
59
67
 
68
+ ## Integration-hub profile
69
+
70
+ Generate a focused, fully synthetic source-integration project explicitly:
71
+
72
+ ```bash
73
+ npx create-t2k@0.4.1 my-integration-hub --profile integration-hub
74
+ cd my-integration-hub
75
+ npm start
76
+ ```
77
+
78
+ This profile maps two independent registry records into one canonical party
79
+ identity, preserves conflicting name evidence, and applies a versioned authority
80
+ order to a conflicting registry state. It runs reconciliation again with the
81
+ opposite input order and reports that specifically scoped proposal-hash
82
+ comparison; it does not claim to check every permutation after more sources are
83
+ added.
84
+
85
+ Every regular `source-records/*.json` file is discovered in canonical filename
86
+ order, so the generated README experiments work without editing the runner:
87
+ reverse the authority priorities while bumping `policyVersion`, or add a third
88
+ synthetic source with the same canonical key and run `npm start` again.
89
+
90
+ The output is a deterministic evidence packet for human review. It preserves
91
+ every canonical record with its complete receipt, the exact loaded
92
+ `@t2kai/core` package version, the complete authority policy, and the full
93
+ forward and reverse reconciliation proposals and issues inside the hashed
94
+ packet. It does not mutate any source record or promote the authority-selected
95
+ candidate to accepted truth. Both included synthetic sources deliberately have
96
+ an `unknown` authentication state. The unkeyed hashes demonstrate deterministic
97
+ self-consistency only; they are not signatures, authentication, or proof that a
98
+ source assertion is true.
99
+
100
+ After an envelope has been mapped, keep it immutable: represent a later
101
+ observation with a new file, source-record key, payload record ID, and event and
102
+ observation times. Bump `policyVersion` after changing authority priorities;
103
+ bump `mappingVersion` and `ontologyVersion` after changing a mapping; and bump
104
+ `ontologyVersion` for any other ontology contract change.
105
+
106
+ Supported profiles are `decision-loop` (the default) and `integration-hub`.
107
+ An unknown or repeated `--profile` option fails before the target directory is
108
+ created.
109
+
60
110
  Apache-2.0. Contributions require DCO sign-off in the public repository.
@@ -18,14 +18,16 @@ Usage:
18
18
  create-t2k [directory] [options]
19
19
 
20
20
  Options:
21
+ --profile <name> Generate decision-loop (default) or integration-hub
21
22
  --no-install Generate the project without installing dependencies
22
23
  --yes Accept non-interactive defaults
23
24
  -h, --help Show this help
24
25
  -v, --version Show the package version
25
26
 
26
27
  The default directory is my-t2k-project. Existing non-empty directories are
27
- never overwritten. Generated projects include decision and optional
28
- persisted-lifecycle examples.`;
28
+ never overwritten. The decision-loop profile includes decision and optional
29
+ persisted-lifecycle examples. The integration-hub profile maps independent
30
+ synthetic sources into a non-mutating reconciliation proposal for human review.`;
29
31
 
30
32
  try {
31
33
  const options = parseArguments(process.argv.slice(2));
@@ -37,6 +39,7 @@ try {
37
39
  await scaffoldProject({
38
40
  targetDirectory: options.targetDirectory,
39
41
  install: options.install,
42
+ profile: options.profile,
40
43
  cwd: process.cwd(),
41
44
  stdout: process.stdout,
42
45
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-t2k",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Create a local T2K governed-decision project in minutes.",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "type": "module",
22
22
  "bin": {
23
- "create-t2k": "./bin/create-t2k.mjs"
23
+ "create-t2k": "bin/create-t2k.mjs"
24
24
  },
25
25
  "engines": {
26
26
  "node": ">=20.10.0"
@@ -29,6 +29,7 @@
29
29
  "bin",
30
30
  "src",
31
31
  "template",
32
+ "template-integration-hub",
32
33
  "README.md",
33
34
  "LICENSE"
34
35
  ],
package/src/scaffold.mjs CHANGED
@@ -5,7 +5,27 @@ import process from "node:process";
5
5
  import { fileURLToPath } from "node:url";
6
6
 
7
7
  const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
8
- const templateRoot = path.join(packageRoot, "template");
8
+ const profiles = {
9
+ "decision-loop": {
10
+ templateRoot: path.join(packageRoot, "template"),
11
+ },
12
+ "integration-hub": {
13
+ templateRoot: path.join(packageRoot, "template-integration-hub"),
14
+ },
15
+ };
16
+
17
+ export const CREATE_T2K_PROFILES = Object.freeze(Object.keys(profiles));
18
+
19
+ function requireProfile(value) {
20
+ if (typeof value !== "string" || !Object.hasOwn(profiles, value)) {
21
+ throw new Error(
22
+ `Unsupported profile: ${String(value)}. Choose one of: ${CREATE_T2K_PROFILES.join(
23
+ ", "
24
+ )}.`
25
+ );
26
+ }
27
+ return value;
28
+ }
9
29
 
10
30
  export function parseArguments(argumentsList) {
11
31
  const options = {
@@ -13,11 +33,14 @@ export function parseArguments(argumentsList) {
13
33
  install: true,
14
34
  help: false,
15
35
  version: false,
36
+ profile: "decision-loop",
16
37
  };
17
38
  const positionals = [];
18
39
  let parseOptions = true;
40
+ let profileProvided = false;
19
41
 
20
- for (const argument of argumentsList) {
42
+ for (let index = 0; index < argumentsList.length; index += 1) {
43
+ const argument = argumentsList[index];
21
44
  if (parseOptions && argument === "--") {
22
45
  parseOptions = false;
23
46
  } else if (parseOptions && ["-h", "--help"].includes(argument)) {
@@ -28,6 +51,27 @@ export function parseArguments(argumentsList) {
28
51
  options.install = false;
29
52
  } else if (parseOptions && argument === "--yes") {
30
53
  // The scaffolder has no interactive choices; this keeps npx usage familiar.
54
+ } else if (parseOptions && argument === "--profile") {
55
+ if (profileProvided) {
56
+ throw new Error("Provide --profile at most once.");
57
+ }
58
+ const value = argumentsList[index + 1];
59
+ if (!value || value.startsWith("-")) {
60
+ throw new Error("--profile requires a profile name.");
61
+ }
62
+ options.profile = requireProfile(value);
63
+ profileProvided = true;
64
+ index += 1;
65
+ } else if (parseOptions && argument.startsWith("--profile=")) {
66
+ if (profileProvided) {
67
+ throw new Error("Provide --profile at most once.");
68
+ }
69
+ const value = argument.slice("--profile=".length);
70
+ if (!value) {
71
+ throw new Error("--profile requires a profile name.");
72
+ }
73
+ options.profile = requireProfile(value);
74
+ profileProvided = true;
31
75
  } else if (parseOptions && argument.startsWith("-")) {
32
76
  throw new Error(`Unknown option: ${argument}`);
33
77
  } else {
@@ -136,16 +180,18 @@ function shellDisplay(value) {
136
180
  export async function scaffoldProject({
137
181
  targetDirectory,
138
182
  install = true,
183
+ profile = "decision-loop",
139
184
  cwd = process.cwd(),
140
185
  stdout = process.stdout,
141
186
  }) {
142
187
  if (typeof targetDirectory !== "string" || !targetDirectory.trim()) {
143
188
  throw new Error("Project directory is required.");
144
189
  }
190
+ const selectedProfile = requireProfile(profile);
145
191
  const targetPath = path.resolve(cwd, targetDirectory);
146
192
  const projectName = packageNameFor(targetPath);
147
193
  await ensureEmptyDirectory(targetPath);
148
- await copyTemplate(templateRoot, targetPath, {
194
+ await copyTemplate(profiles[selectedProfile].templateRoot, targetPath, {
149
195
  "{{PROJECT_NAME}}": projectName,
150
196
  });
151
197
 
@@ -169,9 +215,24 @@ export async function scaffoldProject({
169
215
  stdout.write(" npm install\n");
170
216
  }
171
217
  stdout.write(" npm start\n\n");
172
- stdout.write("The first run computes a recommendation; a human must still authorize it.\n");
173
- stdout.write("Run `npm run db:up && npm run lifecycle` for the persisted closed loop.\n");
174
- stdout.write("Use `npm run db:down` to stop it or `npm run db:reset` to delete its volume.\n");
218
+ if (selectedProfile === "integration-hub") {
219
+ stdout.write(
220
+ "The run maps two synthetic sources into a deterministic evidence proposal for human review.\n"
221
+ );
222
+ stdout.write(
223
+ "It does not authenticate either source, mutate source records, or promote a selected value to accepted truth.\n"
224
+ );
225
+ } else {
226
+ stdout.write(
227
+ "The first run computes a recommendation; a human must still authorize it.\n"
228
+ );
229
+ stdout.write(
230
+ "Run `npm run db:up && npm run lifecycle` for the persisted closed loop.\n"
231
+ );
232
+ stdout.write(
233
+ "Use `npm run db:down` to stop it or `npm run db:reset` to delete its volume.\n"
234
+ );
235
+ }
175
236
 
176
- return { targetPath, projectName };
237
+ return { targetPath, projectName, profile: selectedProfile };
177
238
  }
@@ -4,10 +4,12 @@ This project is a local T2K governed-decision quickstart. Its data is fully
4
4
  synthetic.
5
5
 
6
6
  ```bash
7
- npm install
8
7
  npm start
9
8
  ```
10
9
 
10
+ `create-t2k` installs dependencies by default. Run `npm install` first only if
11
+ this project was generated with `--no-install`.
12
+
11
13
  The run performs five explicit steps:
12
14
 
13
15
  1. validate `ontology-pack.json` against the published T2K schema;
@@ -44,6 +46,10 @@ the local containers while preserving their volume, run `npm run db:down`. To
44
46
  explicitly delete the disposable local volume and all lifecycle data in it, run
45
47
  `npm run db:reset`.
46
48
 
49
+ Compose binds PostgreSQL to `127.0.0.1:55432` only. Its `t2k` username and
50
+ `t2k` password are disposable local-only quickstart credentials; never reuse
51
+ them outside this generated project or expose this database to another host.
52
+
47
53
  ## Connect an MCP host
48
54
 
49
55
  Expose validation, compilation, policy execution, replay, and reward evaluation
@@ -54,7 +60,7 @@ to an MCP host with the safe database-free mode:
54
60
  "mcpServers": {
55
61
  "t2k": {
56
62
  "command": "npx",
57
- "args": ["-y", "@t2kai/mcp@latest"]
63
+ "args": ["-y", "@t2kai/mcp@0.3.0"]
58
64
  }
59
65
  }
60
66
  }
@@ -67,9 +73,15 @@ mutation modes.
67
73
  ## Change the example
68
74
 
69
75
  - Change current facts in `decision-context.json`.
70
- - Change executable rules in `policies/*.json`.
76
+ - Change executable rules in `policies/*.json` and bump the policy `version`.
71
77
  - Add observed outcomes to `episodes/holdout.json` without reusing training data.
72
- - Change concepts and decision contracts in `ontology-pack.json`.
78
+ - Change concepts or decision contracts in `ontology-pack.json` and bump
79
+ `ontologyVersion`.
80
+
81
+ Treat any context, policy, episode, or ontology artifact that has already been
82
+ executed or persisted as immutable evidence. Model a later observation with a
83
+ new context or episode identifier, and keep the prior artifact available for
84
+ replay instead of rewriting history.
73
85
 
74
86
  The quickstart uses local files, local PostgreSQL, and `@t2kai/core`; it does not
75
87
  send data to a hosted service. Set `T2K_DATABASE_URL` to use another Postgres
@@ -2,6 +2,8 @@ services:
2
2
  postgres:
3
3
  image: postgres:16-alpine
4
4
  environment:
5
+ # Disposable local-only quickstart credentials. Never reuse t2k/t2k
6
+ # outside this generated project.
5
7
  POSTGRES_DB: t2k_reference
6
8
  POSTGRES_PASSWORD: t2k
7
9
  POSTGRES_USER: t2k
@@ -11,7 +13,7 @@ services:
11
13
  timeout: 5s
12
14
  retries: 15
13
15
  ports:
14
- - "55432:5432"
16
+ - "127.0.0.1:55432:5432"
15
17
  volumes:
16
18
  - t2k-reference-data:/var/lib/postgresql/data
17
19
 
@@ -15,6 +15,6 @@
15
15
  "lifecycle": "node src/lifecycle.mjs"
16
16
  },
17
17
  "dependencies": {
18
- "@t2kai/core": "^0.3.0"
18
+ "@t2kai/core": "^0.4.1"
19
19
  }
20
20
  }
@@ -10,8 +10,21 @@ import { compileOntologyPackSet } from "@t2kai/core/compiler";
10
10
  import { PostgresReferenceLifecycle } from "@t2kai/core/postgres";
11
11
 
12
12
  const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
13
- const readJson = async (relativePath) =>
14
- JSON.parse(await fs.readFile(path.join(projectRoot, relativePath), "utf8"));
13
+
14
+ async function readJson(relativePath) {
15
+ const contents = await fs.readFile(
16
+ path.join(projectRoot, relativePath),
17
+ "utf8"
18
+ );
19
+ try {
20
+ return JSON.parse(contents);
21
+ } catch (error) {
22
+ const detail = error instanceof Error ? `: ${error.message}` : "";
23
+ throw new SyntaxError(`Invalid JSON in ${relativePath}${detail}`, {
24
+ cause: error,
25
+ });
26
+ }
27
+ }
15
28
  const [manifest, baseline, candidatePolicy, holdout] = await Promise.all([
16
29
  readJson("ontology-pack.json"),
17
30
  readJson("policies/baseline.json"),
@@ -12,8 +12,21 @@ import {
12
12
  import { compileOntologyPackSet } from "@t2kai/core/compiler";
13
13
 
14
14
  const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
15
- const readJson = async (relativePath) =>
16
- JSON.parse(await fs.readFile(path.join(projectRoot, relativePath), "utf8"));
15
+
16
+ async function readJson(relativePath) {
17
+ const contents = await fs.readFile(
18
+ path.join(projectRoot, relativePath),
19
+ "utf8"
20
+ );
21
+ try {
22
+ return JSON.parse(contents);
23
+ } catch (error) {
24
+ const detail = error instanceof Error ? `: ${error.message}` : "";
25
+ throw new SyntaxError(`Invalid JSON in ${relativePath}${detail}`, {
26
+ cause: error,
27
+ });
28
+ }
29
+ }
17
30
 
18
31
  const [manifest, context, baseline, candidate, episodes] = await Promise.all([
19
32
  readJson("ontology-pack.json"),
@@ -0,0 +1,3 @@
1
+ node_modules/
2
+ *.log
3
+ .DS_Store
@@ -0,0 +1,59 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ This is a fully synthetic T2K integration-hub quickstart. It demonstrates how
4
+ two independently governed source records can be mapped into one canonical
5
+ identity without silently merging evidence or declaring either source true.
6
+
7
+ ```bash
8
+ npm start
9
+ ```
10
+
11
+ `create-t2k` installs dependencies by default. Run `npm install` first only if
12
+ this project was generated with `--no-install`.
13
+
14
+ The run performs these explicit steps:
15
+
16
+ 1. validate and compile `ontology-pack.json`;
17
+ 2. canonically discover and map every regular `source-records/*.json` file with
18
+ one versioned mapping;
19
+ 3. preserve all conflicting display-name candidates;
20
+ 4. apply `authority-policy.json` to select a registry-state candidate within
21
+ the proposal;
22
+ 5. compare the forward source order with its reverse (not every possible
23
+ ordering when more than two sources exist); and
24
+ 6. emit a repeatable evidence packet for human review.
25
+
26
+ The selected registry-state value is only a candidate within a non-mutating
27
+ proposal. No source record is changed and no value becomes accepted truth.
28
+ Both source envelopes deliberately use `authenticationState: "unknown"`.
29
+ Production callers must authenticate or attest sources and policies outside
30
+ this example.
31
+
32
+ Each canonical record is paired with its complete source-mapping receipt in the
33
+ evidence packet. The packet also includes the exact loaded `@t2kai/core`
34
+ package version, the complete authority policy, both complete reconciliation
35
+ proposals and their issues, and an explicitly scoped forward-versus-reverse
36
+ hash comparison. All of those fields are included before the packet hash is
37
+ computed. The receipt, policy, proposal, and packet hashes are unkeyed
38
+ deterministic self-consistency checks. They are not signatures, authentication
39
+ tokens, or proof that an assertion is true.
40
+
41
+ ## Explore the hub safely
42
+
43
+ - Treat a source envelope as immutable once it has been mapped. To model a
44
+ later observation, copy it to a new `.json` file and assign a new
45
+ `sourceRecordKey`, payload `record_id`, `eventTime`, and `observedTime`; never
46
+ rewrite the earlier envelope.
47
+ - To reverse the priorities in `authority-policy.json`, also bump
48
+ `policyVersion`, rerun, and inspect the changed proposed authority selection.
49
+ - Add a third synthetic `.json` source with the same `party_key` and its own
50
+ new envelope identifiers and timestamps; it is discovered automatically on
51
+ the next run.
52
+ - When a field mapping changes, bump its `mappingVersion`. Because mappings are
53
+ part of this ontology pack, also bump `ontologyVersion`; bump
54
+ `ontologyVersion` for any other ontology contract change as well.
55
+ - Replace `humanCheckpoint: "always"` only after defining a real review and
56
+ authorization boundary in the calling system.
57
+
58
+ Keep real people, credentials, customer vocabulary, and private source
59
+ locations out of this project.
@@ -0,0 +1,10 @@
1
+ {
2
+ "policyId": "synthetic-party-authority",
3
+ "policyVersion": "1.0.0",
4
+ "prioritiesByDomain": {
5
+ "registry_status": [
6
+ "synthetic_registry_alpha",
7
+ "synthetic_registry_beta"
8
+ ]
9
+ }
10
+ }
@@ -0,0 +1,143 @@
1
+ {
2
+ "$schema": "https://t2k.ai/schemas/t2k-ontology-pack.v1.schema.json",
3
+ "manifestType": "t2k.ontology-pack",
4
+ "manifestVersion": "1.0",
5
+ "ontologyVersion": "1.0.0",
6
+ "ontologyId": "demo.integration-hub",
7
+ "label": "Synthetic Integration Hub",
8
+ "description": "Maps independently governed synthetic party records while preserving source evidence and human review.",
9
+ "packKind": "project",
10
+ "status": "accepted",
11
+ "scope": {
12
+ "domain": "synthetic_integration",
13
+ "description": "A non-production demonstration of canonical mapping and reconciliation.",
14
+ "jurisdictions": ["DEMO"],
15
+ "industries": [],
16
+ "businessStages": [],
17
+ "organizationSizes": [],
18
+ "exclusions": ["production data", "identity proofing", "autonomous truth promotion"]
19
+ },
20
+ "objectTypes": [
21
+ {
22
+ "id": "party",
23
+ "label": "Party",
24
+ "family": "Common party",
25
+ "nodeKind": "operating-entity",
26
+ "identity": ["party_id"],
27
+ "purpose": "A canonical party proposal whose values retain source-level evidence.",
28
+ "properties": [
29
+ {
30
+ "id": "party_id",
31
+ "valueType": "string",
32
+ "required": true,
33
+ "description": "Synthetic canonical identity key.",
34
+ "authorityDomain": "identity",
35
+ "temporal": false
36
+ },
37
+ {
38
+ "id": "display_name",
39
+ "valueType": "string",
40
+ "required": false,
41
+ "description": "A source-provided display-name candidate.",
42
+ "authorityDomain": "identity",
43
+ "temporal": true
44
+ },
45
+ {
46
+ "id": "registry_state",
47
+ "valueType": "string",
48
+ "required": false,
49
+ "description": "A source-provided registry-state candidate.",
50
+ "authorityDomain": "registry_status",
51
+ "temporal": true
52
+ }
53
+ ]
54
+ }
55
+ ],
56
+ "sourceMappings": [
57
+ {
58
+ "id": "synthetic_party_record_v1",
59
+ "mappingVersion": "1.0.0",
60
+ "sourceType": "independent_registry_record",
61
+ "sourceLocator": "synthetic://party-registry",
62
+ "sourceSchemaVersion": "party-record-v1",
63
+ "object": "party",
64
+ "fieldMappings": [
65
+ {
66
+ "sourcePath": "$.party_key",
67
+ "targetProperty": "party_id",
68
+ "required": true,
69
+ "normalizations": ["trim", "uppercase"],
70
+ "valueMap": {},
71
+ "authorityDomain": "identity",
72
+ "conflictPolicy": "require_review"
73
+ },
74
+ {
75
+ "sourcePath": "$.display_name",
76
+ "targetProperty": "display_name",
77
+ "required": true,
78
+ "normalizations": ["trim", "collapse_whitespace"],
79
+ "valueMap": {},
80
+ "authorityDomain": "identity",
81
+ "conflictPolicy": "preserve_all"
82
+ },
83
+ {
84
+ "sourcePath": "$.registry_state",
85
+ "targetProperty": "registry_state",
86
+ "required": true,
87
+ "normalizations": ["trim", "lowercase"],
88
+ "valueMap": {},
89
+ "authorityDomain": "registry_status",
90
+ "conflictPolicy": "prefer_authority"
91
+ }
92
+ ],
93
+ "targetIdentity": ["party_id"],
94
+ "idempotencyPath": "$.record_id",
95
+ "eventTimePath": "$.event_time",
96
+ "observedTimePath": "$.observed_time",
97
+ "authority": "source_specific",
98
+ "riskTier": "high",
99
+ "reviewStatus": "accepted",
100
+ "driftPolicy": "quarantine",
101
+ "lateArrivalPolicy": "quarantine",
102
+ "humanCheckpoint": "always",
103
+ "replayable": true
104
+ }
105
+ ],
106
+ "authorityModel": [
107
+ {
108
+ "domain": "identity",
109
+ "authority": "human_reviewed_source_evidence",
110
+ "status": "accepted",
111
+ "scope": "Identity candidates remain proposals until a human-owned process accepts them."
112
+ },
113
+ {
114
+ "domain": "registry_status",
115
+ "authority": "versioned_priority_policy",
116
+ "status": "accepted",
117
+ "scope": "Priority selects a candidate within the proposal and does not establish truth."
118
+ }
119
+ ],
120
+ "eventTypes": [
121
+ {
122
+ "id": "source_record_observed",
123
+ "source": "integration_hub",
124
+ "createsOrUpdates": "party",
125
+ "humanCheckpoint": "required"
126
+ }
127
+ ],
128
+ "reasoningFunctions": [
129
+ {
130
+ "id": "propose_canonical_reconciliation",
131
+ "input": "receipt-bound source evidence and versioned authority policy",
132
+ "output": "deterministic non-mutating proposal",
133
+ "humanCheckpoint": "required"
134
+ }
135
+ ],
136
+ "extensions": {
137
+ "dataPolicy": {
138
+ "syntheticOnly": true,
139
+ "authenticationProvided": false,
140
+ "truthPromotionAllowed": false
141
+ }
142
+ }
143
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20.10.0"
8
+ },
9
+ "scripts": {
10
+ "start": "node src/run.mjs",
11
+ "check": "node src/run.mjs"
12
+ },
13
+ "dependencies": {
14
+ "@t2kai/core": "^0.4.1"
15
+ }
16
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "sourceSystem": "synthetic-registry-alpha",
3
+ "sourceLocator": "synthetic://registry-alpha/party/ALPHA-0042",
4
+ "sourceRecordKey": "ALPHA-0042",
5
+ "sourceSchemaVersion": "party-record-v1",
6
+ "eventTime": "2026-08-29T15:00:00.000Z",
7
+ "observedTime": "2026-08-29T15:00:05.000Z",
8
+ "authenticationState": "unknown",
9
+ "authorityRef": "synthetic_registry_alpha",
10
+ "dataClassification": "synthetic_demo",
11
+ "purposeTags": ["integration_hub_demo"],
12
+ "retentionPolicy": {
13
+ "policyId": "synthetic-demo-30d",
14
+ "expiresAt": "2026-09-28"
15
+ },
16
+ "payload": {
17
+ "record_id": "ALPHA-0042",
18
+ "party_key": " shared-0042 ",
19
+ "display_name": " Sample Services LLC ",
20
+ "registry_state": " ACTIVE ",
21
+ "event_time": "2026-08-29T15:00:00.000Z",
22
+ "observed_time": "2026-08-29T15:00:05.000Z"
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "sourceSystem": "synthetic-registry-beta",
3
+ "sourceLocator": "synthetic://registry-beta/party/BETA-7001",
4
+ "sourceRecordKey": "BETA-7001",
5
+ "sourceSchemaVersion": "party-record-v1",
6
+ "eventTime": "2026-08-29T15:01:00.000Z",
7
+ "observedTime": "2026-08-29T15:01:08.000Z",
8
+ "authenticationState": "unknown",
9
+ "authorityRef": "synthetic_registry_beta",
10
+ "dataClassification": "synthetic_demo",
11
+ "purposeTags": ["integration_hub_demo"],
12
+ "retentionPolicy": {
13
+ "policyId": "synthetic-demo-30d",
14
+ "expiresAt": "2026-09-28"
15
+ },
16
+ "payload": {
17
+ "record_id": "BETA-7001",
18
+ "party_key": "SHARED-0042",
19
+ "display_name": "Sample Service Company",
20
+ "registry_state": "pending",
21
+ "event_time": "2026-08-29T15:01:00.000Z",
22
+ "observed_time": "2026-08-29T15:01:08.000Z"
23
+ }
24
+ }
@@ -0,0 +1,247 @@
1
+ import assert from "node:assert/strict";
2
+ import fs from "node:fs/promises";
3
+ import { createRequire } from "node:module";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ import {
8
+ executeSourceMapping,
9
+ reconcileCanonicalRecords,
10
+ validateOntologyPackManifest,
11
+ } from "@t2kai/core";
12
+ import {
13
+ compileOntologyPackSet,
14
+ compareCanonicalStrings,
15
+ semanticHash,
16
+ } from "@t2kai/core/compiler";
17
+
18
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
19
+ const loadPackageManifest = createRequire(import.meta.url);
20
+
21
+ async function readJson(relativePath) {
22
+ const contents = await fs.readFile(path.join(root, relativePath), "utf8");
23
+ try {
24
+ return JSON.parse(contents);
25
+ } catch (error) {
26
+ const detail = error instanceof Error ? `: ${error.message}` : "";
27
+ throw new SyntaxError(`Invalid JSON in ${relativePath}${detail}`, {
28
+ cause: error,
29
+ });
30
+ }
31
+ }
32
+
33
+ async function readSourceRecords() {
34
+ const sourceDirectory = path.join(root, "source-records");
35
+ const sourceFiles = (await fs.readdir(sourceDirectory, { withFileTypes: true }))
36
+ .filter((entry) => entry.isFile() && path.extname(entry.name) === ".json")
37
+ .map((entry) => entry.name)
38
+ .sort(compareCanonicalStrings);
39
+
40
+ assert.ok(
41
+ sourceFiles.length >= 2,
42
+ "The integration-hub profile requires at least two source-records/*.json files."
43
+ );
44
+
45
+ return Promise.all(
46
+ sourceFiles.map((sourceFile) =>
47
+ readJson(path.posix.join("source-records", sourceFile))
48
+ )
49
+ );
50
+ }
51
+
52
+ const manifest = await readJson("ontology-pack.json");
53
+ const authorityPolicy = await readJson("authority-policy.json");
54
+ const sourceRecords = await readSourceRecords();
55
+ const sourceSnapshot = structuredClone(sourceRecords);
56
+ const corePackageManifest = loadPackageManifest("@t2kai/core/package.json");
57
+ assert.equal(
58
+ corePackageManifest.name,
59
+ "@t2kai/core",
60
+ "The integration packet must identify the loaded core runtime."
61
+ );
62
+ assert.ok(
63
+ typeof corePackageManifest.version === "string" &&
64
+ corePackageManifest.version.length > 0,
65
+ "The loaded core runtime must expose an exact package version."
66
+ );
67
+
68
+ const validation = validateOntologyPackManifest(manifest);
69
+ assert.equal(
70
+ validation.valid,
71
+ true,
72
+ `Integration-hub manifest failed validation: ${JSON.stringify(validation.errors)}`
73
+ );
74
+
75
+ const compilation = compileOntologyPackSet({
76
+ manifests: [manifest],
77
+ roots: [
78
+ {
79
+ ontologyId: manifest.ontologyId,
80
+ version: manifest.ontologyVersion,
81
+ },
82
+ ],
83
+ });
84
+ assert.equal(compilation.status, "valid", JSON.stringify(compilation.diagnostics));
85
+
86
+ const mapping = manifest.sourceMappings.find(
87
+ (candidate) => candidate.id === "synthetic_party_record_v1"
88
+ );
89
+ assert.ok(mapping, "The integration-hub source mapping is missing.");
90
+
91
+ const mappedResults = sourceRecords.map((sourceRecord) => {
92
+ const { payload, ...envelopeMetadata } = sourceRecord;
93
+ return executeSourceMapping({
94
+ mapping,
95
+ envelope: {
96
+ ...envelopeMetadata,
97
+ payload: structuredClone(payload),
98
+ contentHash: semanticHash(payload),
99
+ },
100
+ });
101
+ });
102
+
103
+ assert.ok(
104
+ mappedResults.every((result) => result.receipt.status === "mapped"),
105
+ "Every synthetic source record must map successfully."
106
+ );
107
+ assert.ok(
108
+ mappedResults.every((result) => result.receipt.humanReviewRequired),
109
+ "Every source receipt must retain the explicit human checkpoint."
110
+ );
111
+ assert.ok(
112
+ mappedResults.every(
113
+ (result) => result.receipt.authenticationState === "unknown"
114
+ ),
115
+ "The synthetic profile must not claim source authentication."
116
+ );
117
+ assert.equal(
118
+ new Set(mappedResults.map((result) => result.receipt.receiptHash)).size,
119
+ mappedResults.length,
120
+ "Each source record must produce independent receipt-bound evidence."
121
+ );
122
+ assert.equal(
123
+ new Set(
124
+ mappedResults.map((result) => semanticHash(result.canonicalRecord.identity))
125
+ ).size,
126
+ 1,
127
+ "Every discovered source record must map to one shared canonical identity."
128
+ );
129
+ assert.ok(
130
+ Object.keys(mappedResults[0].canonicalRecord.identity).length > 0,
131
+ "The shared canonical identity must not be empty."
132
+ );
133
+ assert.deepEqual(sourceRecords, sourceSnapshot, "Source mapping mutated its input.");
134
+
135
+ const mappedSnapshot = structuredClone(mappedResults);
136
+ const reconciliation = reconcileCanonicalRecords({
137
+ results: mappedResults,
138
+ authorityPolicy,
139
+ });
140
+ const reverseOrderReconciliation = reconcileCanonicalRecords({
141
+ results: [...mappedResults].reverse(),
142
+ authorityPolicy,
143
+ });
144
+ assert.deepEqual(
145
+ mappedResults,
146
+ mappedSnapshot,
147
+ "Canonical reconciliation mutated mapped source evidence."
148
+ );
149
+ assert.equal(reconciliation.status, "needs_review");
150
+ assert.equal(reconciliation.humanReviewRequired, true);
151
+ assert.equal(reconciliation.nonMutating, true);
152
+ assert.equal(reconciliation.alternativesPreserved, true);
153
+ assert.equal(
154
+ reconciliation.proposalHash,
155
+ reverseOrderReconciliation.proposalHash,
156
+ "Reconciliation must be deterministic across source input order."
157
+ );
158
+
159
+ const preserveAllField = reconciliation.fields.find(
160
+ (field) =>
161
+ field.conflictPolicy === "preserve_all" &&
162
+ field.resolution === "preserve_all"
163
+ );
164
+ const preferAuthorityField = reconciliation.fields.find(
165
+ (field) =>
166
+ field.conflictPolicy === "prefer_authority" &&
167
+ field.resolution === "preferred_authority"
168
+ );
169
+ assert.ok(
170
+ preserveAllField,
171
+ "At least one conflicting field must exercise preserve_all reconciliation."
172
+ );
173
+ assert.equal(preserveAllField.selectedValue, null);
174
+ assert.ok(preserveAllField.candidates.length >= 2);
175
+ assert.ok(
176
+ preferAuthorityField,
177
+ "At least one conflicting field must exercise prefer_authority reconciliation."
178
+ );
179
+ assert.notEqual(preferAuthorityField.selectedValue, null);
180
+ assert.ok(preferAuthorityField.candidates.length >= 2);
181
+
182
+ const packetWithoutHash = {
183
+ profile: "integration-hub",
184
+ coreRuntime: {
185
+ packageName: corePackageManifest.name,
186
+ packageVersion: corePackageManifest.version,
187
+ },
188
+ ontology: `${manifest.ontologyId}@${manifest.ontologyVersion}`,
189
+ resolutionHash: compilation.resolutionHash,
190
+ authorityPolicy: structuredClone(authorityPolicy),
191
+ sourceEvidence: mappedResults
192
+ .map((result) => ({
193
+ summary: {
194
+ sourceSystem: result.receipt.sourceSystem,
195
+ sourceRecordKey: result.receipt.sourceRecordKey,
196
+ authorityRef: result.receipt.authorityRef,
197
+ authenticationState: result.receipt.authenticationState,
198
+ receiptHash: result.receipt.receiptHash,
199
+ humanReviewRequired: result.receipt.humanReviewRequired,
200
+ },
201
+ canonicalRecord: result.canonicalRecord,
202
+ receipt: result.receipt,
203
+ }))
204
+ .sort((left, right) =>
205
+ compareCanonicalStrings(
206
+ left.receipt.receiptHash,
207
+ right.receipt.receiptHash
208
+ )
209
+ ),
210
+ reconciliation: {
211
+ proposal: reconciliation,
212
+ reverseInputOrderProposal: reverseOrderReconciliation,
213
+ forwardReverseInputOrderCheck: {
214
+ comparisonScope: "forward_and_reverse_input_order_only",
215
+ allPermutationsChecked: mappedResults.length === 2,
216
+ forwardReceiptHashes: mappedResults.map(
217
+ (result) => result.receipt.receiptHash
218
+ ),
219
+ reverseReceiptHashes: [...mappedResults]
220
+ .reverse()
221
+ .map((result) => result.receipt.receiptHash),
222
+ forwardProposalHash: reconciliation.proposalHash,
223
+ reverseProposalHash: reverseOrderReconciliation.proposalHash,
224
+ proposalHashesMatch:
225
+ reconciliation.proposalHash === reverseOrderReconciliation.proposalHash,
226
+ },
227
+ },
228
+ humanReview: {
229
+ status: "pending_human_review",
230
+ proposalOnly: true,
231
+ issues: reconciliation.issues,
232
+ },
233
+ boundaries: {
234
+ syntheticDataOnly: true,
235
+ sourceRecordsMutated: false,
236
+ sourceAuthenticationEstablished: false,
237
+ acceptedTruthCreated: false,
238
+ authoritySelectionIsProposalOnly: true,
239
+ externalAuthenticationAndDispositionRequired: true,
240
+ },
241
+ };
242
+ const output = {
243
+ ...packetWithoutHash,
244
+ evidencePacketHash: semanticHash(packetWithoutHash),
245
+ };
246
+
247
+ console.log(JSON.stringify(output, null, 2));