@phyzess/pappra 0.1.0-beta.1 → 0.1.0-beta.11

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 (50) hide show
  1. package/README.md +31 -12
  2. package/assets/integrations/skills/pappra/SKILL.md +7 -4
  3. package/assets/integrations/skills/pappra/references/hosts.md +21 -11
  4. package/assets/integrations/skills/pappra/references/lifecycle.md +4 -0
  5. package/assets/integrations/skills/pappra/references/operations.md +20 -7
  6. package/dist/app/collaboration.js +6 -13
  7. package/dist/app/doctor.js +26 -7
  8. package/dist/app/init.d.ts +28 -0
  9. package/dist/app/init.js +419 -88
  10. package/dist/cli/commands/docs.d.ts +1 -0
  11. package/dist/cli/commands/docs.js +104 -3
  12. package/dist/cli/commands/host.d.ts +5 -1
  13. package/dist/cli/commands/host.js +80 -6
  14. package/dist/cli/commands/init.d.ts +8 -0
  15. package/dist/cli/commands/init.js +186 -9
  16. package/dist/cli/commands/runtime.d.ts +14 -0
  17. package/dist/cli/commands/runtime.js +263 -0
  18. package/dist/cli/run.js +159 -7
  19. package/dist/code/service.js +14 -8
  20. package/dist/hosts/detect.d.ts +1 -0
  21. package/dist/hosts/detect.js +1 -1
  22. package/dist/hosts/integration/bundle-export.d.ts +24 -0
  23. package/dist/hosts/integration/bundle-export.js +128 -0
  24. package/dist/hosts/integration/bundle.d.ts +4 -1
  25. package/dist/hosts/integration/bundle.js +20 -2
  26. package/dist/hosts/integration/pappra-extension-runtime.mjs +24610 -0
  27. package/dist/hosts/integration/pappra-hook.mjs +24728 -0
  28. package/dist/hosts/integration/service.d.ts +8 -0
  29. package/dist/hosts/integration/service.js +71 -31
  30. package/dist/hosts/integration/support.d.ts +23 -0
  31. package/dist/hosts/integration/support.js +25 -0
  32. package/dist/hosts/integration/templates.d.ts +3 -3
  33. package/dist/hosts/integration/templates.js +15 -10
  34. package/dist/hosts/pi/rpc.d.ts +2 -0
  35. package/dist/hosts/pi/rpc.js +39 -1
  36. package/dist/hosts/pilot.d.ts +77 -77
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/install/runtime.d.ts +1 -1
  40. package/dist/install/runtime.js +117 -10
  41. package/dist/package-info.d.ts +2 -0
  42. package/dist/package-info.js +6 -0
  43. package/dist/schemas/host.js +4 -2
  44. package/dist/schemas/install.d.ts +14 -0
  45. package/dist/schemas/install.js +8 -0
  46. package/package.json +8 -2
  47. package/skills/pappra/SKILL.md +7 -4
  48. package/skills/pappra/references/hosts.md +21 -11
  49. package/skills/pappra/references/lifecycle.md +4 -0
  50. package/skills/pappra/references/operations.md +20 -7
package/README.md CHANGED
@@ -19,34 +19,53 @@ curl -fsSL https://raw.githubusercontent.com/phyzess/pappra/main/examples/minima
19
19
  # Preview first. JSON/config mode is non-interactive and does not prompt.
20
20
  npx @phyzess/pappra@beta init --config ./minimal-choices.json --json
21
21
 
22
- # Apply the same choices. With no runtime installed, apply intentionally
23
- # reports external-actions-pending and exits nonzero after writing config.
22
+ # Apply the same choices. Apply also installs and binds a durable runtime copy,
23
+ # so this converges with exit code 0; add --no-runtime to leave it pending.
24
24
  npx @phyzess/pappra@beta init --config ./minimal-choices.json --apply --json
25
25
  npx @phyzess/pappra@beta doctor --json
