{"_id":"@ao-barbosa/phi-server","_rev":"2-8ff35b22a99ce8efac17d038876dc12e","name":"@ao-barbosa/phi-server","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@ao-barbosa/phi-server","version":"1.0.0","keywords":["phi","server"],"author":{"name":"Earendil Works"},"license":"MIT","_id":"@ao-barbosa/phi-server@1.0.0","maintainers":[{"name":"ao-barbosa","email":"arthur_o.b@hotmail.com"}],"contributors":[{"url":"https://github.com/ao-Barbosa","name":"ao-Barbosa"}],"homepage":"https://github.com/ao-Barbosa/phi#readme","bugs":{"url":"https://github.com/ao-Barbosa/phi/issues"},"dist":{"shasum":"87bdd2180b05c5652fb97846d6d3573bfb3f8cb4","tarball":"https://registry.npmjs.org/@ao-barbosa/phi-server/-/phi-server-1.0.0.tgz","fileCount":67,"integrity":"sha512-64PJkD3fQGDVpZlHa7JPIS3PRmxIKLJ1C6Pywi0frOmf/D2NxOd+GcqVHxXHQS+bLTmM/YTqNywBtN8I0XSCxw==","signatures":[{"sig":"MEQCIBWfogT4GjvX1DvRCFTLHKZO6mVLDAudJMhxCqB5y9gVAiAWurQf6DG1ms01eJ2Wx+b1zODBNYEeApQe7vXZfaSRLw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":312538},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"bun":">=1.4.2"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./unix":{"types":"./dist/transports/unix/index.d.ts","import":"./dist/transports/unix/index.js"},"./testing":{"types":"./dist/testing/index.d.ts","import":"./dist/testing/index.js"}},"gitHead":"69be3c28c70d249af6bf11fe4d911198b5c70af4","scripts":{"dev":"tsgo -p tsconfig.build.json --watch --preserveWatchOutput","test":"bun test --isolate --preload ../../test-support/setup.ts --timeout 30000","build":"tsgo -p tsconfig.build.json","clean":"rm -rf dist","typecheck":"tsgo -p tsconfig.test.json","prepublishOnly":"bun run clean && bun run build"},"_npmUser":{"name":"ao-barbosa","email":"arthur_o.b@hotmail.com"},"repository":{"url":"git+https://github.com/ao-Barbosa/phi.git","type":"git","directory":"packages/server"},"_npmVersion":"11.17.0","description":"experimental server package for phi","directories":{},"_nodeVersion":"24.19.0","dependencies":{"@ao-barbosa/phi-chord":"^1.0.0","@ao-barbosa/phi-protocol":"^1.0.0","@ao-barbosa/phi-agent-core":"^1.0.0"},"_hasShrinkwrap":false,"packageManager":"bun@1.4.2","devDependencies":{"vitest":"4.1.9"},"_npmOperationalInternal":{"tmp":"tmp/phi-server_1.0.0_1788806512111_0.640354246080947","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"_id":"@ao-barbosa/phi-server@1.0.1","bugs":{"url":"https://github.com/ao-Barbosa/phi/issues"},"dist":{"shasum":"5bb86fcb2ede8556f349e3df07cc2d7ad34c5781","tarball":"https://registry.npmjs.org/@ao-barbosa/phi-server/-/phi-server-1.0.1.tgz","fileCount":67,"integrity":"sha512-OGMwjdl0julLPYEfBXjRbQnkrpx4SgSTneHif5e4RqKSynnvrg6acyKHskv5pDjVyrHWZl1LETERRlQNyu6ORQ==","signatures":[{"sig":"MEUCIQDakIWIYdJ8jK2gy9RBlOPAqbM/IL82e2O3I9XTJcJdVwIgQOYYjCaEILBP00IfYc+yDrz4W8jSzy6/UyeC3yprAMU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDoYMilpqei/IWJmY6XW+KCgdAxNtZeWYIiTqcr6uhFqwIhANDgCz/2lu5hEtynOfVVz+zG35I0NCBkPdBQvBf9tvG+"}],"unpackedSize":312562},"main":"./dist/index.js","name":"@ao-barbosa/phi-server","type":"module","types":"./dist/index.d.ts","author":{"name":"Mario Zechner"},"engines":{"bun":">=1.4.2"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./unix":{"types":"./dist/transports/unix/index.d.ts","import":"./dist/transports/unix/index.js"},"./testing":{"types":"./dist/testing/index.d.ts","import":"./dist/testing/index.js"}},"gitHead":"d4a3bef54ccdc2ab06cff573949ae42c8e28f068","license":"MIT","scripts":{"dev":"tsgo -p tsconfig.build.json --watch --preserveWatchOutput","test":"bun test --isolate --preload ../../test-support/setup.ts --timeout 30000","build":"tsgo -p tsconfig.build.json","clean":"rm -rf dist","typecheck":"tsgo -p tsconfig.test.json","prepublishOnly":"bun run clean && bun run build"},"version":"1.0.1","_npmUser":{"name":"ao-barbosa","email":"arthur_o.b@hotmail.com"},"homepage":"https://github.com/ao-Barbosa/phi#readme","keywords":["phi","server"],"repository":{"url":"git+https://github.com/ao-Barbosa/phi.git","type":"git","directory":"packages/server"},"_npmVersion":"11.17.0","description":"experimental server package for phi","directories":{},"maintainers":[{"name":"ao-barbosa","email":"arthur_o.b@hotmail.com"}],"_nodeVersion":"24.19.0","contributors":[{"url":"https://github.com/ao-Barbosa","name":"ao-Barbosa"}],"dependencies":{"@ao-barbosa/phi-chord":"^1.0.1","@ao-barbosa/phi-protocol":"^1.0.1","@ao-barbosa/phi-agent-core":"^1.0.1"},"_hasShrinkwrap":false,"packageManager":"bun@1.4.2","devDependencies":{"vitest":"4.1.9"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/phi-server_1.0.1_1789684953122_0.7579704195589811"}}},"time":{"created":"2026-09-07T18:41:51.906Z","modified":"2026-09-17T22:42:33.480Z","1.0.0":"2026-09-07T18:41:52.246Z","1.0.1":"2026-09-17T22:42:33.224Z"},"bugs":{"url":"https://github.com/ao-Barbosa/phi/issues"},"author":{"name":"Mario Zechner"},"license":"MIT","homepage":"https://github.com/ao-Barbosa/phi#readme","keywords":["phi","server"],"repository":{"url":"git+https://github.com/ao-Barbosa/phi.git","type":"git","directory":"packages/server"},"description":"experimental server package for phi","contributors":[{"url":"https://github.com/ao-Barbosa","name":"ao-Barbosa"}],"maintainers":[{"name":"ao-barbosa","email":"arthur_o.b@hotmail.com"}],"readme":"# @ao-Barbosa/phi-server\n\nExperimental local server for the new durable Session and Agent Harness interfaces.\n\nThe current slice supports server- and Session-scoped facet-service routing and multi-presentation attachment. `RoutedServerServiceHost.attachClient()` creates one connection-scoped server service endpoint with narrow attachment-management capabilities. `RoutedSessionHandle.attachClient()` returns a presentation-scoped Session capability. Its `invokeService()` forwards an opaque service/member envelope to the selected Session endpoint; the server validates the attachment route but does not load the facet contract.\n\n- server service calls and subscriptions route opaquely through the connection's `RoutedServerServiceAttachment`;\n- the application-owned `SessionDirectory` projects the private catalog into replicated presentation-safe state;\n- the application-owned `SessionManagement` creates, removes, attaches, and detaches Sessions without exposing route IDs in business results;\n- attachment changes are published out of band after the router installs or clears the live route;\n- Session service calls route through `invokeService` without server-side business-payload decoding;\n- service subscription updates remain scoped to the requesting attachment;\n- application observations such as transcripts route as ordinary service state without server-owned business schemas.\n\nA Session may have multiple presentation attachments. Repeating `attach` from one connection is idempotent; every successful attachment has a server-generated `attachmentId` delivered only as routing control data. Session requests carry `{ serverId, sessionId, attachmentId }`, and the server rejects stale or mismatched routes. Losing a connection rejects its local responses but releases its attachment only after admitted service calls settle. The host decides when zero presentation demand and worker-local Harness activity permit worker retirement. Server shutdown closes every routed Session handle, releasing its worker and Session writer ownership.\n\n```ts\nimport { randomUUID } from \"node:crypto\";\nimport { MemorySessionRepo, type Session } from \"@ao-Barbosa/phi-agent-core\";\nimport {\n  type RoutedServerServiceHost,\n  type RoutedSessionHandle,\n  type ServerHost,\n  SessionAmbiguousError,\n  SessionNotFoundError,\n} from \"@ao-Barbosa/phi-server\";\nimport { createUnixServer, getUnixSocketPath } from \"@ao-Barbosa/phi-server/unix\";\n\nasync function startServer(\n  serverServices: RoutedServerServiceHost,\n  openRoutedSession: (session: Session) => Promise<RoutedSessionHandle>,\n) {\n  const sessions = new MemorySessionRepo();\n  const host: ServerHost = {\n    serverServices,\n    async resolveSession(sessionId, context) {\n      const matches = (await sessions.list(undefined, context))\n        .filter((metadata) => metadata.id === sessionId);\n      if (matches.length === 0) {\n        throw new SessionNotFoundError(`Unknown session: ${sessionId}`);\n      }\n      if (matches.length > 1) throw new SessionAmbiguousError();\n      return matches[0];\n    },\n    async openSession(metadata, context) {\n      const session = await sessions.open(metadata, context);\n      try {\n        return await openRoutedSession(session);\n      } catch (error) {\n        try {\n          await session.close(context);\n        } catch (cleanupError) {\n          throw new AggregateError(\n            [error, cleanupError],\n            \"Harness creation and Session cleanup failed\",\n          );\n        }\n        throw error;\n      }\n    },\n  };\n\n  const serverId = randomUUID();\n  const server = createUnixServer(host, {\n    serverId,\n    path: getUnixSocketPath(serverId, \"/run/user/1000/phi\"),\n  });\n  await server.start();\n  return server;\n}\n```\n\nApplications supply a required server service host, a bounded Session resolver, and a routed Session factory. Session discovery and management are application-owned services; the protocol server only asks the resolver for metadata when routing an attachment. The host owns acquiring the worker-local Session and Harness. Failures are cleaned up in that worker. Neither an open JavaScript Session nor a Harness crosses the process boundary.\n\n`serverId` is a logical identity supplied by the launcher, not a socket address. The Unix preset requires an explicit physical `path`; `getUnixSocketPath()` derives one from a caller-selected directory. Choose a short, private runtime directory rather than deriving the route from an unbounded home-directory path. A long-lived launcher can reuse the same ID and path when replacing a server process.\n\n`Server` composes transports through `ServerListener`; peer authentication remains application policy and is not implemented by the experimental Unix transport. The Unix submodule provides `createUnixListener()` and `createUnixServer()`. Low-level routed-envelope validation, CBOR, and framing come from `@ao-Barbosa/phi-protocol`; Chord owns service-control parsing, error codes, snapshots and updates, and each subscription's replicated-state encoder.\n\nServer and worker lifecycle is managed outside the public Phi protocol. The replaceable application server converts connection attachments into private demand updates; the worker combines generation-tagged demand with authoritative Harness activity. The experimental coordinator only supplies stable routing and reports generic server-generation connection changes.\n","readmeFilename":"README.md"}