{"record":{"id":"5d02bcb55a37dc28","repo":"Hmbown/CodeWhale","slug":"reserved-id","errorCode":"reserved_id","errorMessage":"\"local\" is reserved for this machine","messagePattern":"\"local\" is reserved for this machine","errorType":"validation","errorClass":"RegistryError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/registry.mjs","lineNumber":84,"sourceCode":"export function active() { return get(list().active); }\n\n/** Switch the active computer. Returns the computer entry. */\nexport function switchTo(id) {\n  const c = get(id); // throws unknown_computer\n  const reg = load();\n  reg.active = c.id;\n  save(reg);\n  return c;\n}\n\n/** Register or update a computer. Returns the entry. */\nexport function register({ id, transport, label, ...rest }) {\n  if (!id || !ID_RE.test(id)) throw new RegistryError(\"invalid_id\", \"computer id must match \" + ID_RE);\n  if (![\"local\", \"ssh\", \"hdc\", \"docker\"].includes(transport)) {\n    throw new RegistryError(\"invalid_transport\", \"transport must be one of: local, ssh, hdc, docker\");\n  }\n  if (id === \"local\" && transport !== \"local\") {\n    throw new RegistryError(\"reserved_id\", '\"local\" is reserved for this machine');\n  }\n  if (transport === \"ssh\") {\n    if (!rest.host || !/^[A-Za-z0-9._-]+$/.test(rest.host)) {\n      throw new RegistryError(\"invalid_host\", \"ssh computers need a valid host (letters, digits, dot, dash, underscore)\");\n    }\n    if (rest.port != null && (!Number.isInteger(rest.port) || rest.port < 1 || rest.port > 65535)) {\n      throw new RegistryError(\"invalid_port\", \"port must be an integer in 1..65535\");\n    }\n    if (rest.user != null && !/^[a-zA-Z0-9._-]+$/.test(rest.user)) {\n      throw new RegistryError(\"invalid_user\", \"user must be a plain name\");\n    }\n  }\n  if (transport === \"hdc\") {\n    if (rest.target != null && !/^[A-Za-z0-9._-]*$/.test(rest.target)) {\n      throw new RegistryError(\"invalid_target\", \"hdc target key contains invalid characters\");\n    }\n    rest.platform = \"harmonyos\";\n  }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/registry.mjs#L66-L102","documentation":"RegistryError \"reserved_id\": the id \"local\" always refers to the machine the plugin runs on, so register() rejects registering \"local\" with a transport other than \"local\", and remove() refuses to delete it. This keeps the implicit local computer usable as the default active target. It is a semantic rule on top of the ID_RE format check.","triggerScenarios":"register({ id: \"local\", transport: \"ssh\", host: \"...\" }) — shadowing the built-in local entry with a remote transport; remove(\"local\") — attempting to delete the built-in entry.","commonSituations":"Script that registers every machine in an inventory list which happens to include the controller itself named \"local\"; cleanup script trying to reset the registry by deleting all entries including \"local\".","solutions":["For a remote machine, pick a different id (e.g. \"remote-local\", the actual hostname slug).","If you truly mean this machine, omit the entry entirely — \"local\" is registered implicitly with transport \"local\".","Skip id \"local\" in bulk remove/registration loops; treat it as a reserved constant.","To reset the active computer, set active to another registered id rather than removing \"local\"."],"exampleFix":"// before\nremove(\"local\"); // reset registry\n// after\nfor (const id of Object.keys(load().computers)) {\n  if (id !== \"local\") remove(id);\n}","handlingStrategy":"validation","validationCode":"if (id === \"local\" && transport !== \"local\") throw new Error('\"local\" is reserved; pick another id');\nif (action === \"remove\" && id === \"local\") throw new Error('\"local\" cannot be removed');","typeGuard":"const isReservedId = (id) => id === \"local\";","tryCatchPattern":"try {\n  remove(id);\n} catch (e) {\n  if (e?.code === \"reserved_id\") console.warn('\"local\" is a builtin and stays registered');\n  else throw e;\n}","preventionTips":["Filter out \"local\" in bulk register/remove loops","Treat \"local\" as a reserved constant across the codebase","Never name remote machines \"local\"","Use explicit/active-selection APIs instead of deleting the builtin"],"tags":["reserved-identifier","registry","javascript","validation"],"backgroundTag":"invalid-identifier","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}