26
26
  ```
27
27
 
28
28
  `examples/minimal-choices.json` is complete for a host-free, no-graph, single-directory workspace. The example intentionally has no repositories or optional hosts.
29
29
 
30
- `init --json` without `--config` fails closed because JSON mode does not open the interactive wizard; run `npx @phyzess/pappra@beta init` without `--json` in a TTY if you want to enter selections interactively. `--config` and `--json` never prompt.
30
+ For a non-interactive derived setup, `npx @phyzess/pappra@beta init --yes --apply --json` derives repositories, knowledge sources, code engine, validation commands, excludes and hosts from discovery. `--print-choices` prints that `pappra/init-choices/1` document and writes nothing, and `init --json` without selections returns the discovery candidates plus the suggested document. JSON mode never prompts; only a TTY without selections opens the wizard.
31
31
 
32
32
  Development from a checkout works the same way: `pnpm install --frozen-lockfile`, `pnpm build`, then invoke `dist/cli/main.js` by absolute path from the target workspace.
33
33
 
34
- An apply result can be `ok:true` with `status:"external-actions-pending"` and a
35
- nonzero process exit. That is a successful, partial configuration write, not a
36
- claim that a runtime or external tool was installed. Inspect `pendingExternalActions`
37
- and run `doctor` before adding optional integrations.
34
+ `init --apply` also installs a durable runtime copy of the executing package under the
35
+ Pappra data directory and binds it in `machine.json`, so an npx/dlx bootstrap survives
36
+ cache eviction and the command converges with exit code `0`. Pass `--no-runtime` to leave
37
+ that action pending instead; the result is then `ok:true` with
38
+ `status:"external-actions-pending"` and a nonzero exit, which is a partial configuration
39
+ write rather than a claim that a runtime exists.
40
+
41
+ The runtime copy can be managed directly:
42
+
43
+ ```sh
44
+ npx @phyzess/pappra@beta runtime install --apply [--from self|tarball|registry]
45
+ npx @phyzess/pappra@beta runtime status --json
46
+ npx @phyzess/pappra@beta runtime verify --json
47
+ ```
48
+
49
+ A workspace that already has a valid `.pappra/workspace.json` is never rewritten silently.
50
+ `init --yes --reconfigure --apply` rebuilds it from discovery (for example to move the
51
+ recorded runtime version to the running package), backing the previous file up under
52
+ `.pappra/local/backups`. Apply also reports advisory `nextActions`: `pappra code prepare`
53
+ for a selected code engine and `pappra docs scan --apply` to register documents from the
54
+ configured knowledge sources.
38
55
 
39
56
  Optional examples have prerequisites rather than generated files: code-graph and
40
57
  host commands require the selected external CLI/support, and collaboration
41
- requires an explicit controller. They are not needed for the core workflow above.
58
+ requires an explicit controller. `--controller pi-rpc` is the host-directs/Pi-executes
59
+ path, verified end to end against Pi 1.3.0; see [Pi RPC collaboration](docs/pi-rpc.md).
60
+ They are not needed for the core workflow above.
42
61
 
43
62
  ## What it manages
44
63
 
45
64
  - **Workspace configuration:** `.pappra/workspace.json` and checkout-local `.pappra/local/machine.json`.
46
65
  - **Knowledge:** workspace and private document catalogs with explicit preview/apply operations.
47
66
  - **Continuity:** private task checkpoints and bounded advisory resume packets. Resume never grants execution by itself.
48
- - **Code intelligence:** status, explicit preparation and bounded query for selected repositories. Text/structure fallback is available when the optional graph engine is absent.
49
- - **Host integrations:** optional Pi, Codex and Claude Code adapters that merge Pappra-owned entries without taking over user configuration.
67
+ - **Code intelligence:** status, explicit preparation and bounded query for selected repositories. Text/structure fallback is available when the optional graph engine is absent. Registrations are stored under the workspace `.pappra/local/code`, never inside a repository checkout, so a multi-repository workspace does not turn its checkouts into nested workspaces.
68
+ - **Host integrations:** optional Pi, Codex and Claude Code adapters that merge Pappra-owned entries without taking over user configuration. Hooks are copied as a dependency-free bundle; Claude Code uses `${CLAUDE_PROJECT_DIR}` and Pi imports its runtime relatively, while Codex 0.163.0 loads hooks only from `$CODEX_HOME/hooks.json` (`host install --host codex --scope user`). `host bundle --marketplace` exports a marketplace that Claude Code and Codex accept without registering it. Plugin hooks are verified for Pi 1.3.0 and Claude Code 2.1.292 (startup) and unsupported for Codex, so `host install --mode plugin` fails closed with the per-host registration commands. See [host plugin validation](docs/host-plugin-validation.md).
50
69
  - **Bounded collaboration:** an optional, explicitly controlled one-request workflow. It is not a scheduler or daemon.
51
70
 
52
71
  ## Optional integrations and support
@@ -66,11 +85,11 @@ Host names and external protocol identifiers describe supported integration surf
66
85
  pnpm check
67
86
  ```
