@renanlido/tia-openness-mcp 1.8.2 → 1.9.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 (3) hide show
  1. package/README.md +102 -51
  2. package/dist/index.js +202 -10
  3. package/package.json +5 -3
package/README.md CHANGED
@@ -26,28 +26,33 @@ The harness operating guide ships **inside the MCP itself**, in three layers:
26
26
  MCP handshake (`instructions` field). Any client that honors `instructions` (Claude Code,
27
27
  Claude Desktop, ...) gets the gates/serial-only/pipeline rules automatically, with zero setup.
28
28
  2. **`tia_guide(topic)`** — a tool that returns the bundled guide chapters on demand:
29
- `toc` (default) | `full` | `brief` | `gates-guards` | `gui-gates` | `gotchas` | `pipeline` |
30
- `recipes` | `spec-format`. Call it with `{"topic":"pipeline"}` before the first build on a
29
+ `toc` (default) | `full` | `codex` (the guide sized for the 32 KiB Codex reads from AGENTS.md: the recipes
30
+ become a pointer) | `brief` | `gates-guards` | `gui-gates` | `gotchas` | `pipeline` | `recipes` | `spec-format`.
31
+ Call it with `{"topic":"pipeline"}` before the first build on a
31
32
  project, and `{"topic":"gui-gates"}` when a tool returns `requires_human_action` or a compile
32
33
  error mentions a GUI-only setting.
33
34
  3. **Teaching errors on gate signals** — gate responses (`requires_human_action`, the
34
35
  `guiGateHints` on compile results, etc.) carry the relevant next steps inline, so the guide
35
36
  reinforces itself at the moment a gate is actually hit, not only up front.
36
37
 
37
- `tia_guide` is **pure and offline**: it never calls the `serve` API and never returns `isError` —
38
- unlike every other tool in this package, it works **even with the `serve` down**. The chapters are
38
+ `tia_guide` is **pure and offline**: it never calls the `serve` API and never returns `isError`, so it works
39
+ **even with the `serve` down** (so do `tia_spec_validate`, `tia_spec_plan` and `tia_job_status`). The chapters are
39
40
  generated from `mcp/content/*.md` (the canonical source) into `src/content.gen.ts` via
40
41
  `npm run sync` — see [scripts/sync-guide.mjs](scripts/sync-guide.mjs).
41
42
 
42
43
  ## Tools
43
44
 
45
+ **Names:** MCP tools use underscores (`tia_ping`, `tia_readiness`, `tia_compile`). Harness skills use
46
+ hyphens (`tia-init`, `tia-review`); the old dotted skill names were retired.
47
+ Tools and skills are separate interfaces; `tia.ping` is not a tool name.
48
+
44
49
  ### Diagnostics + M1 read-only (class R, auto-approvable)
45
50
  | Tool | Endpoint | Description |
46
51
  |---|---|---|
47
52
  | `tia_ping` | `GET /health` + `GET /readiness` | Diagnoses connectivity and ACTIVATION of the `serve`. `{ base, reachable, activated, latencyMs, hint }`. Ideal for Mac→VM. |
48
53
  | `tia_readiness` | `GET /readiness` | Environment readiness **on the serve host** (x64, Windows group, PublicAPI, registry, instances). |
49
- | `tia_guide` | — (bundled content, no HTTP call) | Returns the operating guide (see "Operating guide embedded" above). Topics: `toc` (default) \| `full` \| `brief` \| `gates-guards` \| `gui-gates` \| `gotchas` \| `pipeline` \| `recipes` \| `spec-format`. Pure/offline — works with the `serve` down. |
50
- | `tia_job_status` | — (does not call `serve`) | Waits (up to `waitSeconds`, default 20, max 25) for a long tool's background job and returns its FINAL result (see "Long operations run as jobs" below). |
54
+ | `tia_guide` | — (bundled content, no HTTP call) | Returns the operating guide (see "Operating guide embedded" above). Topics: `toc` (default) \| `full` \| `codex` (sized for Codex, no recipes) \| `brief` \| `gates-guards` \| `gui-gates` \| `gotchas` \| `pipeline` \| `recipes` \| `spec-format`. Pure/offline — works with the `serve` down. |
55
+ | `tia_job_status` | — (does not call `serve`) | Waits (up to `waitSeconds`, default 20, max 25) for a long tool's background job: returns its final result if the job ends within the wait, otherwise `status:"running"` again; an unknown or forgotten `jobId` answers `not_found` (see "Long operations run as jobs" below). |
51
56
 
52
57
  **M1 (read-only, 1:1 with the API's GET endpoints):** `tia_instances`, `tia_status`, `tia_projects`, `tia_project_info`,
53
58
  `tia_project_languages`, `tia_plcs`, `tia_devices`, `tia_device_tree`, `tia_device_connections`,
@@ -66,8 +71,10 @@ interfaces the CPU sees, plus each adapter's OS status — **no network scan**,
66
71
  | `tia_project_create` | `POST /project/create` | Creates a project (Gd4: empty directory → otherwise 409). |
67
72
  | `tia_project_save` / `tia_project_saveas` / `tia_project_close` / `tia_project_archive` | `POST /project/*` | Project lifecycle. `tia_project_close` KEEPS the TIA process alive (`portalKept`/`pid`) — the next `tia_connect` reuses it; nothing is saved. |
68
73
 
69
- **Trust GATE (G1):** on the 1st connection per `serve` process, TIA requires manual confirmation of a security
70
- dialog ON THE HOST. The proactive flow is **`tia_start` → `tia_show_ui` → (human confirms) → `tia_connect`**.
74
+ **Trust GATE (G1):** setup pre-registers eligible installed executables (Program Files, admin-only ACLs) in the
75
+ Openness allow-list. If the executable is not covered by a current entry, connecting can require a human to
76
+ confirm the security dialog ON THE HOST. When the dialog is needed, the proactive flow is
77
+ **`tia_start` → `tia_show_ui` → (human confirms) → `tia_connect`**.
71
78
  If `tia_connect` hits the dialog, it does NOT retry-storm: it returns `{ status:"requires_human_action",
72
79
  gate:"trust_dialog", youMustDo, resumeToken }` after ~180 s without an answer (`TIA_CONNECT_TIMEOUT_MS`) with
73
80
  `/health` still reachable. Check `tia_status` first — `hasProject:true` means the connect actually succeeded
@@ -76,18 +83,23 @@ gate:"trust_dialog", youMustDo, resumeToken }` after ~180 s without an answer (`
76
83
  until the job ends) — keep polling `tia_job_status`. After the human confirms, call `tia_connect` again with
77
84
  the `resumeToken`.
78
85
 
79
- ### M3 — offline creation/authoring (class M-off) + guards
80
- A **compliant-by-construction** creation surface (~28 tools), all with `dryRun` (Gd11) and schema validation (Gd13):
81
- - **Hardware/network:** `tia_device_create`/`plug`/`unplug`, `tia_device_group_create`, `tia_subnet_create`, `tia_network_connect`/`address`/`disconnect`.
86
+ ### M3 — creation/authoring (class M-off) + guards
87
+ A **compliant-by-construction** creation surface (32 tools) with schema validation (Gd13); every tool except
88
+ `tia_export_block`, `tia_block_compare` and `tia_obj_service` takes `dryRun` (Gd11):
89
+ - **Hardware/network:** `tia_device_create`/`plug`/`unplug`, `tia_device_change_version` (changes the CPU firmware version in place, keeping the program), `tia_device_group_create`, `tia_subnet_create`, `tia_network_connect`/`address`/`disconnect`.
82
90
  - **Tags/constants:** `tia_tagtable_create`, `tia_tag_create`/`delete`, `tia_constant_create`.
83
91
  - **Blocks/types:** `tia_fb_create`, `tia_instancedb_create`, `tia_block_delete`/`set_attribute`, `tia_block_group_create`, `tia_type_group_create`/`type_delete`.
84
92
  - **Code:** `tia_source_put` (textual SCL — Gd6), `tia_import_xml`/`tia_types_import` (graphical SimaticML — Gd6/Gd7), `tia_export_xml`.