68
87
 
69
- The check runs the source policy, type checks, formatting, deterministic tests and a local package smoke test. The package smoke test uses an offline local tarball and an isolated fixture home/state; it does not install a model or contact a provider.
88
+ The check runs the source policy, type checks, formatting, deterministic tests and a local package smoke test. The package smoke test prefers an offline local tarball (falling back to registry resolution when the runner has no offline metadata) and an isolated fixture home/state; it does not install a model or contact a model provider.
70
89
 
71
90
  ## Status and limits
72
91
 
73
- Pappra is development software (`0.1.0-beta.1`) published as `@phyzess/pappra` under the `beta` dist-tag. Releases are published from GitHub Actions with npm trusted publishing (OIDC), so no npm token is stored in this repository. Pin either the moving `beta` tag or an exact version such as `@phyzess/pappra@0.1.0-beta.1`, because pre-release versions are never republished.
92
+ Pappra is development software (`0.1.0-beta.11`) published as `@phyzess/pappra` under the `beta` dist-tag. Releases are published from GitHub Actions with npm trusted publishing (OIDC), so no npm token is stored in this repository. Pin either the moving `beta` tag or an exact version such as `@phyzess/pappra@0.1.0-beta.11`, because pre-release versions are never republished.
74
93
 
75
94
  The deterministic suite covers synthetic workspaces, fixtures and local process boundaries. It does not establish real-model behavior, native host callability on every platform, CodeGraph completeness, Windows/Linux parity or production performance. A host adapter version pin is an observed support claim, not proof that a particular native installation will load or run correctly.
76
95
 
@@ -16,13 +16,16 @@ index, or new writer.
16
16
  2. Read `references/hosts.md` when the host surface is Pi, Codex, or Claude.
17
17
  3. Use `pappra checkpoint` / `pappra resume` for handoffs. A stored checkpoint
18
18
  is context, not permission to execute or to trust a previous session.
19
- 4. Use `pappra docs` and `pappra code` only for the workspace selected by the
20
- current root. Never infer a workspace from an unrelated session.
19
+ 4. Use `pappra docs`, `pappra code`, `pappra runtime` and `pappra host` only for
20
+ the workspace selected by the current root. Never infer a workspace from an
21
+ unrelated session. `pappra docs scan --apply` registers discovered documents;
22
+ `pappra runtime install --apply` keeps a durable copy of this package.
21
23
  5. For a new bounded collaboration request, build an explicit
22
24
  `pappra/collaboration-goal/1` from the user's objective and named choices,
23
25
  run `pappra collab prepare --goal <file> --domain-root <dir>`, admit against a fresh capability
24
- card, then use `pappra collab run` with the reviewed controller. Never turn
25
- prose into identity, approval, or capability claims.
26
+ card, then use `pappra collab run` with the reviewed controller. `--controller
27
+ pi-rpc` launches a real owned Pi session and is verified for Pi 1.3.0. Never
28
+ turn prose into identity, approval, or capability claims.
26
29
 
27
30
  ## One-request collaboration
28
31
 
@@ -2,29 +2,39 @@
2
2
 
3
3
  ## Pi
4
4
 
5
- The integration installs a project extension plus a copied `pappra` skill.
6
- Pi extensions run with host permissions. Load only a trusted copy from this
7
- workspace/target; the generated entrypoint imports the fixed Pappra runtime by
8
- absolute file URL and registers lifecycle handlers only.
5
+ The project integration installs an extension plus a copied `pappra` skill; the
6
+ generated entrypoint imports the fixed Pappra runtime by absolute file URL.
7
+ `pappra host bundle --host pi` exports a self-contained package instead: the
8
+ entry imports `./runtime.mjs` next to it, so the package survives a moved
9
+ checkout. Pi 1.3.0 was verified in a real session through the packaged extension
10
+ (`pi install <dir> -l -a` + `pi -p -a`).
9
11
 
10
12
  ## Codex
11
13
 
12
- The integration installs a command-hook entry and merges only Pappra-owned
13
- entries into `hooks.json`. Existing hooks and unrelated keys are preserved.
14
+ Codex 0.163.0 loads command hooks only from its user configuration directory.
15
+ Wire it with `pappra host install --host codex --scope user`, which merges only
16
+ Pappra-owned entries into `$CODEX_HOME/hooks.json` (existing hooks and unrelated
17
+ keys are preserved) and copies the bundled hook there. Project
18
+ `.codex/hooks.json` and plugin-bundle hooks are not loaded at this version.
14
19
  Codex hook definitions are trusted individually; installation is not trust.
15
20
  Observed 0.163.0 hook keys do not include a compact event, so compact and
16
21
  automatic checkpoint requests remain unsupported.
17
22
 
18
23
  ## Claude Code
19
24
 
20
- The integration installs a command-hook entry and merges only Pappra-owned
21
- entries into `settings.json`. `SessionStart` and `PostCompact` are distinct;
22
- matchers, trust, timeout, and output behavior remain host/version-specific.
23
- Installing a command is not proof it ran.
25
+ The project integration installs a command-hook entry and merges only
26
+ Pappra-owned entries into `settings.json`; the command uses
27
+ `${CLAUDE_PROJECT_DIR}`. `pappra host bundle --host claude --marketplace` exports
28
+ a plugin whose hook uses `${CLAUDE_PLUGIN_ROOT}`; the marketplace validates with
29
+ `claude plugin validate` and startup was verified in a real session. `SessionStart`
30
+ and `PostCompact` are distinct; matchers, trust, timeout, and output behavior
31
+ remain host/version-specific. Installing a command is not proof it ran.
24
32
 
25
33
  ## Common safety
26
34
 
27
35
  All surfaces use the event's canonical cwd/root, bounded stdin, a one-second
28
36
  local deadline, no transcript reads, no arbitrary configured commands, and no
29
37
  network/model/index/session side effects. Paths with spaces or Unicode are
30
- passed as argv/file URLs, never interpolated into a shell.
38
+ passed as argv/file URLs, never interpolated into a shell. Plugin registration is
39
+ host-specific; never claim a hook is loaded because files were written or a
40
+ validator passed.
@@ -14,6 +14,10 @@ Pappra distinguishes four local lifecycle intents:
14
14
  The matrix is version-specific. A host version outside the observed support
15
15
  range is `unsupported`/`unknown`, not a fallback to name similarity.
16
16
 
17
+ Codex 0.163.0 loads these hook keys only from its user configuration directory
18
+ (`$CODEX_HOME/hooks.json`); project `.codex/hooks.json` and plugin bundles are
19
+ not loaded by that version. Claude Code and Pi wire hooks in project scope.
20
+
17
21
  ## What a hook does
18
22
 
19
23
  A hook validates the host payload, resolves the current workspace from the
@@ -1,13 +1,26 @@
1
1
  # Operations reference
2
2
 
3
- - `pappra init` plans or applies workspace configuration.
3
+ - `pappra init` plans or applies workspace configuration. `--yes` derives
4
+ selections from discovery, `--print-choices` prints that document without
5
+ writing, `--reconfigure` rebuilds an existing valid `workspace.json`, and
6
+ `--no-runtime` leaves the durable runtime action pending.
7
+ - `pappra runtime <install|status|verify|remove>` manages the durable runtime
8
+ copy. `install --apply` defaults to `--from self`; writes require `--apply`.
4
9
  - `pappra doctor` is passive: it does not install hooks, start hosts, or fix