85
93
  - **Project-as-code proof (#26/#28):** `tia_export_block` (exports ONE block inline as SimaticML — `sha256`/`normalizedSha256`/`bytes`, no file on the serve host) and `tia_block_compare` (compares a block against the SimaticML you pass, e.g. the file in git — normalized, ignores BOM/formatting/`<Created>`/UIds — `verdict:"equal"|"different"` is the actual roundtrip proof; a raw hash is not). Both read-mostly: exporting an inconsistent block first compiles it (export requires consistency), which can regenerate its instance DB.
86
94
  - **Watch tables:** `tia_watchtable_create`/`delete`.
87
- - **Generic write layer:** `tia_obj_set_attributes`/`invoke`/`create`.
88
-
89
- **Guards (client-side, before touching Openness):** **Gd5** — `typeIdentifier` must use `/V<fw>` (slash), never `:V`
90
- (rejected with `kind:"guard_violation"`; resolve the value via `tia_catalog`). **Gd11** — `dryRun:true` validates the guards
95
+ - **Generic object layer:** `tia_obj_service`/`set_attributes`/`invoke`/`create`. Declared M-off, but not offline-only:
96
+ the serve's `/obj` risk policy lets these reach online, credential and other deploy-gated members of the object
97
+ model only with the `deploy` license scope, and refuses a download through them for every license — use
98
+ `tia_download`.
99
+
100
+ **Guards (client-side, before touching Openness):** **Gd5** — a versioned `typeIdentifier` uses `/V<fw>` (slash),
101
+ never `:V`: a `:V<digit>` is rejected with `kind:"guard_violation"`; the guard does not check that the identifier
102
+ exists (resolve the value via `tia_catalog`). **Gd11** — `dryRun:true` validates the guards
91
103
  and returns the **plan by name WITHOUT mutating** (`status:"plan_ok"`). **Gd6** (advisory) — textual language (SCL) via
92
104
  `tia_source_put`, graphical (LAD/FBD/GRAPH) via `tia_import_xml`; UDTs before blocks. **Gd2** (advisory) — idempotency
93
105
  by name (check existence with the M1 read-only tools before creating; Openness has no rollback).
@@ -120,22 +132,26 @@ is a path **on the serve host**.
120
132
  | `tia_connection_create` | `POST /connections` | M-off — S7 connection (G2: requires ≥2 consistent CPUs; failure attaches diagnostics). |
121
133
  | `tia_download` | `POST /plcs/{plc}/download/plan` + `POST /plcs/{plc}/download` | **GATE G3** — never downloads without human approval bound to the `planHash`. |
122
134
  | `tia_upload` | `POST /stations/upload/plan` · `POST /stations/upload` | **GATE G4** (+G6 read password) — single-use planHash bound to the open project; runs as a job. |
123
- | `tia_online` / `tia_offline` / `tia_online_state` | `POST /plcs/{plc}/online`·`/offline`·`GET …/state` | **G4** (online) / R (state). |
135
+ | `tia_online` / `tia_offline` / `tia_online_state` | `POST /plcs/{plc}/online`·`/offline`·`GET …/state` | **GATE G4** (online, needs `confirm:true`) / **GATE** (offline, no `confirm`) / R (state). |
124
136
  | `tia_accessible_devices` | `POST /plcs/{plc}/online/accessibledevices` | **GATE G7** (net scan). |
125
137
  | `tia_mastersecret_set` / `tia_mastersecret_reset` | `…/online/mastersecret` | **GATE G6** (the secret comes from a human, never from the AI). |
126
138
 
127
139
  **Download GATE (G3, ADR 0008):** `tia_download` NEVER downloads without approval, and the approval is bound to
128
140
  the approved connection/options and the covered software content — **not the hardware configuration**. Flow: `tia_compile` (Gd9 precondition: `errors=0`)
129
141
  → `tia_download dryRun:true`, which asks **serve** for a VERIFIED plan (`POST /plcs/{plc}/download/plan`: fresh compile,
130
- resolved connection, and a **software fingerprint** — content hash of program blocks/UDTs/tag tables; NOT hardware,
131
- system block groups or technology objects — so a hardware change after approval passes the token check undetected:
132
- any hardware change needs fresh human review, not the old approval) → only a `ready` plan returns a single-use `planHash` that expires
142
+ resolved connection, and a **software fingerprint** of program blocks, UDTs and tag tables — blocks and UDTs use Openness
143
+ fingerprints and fall back to modification dates (see `fingerprintItems[].source`), tag tables hash their content; NOT
144
+ hardware, system block groups or technology objects. The approval also binds the open project and the target-address
145
+ set (a change to either is `409 plan_stale`), but any other hardware change after approval passes the token check
146
+ undetected: it needs fresh human review, not the old approval) → only a `ready` plan returns a single-use `planHash` that expires
133
147
  (`TIA_PLAN_TTL_MS`, default 15 min, MCP-process-only) → a human approves the plan **and its fingerprint** → `tia_download
134
148
  approved:true` with the **same `planHash`**. `serve` re-checks the fingerprint **inside** the download call (no window
135
149
  between check and load) and refuses **`409 plan_stale`** if the software changed since the plan. `allowUpgradeTargetDevice:
136
150
  true` (#31) is part of the approved plan — without it, a CPU that requires TIA's "upgrade the target device" confirmation
137
- refuses the load with **`409 upgrade_target_device_required`** (Openness aborts; check the CPU state before retrying —
138
- earlier confirmations in the same pass, like `StopAll`, cannot be undone). A successful dry-run is NOT a handoff —
151
+ refuses the load with **`409 upgrade_target_device_required`**. That does not prove nothing was loaded:
152
+ `details.refusedPhase` and `details.configurations` show how far the pass got (the CPU may already have stopped,
153
+ received the load or restarted), so a human checks the CPU state before a new plan — earlier confirmations in the same
154
+ pass, like `StopAll`, cannot be undone. A successful dry-run is NOT a handoff —
139
155
  it returns `status:"plan_ok"` with the `planHash`. Calling the real download without `approved:true` (or with a
140
156
  wrong/expired/consumed hash or a parameter mismatch) returns a `requires_human_action / download_approval` envelope
141
157
  with a `reasonCode` (`not_approved` \| `unknown` \| `expired` \| `consumed` \| `plan_mismatch` \| `outcome_unknown`).
@@ -145,13 +161,12 @@ The auto-confirmed selections (StopAll/Overwrite/Start/…) remain visible in th
145
161
  (transparency record, P0.5) — pick the connection with `tia_pg_interfaces` (no scan).
146
162
 
147
163
  ### M5 — project-spec ingestion (orchestrates M1–M4)
148
- Accepts the structured **project-spec** (`docs/TIA-BEST-PRACTICES.md` §13.2; JSON Schema at `.claude-plugin/schemas/project-spec.schema.json`):
164
+ Accepts the structured **project-spec** (`docs/TIA-BEST-PRACTICES.md` §13.2; JSON Schema at `schemas/project-spec.schema.json` in the repository):
149
165
  - **`tia_spec_validate`** (R, deterministic, **no serve needed**): validates shape + cross-field rules — R-NAMES (unique names), R-TYPEID (`OrderNumber:<MLFB>/V<fw>`), R-SUBNET (IP∈CIDR, CPU+IO on the same subnet, 1 IO-system), R-LANGFAM (STL/GRAPH only on S7-1500), R-MODLIMIT, and **G5** (`safety.required && autonomous ⇒ REJECT`).
150
- - **`tia_spec_plan`** (no serve needed): turns a valid spec into the ordered operation sequence (subnets→devices→modules→network→tags→blocks→compile).
151
- - **`tia_spec_apply`**: orchestrates the OFFLINE build on an open project (validate → G5 → execute serially → compile), **stops at the 1st error** and **never downloads** (download is GATE G3, always human). `dryRun:true` returns the plan.
166
+ - **`tia_spec_plan`** (no serve needed): turns a valid spec into the ordered operation sequence (subnets→devices→modules→network→tags→blocks→compile; the compile step is dropped when an explicit `verification.ladder` leaves `"compile"` out).
167
+ - **`tia_spec_apply`**: orchestrates the OFFLINE build on an open project (validate → G5 → execute serially → compile, as planned), **stops at the 1st failed step** unless `continueOnError:true` (then it applies the rest and reports `applied_with_errors`), and **never downloads** (download is GATE G3, always human). `dryRun:true` returns the plan.
152
168
 
153
- > **MCP M0–M5 COMPLETE** (105 tools in this branch — the published npm `@renanlido/tia-openness-mcp` 1.7.0 still
154
- > ships 81 until the next release), **runtime-validated** against a real TIA Portal V21 (including a
169
+ > **MCP M0–M5 COMPLETE** (105 tools), **runtime-validated** against a real TIA Portal V21 (including a
155
170
  > **hardware deploy** to an S7-1200) and **published to npm**. Roadmap and milestones in `docs/ROADMAP.md` §3.
156
171
 
157
172
  ### Long operations run as jobs (ADR 0009)
@@ -176,8 +191,9 @@ soft-deadline job runner instead of blocking the call: `tia_connect`, `tia_start
176
191
  `tia_guide`, `tia_spec_validate`, `tia_spec_plan` and `tia_job_status` itself never answer busy (they
177
192
  don't call `serve`). `tia_ping` is the diagnostic exception: it probes `/health` (which bypasses the
178
193
  busy guard) and returns a reachability report instead of `busy` — with no `details.jobId`, so it cannot
179
- be used to obtain the job ID. The same long tool called again with the SAME key (e.g. `tia_connect` for the
180
- same project) returns the same `jobId` instead of starting a second run.
194
+ be used to obtain the job ID. The same long tool called again with the same arguments (the key is the tool plus
195
+ all its arguments) returns the same `jobId` instead of starting a second run; a `tia_connect` that differs in any
196
+ argument (UI, UMAC, `resumeToken`) answers `busy` while the first one runs.
181
197
  - If a `tia_connect`/`tia_start`/`tia_show_ui` job stays `running` for minutes, a **trust dialog (G1)**
182
198
  may be waiting on the serve host — ask a human to look.
183
199
 
@@ -187,13 +203,13 @@ soft-deadline job runner instead of blocking the call: `tia_connect`, `tia_start
187
203
  |---|---|---|
188
204
  | `TIA_API_BASE` | `http://localhost:5000` | Base URL of the `serve` API. |
189
205
  | `TIA_API_TIMEOUT_MS` | `15000` | Per-request timeout (fail fast if the host/VM does not respond). |
190
- | `TIA_SLOW_TIMEOUT_MS` | `120000` | Timeout for slow/cold ops (project create, catalog, download plan and other slow M1–M3 calls). `tia_compile` does NOT use this variable — it has a separate fixed 120 s timeout. |
206
+ | `TIA_SLOW_TIMEOUT_MS` | `120000` | Timeout for slow/cold ops (catalog, download plan and other slow M1–M3 calls). `tia_project_create` uses `TIA_CONNECT_TIMEOUT_MS`; `tia_compile` does NOT use this variable — it has a separate fixed 120 s timeout. |
191
207
  | `TIA_CONNECT_TIMEOUT_MS` | `180000` | Timeout for the calls that start a new TIA (`tia_connect`, `tia_project_create`, `tia_start`, `tia_show_ui`) before a wait is treated as a possible G1 trust-dialog gate. |
192
- | `TIA_SOFT_DEADLINE_MS` | `20000` | Soft deadline for the 14 long tools before they answer `status:"running"` (capped at `25000`). |
208
+ | `TIA_SOFT_DEADLINE_MS` | `20000` | Soft deadline for the 24 long tools before they answer `status:"running"` (capped at `25000`). |
193
209
  | `TIA_PLAN_TTL_MS` | `900000` | Validity of a G3 download `planHash` (15 min); the token lives only in this MCP process. |
194
210
 
195
- > **The MCP sends no key.** The API is **activated by a license** configured in the GUI ("License" tab) — what
196
- > authorizes the server is the host's license, not the client. The MCP is a plain HTTP client: it only points at the base URL.
211
+ > **The MCP sends no host activation key.** The API is **activated by a license** configured in the GUI ("License"
212
+ > tab). Human-provided operation credentials travel in tool calls, not in the MCP launch configuration.
197
213
 
198
214
  ## Mac → Windows VM scenario (pointing at the server)
199
215
 
@@ -218,7 +234,8 @@ soft-deadline job runner instead of blocking the call: `tia_connect`, `tia_start
218
234
  export TIA_API_BASE="http://<vm-ip>:5000"
219
235
  ```
220
236
  3. **Diagnose** with the `tia_ping` tool: `reachable:false` → IP/port/firewall/VM; `activated:false` →
221
- license missing/invalid on the VM; both `true` → ready.
237
+ license missing/invalid on the VM. Both `true` mean reachable and activated, not environment readiness:
238
+ call `tia_readiness` and inspect `ready` and `checks` before proceeding.
222
239
 
223
240
  ## Build / bundle
224
241
 
@@ -229,6 +246,19 @@ npm install
229
246
  npm run build # typecheck + esbuild -> dist/index.js (self-contained)
230
247
  ```
231
248
 
249
+ ### Claude Desktop bundle (`.mcpb`)
250
+
251
+ The same self-contained bundle is staged for Claude Desktop (double-click install, API URL asked in a form):
252
+
253
+ ```bash
254
+ npm run mcpb:stage -- ../.mcpb-stage # build + manifest (version from package.json, tools from the code) + server/index.mjs
255
+ npm run mcpb:verify -- ../.mcpb-stage # starts the staged server over stdio and compares its tools with the manifest
256
+ ```
257
+
258
+ Packing (`mcpb validate` / `mcpb pack`) and attaching the file to the release is done by
259
+ `.github/workflows/release-mcpb.yml`. Not yet verified inside Claude Desktop; see the Claude Desktop section of
260
+ `docs/INSTALL.md` and ADR 0022.
261
+
232
262
  ## Installation
233
263
 
234
264
  ### A) From public npm (normal use, Mac/Windows/Linux)
@@ -245,21 +275,28 @@ npm install -g @renanlido/tia-openness-mcp
245
275
 
246
276
  ```bash
247
277
  cd mcp
248
- npm install -g . # prepack builds and installs the binary
278
+ npm install
279
+ npm run build # creates dist/index.js
280
+ npm install -g . # installs the already-built binary
249
281
  # or: npm pack && npm install -g ./renanlido-tia-openness-mcp-*.tgz
250
282
  ```
251
283
 
252
284
  ## Publishing (public npm + semantic-release)
253
285
 
254
- **Automatic versioning by conventional commits** (`feat` → minor, `fix` → patch, `BREAKING CHANGE`
255
- → major). The `.github/workflows/release-mcp.yml` workflow fires on pushes to `main` **when something under
256
- `mcp/` changes** (and `semantic-release-monorepo` filters the commits by that path), builds and publishes to
257
- **public npm** (`registry.npmjs.org`, `publishConfig.access: public`).
258
-
259
- **Authentication is npm trusted publishing (OIDC)** — there is no `NPM_TOKEN`. The package has a trusted
260
- publisher on npmjs.com pointing at `renanlido/TIAOpenness` + `release-mcp.yml`; the workflow needs
261
- `id-token: write`, and the publish gets provenance automatically. The native Actions `GITHUB_TOKEN` pushes the
262
- release **tag** and creates the **GitHub release**.
286
+ **Automatic versioning by conventional commits** (`feat` → minor, `fix`/`perf` → patch, `BREAKING CHANGE`
287
+ → major; `docs(README)` also produces a patch so documentation corrections reach npm).
288
+ The `.github/workflows/release-mcp.yml` workflow runs on pushes to `main` affecting `mcp/**` or the workflow
289
+ file itself, and on manual dispatch. `semantic-release-monorepo` filters commits by the package path;
290
+ publication happens only when those commits warrant a release. The package is **public**
291
+ (`registry.npmjs.org`, `publishConfig.access: public`); a green workflow alone does not prove a new version exists.
292
+
293
+ **Authentication is npm trusted publishing (OIDC)** — there is no `NPM_TOKEN`. The package stays
294
+ `@renanlido/tia-openness-mcp` after the private source repository moved; its trusted publisher on npmjs.com must
295
+ point at `Nextech-Digital-Solutions/TIAOpenness` + `release-mcp.yml` (GitHub Actions, direct `npm publish`
296
+ allowed). The workflow needs `id-token: write`; the native Actions `GITHUB_TOKEN` pushes the release **tag** and
297
+ creates the **GitHub release**. A new publisher connection expires unless it publishes within two days, so add it
298
+ right before a release and keep the old one until the new one works. OIDC does not imply provenance: npm generates
299
+ no provenance from a private source repository ([npm docs](https://docs.npmjs.com/trusted-publishers/)).
263
300
 
264
301
  **Nothing is committed back to `main`.** `main` is protected by a ruleset that requires the CI checks on every
265
302
  push, so a release commit is rejected (GH013). The released version lives in the tag
@@ -268,6 +305,18 @@ push, so a release commit is rejected (GH013). The released version lives in the
268
305
  handshake reports that version. The checked-in `version` is a dev fallback — don't hand-edit it, and don't expect it
269
306
  to match npm. [`CHANGELOG.md`](CHANGELOG.md) is frozen at 1.7.0; later notes are on the GitHub releases.
270
307
 
308
+ ## Connecting an AI agent
309
+
310
+ **Several agents at once: the guided setup (once published).** `@renanlido/plcware-setup` connects this server to Claude Code,
311
+ Claude Desktop, Codex, Gemini CLI, Cursor and VS Code in one run (`npx @renanlido/plcware-setup`: it asks the API address,
312
+ previews every change and confirms once), and where the agent takes them also installs the harness skills and subagents.
313
+ Setup adds preapproval allowances for the read-only tools (class R: 39 of the 105 `tia_*` tools, listed in
314
+ `src/tool-classes.json`) where the chosen registration route supports them. Existing user permissions are
315
+ preserved: deny/ask rules can still prompt for reads, and existing allow rules can already permit mutations.
316
+ Linked Claude settings files are not modified; Codex's command-registration route installs no preapprovals.
317
+ Setup records every change, so its `uninstall` removes only what it added. **It is not published yet**, so that
318
+ command does not work today: use the per-agent commands below.
319
+
271
320
  ## Registering in Claude Code
272
321
 
273
322
  **Nothing to install** — the recommended way is `npx`, which downloads and runs the published package. One
@@ -300,16 +349,17 @@ Check with `claude mcp list` and `claude mcp get tia`. The **`.mcp.json`** equiv
300
349
  > `"command": "tia-openness-mcp", "args": []` make sense. `npx` skips that step — which is why it is the recommended way.
301
350
 
302
351
  **Other clients** (Claude Desktop, Codex, Gemini CLI, Cursor, VS Code, Windsurf): the canonical install
303
- guide — with each client's exact format and the Windows `cmd /c npx` gotcha — is in
304
- `docs/INSTALL.md` in the repository.
352
+ guide — with the guided setup, each client's exact format and the Windows launch form (plain `npx` first; `cmd /c npx`
353
+ only if the client says the server failed to start) — is in `docs/INSTALL.md` in the repository.
305
354
 
306
355
  **Optional envs** (defaults are built into the MCP — only set them to override): `TIA_API_TIMEOUT_MS` (15000),
307
356
  `TIA_SLOW_TIMEOUT_MS` (120000), `TIA_CONNECT_TIMEOUT_MS` (180000). E.g. `--env TIA_SLOW_TIMEOUT_MS=180000`
308
357
  on `claude mcp add`, or the corresponding key in the `.mcp.json` `env`.
309
358
 
310
- Since it is a **project-scoped** server, Claude Code asks for **approval** the 1st time: `claude mcp list`
311
- (should list `tia`), run `claude` in the project and **approve**, **reload** the session, and ask it to call
312
- `tia_ping` / `tia_readiness`.
359
+ The `--scope user` command makes the server available across your projects. Only the `.mcp.json` alternative
360
+ is **project-scoped** and needs the corresponding project-server approval. Check `claude mcp list` (it should
361
+ list `tia`), approve the project server if prompted, then start or reload the session and call `tia_ping` /
362
+ `tia_readiness`.
313
363
 
314
364
  ## Smoke test
315
365
 
@@ -321,11 +371,12 @@ MCP_COMMAND=tia-openness-mcp MCP_ARGS='[]' npm run smoke # (Windows: use
321
371
 
322
372
  ## Notes
323
373
 
324
- - **The MCP sends no key/secret.** The API is activated by a license on the host (GUI). Secrets (master secret /
325
- UMAC / cert password) never go in `.mcp.json`.
374
+ - **No host activation key is sent by the MCP.** Activation is configured on the host (GUI). Human-provided UMAC
375
+ credentials, CPU master secrets and block/certificate passwords can be sent in tool request bodies; never store
376
+ them in `.mcp.json`.
326
377
  - **Serial-only**: the backend is a serial worker; the MCP must never parallelize tool calls (Gd1).
327
378
  - **stdout belongs to the MCP protocol** — logs go to **stderr**.
328
379
  - The bundle is produced by [scripts/build.mjs](scripts/build.mjs) (esbuild, ESM, shebang + `createRequire`,
329
380
  injected version). `dist/`, `node_modules/`, `*.tgz` are artifacts (gitignored).
330
381
  - When adding/changing tools, **rebuild + reinstall** the binary (`npm run build && npm i -g .`) so the local
331
- install reflects it; in production, pushing to `main` republishes.
382
+ install reflects it. Production publication requires a release-worthy package commit on `main` (see "Publishing").
package/dist/index.js CHANGED
@@ -31587,7 +31587,19 @@ var JobRunner = class {
31587
31587
  var jobs = new JobRunner();
31588
31588
 
31589
31589
  // src/client.ts
31590
- var BASE = (process.env.TIA_API_BASE ?? "http://localhost:5000").replace(/\/+$/, "");
31590
+ function resolveApiBase(raw) {
31591
+ const v = (raw ?? "").trim();
31592
+ return (v === "" ? "http://localhost:5000" : v).replace(/\/+$/, "");
31593
+ }
31594
+ var BASE = resolveApiBase(process.env.TIA_API_BASE);
31595
+ function apiBaseProblem(base) {
31596
+ try {
31597
+ const u = new URL(base);
31598
+ if ((u.protocol === "http:" || u.protocol === "https:") && u.hostname !== "") return null;
31599
+ } catch {
31600
+ }
31601
+ return `TIA_API_BASE is not a URL the MCP can call: "${base}". It needs http:// and the host, e.g. http://localhost:5000 or http://192.168.1.10:5000.`;
31602
+ }
31591
31603
  var TIMEOUT_MS = parsePositiveInt(process.env.TIA_API_TIMEOUT_MS, 15e3);
31592
31604
  var CONNECT_TIMEOUT_MS = parsePositiveInt(process.env.TIA_CONNECT_TIMEOUT_MS, 18e4);
31593
31605
  var SLOW_TIMEOUT_MS = parsePositiveInt(process.env.TIA_SLOW_TIMEOUT_MS, 12e4);
@@ -31620,6 +31632,8 @@ async function tiaFetch(path, init = {}, opts = {}) {
31620
31632
  );
31621
31633
  }
31622
31634
  }
31635
+ const baseProblem = apiBaseProblem(BASE);
31636
+ if (baseProblem) throw new TiaApiError(baseProblem, { kind: "invalid_api_base" });
31623
31637
  const url2 = `${BASE}${path}`;
31624
31638
  const timeout = opts.timeoutMs ?? TIMEOUT_MS;
31625
31639
  const headers = {
@@ -31669,6 +31683,8 @@ function hintFor(err) {
31669
31683
  return "The operation may STILL be running on serve (serial worker). Increase TIA_SLOW_TIMEOUT_MS; only investigate connectivity (IP/port/firewall/VM) if GET /health also fails.";
31670
31684
  case "connection_refused":
31671
31685
  return "Start the API on the serve host: `TIAOpenness.exe serve 5000 --host 0.0.0.0` and check TIA_API_BASE.";
31686
+ case "invalid_api_base":
31687
+ return "Set the PLCWare API URL (TIA_API_BASE, asked when the plugin, extension or bundle was installed) to http://<host>:<port>, then restart the agent so the MCP reads it again.";
31672
31688
  case "license_required":
31673
31689
  return "Server not activated: configure the API key in the TIAOpenness GUI ('License' tab).";
31674
31690
  case "scope_required":
@@ -33980,7 +33996,7 @@ async function planUpload(args, plan, store) {
33980
33996
  );
33981
33997
  }
33982
33998
  const issued = store.issue(plan, projectPath);
33983
- const warning = devices.length > 0 ? `The open project already has ${devices.length} device(s); a backup belongs in a dedicated EMPTY project (tia.backup).` : void 0;
33999
+ const warning = devices.length > 0 ? `The open project already has ${devices.length} device(s); a backup belongs in a dedicated EMPTY project (tia-backup).` : void 0;
33984
34000
  const youMustDo = `GATE G4: upload (read) the hardware configuration and program of the PHYSICAL CPU at ${String(plan.ip)} into the OPEN project "${projectName}" (${projectPath}), which currently holds ${devices.length} device(s) \u2014 it reads the CPU and does not write it. Confirm with a human that it is safe to connect to this machine AND that this is a dedicated backup project, never the working project. After an explicit yes, re-call tia_upload with confirm:true and this planHash.`;
33985
34001
  return gateHandoff("station_upload", {
33986
34002
  plan,
@@ -34110,7 +34126,7 @@ function registerUploadTools(server2) {
34110
34126
  "tia_upload",
34111
34127
  {
34112
34128
  title: "TIA \u2014 station upload (GATE G4)",
34113
- description: "Station upload (GATE G4): goes ONLINE to the PHYSICAL CPU at `ip` and reads its hardware configuration and program into the OPEN project as a new station \u2014 it reads the CPU and does not write or stop it (observed on hardware: the CPU stayed in RUN). Back up into a dedicated EMPTY project, never the working project (skill tia.backup). Without confirm it asks serve for an upload plan (PG/PC interface resolved, the open project's path and devices \u2014 no network access) and returns a single-use planHash bound to that project; after a human confirms, call again with confirm:true and that planHash. A read-protected CPU needs its read-access password from a HUMAN (G6 \u2014 never invented). Needs the deploy license scope (Basic \u2192 403 scope_required) and app \u2265 v1.6.0. Maps to POST /stations/upload/plan and POST /stations/upload. " + LONG_OPERATION_NOTE,
34129
+ description: "Station upload (GATE G4): goes ONLINE to the PHYSICAL CPU at `ip` and reads its hardware configuration and program into the OPEN project as a new station \u2014 it reads the CPU and does not write or stop it (observed on hardware: the CPU stayed in RUN). Back up into a dedicated EMPTY project, never the working project (skill tia-backup). Without confirm it asks serve for an upload plan (PG/PC interface resolved, the open project's path and devices \u2014 no network access) and returns a single-use planHash bound to that project; after a human confirms, call again with confirm:true and that planHash. A read-protected CPU needs its read-access password from a HUMAN (G6 \u2014 never invented). Needs the deploy license scope (Basic \u2192 403 scope_required) and app \u2265 v1.6.0. Maps to POST /stations/upload/plan and POST /stations/upload. " + LONG_OPERATION_NOTE,
34114
34130
  inputSchema: {
34115
34131
  ip: external_exports.string().describe("IPv4 of the PHYSICAL CPU"),
34116
34132
  connectionMode: external_exports.string().optional().describe(`connection mode (e.g., "PN/IE") \u2014 TIA's LOCALIZED name`),
@@ -34536,14 +34552,15 @@ function registerSpecTools(server2) {
34536
34552
  }
34537
34553
 
34538
34554
  // src/content.gen.ts
34539
- var BRIEF = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n4. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n5. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n6. **Prerequisites:** the serve must be running (default `http://localhost:5000` \u2014\n check with `tia_ping`); the FIRST connect per serve process hits the G1 trust dialog\n on the serve host.\n7. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. Offline tools (`tia_guide`,\n `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n `tia_ping` is the diagnostic exception: it probes `/health`, which bypasses the busy guard,\n and returns a reachability report (`reachable:true`, `activated:null` while a job runs) with\n no top-level `kind` and no `details.jobId` \u2014 use it to check reachability, never to obtain the job ID.\n\nSession start: `tia_ping` \u2192 `tia_status` \u2192 (if needed) `tia_start` / `tia_connect`.\nBefore the first build on a project: read `tia_guide {"topic":"pipeline"}` and\n`tia_guide {"topic":"gotchas"}`.\n';
34540
- var GATES_GUARDS = '# Gates vs guards\n\n## GATES vs GUARDS\n\n- **GATES (human-only \u2014 never auto-bypass):** trust dialog (**G1**), download / CPU-STOP\n (**G3**), go-online (**G4**, which includes a **station upload** (`tia_upload`): it goes\n online to read the CPU), network scan / accessible-devices (**G7**), master-secret/UMAC\n (**G6**, which includes a CPU **read-access password** for an upload, a block **know-how\n password** (`tia_block_protect`), a certificate file\'s password (`tia_certificate_import`)\n and the **password-policy** values (`tia_password_policy_set`)), **safety / F-logic\n (G5) \u2014 never autonomous**.\n- **GUARDS (tool-enforced preconditions):** compile-clean before deploy, consistency,\n dry-run\u2192approve, idempotency by name, `OrderNumber:<MLFB>/V<fw>` format, serial-only.\n- Back up a physical CPU with the **`tia.backup`** skill (dedicated empty project; the upload\n token is bound to the project shown in the handoff).\n- **Picking the G3 download path (no gate, no scan):** `tia_pg_interfaces` lists the connection\n modes/PG-PC interfaces TIA already sees for the CPU (plus the OS status of each adapter) \u2014\n use it to fill `connectionMode`/`pcInterfaceName`/`targetInterfaceName` for `tia_download`\n instead of reaching for `tia_accessible_devices` (a real network scan, GATE G7).\n- **GUI-ONLY settings (NOT exposed via Openness \u2014 surface as a human gate, do not script):**\n "Permit access with PUT/GET communication", OPC UA **runtime license** / server-interface\n creation. (OPC UA server **activation** is the exception \u2014 settable via Openness with\n `tia_obj_set_attributes {OpcUaServer:true}` on the "OPC UA" device-item.)\n\n**Deploy-time approval gates** (download / online / network-scan / secret / safety = **G3/G4/G7/G6/G5**)\nare a *different* class \u2014 see the **`tia.handoff`** skill. Those are "a human **approves an action**",\nnot "a human **clicks a GUI setting**". Both are human interaction points; surface them as\n`requires_human_action` with concrete guidance, never as a tool failure.\n';
34541
- var GUI_GATES = '# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect` \u2192 `requires_human_action` (`trust_dialog`), or the **1st** TIA-starting call per `serve` process goes **~180 s** (`TIA_CONNECT_TIMEOUT_MS`) without an answer \u2014 `tia_connect`, `tia_start`, `tia_show_ui` and `tia_project_create` all share that wait, and a client timeout with `/health` alive yields the same `trust_dialog` handoff. A `running` answer from any of them can still mean a trust dialog is waiting on the serve host | TIA shows a one-time security prompt the first time an Openness app attaches, **per process** | On the **serve host**, in TIA Portal, click **"Yes to all"** in the access dialog. *Caveat:* it can false-positive on a client timeout with **no** real dialog \u2014 check `tia_status` (**`hasProject:true`**, not `attached:true`) and\u2026 If the handoff state is `TRUST_DIALOG_DENIED_OR_EXPIRED`, the dialog was denied or left to expire: the serve lists what it closed (`closedPids`), what is still running (`stillRunningPids`) and what it could not confirm (`unknownPids`) \u2014 close any still-running TIA (no project inside) before re-calling, and for an unconfirmed pid first verify in Task Manager that it is a TIA Portal started by this serve with no open project, with a human ready to click **"Yes to all"**. |\n| **OPC UA license** | `tia_compile` **ERROR**: *"The selected OPC UA license is not sufficient\u2026"* | License selection is GUI-only (no Openness service); a fresh project **or a firmware change** leaves it unset | CPU \u2192 **Properties \u2192 General \u2192 Runtime licenses \u2192 OPC UA** \u2192 *Type of required license* \u2192 select **"SIMATIC OPC UA S7-1200 Basic"** (the 1214C option). Recompile. |\n| **OPC UA interface** | OPC UA client connects but the DB nodes aren\'t there (`ns=4` empty / no `ServerInterfaces`) | The **S7-1200 does NOT auto-expose DBs** (unlike the S7-1500) \u2014 a server interface must be created by hand | CPU \u2192 **OPC UA \u2192 Server interfaces \u2192 Add new server interface** \u2192 add/drag the DB (e.g. `ModbusData`) into it. Recompile; data appears under `ns=4`. |\n| **PUT/GET** | S7 client (`nodes7`/`snap7`) connects on port 102 but reads return access-denied (`ROSCTR=2` / "BAD") | *"Permit access with PUT/GET"* is a GUI-only protection setting | CPU \u2192 **Properties \u2192 Protection & Security \u2192 Connection mechanisms** \u2192 check **"Permit access with PUT/GET communication from remote partner"**. Compile + download (`hardware:true`). |\n| **FW-change reset** | After `tia_device_change_version`: OPC UA server off, the license error on compile, blocks `isConsistent:false` | `DeviceItem.ChangeType` **resets GUI-gated comm settings** (server activation + license); the interface & PUT/GET survive | `tia_project_archive` **before** the FW change. After: re-set `OpcUaServer:true` via `tia_obj_set_attributes` (scriptable), re-select the license (row above), recompile. |\n\n**Not a gate (now scriptable):** *activating* the OPC UA server \u2014 `tia_obj_set_attributes {OpcUaServer:true}`\non the "OPC UA" device-item (it auto-generates the server certificate). Only the **license** and the\n**server interface** stay GUI-only.\n';
34555
+ var BRIEF = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n4. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n5. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n6. **Prerequisites:** the serve must be running (default `http://localhost:5000` \u2014\n check with `tia_ping`); the FIRST connect per serve process hits the G1 trust dialog\n on the serve host.\n7. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. `tia_ping` probes `/health`: never busy,\n `activated:null` while a job runs, and no job ID in it \u2014 use it for reachability only. Offline\n tools (`tia_guide`, `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n\nSession start: `tia_ping` \u2192 `tia_status` \u2192 (if needed) `tia_start` / `tia_connect`.\nBefore the first build on a project: read `tia_guide {"topic":"pipeline"}` and\n`tia_guide {"topic":"gotchas"}`.\n\n**Tool names** are written bare (`tia_status`) here and in the skills. Claude Code shows them qualified:\n`mcp__plugin_tia-harness_tia__tia_status` (plugin; what a subagent `tools:` list needs) or\n`mcp__tia__tia_status` (standalone). Other clients may display them differently; the `tia_*` suffix\nis the tool.\n';
34556
+ var GATES_GUARDS = '# Gates vs guards\n\n## GATES vs GUARDS\n\n- **GATES (human-only \u2014 never auto-bypass):** trust dialog (**G1**), download / CPU-STOP\n (**G3**), go-online (**G4**, which includes a **station upload** (`tia_upload`): it goes\n online to read the CPU), network scan / accessible-devices (**G7**), master-secret/UMAC\n (**G6**, which includes a CPU **read-access password** for an upload, a block **know-how\n password** (`tia_block_protect`), a certificate file\'s password (`tia_certificate_import`)\n and the **password-policy** values (`tia_password_policy_set`)), **safety / F-logic\n (G5) \u2014 never autonomous**.\n- **GUARDS (tool-enforced preconditions):** compile-clean before deploy, consistency,\n dry-run\u2192approve, idempotency by name (advisory: re-runs do not converge), `OrderNumber:<MLFB>/V<fw>`\n format, serial-only.\n- Back up a physical CPU with the **`tia-backup`** skill (dedicated empty project; the upload\n token is bound to the project shown in the handoff).\n- **Picking the G3 download path (no gate, no scan):** `tia_pg_interfaces` lists the connection\n modes/PG-PC interfaces TIA already sees for the CPU (plus the OS status of each adapter) \u2014\n use it to fill `connectionMode`/`pcInterfaceName`/`targetInterfaceName` for `tia_download`\n instead of reaching for `tia_accessible_devices` (a real network scan, GATE G7).\n- **GUI-ONLY settings (NOT exposed via Openness \u2014 surface as a human gate, do not script):**\n "Permit access with PUT/GET communication", OPC UA **runtime license** / server-interface\n creation. (OPC UA server **activation** is the exception \u2014 settable via Openness with\n `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item.)\n\n**Deploy-time approval gates** (download / online / network-scan / secret / safety = **G3/G4/G7/G6/G5**)\nare a *different* class \u2014 see the **`tia-handoff`** skill. Those are "a human **approves an action**",\nnot "a human **clicks a GUI setting**". Both are human interaction points; surface them as\n`requires_human_action` with concrete guidance, never as a tool failure.\n';
34557
+ var GUI_GATES = '# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect` \u2192 `requires_human_action` (`trust_dialog`), or the **1st** TIA-starting call per `serve` process goes **~180 s** (`TIA_CONNECT_TIMEOUT_MS`) without an answer \u2014 `tia_connect`, `tia_start`, `tia_show_ui` and `tia_project_create` all share that wait, and a client timeout with `/health` alive yields the same `trust_dialog` handoff. A `running` answer from any of them can still mean a trust dialog is waiting on the serve host | TIA shows a one-time security prompt the first time an Openness app attaches, **per process** | On the **serve host**, in TIA Portal, click **"Yes to all"** in the access dialog. *Caveat:* it can false-positive on a client timeout with **no** real dialog \u2014 check `tia_status` (**`hasProject:true`**, not `attached:true`) and\u2026 If the handoff state is `TRUST_DIALOG_DENIED_OR_EXPIRED`, the dialog was denied or left to expire: the serve lists what it closed (`closedPids`), what is still running (`stillRunningPids`) and what it could not confirm (`unknownPids`) \u2014 close any still-running TIA (no project inside) before re-calling, and for an unconfirmed pid first verify in Task Manager that it is a TIA Portal started by this serve with no open project, with a human ready to click **"Yes to all"**. |\n| **OPC UA license** | `tia_compile` **ERROR**: *"The selected OPC UA license is not sufficient\u2026"* | License selection is GUI-only (no Openness service); a fresh project **or a firmware change** leaves it unset | CPU \u2192 **Properties \u2192 General \u2192 Runtime licenses \u2192 OPC UA** \u2192 *Type of required license* \u2192 select **"SIMATIC OPC UA S7-1200 Basic"** (the 1214C option). Recompile. |\n| **OPC UA interface** | OPC UA client connects but the DB nodes aren\'t there (`ns=4` empty / no `ServerInterfaces`) | The **S7-1200 does NOT auto-expose DBs** (unlike the S7-1500) \u2014 a server interface must be created by hand | CPU \u2192 **OPC UA \u2192 Server interfaces \u2192 Add new server interface** \u2192 add/drag the DB (e.g. `ModbusData`) into it. Recompile; data appears under `ns=4`. |\n| **PUT/GET** | S7 client (`nodes7`/`snap7`) connects on port 102 but reads return access-denied (`ROSCTR=2` / "BAD") | *"Permit access with PUT/GET"* is a GUI-only protection setting | CPU \u2192 **Properties \u2192 Protection & Security \u2192 Connection mechanisms** \u2192 check **"Permit access with PUT/GET communication from remote partner"**. Compile + download (`hardware:true`). |\n| **FW-change reset** | After `tia_device_change_version`: OPC UA server off, the license error on compile, blocks `isConsistent:false` | `DeviceItem.ChangeType` **resets GUI-gated comm settings** (server activation + license); the interface & PUT/GET survive | `tia_project_archive` **before** the FW change. After: re-set `OpcUaServer:true` via `tia_obj_set_attributes` (scriptable), re-select the license (row above), recompile. |\n\n**Not a gate (now scriptable):** *activating* the OPC UA server \u2014 `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`\non the "OPC UA" device-item (it auto-generates the server certificate). Only the **license** and the\n**server interface** stay GUI-only.\n';
34542
34558
  var GOTCHAS = '# Hard-won gotchas (runtime-validated)\n\n## Hard-won gotchas\n\n1. **Always compile before deploy.** `tia_compile` aggregates **hardware + software**; a\n **clean** compile (`errors:0`) is the precondition for download and for S7 connections.\n2. **The serve is a SINGLE serial worker** \u2014 one Openness op at a time. Do **not** fire\n concurrent `tia_*` calls; a hung Openness op can stall the serve (may need a restart).\n3. **Changing an FB\'s interface (e.g. regenerating it via `tia_source_put`) leaves its\n instance DB inconsistent.** Recompile FIRST: a software-scope `tia_compile` regenerates\n the instance DB in most cases \u2014 read the compile result\'s **`blockChanges`** (`tia_compile`\n and `tia_source_put {compile:true}` both return it): a `"change":"modified"` entry on the\n instance DB is your confirmation it was regenerated \u2014 **export and commit it**\n (`tia_export_block`/`tia_block_compare`) so what\'s versioned matches the project. Only if\n the DB still reports inconsistent after a compile, delete it (`tia_block_delete`),\n recreate it (`tia_instancedb_create`) and recompile.\n4. **Firmware rule: project FW \u2264 device FW.** Bump the project FW **in-place** with\n `tia_device_change_version` (`DeviceItem.ChangeType`), which preserves the **program** \u2014 never\n set the project higher than the physical CPU. **\u26A0\uFE0F It RESETS GUI-gated comm settings** (the\n **OPC UA server activation** + **runtime-license**; the server interface and PUT/GET survive):\n **archive first** (`tia_project_archive`) on a CPU with hand-configured OPC UA, recompile after\n (it marks blocks inconsistent), and re-verify. Same-version `ChangeType` is rejected.\n5. **Use a NON-optimized DB** for Modbus (`MB_HOLD_REG`) and S7 (absolute addressing); OPC UA\n works with optimized or not.\n6. **Order numbers use `/V<fw>`, not `:V<fw>`** (guard Gd5).\n7. **A station upload (`tia_upload`) ADDS a new station to the open project \u2014 back up into a\n dedicated EMPTY project.** Observed on hardware (S7-1200 1214C, 2026-09-26): the upload read\n the CPU into an empty project (0 \u2192 1 device, twice) in ~75 s (76.7 s and 74.2 s); the CPU\n stayed in RUN the whole time (owner watching its LEDs during the second upload). Protect the\n working project FIRST: `tia_project_create` CLOSES the current project without saving, so\n `tia_project_save` + `tia_project_archive` before creating the backup project \u2014 and pass the\n archive `name` WITH the `.zap21` extension (`name` absent or extension-less fails; with\n `.zap21` it archived 1.6 MB).\n8. **One wrong know-how password can lock a block for the session.** Observed on the bench\n (2026-10-12): after one rejected unprotect (`tia_block_protect {protect:false}`), TIA refused\n the CORRECT password of that block for the rest of the session (cause not confirmed \u2014 possibly\n brute-force protection). Never retry with a guess \u2014 ask the human for the password (G6); if a\n password the human confirms is refused, stop and hand off instead of retrying.\n\n## Prerequisites (environment)\n\n- The **`tia` serve must be running** (default `http://localhost:5000`, e.g.\n `TIAOpenness.exe serve 5000`). The MCP is a pure HTTP client; point it at the serve host via\n `TIA_API_BASE` if it runs elsewhere.\n- The Windows user must belong to the **"Siemens TIA Openness"** local group.\n- The **FIRST connection per serve process shows a trust dialog** that a **human must confirm**\n ("Yes to all") on the serve host \u2014 this **cannot be automated** (gate G1).\n';
34543
34559
  var PIPELINE = '# The build pipeline (spec \u2192 verified project)\n\nStages in order \u2014 the class tells you what each stage may do:\n\n| # | Stage | Tool(s) | Class | What it does |\n|---|---|---|---|---|\n| 0 | Validate the spec | `tia_spec_validate` | R (pure) | JSON-Schema + cross-field engineering rules (unique names, same-subnet IPs, Gd5 order-number format, per-CPU module limits, language-by-family, the G5 safety rule). Needs no serve. |\n| 1 | Plan | `tia_spec_plan` | R (pure) | Turns a VALID spec into the ordered list of M-off operations. Nothing mutates. |\n| 2 | Scaffold | `tia_spec_apply` (or the M-off tools manually) | M-off | Creates the project content in dependency order (see below). Stops at every gate. |\n| 3 | Verify | `tia_compile` | M-off | THE offline verifier: aggregates hardware + software. Gd8: only ERRORs block. `errors:0` is the Gd9 precondition for any deploy. |\n| 4 | Handoff / deploy | `tia_download` | GATE G3 | `dryRun:true` asks serve for a VERIFIED plan (clean compile, resolved connection, software fingerprint) \u2192 plan + `planHash` \u2192 a HUMAN approves \u2192 re-call with `approved:true` + the SAME `planHash` (serve re-checks the fingerprint and refuses `plan_stale` if the software changed). The approval covers the connection/options and the covered software content \u2014 NOT the hardware configuration (a hardware change after approval passes the token check). Re-plan (new dryRun) + fresh human approval only when the hardware configuration changed AFTER the dryRun that produced the token \u2014 the fingerprint cannot detect that change, so the human must confirm nothing hardware-side moved; never reuse the old token for changed hardware. Fingerprint limits: user program blocks, UDTs and tag tables only \u2014 no hardware configuration, system block groups, S7-1500 software units or technology objects; per-object fallback to modification dates (`source:"dates"`, warned in the plan \u2014 dates can false-positive `plan_stale`). Never self-approve. Pick the connection with `tia_pg_interfaces` (no scan). |\n\nScaffold order (dependency-correct): subnets \u2192 devices (CPUs first) \u2192 modules \u2192\nnetwork/IP/IO-system \u2192 protection recipe (`tia_guide {"topic":"recipes"}`) \u2192 tag\ntables \u2192 tags \u2192 constants \u2192 UDTs BEFORE dependent blocks \u2192 FB shells + instance DBs \u2192\nlogic (SCL/STL via `tia_source_put`; LAD/FBD/GRAPH via `tia_import_xml` \u2014 Gd6 format\nrouting) \u2192 `tia_compile`.\n\n## The approval envelope (what a gate handoff looks like)\n\nGated tools return `status:"requires_human_action"` with:\n\n- `gate` \u2014 which gate (e.g. `download_approval`, `station_upload`, `go_online`, `trust_dialog`);\n- `youMustDo` \u2014 what the human must confirm, in plain words;\n- `plan` + `planHash` \u2014 exactly what would be executed (the hash binds the approval to\n this exact plan; a changed plan needs a new approval); the download\'s plan also carries\n `fingerprint` (the software content the plan was verified against \u2014 show it too);\n- `nextSteps` \u2014 how to resume after the human\'s yes.\n\nRelay the envelope to the human, wait for an explicit yes, resume exactly as\ninstructed. The AI never approves, never invents a secret, never deploys F-logic.\n\n## After scaffolding\n\n- Re-run `tia_compile` after ANY authoring change.\n- `tia_project_save` regularly; `tia_project_archive` BEFORE risky operations\n (firmware change \u2014 see `tia_guide {"topic":"gotchas"}`).\n- Auditing an existing project is class R: read blocks/types/tags via `tia_plc_*` and\n check the engineering baseline (optimized access, 100% symbolic, UDT-typed\n interfaces, FB + instance-DB, uniform naming).\n- **The project matches what\'s versioned \u2014 prove it, don\'t assume it.** A raw hash of an\n export is NOT proof (two exports of the same block differ in `<Created>`/UIds). Use\n `tia_export_block` to pull a block inline and `tia_block_compare` to diff it against the\n committed XML (normalized \u2014 ignores formatting/BOM/`<Created>`/UIds); `verdict:"equal"` is\n the actual round-trip proof. After `tia_compile`/`tia_source_put`, read `blockChanges` and\n export/commit any regenerated instance DBs before calling the project verified.\n\n## Libraries, HMI, CAx and PLC security\n\nReads are class R; every change is class M-off (offline, with `dryRun`) and reaches the CPU\nonly through a later `tia_compile` + human-gated `tia_download` (G3). Every file path is a\npath ON THE SERVE HOST.\n\n- **Project library:** `tia_library_mastercopies` / `tia_library_types` read it;\n `tia_library_mastercopy_create` turns a DEVICE into a master copy (a block cannot be a source).\n `tia_block_from_mastercopy` needs a master copy that holds PLC blocks \u2014 a device copy is\n refused (`409 mastercopy_not_blocks` after app 1.6.3; up to 1.6.3 a 500).\n- **Global libraries** live in the TIA Portal session, not the project: `tia_global_libraries`,\n `tia_global_library_create` / `_open` / `_save` / `_close`. Save/close take the name from\n `tia_global_libraries` (exact name first, then ignoring case). After app 1.6.3 a name that\n picks no single open USER library is refused, nothing saved or closed: `404 not_found`\n (`details.userLibraries` lists the names that work), or `409 conflict` for a read-only\n system/corporate library or a name several user libraries match only ignoring case; up to\n 1.6.3 the serve reports success even for an unknown name. A library opened read-only\n (`readWrite:false`) cannot be saved: `409 conflict` (`details.readOnly`) after app 1.6.3, a\n 500 up to 1.6.3 \u2014 close it and open it again with `readWrite:true` to change and save it.\n- **HMI:** `tia_hmis` and `tia_hmi_screens` read any HMI; screen files\n (`tia_hmi_screen_export`, `tia_hmi_screens_import`) work for WinCC **Classic** only, and the\n import OVERWRITES same-named screens.\n- **CAx (AutomationML):** `tia_cax_export` (one device or the whole project) and\n `tia_cax_import` (`option`: `RetainTiaDevice` default / `OverwriteTiaDevice` /\n `MoveToParkingLot`). Archive the project before an overwrite. A failed transfer is an error\n (`500 cax_transfer_failed`) after app 1.6.3; up to 1.6.3 the serve returns an opaque\n `result` even on failure \u2014 check the devices with `tia_devices`.\n- **PLC security:** `tia_certificates` / `tia_certificate_template` / `tia_password_policy`\n read; `tia_certificate_import` / `_export` / `_delete`, `tia_password_policy_set` and\n `tia_block_protect` change the project. **G6:** a block or certificate password and the\n password-policy values come from a HUMAN \u2014 never invent, guess or reuse one; dryRun plans\n show a password as `[redacted]`. A CPU without the certificate manager or a policy service\n answers 409.\n- **Multiuser:** `tia_local_sessions` lists the local sessions (empty in a single-user project).\n';
34544
- var RECIPES = '# Recipes (runtime-verified) & scaffold order\n\n## Pipeline order (dependency-correct)\n\n`tia_spec_apply` already encodes this; use it manually only when the spec maps imperfectly.\n\n1. **Subnets** (`tia_subnet_create`) \u2014 before connecting devices to them.\n2. **Devices** (`tia_device_create`, `OrderNumber:<MLFB>/V<fw>`) \u2014 CPUs first.\n3. **Modules** (`tia_device_plug`) \u2014 into existing devices, by slot.\n4. **Network** (`tia_network_connect`, IP, `createIoSystem`) \u2014 CPU + its IO-devices on the\n **same** subnet; exactly one `createIoSystem` per IO-system.\n5. **Protection recipe** (below) \u2014 so the CPU can compile clean.\n6. **Tag tables** (`tia_tagtable_create`) \u2192 **tags** (`tia_tag_create`) \u2192 **constants**.\n7. **UDTs first** (`tia_types_import`), **then** blocks that use them.\n8. **Blocks** \u2014 FB shells (`tia_fb_create`) + instance DBs (`tia_instancedb_create`);\n logic via `tia_source_put` (SCL) or `tia_import_xml` (LAD/FBD/GRAPH). Gd6 format routing.\n9. **Compile** (`tia_compile`) \u2014 the verifier; only `Error` blocks. It compiles the **software**\n scope (not just the CPU device item), so it makes freshly-generated blocks consistent and, in\n most cases, **regenerates** any instance DB left inconsistent by an FB interface change.\n **Recompile first**; only if the DB still reports inconsistent after a compile, delete it\n (`tia_block_delete`), recreate it (`tia_instancedb_create`) and recompile.\n\n## Recipe \u2014 unlock a freshly-created CPU so it compiles clean (VERIFIED V21, firmware-dependent)\n\nA bare CPU added via Openness may fail `compile` with **protection** errors: the\n*confidential-PLC-configuration-data* password is unset, the *communication certificate*\ncan\'t be generated without it, and (on newer firmware) the *access control* defaults to a\nprotected level needing a password. **The recipe differs by CPU family/firmware \u2014 there is\nno single universal form.** Fix, in order:\n\n**(1) Confidential-data password \u2192 also auto-generates the certificate** (common to both\nfamilies):\n\n```\n# find the CPU device-item handle:\ntia_obj_roots -> the device handle (role:"device")\ntia_obj_items { handle:<device>, composition:"DeviceItems" } -> the CPU item handle\n# acquire the service ON THE CPU MODULE (not the rack) and invoke Protect:\ntia_obj_service { handle:<cpu>, type:"Siemens.Engineering.HW.Features.PlcMasterSecretConfigurator" } -> <svc>\ntia_obj_invoke { handle:<svc>, name:"Protect", args:["<password>"] }\n```\n\n**(2) Clear the access-control error \u2014 pick the variant for the CPU\'s family/firmware:**\n\n- **S7-1500 V2.9** (verified 2026 on real hardware \u2014 a 1516-3 V2.9, 3 errors \u2192 0): set\n `PlcProtectionAccessLevel = "FullAccess"` **on the CPU device item**:\n\n ```\n tia_obj_set_attributes { handle:<cpu>, attributes:{ "PlcProtectionAccessLevel":"FullAccess" } }\n ```\n\n- **S7-1200 V4.7** (new security model, FW \u2273 V4.5; per `docs/HARNESS-KNOWLEDGE.md` \xA72,\n runtime-observed): set `PlcAccessControlConfiguration = "Disabled"` on the\n **`PlcAccessControlConfigurationProvider`** SERVICE \u2014 not a direct attribute on the CPU\n item:\n\n ```\n tia_obj_service { handle:<cpu>, type:"Siemens.Engineering.HW.Features.PlcAccessControlConfigurationProvider" } -> <svc2>\n tia_obj_set_attributes { handle:<svc2>, attributes:{ "PlcAccessControlConfiguration":"Disabled" } }\n ```\n\n \u26A0\uFE0F **The two variants are mutually exclusive \u2014 the wrong one returns HTTP 500 on the\n other family:** `PlcAccessControlConfiguration` isn\'t on a 1500\'s CPU item, and\n `PlcProtectionAccessLevel` isn\'t the right model on a 1200 V4.7 item. Detect the\n family/FW \u2014 or the compile-error signature \u2014 before picking a variant.\n\n- **S7-1200 V4.0** (old security model): nothing to do here \u2014 the same bare-CPU condition\n is only a **WARNING**, not an error; a plain `tia_compile` already returns `errors: 0`.\n\nThen `tia_compile` \u2192 `state: Warning, errors: 0` (any remaining warnings \u2014 e.g. CPU-display\npassword \u2014 are benign and do **not** block; Gd8).\n\n> **Requires the `tia_obj_service` tool** (acquire `GetService<T>` \u2192 handle) for step 1 and\n> for the S7-1200 V4.7 variant of step 2. Without it the MCP cannot run either.\n\n### Open policy \u2014 who supplies the confidential password\n\n`Protect()` sets an **offline project** password (it is not the online master secret / G6).\nThe repo docs treat it as offline authoring ("no human needed"), but it protects confidential\nconfig data \u2014 so this is a **harness policy decision**: either (a) the human/spec supplies it\n(`spec.security.confidentialPassword`), or (b) the harness uses a documented project default.\nDefault to asking the human if the spec doesn\'t carry it; never invent a *secret the user\nmust later know* silently. The online master secret (`tia_mastersecret_set`, G6) is **always**\nhuman-supplied.\n\n## S7 connection precondition (G2)\n\n`tia_connection_create` needs **\u2265 2 CONSISTENT CPUs** (both compile clean). Two *bare* CPUs\nnever form a valid S7 connection \u2014 apply the protection recipe + `tia_compile` to make each\nconsistent first, then create the connection. Use `tia_connections_diagnose` on failure.\n\n## Recipe \u2014 bump the project firmware **in-place** (keeps the program) (VERIFIED, V21 / S7-1200 1214C)\n\nBumped a project **V4.0 \u2192 V4.4** on a real S7-1200 1214C **without losing blocks or tags**\n(verified 2026-06-07). Use this for **auto-FW-match**: align the project to the firmware\nactually read from the CPU. `DeviceItem.ChangeType(typeIdentifier)` changes the item type\nin place and **preserves the software** \u2014 it does **not** require delete/recreate.\n\n```\n# find the CPU device-item handle:\ntia_obj_roots -> the device handle (role:"device")\ntia_obj_items { handle:<device>, composition:"DeviceItems" } -> the CPU item handle (not the rack)\n# change the CPU\'s type to the SAME MLFB with the target /V<fw> suffix:\ntia_obj_invoke { handle:<cpu>, name:"ChangeType",\n args:["OrderNumber:6ES7 214-1HG40-0XB0/V4.4"] }\n# then recompile \u2014 a regenerated FB may need a fresh compile before download:\ntia_compile { ... }\n```\n\n- **Rule: `project FW \u2264 device FW`** \u2014 never set the project firmware **higher** than the physical\n device\'s (download would be rejected). Bumping the project *up to* the device FW is the safe move.\n- Keep the **same MLFB**, swap only the `/V<fw>` suffix. The program (blocks/tags) survives.\n- After `ChangeType` the CPU/blocks can be inconsistent; **always recompile** before any handoff.\n- **\u26A0\uFE0F `ChangeType` RESETS GUI-gated comm settings** (runtime-validated on the 1214C): it **disabled\n the OPC UA server** (`OpcUaServer`\u2192`false`) and **cleared the OPC UA runtime-license** selection\n (the custom server interface and PUT/GET *survived*). So **`tia_project_archive` first** on a CPU\n with hand-configured OPC UA/PUT-GET, and **re-verify after**. Recovery: `tia_obj_set_attributes\n {OpcUaServer:true}` on the "OPC UA" device-item (it **is** writable; re-select the license in the\n GUI). `ChangeType` to the **same** version is rejected ("Cannot change the type of the device item").\n\n## Recipe \u2014 enable a **Modbus TCP server** (`MB_SERVER`) on the S7-1200 (VERIFIED, FW V4.0)\n\nLets an external client (e.g. a Node backend) read/write the CPU over **Modbus TCP, port 502**\n(verified 2026-06-07; full backend/app detail in `docs/COMM-SCENARIOS.md`).\n\n1. **Non-optimized DB with an `Array of Word`** for the holding-register block (`MB_HOLD_REG`).\n Modbus needs a byte-addressable (non-optimized) DB \u2014 optimized access won\'t map.\n2. **On FW V4.0 use `MB_SERVER` V1.x**, which takes **`CONNECT_ID` + `IP_PORT`** parameters\n (**not** `CONNECT`/`TCON`, which the newer instruction versions use). Pin the instruction\n version when generating the FB.\n3. Instantiate `MB_SERVER` as a **multi-instance inside an FB** (its instance lives in the FB\'s\n instance DB), call it cyclically.\n4. **Map a holding register \u2192 a command tag** (e.g. `MB_HOLD_REG[0]` \u2192 `LedCmd`), so writing the\n register drives the output.\n\n> **Instance-DB gotcha (the big one):** when you regenerate the FB via `tia_source_put`, the\n> existing **instance DB** can go inconsistent (its interface no longer matches the FB).\n> **Recompile first** \u2014 a software-scope `tia_compile` regenerates the instance DB in most cases.\n> Only if it still reports inconsistent after a compile (typical when the interface was edited via\n> source), delete + recreate it, then recompile:\n>\n> ```\n> tia_compile { ... } # try first\n> tia_block_delete { ... the stale instance DB ... } # only if still inconsistent\n> tia_instancedb_create { ... fresh instance DB for the FB ... }\n> tia_compile { ... }\n> ```\n>\n> (Matches the \xA7Pipeline note: recompile first, delete+recreate only as the fallback.)\n\n## Recipe \u2014 enable **S7 / PUT-GET** on the S7-1200 (port 102)\n\nLets an external S7 client (e.g. `nodes7`) read/write the CPU over **S7comm, port 102**.\n\n1. **GATE (human, GUI only):** enable PUT/GET \u2014 *Properties \u2192 Protection & Security \u2192\n Connection mechanisms \u2192 "Permit access with PUT/GET communication"*. **Not exposed by\n Openness** on this CPU/FW (we tried `PlcAccessLevelProvider` \u2014 no toggle). Mark it as a\n **human gate** and surface it in `tia.handoff`; do **not** attempt to script it.\n2. **Non-optimized DB** for the data the client touches (PUT/GET addresses absolute offsets, so\n the DB must be byte-addressable / non-optimized).\n3. Compile + download as usual; the client then reads/writes the DB by area+offset.\n\n## Recipe \u2014 enable **OPC UA** on the S7-1200 (port 4840)\n\nLets an external OPC UA client read/write the CPU over **OPC UA, port 4840**. This path is the\nmost gated \u2014 most of it is **human GUI steps**, not Openness.\n\n**Prerequisite \u2014 firmware \u2265 V4.4.** OPC UA server isn\'t available on V4.0. If the project is on\nan older FW, bump it in-place first (see *bump the project firmware in-place* above \u2014\n`ChangeType` to `.../V4.4`).\n\nThen the setup sequence. **Step 1 is scriptable; steps 2\u20133 are human/GUI** on this CPU/FW (for those two\nwe tried `CommunicationManagement` and `OpcUaUserManagement\u2192404`):\n\n1. **Activate the OPC UA server** \u2014 *Properties \u2192 OPC UA \u2192 Server* (enable). *(This step **is**\n scriptable via Openness: `tia_obj_set_attributes` `{OpcUaServer:true}` on the "OPC UA"\n device-item \u2014 it auto-generates the server certificate. Steps 2\u20133 stay GUI-only.)*\n2. **Select the runtime license** \u2014 *"SIMATIC OPC UA S7-1200 Basic"* (Runtime licenses).\n3. **Create a server interface** that **exposes the DB** \u2014 the **S7-1200 does NOT auto-expose**\n tags/DBs to OPC UA (unlike the S7-1500), so you must add a server interface and place the DB\n nodes in it manually.\n\n**Finding the node IDs (client side):** browse `ns=3;s=ServerInterfaces` with any OPC UA client;\nthe actual data nodes show up under **`ns=4`**. Use those node IDs from the backend.\n\n> What Openness *can* still do here: create the DB/blocks, compile, download \u2014 **and activate the OPC UA\n> server** (step 1: `tia_obj_set_attributes {OpcUaServer:true}`; do NOT gate it on a human). Only **three**\n> items are truly human/GUI: the **runtime license**, the **server interface** \u2014 and **PUT/GET** in the S7\n> recipe. See `docs/TIA-Openness-Casos-de-Uso.md` \xA78c for the full "GUI-only gates" table.\n\n## Where to stop\n\nEverything above is **offline (M-off)**. `tia_download` / `tia_online` (G3/G4) are **not**\npart of scaffold \u2014 they belong to `tia.handoff` and require explicit human approval.\n';
34560
+ var RECIPES = '# Recipes (runtime-verified) & scaffold order\n\n## Pipeline order (dependency-correct)\n\n`tia_spec_apply` already encodes this; use it manually only when the spec maps imperfectly.\n\n1. **Subnets** (`tia_subnet_create`) \u2014 before connecting devices to them.\n2. **Devices** (`tia_device_create`, `OrderNumber:<MLFB>/V<fw>`) \u2014 CPUs first.\n3. **Modules** (`tia_device_plug`) \u2014 into existing devices, by slot.\n4. **Network** (`tia_network_connect`, IP, `createIoSystem`) \u2014 CPU + its IO-devices on the\n **same** subnet; exactly one `createIoSystem` per IO-system.\n5. **Protection recipe** (below) \u2014 so the CPU can compile clean.\n6. **Tag tables** (`tia_tagtable_create`) \u2192 **tags** (`tia_tag_create`) \u2192 **constants**.\n7. **UDTs first** (`tia_types_import`), **then** blocks that use them.\n8. **Blocks** \u2014 FB shells (`tia_fb_create`) + instance DBs (`tia_instancedb_create`);\n logic via `tia_source_put` (SCL) or `tia_import_xml` (LAD/FBD/GRAPH). Gd6 format routing.\n9. **Compile** (`tia_compile`) \u2014 the verifier; only `Error` blocks. It compiles the **software**\n scope (not just the CPU device item), so it makes freshly-generated blocks consistent and, in\n most cases, **regenerates** any instance DB left inconsistent by an FB interface change.\n **Recompile first**; only if the DB still reports inconsistent after a compile, delete it\n (`tia_block_delete`), recreate it (`tia_instancedb_create`) and recompile.\n\n## Recipe \u2014 unlock a freshly-created CPU so it compiles clean (VERIFIED V21, firmware-dependent)\n\nA bare CPU added via Openness may fail `compile` with **protection** errors: the\n*confidential-PLC-configuration-data* password is unset, the *communication certificate*\ncan\'t be generated without it, and (on newer firmware) the *access control* defaults to a\nprotected level needing a password. **The recipe differs by CPU family/firmware \u2014 there is\nno single universal form.** Fix, in order:\n\n**Tell the human first.** The recipe lowers the CPU\'s protection in the project: it sets the\nconfidential-configuration password (typed by the human) and then either sets the access level\nto **Full access** (S7-1500) or turns access control **off** (S7-1200, FW V4.5+). The CPU runs\nwith that protection after the next download. Name these changes when you ask for the password\nand list them in the report; the human may pick a stricter level in the TIA GUI before deploying.\n\n**(1) Confidential-data password \u2192 also auto-generates the certificate** (common to both\nfamilies):\n\n```\n# find the CPU device-item handle:\ntia_obj_roots -> the device handle (role:"device")\ntia_obj_items { handle:<device>, composition:"DeviceItems" } -> the CPU item handle\n# acquire the service ON THE CPU MODULE (not the rack) and invoke Protect:\ntia_obj_service { handle:<cpu>, type:"Siemens.Engineering.HW.Features.PlcMasterSecretConfigurator" } -> <svc>\ntia_obj_invoke { handle:<svc>, name:"Protect", args:["<password>"] }\n```\n\n**(2) Clear the access-control error \u2014 pick the variant for the CPU\'s family/firmware:**\n\n- **S7-1500 V2.9** (verified 2026 on real hardware \u2014 a 1516-3 V2.9, 3 errors \u2192 0): set\n `PlcProtectionAccessLevel = "FullAccess"` **on the CPU device item**:\n\n ```\n tia_obj_set_attributes { handle:<cpu>, attributes:{ "PlcProtectionAccessLevel":"FullAccess" } }\n ```\n\n- **S7-1200 V4.7** (new security model, FW \u2273 V4.5; per `docs/HARNESS-KNOWLEDGE.md` \xA72,\n runtime-observed): set `PlcAccessControlConfiguration = "Disabled"` on the\n **`PlcAccessControlConfigurationProvider`** SERVICE \u2014 not a direct attribute on the CPU\n item:\n\n ```\n tia_obj_service { handle:<cpu>, type:"Siemens.Engineering.HW.Features.PlcAccessControlConfigurationProvider" } -> <svc2>\n tia_obj_set_attributes { handle:<svc2>, attributes:{ "PlcAccessControlConfiguration":"Disabled" } }\n ```\n\n \u26A0\uFE0F **The two variants are mutually exclusive \u2014 the wrong one returns HTTP 500 on the\n other family:** `PlcAccessControlConfiguration` isn\'t on a 1500\'s CPU item, and\n `PlcProtectionAccessLevel` isn\'t the right model on a 1200 V4.7 item. Detect the\n family/FW \u2014 or the compile-error signature \u2014 before picking a variant.\n\n- **S7-1200 V4.0** (old security model): nothing to do here \u2014 the same bare-CPU condition\n is only a **WARNING**, not an error; a plain `tia_compile` already returns `errors: 0`.\n\nThen `tia_compile` \u2192 `state: Warning, errors: 0` (any remaining warnings \u2014 e.g. CPU-display\npassword \u2014 are benign and do **not** block; Gd8).\n\n> **Requires the `tia_obj_service` tool** (acquire `GetService<T>` \u2192 handle) for step 1 and\n> for the S7-1200 V4.7 variant of step 2. Without it the MCP cannot run either.\n\n### Policy \u2014 who supplies the confidential password\n\n`Protect()` sets an **offline project** password (it is not the online master secret / G6), but\nit protects confidential configuration data, so **the human supplies it, every time** (the\nrecommended policy, pending the product owner\'s confirmation): the project-spec has no field\nfor it, and a skill never invents, defaults, stores or logs it. The online master secret (`tia_mastersecret_set`, G6) is **always**\nhuman-supplied too.\n\n## S7 connection precondition (G2)\n\n`tia_connection_create` needs **\u2265 2 CONSISTENT CPUs** (both compile clean). Two *bare* CPUs\nnever form a valid S7 connection \u2014 apply the protection recipe + `tia_compile` to make each\nconsistent first, then create the connection. Use `tia_connections_diagnose` on failure.\n\n## Recipe \u2014 bump the project firmware **in-place** (keeps the program) (VERIFIED, V21 / S7-1200 1214C)\n\nBumped a project **V4.0 \u2192 V4.4** on a real S7-1200 1214C **without losing blocks or tags**\n(verified 2026-06-07). Use this for **auto-FW-match**: align the project to the firmware\nactually read from the CPU. `DeviceItem.ChangeType(typeIdentifier)` changes the item type\nin place and **preserves the software** \u2014 it does **not** require delete/recreate.\n\n```\n# archive first (see the warning below), then change the CPU\'s type to the SAME MLFB with the target /V<fw>:\ntia_device_change_version { plc:"<plc>", typeIdentifier:"OrderNumber:6ES7 214-1HG40-0XB0/V4.4" }\n# then recompile \u2014 a regenerated FB may need a fresh compile before download:\ntia_compile { ... }\n```\n\n(`tia_device_change_version` runs `ChangeType` on the CPU item for you; the raw form, `tia_obj_invoke`\nwith `name:"ChangeType"` on the CPU item handle from `tia_obj_roots` / `tia_obj_items`, does the same.)\n\n- **Rule: `project FW \u2264 device FW`** \u2014 never set the project firmware **higher** than the physical\n device\'s (download would be rejected). Bumping the project *up to* the device FW is the safe move.\n- Keep the **same MLFB**, swap only the `/V<fw>` suffix. The program (blocks/tags) survives.\n- After `ChangeType` the CPU/blocks can be inconsistent; **always recompile** before any handoff.\n- **\u26A0\uFE0F `ChangeType` RESETS GUI-gated comm settings** (runtime-validated on the 1214C): it **disabled\n the OPC UA server** (`OpcUaServer`\u2192`false`) and **cleared the OPC UA runtime-license** selection\n (the custom server interface and PUT/GET *survived*). So **`tia_project_archive` first** on a CPU\n with hand-configured OPC UA/PUT-GET, and **re-verify after**. Recovery: `tia_obj_set_attributes\n {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item (it **is** writable; re-select the license in the\n GUI). `ChangeType` to the **same** version is rejected ("Cannot change the type of the device item").\n\n## Recipe \u2014 enable a **Modbus TCP server** (`MB_SERVER`) on the S7-1200 (VERIFIED, FW V4.0)\n\nLets an external client (e.g. a Node backend) read/write the CPU over **Modbus TCP, port 502**\n(verified 2026-06-07; full backend/app detail in `docs/COMM-SCENARIOS.md`).\n\n1. **Non-optimized DB with an `Array of Word`** for the holding-register block (`MB_HOLD_REG`).\n Modbus needs a byte-addressable (non-optimized) DB \u2014 optimized access won\'t map.\n2. **On FW V4.0 use `MB_SERVER` V1.x**, which takes **`CONNECT_ID` + `IP_PORT`** parameters\n (**not** `CONNECT`/`TCON`, which the newer instruction versions use). Pin the instruction\n version when generating the FB.\n3. Instantiate `MB_SERVER` as a **multi-instance inside an FB** (its instance lives in the FB\'s\n instance DB), call it cyclically.\n4. **Map a holding register \u2192 a command tag** (e.g. `MB_HOLD_REG[0]` \u2192 `LedCmd`), so writing the\n register drives the output.\n\n> **Instance-DB gotcha (the big one):** when you regenerate the FB via `tia_source_put`, the\n> existing **instance DB** can go inconsistent (its interface no longer matches the FB).\n> **Recompile first** \u2014 a software-scope `tia_compile` regenerates the instance DB in most cases.\n> Only if it still reports inconsistent after a compile (typical when the interface was edited via\n> source), delete + recreate it, then recompile:\n>\n> ```\n> tia_compile { ... } # try first\n> tia_block_delete { ... the stale instance DB ... } # only if still inconsistent\n> tia_instancedb_create { ... fresh instance DB for the FB ... }\n> tia_compile { ... }\n> ```\n>\n> (Matches the \xA7Pipeline note: recompile first, delete+recreate only as the fallback.)\n\n## Recipe \u2014 enable **S7 / PUT-GET** on the S7-1200 (port 102)\n\nLets an external S7 client (e.g. `nodes7`) read/write the CPU over **S7comm, port 102**.\n\n1. **GATE (human, GUI only):** enable PUT/GET \u2014 *Properties \u2192 Protection & Security \u2192\n Connection mechanisms \u2192 "Permit access with PUT/GET communication"*. **Not exposed by\n Openness** on this CPU/FW (we tried `PlcAccessLevelProvider` \u2014 no toggle). Mark it as a\n **human gate** and surface it in `tia-handoff`; do **not** attempt to script it.\n2. **Non-optimized DB** for the data the client touches (PUT/GET addresses absolute offsets, so\n the DB must be byte-addressable / non-optimized).\n3. Compile + download as usual; the client then reads/writes the DB by area+offset.\n\n## Recipe \u2014 enable **OPC UA** on the S7-1200 (port 4840)\n\nLets an external OPC UA client read/write the CPU over **OPC UA, port 4840**. This path is the\nmost gated \u2014 most of it is **human GUI steps**, not Openness.\n\n**Prerequisite \u2014 firmware \u2265 V4.4.** OPC UA server isn\'t available on V4.0. If the project is on\nan older FW, bump it in-place first (see *bump the project firmware in-place* above \u2014\n`ChangeType` to `.../V4.4`).\n\nThen the setup sequence. **Step 1 is scriptable; steps 2\u20133 are human/GUI** on this CPU/FW (for those two\nwe tried `CommunicationManagement` and `OpcUaUserManagement\u2192404`):\n\n1. **Activate the OPC UA server** \u2014 *Properties \u2192 OPC UA \u2192 Server* (enable). *(This step **is**\n scriptable via Openness: `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA"\n device-item \u2014 it auto-generates the server certificate. Steps 2\u20133 stay GUI-only.)*\n2. **Select the runtime license** \u2014 *"SIMATIC OPC UA S7-1200 Basic"* (Runtime licenses).\n3. **Create a server interface** that **exposes the DB** \u2014 the **S7-1200 does NOT auto-expose**\n tags/DBs to OPC UA (unlike the S7-1500), so you must add a server interface and place the DB\n nodes in it manually.\n\n**Finding the node IDs (client side):** browse `ns=3;s=ServerInterfaces` with any OPC UA client;\nthe actual data nodes show up under **`ns=4`**. Use those node IDs from the backend.\n\n> What Openness *can* still do here: create the DB/blocks, compile, download \u2014 **and activate the OPC UA\n> server** (step 1: `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`; do NOT gate it on a human). Only **three**\n> items are truly human/GUI: the **runtime license**, the **server interface** \u2014 and **PUT/GET** in the S7\n> recipe. See `docs/TIA-Openness-Casos-de-Uso.md` \xA78c for the full "GUI-only gates" table.\n\n## Where to stop\n\nEverything above is **offline (M-off)**. `tia_download` / `tia_online` (G3/G4) are **not**\npart of scaffold \u2014 they belong to `tia-handoff` and require explicit human approval.\n';
34545
34561
  var SPEC_FORMAT = '# The project-spec (input model)\n\nA project-spec is ONE JSON document describing the whole project. Always run it\nthrough the pipeline front door: `tia_spec_validate` (rung 0, pure) \u2192 `tia_spec_plan`\n(dry) \u2192 `tia_spec_apply` (M-off, stops at gates).\n\nRules the validator enforces (beyond the JSON Schema): unique device/tag/block names;\nevery network node IP inside the subnet CIDR (same-subnet rule); `OrderNumber:<MLFB>/V<fw>`\nformat with `/V` \u2014 never `:V` (Gd5); per-CPU module limits; language by family (e.g.\nS7-1200 has no GRAPH); and the G5 rule \u2014 a spec with safety content marked autonomous\nis REJECTED (F-logic is never autonomous).\n\nMinimal example:\n\n```json\n{\n "project": { "name": "Line2", "directory": "C:\\\\TIA\\\\Line2" },\n "conventions": {\n "namingScheme": "plcopen",\n "optimizedAccess": true,\n "symbolicOnly": true,\n "defaultLanguages": { "interlocks": "LAD", "algorithms": "SCL", "sequencers": "GRAPH" }\n },\n "devices": [\n {\n "name": "Line2_CPU",\n "typeIdentifier": "OrderNumber:6ES7 511-1AK02-0AB0/V2.9",\n "role": "cpu",\n "family": "S7-1500"\n }\n ],\n "network": {\n "subnet": { "type": "System:Subnet.Ethernet", "name": "PN_Line2", "cidr": "192.168.0.0/24" },\n "nodes": [{ "device": "Line2_CPU", "ip": "192.168.0.1", "createIoSystem": true }]\n },\n "dataTypes": [\n {\n "name": "UDT_Motor",\n "members": [\n { "name": "xStart", "dataType": "Bool", "comment": "Start command" },\n { "name": "rSpeed", "dataType": "Real", "comment": "Speed [%]" }\n ]\n }\n ],\n "tagTables": [{ "name": "IO", "purpose": "IO" }],\n "tags": [{ "table": "IO", "name": "Conv01_Run", "dataType": "Bool", "address": "%Q0.0" }]\n}\n```\n\nResolve every concrete MLFB + firmware via `tia_catalog` before building \u2014 never guess\nan order number. Project firmware must be \u2264 the physical device\'s firmware.\n';
34546
34562
  var FULL_GUIDE = [BRIEF, GATES_GUARDS, GUI_GATES, GOTCHAS, PIPELINE, RECIPES, SPEC_FORMAT].join("\n---\n\n");
34563
+ var CODEX_GUIDE = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n4. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n5. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n6. **Prerequisites:** the serve must be running (default `http://localhost:5000` \u2014\n check with `tia_ping`); the FIRST connect per serve process hits the G1 trust dialog\n on the serve host.\n7. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. `tia_ping` probes `/health`: never busy,\n `activated:null` while a job runs, and no job ID in it \u2014 use it for reachability only. Offline\n tools (`tia_guide`, `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n\nSession start: `tia_ping` \u2192 `tia_status` \u2192 (if needed) `tia_start` / `tia_connect`.\nBefore the first build on a project: read `tia_guide {"topic":"pipeline"}` and\n`tia_guide {"topic":"gotchas"}`.\n\n**Tool names** are written bare (`tia_status`) here and in the skills. Claude Code shows them qualified:\n`mcp__plugin_tia-harness_tia__tia_status` (plugin; what a subagent `tools:` list needs) or\n`mcp__tia__tia_status` (standalone). Other clients may display them differently; the `tia_*` suffix\nis the tool.\n\n---\n\n# Gates vs guards\n\n## GATES vs GUARDS\n\n- **GATES (human-only \u2014 never auto-bypass):** trust dialog (**G1**), download / CPU-STOP\n (**G3**), go-online (**G4**, which includes a **station upload** (`tia_upload`): it goes\n online to read the CPU), network scan / accessible-devices (**G7**), master-secret/UMAC\n (**G6**, which includes a CPU **read-access password** for an upload, a block **know-how\n password** (`tia_block_protect`), a certificate file\'s password (`tia_certificate_import`)\n and the **password-policy** values (`tia_password_policy_set`)), **safety / F-logic\n (G5) \u2014 never autonomous**.\n- **GUARDS (tool-enforced preconditions):** compile-clean before deploy, consistency,\n dry-run\u2192approve, idempotency by name (advisory: re-runs do not converge), `OrderNumber:<MLFB>/V<fw>`\n format, serial-only.\n- Back up a physical CPU with the **`tia-backup`** skill (dedicated empty project; the upload\n token is bound to the project shown in the handoff).\n- **Picking the G3 download path (no gate, no scan):** `tia_pg_interfaces` lists the connection\n modes/PG-PC interfaces TIA already sees for the CPU (plus the OS status of each adapter) \u2014\n use it to fill `connectionMode`/`pcInterfaceName`/`targetInterfaceName` for `tia_download`\n instead of reaching for `tia_accessible_devices` (a real network scan, GATE G7).\n- **GUI-ONLY settings (NOT exposed via Openness \u2014 surface as a human gate, do not script):**\n "Permit access with PUT/GET communication", OPC UA **runtime license** / server-interface\n creation. (OPC UA server **activation** is the exception \u2014 settable via Openness with\n `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item.)\n\n**Deploy-time approval gates** (download / online / network-scan / secret / safety = **G3/G4/G7/G6/G5**)\nare a *different* class \u2014 see the **`tia-handoff`** skill. Those are "a human **approves an action**",\nnot "a human **clicks a GUI setting**". Both are human interaction points; surface them as\n`requires_human_action` with concrete guidance, never as a tool failure.\n\n---\n\n# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect` \u2192 `requires_human_action` (`trust_dialog`), or the **1st** TIA-starting call per `serve` process goes **~180 s** (`TIA_CONNECT_TIMEOUT_MS`) without an answer \u2014 `tia_connect`, `tia_start`, `tia_show_ui` and `tia_project_create` all share that wait, and a client timeout with `/health` alive yields the same `trust_dialog` handoff. A `running` answer from any of them can still mean a trust dialog is waiting on the serve host | TIA shows a one-time security prompt the first time an Openness app attaches, **per process** | On the **serve host**, in TIA Portal, click **"Yes to all"** in the access dialog. *Caveat:* it can false-positive on a client timeout with **no** real dialog \u2014 check `tia_status` (**`hasProject:true`**, not `attached:true`) and\u2026 If the handoff state is `TRUST_DIALOG_DENIED_OR_EXPIRED`, the dialog was denied or left to expire: the serve lists what it closed (`closedPids`), what is still running (`stillRunningPids`) and what it could not confirm (`unknownPids`) \u2014 close any still-running TIA (no project inside) before re-calling, and for an unconfirmed pid first verify in Task Manager that it is a TIA Portal started by this serve with no open project, with a human ready to click **"Yes to all"**. |\n| **OPC UA license** | `tia_compile` **ERROR**: *"The selected OPC UA license is not sufficient\u2026"* | License selection is GUI-only (no Openness service); a fresh project **or a firmware change** leaves it unset | CPU \u2192 **Properties \u2192 General \u2192 Runtime licenses \u2192 OPC UA** \u2192 *Type of required license* \u2192 select **"SIMATIC OPC UA S7-1200 Basic"** (the 1214C option). Recompile. |\n| **OPC UA interface** | OPC UA client connects but the DB nodes aren\'t there (`ns=4` empty / no `ServerInterfaces`) | The **S7-1200 does NOT auto-expose DBs** (unlike the S7-1500) \u2014 a server interface must be created by hand | CPU \u2192 **OPC UA \u2192 Server interfaces \u2192 Add new server interface** \u2192 add/drag the DB (e.g. `ModbusData`) into it. Recompile; data appears under `ns=4`. |\n| **PUT/GET** | S7 client (`nodes7`/`snap7`) connects on port 102 but reads return access-denied (`ROSCTR=2` / "BAD") | *"Permit access with PUT/GET"* is a GUI-only protection setting | CPU \u2192 **Properties \u2192 Protection & Security \u2192 Connection mechanisms** \u2192 check **"Permit access with PUT/GET communication from remote partner"**. Compile + download (`hardware:true`). |\n| **FW-change reset** | After `tia_device_change_version`: OPC UA server off, the license error on compile, blocks `isConsistent:false` | `DeviceItem.ChangeType` **resets GUI-gated comm settings** (server activation + license); the interface & PUT/GET survive | `tia_project_archive` **before** the FW change. After: re-set `OpcUaServer:true` via `tia_obj_set_attributes` (scriptable), re-select the license (row above), recompile. |\n\n**Not a gate (now scriptable):** *activating* the OPC UA server \u2014 `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`\non the "OPC UA" device-item (it auto-generates the server certificate). Only the **license** and the\n**server interface** stay GUI-only.\n\n---\n\n# Hard-won gotchas (runtime-validated)\n\n## Hard-won gotchas\n\n1. **Always compile before deploy.** `tia_compile` aggregates **hardware + software**; a\n **clean** compile (`errors:0`) is the precondition for download and for S7 connections.\n2. **The serve is a SINGLE serial worker** \u2014 one Openness op at a time. Do **not** fire\n concurrent `tia_*` calls; a hung Openness op can stall the serve (may need a restart).\n3. **Changing an FB\'s interface (e.g. regenerating it via `tia_source_put`) leaves its\n instance DB inconsistent.** Recompile FIRST: a software-scope `tia_compile` regenerates\n the instance DB in most cases \u2014 read the compile result\'s **`blockChanges`** (`tia_compile`\n and `tia_source_put {compile:true}` both return it): a `"change":"modified"` entry on the\n instance DB is your confirmation it was regenerated \u2014 **export and commit it**\n (`tia_export_block`/`tia_block_compare`) so what\'s versioned matches the project. Only if\n the DB still reports inconsistent after a compile, delete it (`tia_block_delete`),\n recreate it (`tia_instancedb_create`) and recompile.\n4. **Firmware rule: project FW \u2264 device FW.** Bump the project FW **in-place** with\n `tia_device_change_version` (`DeviceItem.ChangeType`), which preserves the **program** \u2014 never\n set the project higher than the physical CPU. **\u26A0\uFE0F It RESETS GUI-gated comm settings** (the\n **OPC UA server activation** + **runtime-license**; the server interface and PUT/GET survive):\n **archive first** (`tia_project_archive`) on a CPU with hand-configured OPC UA, recompile after\n (it marks blocks inconsistent), and re-verify. Same-version `ChangeType` is rejected.\n5. **Use a NON-optimized DB** for Modbus (`MB_HOLD_REG`) and S7 (absolute addressing); OPC UA\n works with optimized or not.\n6. **Order numbers use `/V<fw>`, not `:V<fw>`** (guard Gd5).\n7. **A station upload (`tia_upload`) ADDS a new station to the open project \u2014 back up into a\n dedicated EMPTY project.** Observed on hardware (S7-1200 1214C, 2026-09-26): the upload read\n the CPU into an empty project (0 \u2192 1 device, twice) in ~75 s (76.7 s and 74.2 s); the CPU\n stayed in RUN the whole time (owner watching its LEDs during the second upload). Protect the\n working project FIRST: `tia_project_create` CLOSES the current project without saving, so\n `tia_project_save` + `tia_project_archive` before creating the backup project \u2014 and pass the\n archive `name` WITH the `.zap21` extension (`name` absent or extension-less fails; with\n `.zap21` it archived 1.6 MB).\n8. **One wrong know-how password can lock a block for the session.** Observed on the bench\n (2026-10-12): after one rejected unprotect (`tia_block_protect {protect:false}`), TIA refused\n the CORRECT password of that block for the rest of the session (cause not confirmed \u2014 possibly\n brute-force protection). Never retry with a guess \u2014 ask the human for the password (G6); if a\n password the human confirms is refused, stop and hand off instead of retrying.\n\n## Prerequisites (environment)\n\n- The **`tia` serve must be running** (default `http://localhost:5000`, e.g.\n `TIAOpenness.exe serve 5000`). The MCP is a pure HTTP client; point it at the serve host via\n `TIA_API_BASE` if it runs elsewhere.\n- The Windows user must belong to the **"Siemens TIA Openness"** local group.\n- The **FIRST connection per serve process shows a trust dialog** that a **human must confirm**\n ("Yes to all") on the serve host \u2014 this **cannot be automated** (gate G1).\n\n---\n\n# The build pipeline (spec \u2192 verified project)\n\nStages in order \u2014 the class tells you what each stage may do:\n\n| # | Stage | Tool(s) | Class | What it does |\n|---|---|---|---|---|\n| 0 | Validate the spec | `tia_spec_validate` | R (pure) | JSON-Schema + cross-field engineering rules (unique names, same-subnet IPs, Gd5 order-number format, per-CPU module limits, language-by-family, the G5 safety rule). Needs no serve. |\n| 1 | Plan | `tia_spec_plan` | R (pure) | Turns a VALID spec into the ordered list of M-off operations. Nothing mutates. |\n| 2 | Scaffold | `tia_spec_apply` (or the M-off tools manually) | M-off | Creates the project content in dependency order (see below). Stops at every gate. |\n| 3 | Verify | `tia_compile` | M-off | THE offline verifier: aggregates hardware + software. Gd8: only ERRORs block. `errors:0` is the Gd9 precondition for any deploy. |\n| 4 | Handoff / deploy | `tia_download` | GATE G3 | `dryRun:true` asks serve for a VERIFIED plan (clean compile, resolved connection, software fingerprint) \u2192 plan + `planHash` \u2192 a HUMAN approves \u2192 re-call with `approved:true` + the SAME `planHash` (serve re-checks the fingerprint and refuses `plan_stale` if the software changed). The approval covers the connection/options and the covered software content \u2014 NOT the hardware configuration (a hardware change after approval passes the token check). Re-plan (new dryRun) + fresh human approval only when the hardware configuration changed AFTER the dryRun that produced the token \u2014 the fingerprint cannot detect that change, so the human must confirm nothing hardware-side moved; never reuse the old token for changed hardware. Fingerprint limits: user program blocks, UDTs and tag tables only \u2014 no hardware configuration, system block groups, S7-1500 software units or technology objects; per-object fallback to modification dates (`source:"dates"`, warned in the plan \u2014 dates can false-positive `plan_stale`). Never self-approve. Pick the connection with `tia_pg_interfaces` (no scan). |\n\nScaffold order (dependency-correct): subnets \u2192 devices (CPUs first) \u2192 modules \u2192\nnetwork/IP/IO-system \u2192 protection recipe (`tia_guide {"topic":"recipes"}`) \u2192 tag\ntables \u2192 tags \u2192 constants \u2192 UDTs BEFORE dependent blocks \u2192 FB shells + instance DBs \u2192\nlogic (SCL/STL via `tia_source_put`; LAD/FBD/GRAPH via `tia_import_xml` \u2014 Gd6 format\nrouting) \u2192 `tia_compile`.\n\n## The approval envelope (what a gate handoff looks like)\n\nGated tools return `status:"requires_human_action"` with:\n\n- `gate` \u2014 which gate (e.g. `download_approval`, `station_upload`, `go_online`, `trust_dialog`);\n- `youMustDo` \u2014 what the human must confirm, in plain words;\n- `plan` + `planHash` \u2014 exactly what would be executed (the hash binds the approval to\n this exact plan; a changed plan needs a new approval); the download\'s plan also carries\n `fingerprint` (the software content the plan was verified against \u2014 show it too);\n- `nextSteps` \u2014 how to resume after the human\'s yes.\n\nRelay the envelope to the human, wait for an explicit yes, resume exactly as\ninstructed. The AI never approves, never invents a secret, never deploys F-logic.\n\n## After scaffolding\n\n- Re-run `tia_compile` after ANY authoring change.\n- `tia_project_save` regularly; `tia_project_archive` BEFORE risky operations\n (firmware change \u2014 see `tia_guide {"topic":"gotchas"}`).\n- Auditing an existing project is class R: read blocks/types/tags via `tia_plc_*` and\n check the engineering baseline (optimized access, 100% symbolic, UDT-typed\n interfaces, FB + instance-DB, uniform naming).\n- **The project matches what\'s versioned \u2014 prove it, don\'t assume it.** A raw hash of an\n export is NOT proof (two exports of the same block differ in `<Created>`/UIds). Use\n `tia_export_block` to pull a block inline and `tia_block_compare` to diff it against the\n committed XML (normalized \u2014 ignores formatting/BOM/`<Created>`/UIds); `verdict:"equal"` is\n the actual round-trip proof. After `tia_compile`/`tia_source_put`, read `blockChanges` and\n export/commit any regenerated instance DBs before calling the project verified.\n\n## Libraries, HMI, CAx and PLC security\n\nReads are class R; every change is class M-off (offline, with `dryRun`) and reaches the CPU\nonly through a later `tia_compile` + human-gated `tia_download` (G3). Every file path is a\npath ON THE SERVE HOST.\n\n- **Project library:** `tia_library_mastercopies` / `tia_library_types` read it;\n `tia_library_mastercopy_create` turns a DEVICE into a master copy (a block cannot be a source).\n `tia_block_from_mastercopy` needs a master copy that holds PLC blocks \u2014 a device copy is\n refused (`409 mastercopy_not_blocks` after app 1.6.3; up to 1.6.3 a 500).\n- **Global libraries** live in the TIA Portal session, not the project: `tia_global_libraries`,\n `tia_global_library_create` / `_open` / `_save` / `_close`. Save/close take the name from\n `tia_global_libraries` (exact name first, then ignoring case). After app 1.6.3 a name that\n picks no single open USER library is refused, nothing saved or closed: `404 not_found`\n (`details.userLibraries` lists the names that work), or `409 conflict` for a read-only\n system/corporate library or a name several user libraries match only ignoring case; up to\n 1.6.3 the serve reports success even for an unknown name. A library opened read-only\n (`readWrite:false`) cannot be saved: `409 conflict` (`details.readOnly`) after app 1.6.3, a\n 500 up to 1.6.3 \u2014 close it and open it again with `readWrite:true` to change and save it.\n- **HMI:** `tia_hmis` and `tia_hmi_screens` read any HMI; screen files\n (`tia_hmi_screen_export`, `tia_hmi_screens_import`) work for WinCC **Classic** only, and the\n import OVERWRITES same-named screens.\n- **CAx (AutomationML):** `tia_cax_export` (one device or the whole project) and\n `tia_cax_import` (`option`: `RetainTiaDevice` default / `OverwriteTiaDevice` /\n `MoveToParkingLot`). Archive the project before an overwrite. A failed transfer is an error\n (`500 cax_transfer_failed`) after app 1.6.3; up to 1.6.3 the serve returns an opaque\n `result` even on failure \u2014 check the devices with `tia_devices`.\n- **PLC security:** `tia_certificates` / `tia_certificate_template` / `tia_password_policy`\n read; `tia_certificate_import` / `_export` / `_delete`, `tia_password_policy_set` and\n `tia_block_protect` change the project. **G6:** a block or certificate password and the\n password-policy values come from a HUMAN \u2014 never invent, guess or reuse one; dryRun plans\n show a password as `[redacted]`. A CPU without the certificate manager or a policy service\n answers 409.\n- **Multiuser:** `tia_local_sessions` lists the local sessions (empty in a single-user project).\n\n---\n\n# Recipes (runtime-verified)\n\nNot copied here: Codex reads at most 32 KiB of AGENTS.md and cuts the rest without a word. Call\n`tia_guide {"topic":"recipes"}` for the verified recipes (unlocking a freshly-created CPU, the in-place firmware\nbump, Modbus TCP, S7 PUT/GET and OPC UA on the S7-1200, the scaffold order) before you need one.\n\n---\n\n# The project-spec (input model)\n\nA project-spec is ONE JSON document describing the whole project. Always run it\nthrough the pipeline front door: `tia_spec_validate` (rung 0, pure) \u2192 `tia_spec_plan`\n(dry) \u2192 `tia_spec_apply` (M-off, stops at gates).\n\nRules the validator enforces (beyond the JSON Schema): unique device/tag/block names;\nevery network node IP inside the subnet CIDR (same-subnet rule); `OrderNumber:<MLFB>/V<fw>`\nformat with `/V` \u2014 never `:V` (Gd5); per-CPU module limits; language by family (e.g.\nS7-1200 has no GRAPH); and the G5 rule \u2014 a spec with safety content marked autonomous\nis REJECTED (F-logic is never autonomous).\n\nMinimal example:\n\n```json\n{\n "project": { "name": "Line2", "directory": "C:\\\\TIA\\\\Line2" },\n "conventions": {\n "namingScheme": "plcopen",\n "optimizedAccess": true,\n "symbolicOnly": true,\n "defaultLanguages": { "interlocks": "LAD", "algorithms": "SCL", "sequencers": "GRAPH" }\n },\n "devices": [\n {\n "name": "Line2_CPU",\n "typeIdentifier": "OrderNumber:6ES7 511-1AK02-0AB0/V2.9",\n "role": "cpu",\n "family": "S7-1500"\n }\n ],\n "network": {\n "subnet": { "type": "System:Subnet.Ethernet", "name": "PN_Line2", "cidr": "192.168.0.0/24" },\n "nodes": [{ "device": "Line2_CPU", "ip": "192.168.0.1", "createIoSystem": true }]\n },\n "dataTypes": [\n {\n "name": "UDT_Motor",\n "members": [\n { "name": "xStart", "dataType": "Bool", "comment": "Start command" },\n { "name": "rSpeed", "dataType": "Real", "comment": "Speed [%]" }\n ]\n }\n ],\n "tagTables": [{ "name": "IO", "purpose": "IO" }],\n "tags": [{ "table": "IO", "name": "Conv01_Run", "dataType": "Bool", "address": "%Q0.0" }]\n}\n```\n\nResolve every concrete MLFB + firmware via `tia_catalog` before building \u2014 never guess\nan order number. Project firmware must be \u2264 the physical device\'s firmware.\n';
34547
34564
 
34548
34565
  // src/tools/guide.ts
34549
34566
  var TOPICS = {
@@ -34554,7 +34571,11 @@ var TOPICS = {
34554
34571
  pipeline: { summary: "the build pipeline validate\u2192plan\u2192scaffold\u2192verify\u2192handoff + the approval envelope", text: PIPELINE },
34555
34572
  recipes: { summary: "verified recipes: bare-CPU protection unlock, in-place firmware bump, S7 preconditions", text: RECIPES },
34556
34573
  "spec-format": { summary: "the project-spec JSON model, validator rules and a minimal example", text: SPEC_FORMAT },
34557
- full: { summary: "the whole guide (every chapter, concatenated)", text: FULL_GUIDE }
34574
+ full: { summary: "the whole guide (every chapter, concatenated)", text: FULL_GUIDE },
34575
+ codex: {
34576
+ summary: "the whole guide without the recipes (a pointer to them instead), sized for the 32 KiB Codex reads from AGENTS.md",
34577
+ text: CODEX_GUIDE
34578
+ }
34558
34579
  };
34559
34580
  var GUIDE_TOPIC_IDS = Object.keys(TOPICS);
34560
34581
  function tocText() {
@@ -34577,20 +34598,191 @@ function registerGuideTool(server2) {
34577
34598
  title: "TIA \u2014 the operating guide (READ FIRST)",
34578
34599
  description: "THE OPERATING GUIDE for driving the tia_* tools \u2014 read the relevant topic BEFORE authoring, changing hardware or preparing a deploy. Returns bundled markdown: gates vs guards (G1..G7 are human-only), the build pipeline (validate\u2192plan\u2192scaffold\u2192verify\u2192handoff), runtime-validated gotchas, GUI-gate handoffs, the bare-CPU protection recipe, and the project-spec format. Default topic 'toc' lists the chapters; 'full' returns everything. Pure/offline (class R): does NOT call the serve \u2014 works with the serve down.",
34579
34600
  inputSchema: {
34580
- topic: external_exports.string().optional().describe('one of: toc | full | brief | gates-guards | gui-gates | gotchas | pipeline | recipes | spec-format (default "toc")')
34601
+ topic: external_exports.string().optional().describe('one of: toc | full | codex | brief | gates-guards | gui-gates | gotchas | pipeline | recipes | spec-format (default "toc")')
34581
34602
  }
34582
34603
  },
34583
34604
  async ({ topic }) => guideFlow(topic)
34584
34605
  );
34585
34606
  }
34586
34607
 
34608
+ // src/tool-classes.json
34609
+ var tool_classes_default = {
34610
+ $comment: [
34611
+ "The class of every tia_* tool: the ONE source of truth (#69). R = read-only, safe anytime; M-off = offline mutation; GATE = touches the physical world or a human-only decision.",
34612
+ "The server sets annotations.readOnlyHint from it (src/toolClasses.ts), and the setup CLI pre-approves the R tools in each agent from a copy of this file.",
34613
+ "preapprovedEver is APPEND-ONLY: every name a released setup may pre-approve. A tool listed there must stay class R forever (test/tool-classes.test.ts); to make it mutating, give the tool a new name."
34614
+ ],
34615
+ classes: {
34616
+ tia_accessible_devices: "GATE",
34617
+ tia_block_compare: "M-off",
34618
+ tia_block_delete: "M-off",
34619
+ tia_block_from_mastercopy: "M-off",
34620
+ tia_block_group_create: "M-off",
34621
+ tia_block_protect: "M-off",
34622
+ tia_block_set_attribute: "M-off",
34623
+ tia_catalog: "R",
34624
+ tia_cax_export: "M-off",
34625
+ tia_cax_import: "M-off",
34626
+ tia_certificate_delete: "M-off",
34627
+ tia_certificate_export: "M-off",
34628
+ tia_certificate_import: "M-off",
34629
+ tia_certificate_template: "R",
34630
+ tia_certificates: "R",
34631
+ tia_compile: "M-off",
34632
+ tia_connect: "M-off",
34633
+ tia_connection_create: "M-off",
34634
+ tia_connections_diagnose: "R",
34635
+ tia_constant_create: "M-off",
34636
+ tia_device_change_version: "M-off",
34637
+ tia_device_connections: "R",
34638
+ tia_device_create: "M-off",
34639
+ tia_device_group_create: "M-off",
34640
+ tia_device_plug: "M-off",
34641
+ tia_device_tree: "R",
34642
+ tia_device_unplug: "M-off",
34643
+ tia_devices: "R",
34644
+ tia_disconnect: "M-off",
34645
+ tia_download: "GATE",
34646
+ tia_export_block: "M-off",
34647
+ tia_export_xml: "M-off",
34648
+ tia_fb_create: "M-off",
34649
+ tia_global_libraries: "R",
34650
+ tia_global_library_close: "M-off",
34651
+ tia_global_library_create: "M-off",
34652
+ tia_global_library_open: "M-off",
34653
+ tia_global_library_save: "M-off",
34654
+ tia_guide: "R",
34655
+ tia_hmi_screen_export: "M-off",
34656
+ tia_hmi_screens: "R",
34657
+ tia_hmi_screens_import: "M-off",
34658
+ tia_hmis: "R",
34659
+ tia_import_xml: "M-off",
34660
+ tia_instancedb_create: "M-off",
34661
+ tia_instances: "R",
34662
+ tia_job_status: "R",
34663
+ tia_library_mastercopies: "R",
34664
+ tia_library_mastercopy_create: "M-off",
34665
+ tia_library_types: "R",
34666
+ tia_local_sessions: "R",
34667
+ tia_mastersecret_reset: "GATE",
34668
+ tia_mastersecret_set: "GATE",
34669
+ tia_network_address: "M-off",
34670
+ tia_network_connect: "M-off",
34671
+ tia_network_disconnect: "M-off",
34672
+ tia_obj_create: "M-off",
34673
+ tia_obj_creationinfos: "R",
34674
+ tia_obj_get: "R",
34675
+ tia_obj_info: "R",
34676
+ tia_obj_invoke: "M-off",
34677
+ tia_obj_items: "R",
34678
+ tia_obj_roots: "R",
34679
+ tia_obj_service: "M-off",
34680
+ tia_obj_services: "R",
34681
+ tia_obj_set_attributes: "M-off",
34682
+ tia_offline: "GATE",
34683
+ tia_online: "GATE",
34684
+ tia_online_state: "R",
34685
+ tia_password_policy: "R",
34686
+ tia_password_policy_set: "M-off",
34687
+ tia_pg_interfaces: "R",
34688
+ tia_ping: "R",
34689
+ tia_plc_blocks: "R",
34690
+ tia_plc_tags: "R",
34691
+ tia_plc_types: "R",
34692
+ tia_plc_watchtables: "R",
34693
+ tia_plcs: "R",
34694
+ tia_project_archive: "M-off",
34695
+ tia_project_close: "M-off",
34696
+ tia_project_create: "M-off",
34697
+ tia_project_info: "R",
34698
+ tia_project_languages: "R",
34699
+ tia_project_save: "M-off",
34700
+ tia_project_saveas: "M-off",
34701
+ tia_projects: "R",
34702
+ tia_readiness: "R",
34703
+ tia_show_ui: "M-off",
34704
+ tia_source_put: "M-off",
34705
+ tia_spec_apply: "M-off",
34706
+ tia_spec_plan: "R",
34707
+ tia_spec_validate: "R",
34708
+ tia_start: "M-off",
34709
+ tia_status: "R",
34710
+ tia_subnet_create: "M-off",
34711
+ tia_subnets: "R",
34712
+ tia_tag_create: "M-off",
34713
+ tia_tag_delete: "M-off",
34714
+ tia_tagtable_create: "M-off",
34715
+ tia_type_delete: "M-off",
34716
+ tia_type_group_create: "M-off",
34717
+ tia_types_import: "M-off",
34718
+ tia_upload: "GATE",
34719
+ tia_watchtable_create: "M-off",
34720
+ tia_watchtable_delete: "M-off"
34721
+ },
34722
+ preapprovedEver: [
34723
+ "tia_catalog",
34724
+ "tia_certificate_template",
34725
+ "tia_certificates",
34726
+ "tia_connections_diagnose",
34727
+ "tia_device_connections",
34728
+ "tia_device_tree",
34729
+ "tia_devices",
34730
+ "tia_global_libraries",
34731
+ "tia_guide",
34732
+ "tia_hmi_screens",
34733
+ "tia_hmis",
34734
+ "tia_instances",
34735
+ "tia_job_status",
34736
+ "tia_library_mastercopies",
34737
+ "tia_library_types",
34738
+ "tia_local_sessions",
34739
+ "tia_obj_creationinfos",
34740
+ "tia_obj_get",
34741
+ "tia_obj_info",
34742
+ "tia_obj_items",
34743
+ "tia_obj_roots",
34744
+ "tia_obj_services",
34745
+ "tia_online_state",
34746
+ "tia_password_policy",
34747
+ "tia_pg_interfaces",
34748
+ "tia_ping",
34749
+ "tia_plc_blocks",
34750
+ "tia_plc_tags",
34751
+ "tia_plc_types",
34752
+ "tia_plc_watchtables",
34753
+ "tia_plcs",
34754
+ "tia_project_info",
34755
+ "tia_project_languages",
34756
+ "tia_projects",
34757
+ "tia_readiness",
34758
+ "tia_spec_plan",
34759
+ "tia_spec_validate",
34760
+ "tia_status",
34761
+ "tia_subnets"
34762
+ ]
34763
+ };
34764
+
34765
+ // src/toolClasses.ts
34766
+ var TOOL_CLASSES = tool_classes_default.classes;
34767
+ var PREAPPROVED_EVER = tool_classes_default.preapprovedEver;
34768
+ function classifyTools(server2) {
34769
+ const register = server2.registerTool.bind(server2);
34770
+ server2.registerTool = (name, config2, cb) => {
34771
+ const cls = TOOL_CLASSES[name];
34772
+ if (cls === void 0) throw new Error(`the tool ${name} has no class in src/tool-classes.json; classify it before registering it`);
34773
+ const annotations = { ...config2["annotations"] ?? {}, readOnlyHint: cls === "R" };
34774
+ return register(name, { ...config2, annotations }, cb);
34775
+ };
34776
+ }
34777
+
34587
34778
  // src/index.ts
34588
34779
  var server = new McpServer(
34589
- { name: "tia-openness", version: "1.8.2" },
34780
+ { name: "tia-openness", version: "1.9.1" },
34590
34781
  // Camada 1 (ambiente): o brief operacional viaja no handshake MCP — qualquer cliente
34591
34782
  // que honre `instructions` recebe gates/serial-only/pipeline sem instalar nada.
34592
34783
  { instructions: BRIEF }
34593
34784
  );
34785
+ classifyTools(server);
34594
34786
  registerDiagnosticTools(server);
34595
34787
  registerGuideTool(server);
34596
34788
  registerJobTools(server);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renanlido/tia-openness-mcp",
3
- "version": "1.8.2",
3
+ "version": "1.9.1",
4
4
  "description": "MCP server (stdio) — thin HTTP client over the TIA Openness `serve` API. Zero Openness/net48 references.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "git+https://github.com/renanlido/TIAOpenness.git",
18
+ "url": "git+https://github.com/Nextech-Digital-Solutions/TIAOpenness.git",
19
19
  "directory": "mcp"
20
20
  },
21
21
  "publishConfig": {
@@ -24,11 +24,13 @@
24
24
  "scripts": {
25
25
  "typecheck": "tsc --noEmit",
26
26
  "bundle": "node scripts/build.mjs",
27
- "sync": "node scripts/sync-guide.mjs",
27
+ "sync": "node scripts/sync-guide.mjs && node scripts/sync-agents.mjs",
28
28
  "build": "npm run typecheck && npm run bundle",
29
29
  "start": "node dist/index.js",
30
30
  "dev": "node --experimental-strip-types src/index.ts",
31
31
  "smoke": "node scripts/smoke.mjs",
32
+ "mcpb:stage": "node scripts/stage-mcpb.mjs",
33
+ "mcpb:verify": "node scripts/verify-mcpb-stage.mjs",
32
34
  "test": "vitest run",
33
35
  "coverage": "vitest run --coverage",
34
36
  "prepack": "npm run build",