5
- state.
6
- - `pappra checkpoint` writes a task checkpoint; `pappra resume` reads a
7
- stored snapshot and reports whether execution is allowed.
8
- - `pappra docs` manages knowledge documents.
9
- - `pappra code` operates on an explicitly selected repository and keeps
10
- index mutations behind an explicit `--apply`.
10
+ state. `runtime verify` is the active runtime check.
11
+ - `pappra checkpoint` writes a task checkpoint; `pappra resume` reads a stored
12
+ snapshot and reports whether execution is allowed.
13
+ - `pappra docs <list|check|archive|scan>` manages the knowledge catalog.
14
+ `scan --apply` registers documents found under the configured sources.
15
+ - `pappra code` operates on an explicitly selected repository and keeps index
16
+ mutations behind an explicit `--apply`.
17
+ - `pappra host <detect|describe|plan|install|verify|bundle>` wires an optional
18
+ host. Codex 0.163.0 loads hooks only from `$CODEX_HOME/hooks.json`, so use
19
+ `install --host codex --scope user`; `bundle --marketplace` exports a plugin
20
+ directory without registering it, and `install --mode plugin` fails closed.
21
+ - `pappra collab <prepare|run|query>` runs one bounded collaboration request.
22
+ `run` requires `--controller fixture|pi-rpc`; `pi-rpc` launches a real Pi RPC
23
+ session.
11
24
 
12
25
  Preserve user bytes. If an operation reports a conflict or residual path,
13
26
  inspect that path and resolve ownership before retrying. Never delete an
@@ -461,17 +461,6 @@ function currentNativeResult(file, baseline) {
461
461
  return null;
462
462
  }
463
463
  }
464
- function regularFileSize(file) {
465
- if (file === null || !path.isAbsolute(file))
466
- return null;
467
- try {
468
- const observed = fs.lstatSync(file);
469
- return observed.isFile() ? observed.size : null;
470
- }
471
- catch {
472
- return null;
473
- }
474
- }
475
464
  function writeNewFile(file, bytes) {
476
465
  fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
477
466
  fs.writeFileSync(file, bytes, { flag: 'wx', mode: 0o600 });
@@ -1359,10 +1348,14 @@ export class PiRpcController {
1359
1348
  possible_start: stage === 'identity',
1360
1349
  };
1361
1350
  }
1362
- const nativeSessionFile = started.session.sessionFile();
1363
- const nativeSessionBaseline = regularFileSize(nativeSessionFile);
1351
+ let nativeSessionFile = null;
1352
+ let nativeSessionBaseline = 0;
1364
1353
  try {
1365
1354
  await started.session.prompt();
1355
+ // The handle sampled the baseline before it sent the prompt; read it afterwards so
1356
+ // both values describe the launch that just completed.
1357
+ nativeSessionFile = started.session.sessionFile();
1358
+ nativeSessionBaseline = started.session.promptBaseline();
1366
1359
  }
1367
1360
  catch (error) {
1368
1361
  await started.session.finish().catch(() => undefined);
@@ -259,7 +259,7 @@ function runtimeCheck(targetVersion, machineRuntime, passive, machinePath, obser
259
259
  source: machinePath ?? dataDir,
260
260
  observedAt,
261
261
  nextActions: [
262
- 'Run an explicit pappra init --apply --install-runtime with a chosen local tarball or exact version when authorized.',
262
+ 'Run pappra runtime install --apply (from self, tarball, or an exact version) or pappra init --apply when authorized.',
263
263
  ],
264
264
  });
265
265
  }
@@ -335,7 +335,7 @@ function runtimeCheck(targetVersion, machineRuntime, passive, machinePath, obser
335
335
  ]
336
336
  : [],
337
337
  nextActions: [
338
- 'Run an explicit pappra init --apply --install-runtime with a chosen local tarball or exact version when authorized.',
338
+ 'Run pappra runtime install --apply (from self, tarball, or an exact version) or pappra init --apply when authorized.',
339
339
  ],
340
340
  });
341
341
  }
@@ -886,14 +886,33 @@ export async function runDoctor(options = {}) {
886
886
  ],
887
887
  }));
888
888
  const selectedHosts = machine?.selectedHosts ?? [];
889
- const hostRootBase = root ?? homeDir;
889
+ // Passive observation only: a host install can target the private default root, a
890
+ // project directory, or Codex's user configuration directory.
891
+ const hostInstallRoots = (host) => {
892
+ const roots = [
893
+ join(root ?? homeDir, '.pappra', 'local', 'hosts', host),
894
+ join(root ?? homeDir, `.${host}`),
895
+ ];
896
+ if (host === 'codex') {
897
+ roots.push(process.env['CODEX_HOME'] ?? join(homeDir, '.codex'));
898
+ }
899
+ return roots;
900
+ };
890
901
  const installedHostBundle = (await Promise.all(selectedHosts.map(async (host) => {
891
- const path = join(hostRootBase, '.pappra', 'local', 'hosts', host, 'pappra-host.json');
892
- return (await observePath(path)).kind === 'file' ? path : null;
902
+ for (const base of hostInstallRoots(host)) {
903
+ const path = join(base, 'pappra-host.json');
904
+ if ((await observePath(path)).kind === 'file')
905
+ return path;
906
+ }
907
+ return null;
893
908
  }))).find((path) => path !== null) ?? null;
894
909
  const installedHostSkill = (await Promise.all(selectedHosts.map(async (host) => {
895
- const path = join(hostRootBase, '.pappra', 'local', 'hosts', host, 'skills', 'pappra', 'SKILL.md');
896
- return (await observePath(path)).kind === 'file' ? path : null;
910
+ for (const base of hostInstallRoots(host)) {
911
+ const path = join(base, 'skills', 'pappra', 'SKILL.md');
912
+ if ((await observePath(path)).kind === 'file')
913
+ return path;
914
+ }
915
+ return null;
897
916
  }))).find((path) => path !== null) ?? null;
898
917
  checks.push(...hostChecks(selectedHosts, homeDir, pathEnv, observedAt));
899
918
  checks.push(makeCheck({
@@ -14,6 +14,8 @@ export interface InitFailure {
14
14
  readonly message: string;
15
15
  readonly diagnostics: readonly Diagnostic[];
16
16
  readonly nextAction: string | null;
17
+ /** Machine-readable payload for callers that cannot prompt. */
18
+ readonly details?: Readonly<Record<string, unknown>>;
17
19
  }
18
20
  export interface InitRootResolution {
19
21
  readonly requestedRoot: string;
@@ -114,6 +116,8 @@ export interface PlanInitOptions {
114
116
  readonly root: string;
115
117
  readonly choices?: InitChoices | null;
116
118
  readonly runtimeVersion?: string;
119
+ /** Rebuilds workspace.json from selections even when a valid config exists. */
120
+ readonly reconfigure?: boolean;
117
121
  readonly planId?: string;
118
122
  readonly discoveredAt?: string;
119
123
  /** Reuse an immediately preceding inspectInitContext result. */
@@ -130,6 +134,30 @@ export declare function inspectInitContext(rootPath: string): Promise<InitContex
130
134
  export declare function listRepositoryCandidates(discovery: WorkspaceDiscovery): readonly RepositoryCandidate[];
131
135
  /** Lists knowledge source choices derived only from current discovery. */
132
136
  export declare function listKnowledgeCandidates(discovery: WorkspaceDiscovery): readonly KnowledgeCandidate[];
137
+ export interface InitChoiceRule {
138
+ readonly field: string;
139
+ readonly value: string;
140
+ readonly reason: string;
141
+ }
142
+ export interface InitChoiceCandidates {
143
+ readonly repositories: readonly string[];
144
+ readonly knowledge: readonly string[];
145
+ readonly validation: readonly string[];
146
+ readonly hosts: readonly string[];
147
+ }
148
+ export interface DerivedInitChoices {
149
+ readonly choices: InitChoices;
150
+ readonly rules: readonly InitChoiceRule[];
151
+ readonly candidates: InitChoiceCandidates;
152
+ }
153
+ /**
154
+ * Derives deterministic init selections from discovery alone. Every value is
155
+ * reported with the rule that produced it so a caller can audit the choice
156
+ * before applying it; nothing here writes, installs or prompts.
157
+ */
158
+ export declare function deriveInitChoices(discovery: WorkspaceDiscovery, options?: {
159
+ readonly pathEnv?: string;
160
+ }): Promise<DerivedInitChoices>;
133
161
  /**
134
162
  * Produces a strict plan and exact in-memory writes. No target file is created
135
163
  * or modified by this function.