@peer2peer/ext-ix 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -4
- package/SPEC.md +94 -4
- package/dist/extension.d.ts +17 -3
- package/dist/extension.js +77 -14
- package/dist/footprint-command.d.ts +1 -1
- package/dist/footprint-command.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/ix.d.ts +138 -0
- package/dist/ix.js +354 -10
- package/dist/listener.d.ts +48 -0
- package/dist/listener.js +203 -0
- package/dist/memory.d.ts +50 -0
- package/dist/memory.js +315 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,21 +8,25 @@ Share what your Ix graph knows with the agent sessions you work with:
|
|
|
8
8
|
- **Footprints** (`x:ix.footprint`, a state kind): this session's footprint from your local Ix, per agent: the symbols changed (from `git diff` hunks), the code one hop downstream (ring 1; ring 2 optional) and the regions involved. Published to the session's status audience only, kept by peers as the session's latest value, never an event and never shown to a model. File, symbol and region names are hashed by default for every audience, and overlaps still work (both sides derive the same key from the repository); readable names are opt-in per circle with `p2p ix config --circle <cid> names=plain` (SPEC §8.6 says exactly what hashing hides and what it doesn't).
|
|
9
9
|
- **Semantic conflicts**: two live sessions whose changes touch *connected* files (per your Ix graph), not just the same file.
|
|
10
10
|
|
|
11
|
-
A peer without this extension sees a one-line fallback, such as "alice@…: shared an Ix subgraph (auth/*): install Ix to open it". The kinds are specified in [SPEC.md](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.
|
|
11
|
+
A peer without this extension sees a one-line fallback, such as "alice@…: shared an Ix subgraph (auth/*): install Ix to open it". The kinds are specified in [SPEC.md](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.1/packages/ext-ix/SPEC.md).
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
15
|
```
|
|
16
16
|
npm i -g @peer2peer/cli @peer2peer/ext-ix # side by side: p2p can find it
|
|
17
17
|
p2p extensions enable ix # opt in (writes config.json; or P2P_EXTENSIONS=ix)
|
|
18
|
-
p2p extensions # → @peer2peer/ext-ix 0.1.
|
|
18
|
+
p2p extensions # → @peer2peer/ext-ix 0.1.1 (x:ix.*)
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
**Trust:** an extension runs inside `p2p` with your identity (it can read `~/.p2p` and your keys). Enable it only if you trust where it came from. `p2p` announces the first load from each new location.
|
|
22
22
|
|
|
23
|
-
Ix itself comes from https://github.com/ix-infrastructure/Ix. Previewing what peers send needs only this package. Sending an impact report, resolving a reference, importing a note and conflict detection run your local `ix`. Notes use `ix note
|
|
23
|
+
Ix itself comes from https://github.com/ix-infrastructure/Ix. Previewing what peers send needs only this package. Sending an impact report, resolving a reference, importing a note and conflict detection run your local `ix`. Notes use `ix note`. ext-ix runs it only against your **local** graph, and only when it is the open-source one (Ix after 0.13.0, without Ix Pro), which writes to the local backend. With Ix Pro installed, its `ix note` writes to your cloud org, so `import` and `note --ix-note` answer `graph_target`. With an older Ix, they answer `graph_target` too, and say to upgrade.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
**Graph memory:** with an open-source `ix note`, `p2p watch` writes your own sessions in shared projects into your local graph as they run: a session record, status lines and the files edited, framed as untrusted records. It writes only to a port your own process holds. **Docker on Linux:** `ix docker start` publishes the port through Docker's proxy, which runs as root, so p2p refuses it until you set `"ixTrustRootListener": true` in p2p's config.json by hand. Do that only if this machine's Docker is yours alone. On a machine other people log in to, turn graph memory off. Background writes also move Ix's `-` shorthand (the last note or session you showed or created, `<IX_HOME>/recent.json`) to graph memory's latest, so after a few seconds `ix note show -` may name a Peer2Peer record instead of your own last note. It never writes peers' content or message bodies, and it runs off the hook path, best effort. `"ixMemory": false` in config.json turns it off. See [SPEC.md §10](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.1/packages/ext-ix/SPEC.md#10-graph-memory-the-users-own-sessions-in-the-local-graph).
|
|
26
|
+
|
|
27
|
+
**Graph targets:** every `ix` call takes its endpoint only from `p2p`'s chokepoint (`ExtContext.graphTarget`): a private project, or a session bound to one, is local only. `ix` runs with an allowlisted environment and `IX_ENDPOINT` pinned to that target, so an `IX_ENDPOINT`, `IX_PAT` or Ix Pro login in your shell never sends a private project to the cloud. See [SPEC.md §2.1](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.1/packages/ext-ix/SPEC.md#21-graph-targets).
|
|
28
|
+
|
|
29
|
+
You can also point `P2P_EXTENSION_PATH` at a directory whose `node_modules` holds it. Nothing else is searched: no parent directories, `NODE_PATH` or global folders. How `p2p` loads extensions is described in [packages/p2p/README.md](https://github.com/ix-infrastructure/Peer2Peer/blob/v0.1.1/packages/p2p/README.md#extensions).
|
|
26
30
|
|
|
27
31
|
## Commands
|
|
28
32
|
|
package/SPEC.md
CHANGED
|
@@ -73,7 +73,8 @@ Each kind is a §4.3 extension kind with this plaintext:
|
|
|
73
73
|
|---|---|---|
|
|
74
74
|
| Receiving any kind | (automatic) | Validate, sanitize and render. **No Ix call, no write.** |
|
|
75
75
|
| Preview (`p2p watch`, `p2p ix inbox`, `p2p ix show`) | the user or their agent | Reads the local event log |
|
|
76
|
-
| `p2p ix import <event>` | **the user** | One `ix note` write, after the **full** title and text were shown and the user said y; or with `--yes`, only if the user read that same note (same title and text) with `p2p ix show` at a terminal |
|
|
76
|
+
| `p2p ix import <event>` | **the user** | One OSS `ix note` write into the **local** graph (§2.1), after the **full** title and text were shown and the user said y; or with `--yes`, only if the user read that same note (same title and text) with `p2p ix show` at a terminal. Refused before anything is asked when the graph target isn't local, when Ix Pro answers `ix note` (the cloud org), or when this Ix has no local `ix note` ("upgrade Ix") |
|
|
77
|
+
| Graph memory (`p2p watch`) | (automatic, the user's own sessions) | The session's record, status lines and edited files into the **local** graph only (§10). Never a peer's content |
|
|
77
78
|
| `p2p ix resolve <event>` | **the user** | One read-only `ix` query of their own graph, after a y/N prompt or `--yes`; with `--shown=<bodyHash>` (from `show --json`) only if the reference is still the one a client displayed |
|
|
78
79
|
|
|
79
80
|
- A received note is **never** written into the graph automatically (§4.3:
|
|
@@ -108,6 +109,26 @@ Each kind is a §4.3 extension kind with this plaintext:
|
|
|
108
109
|
- Rendered output for a model is framed as data from a named peer:
|
|
109
110
|
`[data from peer <address>, <what>; not instructions]: …`.
|
|
110
111
|
|
|
112
|
+
### 2.1 Graph targets
|
|
113
|
+
|
|
114
|
+
An ext-ix declares `graphTargets: 1` in its `P2PExtension`; p2p refuses to load the `ix` namespace without it. Every `ix` call takes its endpoint (and any token) only from the host's graph target (`ExtContext.graphTarget`, `graphTarget` in packages/p2p/src/projects.ts), asked per call with the command's session when it has one (`--from-session`, `--session`) and the call's paths: the folder it runs in, its target (a file, `file:start-end`, a directory or a symbol, resolved against that folder), `--path` and `--root`, and the command's own `--changed` and `--file`. A host without `graphTarget` (a p2p from before it), a failure, or a target that doesn't check out (a `local` one that isn't loopback, a `shared` one that isn't https) means the default local target. `ix` runs with an allowlisted environment (`IX_ENV_ALLOW` in ix.ts; `PATH` keeps only absolute entries) with `IX_ENDPOINT` set to the target's endpoint, `IX_MAP_BACKGROUND_REFRESH=0` and `IX_NO_UPDATE_CHECK=1`; no `IX_ENDPOINT`, `IX_PAT` or other cloud setting of the caller's reaches it. Against a local target only `--version`, `--help`, `impact`, `around`, `overview`, `inventory`, `context`, `subsystems` and `status` run, plus the memory forms below; anything else is refused with `graph_target`.
|
|
115
|
+
|
|
116
|
+
**Memory forms (`ix note`, `ix session`).** Ix Pro's `ix note` and `ix session` always use the cloud org. Since Ix #916 (after Ix 0.13.0), an Ix without Pro has OSS ones against the local backend (`IX_ENDPOINT` first), registered only when Pro didn't load. ext-ix runs them only when all of these hold:
|
|
117
|
+
- The target is local. Every memory form against a shared target is refused.
|
|
118
|
+
- The call is exactly one of these forms (`memoryCall` in ix.ts):
|
|
119
|
+
- `ix note --json show <id>`;
|
|
120
|
+
- `ix note --tag=<t> [--session=<ref>] [--actor=p2p[:<address>]] --json`, with the text on stdin;
|
|
121
|
+
- `ix session --json create p2p-<sid> --purpose=<one line, ≤200> --actor=p2p[:<address>] --ttl=<1-8760>`.
|
|
122
|
+
|
|
123
|
+
It has no positional text, no other flag or subcommand, and no flag twice.
|
|
124
|
+
- `ix --help` shows the OSS commands, asked once per command or batch (`memorySupport`). With Pro loaded, the help has a "Pro:" section and no "Memory:" one; an Ix before #916 has neither. Both are refused before any write: Pro with "Ix Pro is installed … cloud org", the older Ix with "upgrade Ix". This is a capability check, never a trial write.
|
|
125
|
+
- The target's port is held only by this user's process, on every loopback or wildcard address (listener.ts: `/proc/net/tcp{,6}` on Linux; `netstat -an` matched by `lsof` on macOS). A root-owned listener counts only when the host's local target carries `trustRootListener` (the person's `ixTrustRootListener: true` in config.json). Docker's port proxy on Linux is root's. This is checked before every write, and once per command for a read. Otherwise the call fails with `ix_listener`, and so does any other platform.
|
|
126
|
+
- `ix --help` is asked again right before every `ix session create`.
|
|
127
|
+
- After a write, stderr says `→ local backend <the target's endpoint>`, as the OSS commands print it. Otherwise the call fails with `ix_unconfirmed`, **whatever the exit code**.
|
|
128
|
+
- `ix session --json show <ref>` (a read) is also allowed: graph memory uses it to check that a remembered session still exists.
|
|
129
|
+
|
|
130
|
+
So `p2p ix import` and `p2p ix note --ix-note` work against the local graph with an OSS `ix note`, and stay refused with Ix Pro or an older Ix. The threat model ("Graph targets") says why.
|
|
131
|
+
|
|
111
132
|
## 3. `x:ix.note`: a shared Ix session note
|
|
112
133
|
|
|
113
134
|
**Body (v1):**
|
|
@@ -263,8 +284,10 @@ shared an Ix blast-radius report (<level> risk, <n> affected): install Ix to ope
|
|
|
263
284
|
| `ix overview <file> --format json` | footprint: the coarse fallback | `{keyItems?[{name,kind}], childrenByKind?, …}` |
|
|
264
285
|
| `ix impact <t> --format json` | `p2p ix impact` | **leaf shape:** `{resolvedTarget:{kind,name}, graph?, depth, systemPath?, riskSummary, riskLevel, riskCategory, atRiskBehavior[], nextStep?, summary:{callers,callees}, callerList?[{kind,name}], calleeList?, propagationBuckets?[{region,regionKind,count,members[]}], decisions?, tasks?, bugs?}`. **Container shape:** the same with `summary:{members,directImporters,directDependents,memberLevelCallers}` and `topImpactedMembers?[{name,kind,id,callerCount,path,lineStart,lineEnd}]`. An unresolved target prints `{error, message}`. |
|
|
265
286
|
| `ix around <path> --format json --limit 20` | semantic conflicts | `{path, symbols:[{name,kind,path,callers:{total,rows:[{path,line?,name?}]}, users:{…}, tests:{…}}], importers:{total,rows:[{path,line?}],tests}}`. Paths are workspace-relative. |
|
|
287
|
+
| `ix --help` | which `ix note` / `ix session` answer (§2.1) | text: a `Memory:` heading followed by indented `note …` and `session …` lines means the OSS commands (Pro not loaded); a `Pro:` heading means Ix Pro's |
|
|
266
288
|
| `ix note --json show <id>` | `p2p ix note --ix-note` | `{id, text, tag, actor?, nodeIds, at, stale, sessionName?, …}` |
|
|
267
|
-
| `ix note --tag=… [--session=…] [--actor=…] --json` (text on stdin) | `p2p ix import
|
|
289
|
+
| `ix note --tag=… [--session=…] [--actor=…] --json` (text on stdin) | `p2p ix import`, graph memory | `{id, text, tag, nodeIds, at, stale}` on stdout; `→ local backend <endpoint>` on stderr |
|
|
290
|
+
| `ix session --json create <name> --purpose=… --actor=… --ttl=…` | graph memory | `{sessionId, name, purpose, actor, actors, ttlHours, createdAt, lastLoadedAt}` on stdout; `→ local backend <endpoint>` on stderr |
|
|
268
291
|
| `ix overview` / `inventory` / `context` / `subsystems … --format llm` | `p2p ix resolve` | text, passed through (capped). `subsystems --target` is sent to the Ix backend as a region-name query (`getSubsystemMap({target})`), not opened as a path; names with `..`, `.` or empty segments are refused anyway. |
|
|
269
292
|
|
|
270
293
|
`ix` and `git` are resolved to absolute paths from PATH's absolute entries before
|
|
@@ -272,8 +295,9 @@ they run with the repository as their working directory, so a program planted in
|
|
|
272
295
|
a cloned repo (Windows searches the current directory first) never runs.
|
|
273
296
|
|
|
274
297
|
The CLI prints plugin warnings (`ix: failed to load …`) on stderr, and they
|
|
275
|
-
are ignored. `ix note` and `ix session` come from the Ix Pro plugin
|
|
276
|
-
|
|
298
|
+
are ignored. `ix note` and `ix session` come from the Ix Pro plugin when
|
|
299
|
+
it is installed (cloud), and from open-source Ix after 0.13.0 otherwise
|
|
300
|
+
(the local backend; §2.1); `impact`, `around`, `overview`, `inventory`,
|
|
277
301
|
`context` and `subsystems` are open-source Ix.
|
|
278
302
|
|
|
279
303
|
## 7. Semantic conflicts
|
|
@@ -693,3 +717,69 @@ per peer user and three in all per 10 minutes. Only these derived lines are
|
|
|
693
717
|
read: a peer's footprint body never reaches the model. The mod's standing
|
|
694
718
|
instruction tells the model not to name anything to the peer when a line
|
|
695
719
|
says `(hashed: names stay private)`, only to ask whether to sync.
|
|
720
|
+
|
|
721
|
+
## 10. Graph memory: the user's own sessions in the local graph
|
|
722
|
+
|
|
723
|
+
`P2PExtension.memory` is optional in the extension API (v1). An older
|
|
724
|
+
ext-ix has none, and an older p2p never asks. It has two calls:
|
|
725
|
+
`available(ctx)` and `write(ctx, {sid, items})`.
|
|
726
|
+
|
|
727
|
+
The host (packages/p2p/src/graph-memory.ts) gathers the items in
|
|
728
|
+
`p2p watch`, from the statuses this device posted for its own sessions,
|
|
729
|
+
**only for sessions whose project ceiling is shared**. A private, unmapped,
|
|
730
|
+
`.p2p-private` or unbound session is never gathered.
|
|
731
|
+
They are never a peer's, another device's or a message's. It queues them
|
|
732
|
+
(at most 64; `p2p doctor` counts drops) and hands them over in batches of
|
|
733
|
+
one session each, off the hook path. Before each batch it checks that the
|
|
734
|
+
session's graph target is local. A batch for a shared target is dropped as
|
|
735
|
+
`not_local` and never handed over.
|
|
736
|
+
|
|
737
|
+
| item | written as |
|
|
738
|
+
|---|---|
|
|
739
|
+
| `start` (label, repo, branch) | once per session: `ix session --json create p2p-<sid> --purpose="Peer2Peer session <label> (repo <r>, branch <b>)" --actor=p2p:<address> --ttl=720`, then a note `Session started <ISO>: …` |
|
|
740
|
+
| `status` (summary) | a note `Status (<ISO>): <line>` |
|
|
741
|
+
| `files` (repo-relative paths new since the last batch) | a note `Edited (<ISO>): a, b, …` (at most 50 named) |
|
|
742
|
+
| `end` | a note `Session ended <ISO>.` |
|
|
743
|
+
|
|
744
|
+
Each note is `ix note --tag=finding --session=<the record's id> --actor=… --json`,
|
|
745
|
+
with the text on stdin. The text's first line is `Recorded by Peer2Peer
|
|
746
|
+
(agent-generated, untrusted)`. A file name is dropped if it has whitespace
|
|
747
|
+
or a control character, or is longer than 200 characters. It runs through the guarded runner (§2.1), so the
|
|
748
|
+
target must be local, the call must be one of the exact forms, Ix must
|
|
749
|
+
answer with the OSS commands, and stderr must confirm the local backend.
|
|
750
|
+
Text is one line, with control and format characters removed, and capped.
|
|
751
|
+
A path that isn't repo-relative is dropped. The extension's store
|
|
752
|
+
(`memory`) keeps the Ix session id of each Peer2Peer session, for the
|
|
753
|
+
newest 50, with the endpoint it was created at. In a new batch, a remembered
|
|
754
|
+
id is checked once with `ix session --json show` and made again if it is
|
|
755
|
+
gone or belongs to another endpoint. The host leases each session to one
|
|
756
|
+
drain at a time, across processes, under its state lock, so a record is
|
|
757
|
+
never created twice.
|
|
758
|
+
|
|
759
|
+
`write` gets an `AbortSignal`. When the host's deadline for the batch
|
|
760
|
+
passes, it aborts. The writer checks the signal before every write and
|
|
761
|
+
writes nothing after it fires. The host then waits at most 30 s for the
|
|
762
|
+
writer to settle. If it doesn't, the host gives up on it, keeps that
|
|
763
|
+
session's lease until the lease expires, and counts the items as `timeout`.
|
|
764
|
+
Before handing over each session's batch, the host checks again that the
|
|
765
|
+
session's ceiling is still shared, and drops the batch as `not_shared` if
|
|
766
|
+
not. The extension's store is MACed with `localMac` when the host offers
|
|
767
|
+
it, and a store that doesn't verify counts as empty.
|
|
768
|
+
|
|
769
|
+
`p2p ix note --ix-note <id> --from-session B` refuses a record of another
|
|
770
|
+
session A (`not_shared`), unless `ExtContext.mayShareSessionContext(A, B)`
|
|
771
|
+
says yes. That needs both ceilings shared, B's audience within A's, and the
|
|
772
|
+
same graph target. A record is recognised by its Ix session (one in the
|
|
773
|
+
store, or a `p2p-<sid>` name) or by its first line. One whose session can't
|
|
774
|
+
be traced back, or any record on a host without that call, is refused.
|
|
775
|
+
|
|
776
|
+
`available` answers `{ok: true}` only for an Ix with the OSS `ix note`
|
|
777
|
+
and a port held by this user. Otherwise it answers `ix_missing`, `ix_pro`
|
|
778
|
+
(Ix Pro answers: the cloud), `ix_upgrade` (an Ix before #916) or
|
|
779
|
+
`ix_listener`. The host then gathers nothing, and asks
|
|
780
|
+
again every 5 minutes. A write the guard refuses (`graph_target`), or one
|
|
781
|
+
that doesn't confirm the local backend (`ix_unconfirmed`), stops the batch
|
|
782
|
+
and reports `unavailable` the same way.
|
|
783
|
+
|
|
784
|
+
Message bodies are never written. A note a peer shares reaches the graph
|
|
785
|
+
only when the user imports it (`p2p ix import`), as before.
|
package/dist/extension.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ExtCommand, ExtContext, ExtReceived, ExtReceiveInput, P2PExtension } from "@peer2peer/cli";
|
|
2
|
-
import { type IxRunner } from "./ix.js";
|
|
2
|
+
import { type IxRunner, type TargetFn } from "./ix.js";
|
|
3
|
+
import { type ListenerCheck } from "./listener.js";
|
|
3
4
|
import { type NoteBody } from "./note.js";
|
|
4
5
|
import { type RepoRef } from "./repo.js";
|
|
5
|
-
export declare const VERSION = "0.1.
|
|
6
|
+
export declare const VERSION = "0.1.1";
|
|
6
7
|
export declare const KINDS: readonly ["x:ix.note", "x:ix.subgraph", "x:ix.impact"];
|
|
7
8
|
/** Cap on local Ix output a command hands back (resolve). */
|
|
8
9
|
export declare const MAX_RESOLVE_OUTPUT: number;
|
|
@@ -15,8 +16,21 @@ export interface Deps {
|
|
|
15
16
|
ix?: (ctx: ExtContext) => IxRunner;
|
|
16
17
|
/** The clock (footprint debounce and timestamps). */
|
|
17
18
|
now?: () => number;
|
|
19
|
+
/** Who listens on the local endpoint's port (listener.ts); tests stand in for the operating system. */
|
|
20
|
+
listener?: ListenerCheck;
|
|
18
21
|
}
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The graph target of a call (packages/p2p/src/projects.ts graphTarget, through ExtContext): the
|
|
24
|
+
* only place an `ix` endpoint comes from. A p2p from before graph targets has none to give: local.
|
|
25
|
+
* Any failure is local too.
|
|
26
|
+
*/
|
|
27
|
+
export declare function targetOf(ctx: ExtContext, sid?: string, extra?: readonly string[]): TargetFn;
|
|
28
|
+
/**
|
|
29
|
+
* The `ix` a command runs: each call pinned to the graph target of session `sid` (when the command
|
|
30
|
+
* has one), its folders, the paths the call names (callPaths) and `extra` (the command's own path
|
|
31
|
+
* arguments: --changed, --file), and limited to the commands that target allows.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runner(ctx: ExtContext, deps: Deps, sid?: string, extra?: readonly string[]): IxRunner;
|
|
20
34
|
export interface Here {
|
|
21
35
|
/** git's spelling of the root (local only, never sent). */
|
|
22
36
|
root?: string;
|
package/dist/extension.js
CHANGED
|
@@ -22,12 +22,14 @@ import { audienceOf } from "./overlap-command.js";
|
|
|
22
22
|
import { FOOTPRINT_KIND, FOOTPRINT_TTL, parseFootprintBody } from "./footprint.js";
|
|
23
23
|
import { footprintCommands } from "./footprint-command.js";
|
|
24
24
|
import { buildImpact, IMPACT_KIND, impactFallback, parseImpactBody, renderImpact } from "./impact.js";
|
|
25
|
-
import { ixAvailable, ixJson, ixRunner } from "./ix.js";
|
|
25
|
+
import { callPaths, checkedTarget, guardRunner, refuseForTarget, ixAvailable, ixJson, ixRunner, IX_NOTE_ID_RE, localTarget, memoryRefusal, memorySupport } from "./ix.js";
|
|
26
|
+
import { ixMemory, recordOf } from "./memory.js";
|
|
27
|
+
import { checkLoopbackListener } from "./listener.js";
|
|
26
28
|
import { buildNote, NOTE_KIND, parseNoteBody, renderNote } from "./note.js";
|
|
27
29
|
import { compareRepo, localRepo, normalizeRemote } from "./repo.js";
|
|
28
30
|
import { buildSubgraph, describeSelector, parseSubgraphBody, renderSubgraph, resolveArgv, SUBGRAPH_KIND } from "./subgraph.js";
|
|
29
31
|
import { frame, InvalidBody, IxExtError, line, NOTE_TAGS, SPEC_VERSION, toRepoRelative } from "./text.js";
|
|
30
|
-
export const VERSION = "0.1.
|
|
32
|
+
export const VERSION = "0.1.1";
|
|
31
33
|
export const KINDS = [NOTE_KIND, SUBGRAPH_KIND, IMPACT_KIND];
|
|
32
34
|
/** Cap on local Ix output a command hands back (resolve). */
|
|
33
35
|
export const MAX_RESOLVE_OUTPUT = 32 * 1024;
|
|
@@ -112,8 +114,42 @@ function need(opts, k, flag) {
|
|
|
112
114
|
throw usage(`${flag} is required`);
|
|
113
115
|
return v;
|
|
114
116
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
/**
|
|
118
|
+
* The graph target of a call (packages/p2p/src/projects.ts graphTarget, through ExtContext): the
|
|
119
|
+
* only place an `ix` endpoint comes from. A p2p from before graph targets has none to give: local.
|
|
120
|
+
* Any failure is local too.
|
|
121
|
+
*/
|
|
122
|
+
export function targetOf(ctx, sid, extra = []) {
|
|
123
|
+
const memo = new Map();
|
|
124
|
+
const more = extra.filter((p) => typeof p === "string" && p !== "").map((p) => (isAbsolute(p) ? p : resolvePath(ctx.cwd, p)));
|
|
125
|
+
return (call) => {
|
|
126
|
+
const paths = [...new Set([...more, ...callPaths(call)])];
|
|
127
|
+
const key = JSON.stringify(paths);
|
|
128
|
+
let p = memo.get(key);
|
|
129
|
+
if (!p) {
|
|
130
|
+
p = (async () => {
|
|
131
|
+
if (!ctx.graphTarget)
|
|
132
|
+
return localTarget();
|
|
133
|
+
try {
|
|
134
|
+
return checkedTarget(await ctx.graphTarget({ ...(sid ? { sid } : {}), paths }));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return localTarget();
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
memo.set(key, p);
|
|
141
|
+
}
|
|
142
|
+
return p;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The `ix` a command runs: each call pinned to the graph target of session `sid` (when the command
|
|
147
|
+
* has one), its folders, the paths the call names (callPaths) and `extra` (the command's own path
|
|
148
|
+
* arguments: --changed, --file), and limited to the commands that target allows.
|
|
149
|
+
*/
|
|
150
|
+
export function runner(ctx, deps, sid, extra = []) {
|
|
151
|
+
const target = targetOf(ctx, sid, extra);
|
|
152
|
+
return guardRunner(deps.ix ? deps.ix(ctx) : ixRunner({ env: ctx.env, cwd: ctx.cwd, target }), target, ctx.cwd, deps.listener ? { listener: deps.listener } : {});
|
|
117
153
|
}
|
|
118
154
|
export async function repoOf(ctx) {
|
|
119
155
|
const r = await localRepo(ctx.cwd, { ...process.env, ...ctx.env });
|
|
@@ -199,11 +235,20 @@ export function ixCommands(deps = {}) {
|
|
|
199
235
|
let tag = opts.tag;
|
|
200
236
|
let at;
|
|
201
237
|
if (typeof opts.ixNote === "string") {
|
|
202
|
-
if (
|
|
238
|
+
if (!IX_NOTE_ID_RE.test(opts.ixNote))
|
|
203
239
|
throw usage("--ix-note must be a note id");
|
|
204
|
-
const n = (await ixJson(runner(ctx, deps), ["note", "--json", "show", opts.ixNote]));
|
|
240
|
+
const n = (await ixJson(runner(ctx, deps, fromSession), ["note", "--json", "show", opts.ixNote]));
|
|
205
241
|
if (typeof n?.text !== "string")
|
|
206
242
|
throw new IxExtError("ix_failed", "ix note show returned no text");
|
|
243
|
+
// Graph memory's own records (memory.ts) hold a session's context: they go out only from that
|
|
244
|
+
// session, or from one whose reach is no wider than its (both shared, and p2p says so). A
|
|
245
|
+
// private project's record, one whose session can't be told, or an older p2p: refused.
|
|
246
|
+
const rec = await recordOf(ctx, n);
|
|
247
|
+
if (rec && rec.sid !== fromSession) {
|
|
248
|
+
const ok = rec.sid !== undefined && typeof ctx.mayShareSessionContext === "function" && (await ctx.mayShareSessionContext(rec.sid, fromSession).catch(() => false)) === true;
|
|
249
|
+
if (!ok)
|
|
250
|
+
throw new IxExtError("not_shared", "that Ix note is a Peer2Peer record of another session's context, which this session may not pass on (share it from that session, or write your own note)");
|
|
251
|
+
}
|
|
207
252
|
text = n.text;
|
|
208
253
|
tag ??= typeof n.tag === "string" && NOTE_TAGS.includes(n.tag) ? n.tag : undefined;
|
|
209
254
|
at = typeof n.at === "string" ? n.at : undefined;
|
|
@@ -355,7 +400,7 @@ export function ixCommands(deps = {}) {
|
|
|
355
400
|
throw usage("--depth must be 1, 2 or 3");
|
|
356
401
|
argv.push("--depth", String(d));
|
|
357
402
|
}
|
|
358
|
-
ixOut = await ixJson(runner(ctx, deps), argv);
|
|
403
|
+
ixOut = await ixJson(runner(ctx, deps, fromSession || undefined, opts.changed ?? []), argv);
|
|
359
404
|
}
|
|
360
405
|
const repo = opts.withoutRepo ? { roots: here.roots } : here;
|
|
361
406
|
const changed = opts.changed?.map((r) => (isAbsolute(r) ? r : resolvePath(ctx.cwd, r)));
|
|
@@ -418,7 +463,7 @@ export function ixCommands(deps = {}) {
|
|
|
418
463
|
{
|
|
419
464
|
name: "import",
|
|
420
465
|
args: "<event>",
|
|
421
|
-
description: "Write a received Ix note into your Ix graph (asks first; the user's decision, never the agent's)",
|
|
466
|
+
description: "Write a received Ix note into your local Ix graph (asks first; the user's decision, never the agent's). Needs an Ix with the OSS `ix note`",
|
|
422
467
|
options: [
|
|
423
468
|
{ flags: "--tag <tag>", description: "Override the note's tag" },
|
|
424
469
|
{ flags: "--session <name>", description: "Attach it to one of your Ix sessions" },
|
|
@@ -435,6 +480,25 @@ export function ixCommands(deps = {}) {
|
|
|
435
480
|
if (session !== undefined && !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(session))
|
|
436
481
|
throw usage("--session must be an Ix session name or id");
|
|
437
482
|
const address = line(e.from.address, 80);
|
|
483
|
+
const actor = /^[A-Za-z0-9._@-]{1,80}$/.test(address) ? [`--actor=p2p:${address}`] : [];
|
|
484
|
+
const argv = ["note", `--tag=${tag}`, ...(session ? [`--session=${session}`] : []), ...actor, "--json"];
|
|
485
|
+
// Before anything is asked: the graph target must allow this exact call (local, never shared),
|
|
486
|
+
// and the `ix` that answers must have the OSS `ix note` (the local backend), not Ix Pro's (the
|
|
487
|
+
// cloud org) or none (an Ix from before #916: upgrade). The guarded runner checks both again.
|
|
488
|
+
const target = await targetOf(ctx)({ argv, cwd: ctx.cwd });
|
|
489
|
+
const refused = refuseForTarget(argv, target);
|
|
490
|
+
if (refused)
|
|
491
|
+
throw refused;
|
|
492
|
+
const ix = runner(ctx, deps);
|
|
493
|
+
if (!(await ixAvailable(ix)))
|
|
494
|
+
throw new IxExtError("ix_missing", "Ix isn't installed: https://github.com/ix-infrastructure/Ix");
|
|
495
|
+
const support = await memorySupport(ix);
|
|
496
|
+
if (support !== "oss")
|
|
497
|
+
throw memoryRefusal(support, target);
|
|
498
|
+
// And the local endpoint's port must be this user's (listener.ts): checked again by the guard.
|
|
499
|
+
const held = await (deps.listener ?? ((e, o) => checkLoopbackListener(e, { trustRoot: o?.trustRoot === true })))(target.endpoint, { trustRoot: target.kind === "local" && target.trustRootListener === true }).catch(() => ({ ok: false, why: "couldn't tell who listens on its port" }));
|
|
500
|
+
if (!held.ok)
|
|
501
|
+
throw new IxExtError("ix_listener", `the local Ix endpoint ${target.endpoint} isn't one Peer2Peer can trust: ${held.why}`);
|
|
438
502
|
const text = `Shared by ${address} over Peer2Peer${b.title ? `: ${b.title}` : ""}\n\n${b.text}`;
|
|
439
503
|
// M1: consent covers exactly what is written. Either the full title and text are shown here
|
|
440
504
|
// and the user agrees, or --yes after the user read this very note with `p2p ix show` at a terminal.
|
|
@@ -451,11 +515,6 @@ export function ixCommands(deps = {}) {
|
|
|
451
515
|
if (!ok)
|
|
452
516
|
throw new IxExtError("consent_required", "not imported: the user didn't agree (run it in a terminal, or `p2p ix show` it there and then import with --yes)");
|
|
453
517
|
}
|
|
454
|
-
const ix = runner(ctx, deps);
|
|
455
|
-
if (!(await ixAvailable(ix)))
|
|
456
|
-
throw new IxExtError("ix_missing", "Ix isn't installed: https://github.com/ix-infrastructure/Ix");
|
|
457
|
-
const actor = /^[A-Za-z0-9._@-]{1,80}$/.test(address) ? [`--actor=p2p:${address}`] : [];
|
|
458
|
-
const argv = ["note", `--tag=${tag}`, ...(session ? [`--session=${session}`] : []), ...actor, "--json"];
|
|
459
518
|
const r = await ix.run(argv, { stdin: text });
|
|
460
519
|
if (r.code !== 0)
|
|
461
520
|
throw new IxExtError("ix_failed", `ix note failed (exit ${r.code})${r.stderr ? `: ${line(r.stderr, 300)}` : ""}`);
|
|
@@ -521,7 +580,7 @@ export function ixCommands(deps = {}) {
|
|
|
521
580
|
const repo = opts.repo ?? own?.repo;
|
|
522
581
|
if (mine.length === 0)
|
|
523
582
|
return { json: { conflicts: [], errors: [], checked: 0 }, human: "No files of yours to check (give --file, or --session with a posted status)." };
|
|
524
|
-
const ix = runner(ctx, deps);
|
|
583
|
+
const ix = runner(ctx, deps, typeof opts.session === "string" ? opts.session : undefined, mine);
|
|
525
584
|
if (!(await ixAvailable(ix)))
|
|
526
585
|
throw new IxExtError("ix_missing", "Ix isn't installed: https://github.com/ix-infrastructure/Ix");
|
|
527
586
|
// For a session: only sessions its status reaches (project boundaries), and this user's own.
|
|
@@ -538,6 +597,8 @@ export function ixCommands(deps = {}) {
|
|
|
538
597
|
export function createIxExtension(deps = {}) {
|
|
539
598
|
return {
|
|
540
599
|
api: 1,
|
|
600
|
+
// Every Ix call takes its endpoint from ExtContext.graphTarget (p2p refuses an ext-ix without this).
|
|
601
|
+
graphTargets: 1,
|
|
541
602
|
ns: "ix",
|
|
542
603
|
name: "@peer2peer/ext-ix",
|
|
543
604
|
version: VERSION,
|
|
@@ -546,6 +607,8 @@ export function createIxExtension(deps = {}) {
|
|
|
546
607
|
commands: ixCommands(deps),
|
|
547
608
|
// x:ix.footprint is a state kind: published to the session's status audience, kept latest-wins.
|
|
548
609
|
state: { [FOOTPRINT_KIND]: { ttl: FOOTPRINT_TTL } },
|
|
610
|
+
// Graph memory (SPEC §10): this device's own sessions' context, into the local graph only.
|
|
611
|
+
memory: ixMemory((ctx, sid) => runner(ctx, deps, sid), deps.listener),
|
|
549
612
|
};
|
|
550
613
|
}
|
|
551
614
|
/** What `p2p` loads. */
|
|
@@ -51,7 +51,7 @@ export declare function repoNameKey(root: string, ref: RepoRef, env: NodeJS.Proc
|
|
|
51
51
|
why: string;
|
|
52
52
|
}>;
|
|
53
53
|
export interface FootprintHelpers {
|
|
54
|
-
runner(ctx: ExtContext, deps: Deps): IxRunner;
|
|
54
|
+
runner(ctx: ExtContext, deps: Deps, sid?: string): IxRunner;
|
|
55
55
|
repoOf(ctx: ExtContext): Promise<Here>;
|
|
56
56
|
}
|
|
57
57
|
export declare function footprintCommands(deps: Deps, h: FootprintHelpers): ExtCommand[];
|
|
@@ -230,7 +230,7 @@ export function footprintCommands(deps, h) {
|
|
|
230
230
|
});
|
|
231
231
|
let fallback = [];
|
|
232
232
|
if (opts.fallback && r.withoutFootprint.length)
|
|
233
|
-
fallback = await conflictPeersWithoutFootprint(ctx, sid, r.withoutFootprint, h.runner(ctx, deps));
|
|
233
|
+
fallback = await conflictPeersWithoutFootprint(ctx, sid, r.withoutFootprint, h.runner(ctx, deps, sid));
|
|
234
234
|
// Readable names (`detail`) only for a person at a terminal; --json (what a client, or a
|
|
235
235
|
// model's shell, reads) carries the model-safe line only.
|
|
236
236
|
const lines = r.overlaps.map((o) => (ctx.interactive ? o.detail : o.message));
|
|
@@ -283,7 +283,7 @@ export function footprintCommands(deps, h) {
|
|
|
283
283
|
throw new IxExtError("not_a_repo", "not in a git repository: a footprint needs the session's repo (P2P_WORKDIR)");
|
|
284
284
|
if (!here.ref)
|
|
285
285
|
throw new IxExtError("no_remote", "this repository has no origin remote: a footprint names its repo by its remote");
|
|
286
|
-
const ix = h.runner(ctx, deps);
|
|
286
|
+
const ix = h.runner(ctx, deps, sid);
|
|
287
287
|
// No Ix: no footprint, one clear error (a client stops asking for this run).
|
|
288
288
|
if (!(await ixAvailable(ix)))
|
|
289
289
|
throw new IxExtError("ix_missing", "Ix isn't installed: https://github.com/ix-infrastructure/Ix");
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export { NOTE_KIND, parseNoteBody, buildNote, renderNote, noteFallback, type Not
|
|
|
3
3
|
export { SUBGRAPH_KIND, parseSubgraphBody, parseSelector, buildSubgraph, renderSubgraph, subgraphFallback, resolveArgv, describeSelector, splitPattern, type SubgraphBody, type Selector, type SubgraphInput, } from "./subgraph.js";
|
|
4
4
|
export { IMPACT_KIND, parseImpactBody, buildImpact, renderImpact, impactFallback, type ImpactBody, type ImpactInput, type ImpactSymbol, type ImpactComponent } from "./impact.js";
|
|
5
5
|
export { semanticConflicts, ixNeighbourhood, parseAround, type SemanticConflict, type PeerChanges, type Neighbourhood, type NeighbourhoodFn, type Relation, type ConflictOptions } from "./conflicts.js";
|
|
6
|
-
export { ixRunner, ixAvailable, ixJson, type IxRunner, type IxResult } from "./ix.js";
|
|
6
|
+
export { ixRunner, ixAvailable, ixJson, ixEnv, guardRunner, refuseForTarget, checkedTarget, localTarget, isLoopbackEndpoint, memoryCall, memorySupport, parseMemorySupport, confirmsLocalWrite, IX_ENV_ALLOW, LOCAL_IX_COMMANDS, DEFAULT_IX_ENDPOINT, type IxRunner, type IxResult, type IxTarget, type MemoryCall, type MemorySupport } from "./ix.js";
|
|
7
|
+
export { ixMemory, memoryText, memoryPurpose, memorySessionName, memoryActor, MEMORY_TTL_HOURS } from "./memory.js";
|
|
7
8
|
export { normalizeRemote, parseRepo, localRepo, compareRepo, type RepoRef, type LocalRepo } from "./repo.js";
|
|
8
9
|
export { SPEC_VERSION, MAX_BODY_BYTES, LIMITS, NOTE_TAGS, RISK_LEVELS, InvalidBody, IxExtError, toRepoRelative, scrubPaths, type NoteTag, type RiskLevel } from "./text.js";
|
|
9
10
|
export { FOOTPRINT_KIND, FOOTPRINT_TTL, MAX_FOOTPRINT_BYTES, FP_LIMITS, parseFootprintBody, assembleFootprint, footprintFallback, footprintDigest, symbolKey, wireQualifiedKey, type FootprintBody, type FpActor, type FpComponent, type RawActor, } from "./footprint.js";
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,8 @@ export { NOTE_KIND, parseNoteBody, buildNote, renderNote, noteFallback } from ".
|
|
|
10
10
|
export { SUBGRAPH_KIND, parseSubgraphBody, parseSelector, buildSubgraph, renderSubgraph, subgraphFallback, resolveArgv, describeSelector, splitPattern, } from "./subgraph.js";
|
|
11
11
|
export { IMPACT_KIND, parseImpactBody, buildImpact, renderImpact, impactFallback } from "./impact.js";
|
|
12
12
|
export { semanticConflicts, ixNeighbourhood, parseAround } from "./conflicts.js";
|
|
13
|
-
export { ixRunner, ixAvailable, ixJson } from "./ix.js";
|
|
13
|
+
export { ixRunner, ixAvailable, ixJson, ixEnv, guardRunner, refuseForTarget, checkedTarget, localTarget, isLoopbackEndpoint, memoryCall, memorySupport, parseMemorySupport, confirmsLocalWrite, IX_ENV_ALLOW, LOCAL_IX_COMMANDS, DEFAULT_IX_ENDPOINT } from "./ix.js";
|
|
14
|
+
export { ixMemory, memoryText, memoryPurpose, memorySessionName, memoryActor, MEMORY_TTL_HOURS } from "./memory.js";
|
|
14
15
|
export { normalizeRemote, parseRepo, localRepo, compareRepo } from "./repo.js";
|
|
15
16
|
export { SPEC_VERSION, MAX_BODY_BYTES, LIMITS, NOTE_TAGS, RISK_LEVELS, InvalidBody, IxExtError, toRepoRelative, scrubPaths } from "./text.js";
|
|
16
17
|
export { FOOTPRINT_KIND, FOOTPRINT_TTL, MAX_FOOTPRINT_BYTES, FP_LIMITS, parseFootprintBody, assembleFootprint, footprintFallback, footprintDigest, symbolKey, wireQualifiedKey, } from "./footprint.js";
|
package/dist/ix.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IxExtError } from "./text.js";
|
|
2
|
+
import { type ListenerCheck } from "./listener.js";
|
|
1
3
|
export interface IxResult {
|
|
2
4
|
code: number;
|
|
3
5
|
stdout: string;
|
|
@@ -11,9 +13,145 @@ export interface IxRunner {
|
|
|
11
13
|
}): Promise<IxResult>;
|
|
12
14
|
}
|
|
13
15
|
export declare const IX_TIMEOUT_MS = 30000;
|
|
16
|
+
/**
|
|
17
|
+
* Where an `ix` call may go: the graph target p2p's chokepoint gave (ExtContext.graphTarget,
|
|
18
|
+
* packages/p2p/src/projects.ts graphTarget). Never taken from the environment.
|
|
19
|
+
*/
|
|
20
|
+
export type IxTarget = {
|
|
21
|
+
kind: "local";
|
|
22
|
+
endpoint: string;
|
|
23
|
+
why?: string;
|
|
24
|
+
trustRootListener?: true;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "shared";
|
|
27
|
+
circle: string;
|
|
28
|
+
endpoint: string;
|
|
29
|
+
token?: string;
|
|
30
|
+
};
|
|
31
|
+
/** Ix's own default backend (ix-cli DEFAULT_ENDPOINT). */
|
|
32
|
+
export declare const DEFAULT_IX_ENDPOINT = "http://localhost:8090";
|
|
33
|
+
/** http(s) to localhost, 127.0.0.0/8 or ::1, no credentials, query or fragment (as p2p's isLoopbackEndpoint). */
|
|
34
|
+
export declare function isLoopbackEndpoint(url: unknown): url is string;
|
|
35
|
+
/** A loopback endpoint as `origin + pathname`, trailing slashes dropped; undefined when it isn't one. */
|
|
36
|
+
export declare function normalizeLoopbackEndpoint(url: unknown): string | undefined;
|
|
37
|
+
/** A shared graph's endpoint as `origin + pathname`: https, off this machine, no credentials, query or fragment. */
|
|
38
|
+
export declare function normalizeSharedEndpoint(url: unknown): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The local target a library caller (or a p2p from before graph targets) gets: Ix's default
|
|
41
|
+
* backend. Never from the environment (IX_ENDPOINT is exactly what an agent or a Pro login sets):
|
|
42
|
+
* a person's other local port comes from p2p's config.json, through the host's target.
|
|
43
|
+
*/
|
|
44
|
+
export declare function localTarget(_env?: Record<string, string | undefined>): IxTarget;
|
|
45
|
+
/**
|
|
46
|
+
* A target as given, checked again here (a buggy or older host is not trusted with it): a local
|
|
47
|
+
* one must name a loopback endpoint, a shared one an https endpoint off this machine. Anything else
|
|
48
|
+
* is the default local target.
|
|
49
|
+
*/
|
|
50
|
+
export declare function checkedTarget(t: unknown): IxTarget;
|
|
51
|
+
/**
|
|
52
|
+
* What an `ix` child sees of the environment: these names only (case-insensitively, as on
|
|
53
|
+
* Windows). No IX_ENDPOINT, IX_PAT, IX_ORG or any other IX_* cloud or login setting of the caller's
|
|
54
|
+
* (Ix Pro's PAT mode is driven by the environment alone), no P2P_* (the person token), no
|
|
55
|
+
* NODE_OPTIONS, proxies, LD_* or DYLD_*. IX_HOME (where Ix keeps its local state, the workspace
|
|
56
|
+
* registry) and IX_TOKEN (the local backend's token, which Ix sends to a loopback endpoint only)
|
|
57
|
+
* stay.
|
|
58
|
+
*/
|
|
59
|
+
export declare const IX_ENV_ALLOW: readonly string[];
|
|
60
|
+
/**
|
|
61
|
+
* The environment an `ix` call runs with: IX_ENV_ALLOW from `env`, then the target pinned:
|
|
62
|
+
* IX_ENDPOINT is the target's endpoint (Ix reads it before config.yaml's `endpoint`, which Ix Pro
|
|
63
|
+
* rewrites to the cloud cluster on `ix login`); a shared target's token, when it has one, goes as
|
|
64
|
+
* IX_PAT; readers never start a background `ix map` (Ix Pro routes a map to the cloud whenever an
|
|
65
|
+
* org session is active in config.yaml, whatever IX_ENDPOINT says); no update check.
|
|
66
|
+
*/
|
|
67
|
+
export declare function ixEnv(env: Record<string, string | undefined>, target: IxTarget): NodeJS.ProcessEnv;
|
|
68
|
+
/** PATH with its relative and empty entries dropped (they mean the current directory: a repository's own `node`). */
|
|
69
|
+
export declare function absolutePath(v: string, platform?: NodeJS.Platform): string;
|
|
70
|
+
/** What one `ix` call is for its graph target: its argv and the folder it runs in. */
|
|
71
|
+
export interface IxCall {
|
|
72
|
+
argv: readonly string[];
|
|
73
|
+
cwd: string;
|
|
74
|
+
}
|
|
75
|
+
/** Resolves the target of one call. */
|
|
76
|
+
export type TargetFn = (call: IxCall) => Promise<IxTarget>;
|
|
77
|
+
/**
|
|
78
|
+
* The paths an `ix` call names, absolute: the folder it runs in, its positional target (a file, a
|
|
79
|
+
* `file:start-end` range, a directory or a symbol, resolved against the cwd: a symbol only names
|
|
80
|
+
* the cwd's project again), and the values of `--path` and `--root`. Every one's project is
|
|
81
|
+
* intersected into the call's graph target, so a call can't reach past a private project it names.
|
|
82
|
+
*/
|
|
83
|
+
export declare function callPaths(call: IxCall): string[];
|
|
84
|
+
/**
|
|
85
|
+
* The `ix` subcommands ext-ix may run against a local target: reads of the local graph only. Ix
|
|
86
|
+
* Pro's own commands (`ix note` writes and reads Ix-memory in the cloud, whatever IX_ENDPOINT says)
|
|
87
|
+
* and `ix map` (routed to the cloud when an org session is active) are refused, so a private
|
|
88
|
+
* project's content never reaches the cloud through ext-ix. The exceptions are the memory calls
|
|
89
|
+
* (memoryCall): exact forms of `ix note` and `ix session`, allowed against a local target only and
|
|
90
|
+
* only when the `ix` that answers is the OSS one (guardRunner, memorySupport).
|
|
91
|
+
*/
|
|
92
|
+
export declare const LOCAL_IX_COMMANDS: readonly string[];
|
|
93
|
+
/** An Ix note id (`ix note show <id>`): what --ix-note accepts. */
|
|
94
|
+
export declare const IX_NOTE_ID_RE: RegExp;
|
|
95
|
+
/** An Ix session reference (`--session=`): a name or an id. */
|
|
96
|
+
export declare const IX_SESSION_REF_RE: RegExp;
|
|
97
|
+
/** The sessions ext-ix creates: `p2p-` and a session id (or its hash). */
|
|
98
|
+
export declare const IX_SESSION_NAME_RE: RegExp;
|
|
99
|
+
/** `--actor=`: `p2p`, or `p2p:` and a Peer2Peer address. A label on the OSS backend, never an identity. */
|
|
100
|
+
export declare const IX_ACTOR_RE: RegExp;
|
|
101
|
+
/** Longest `--purpose=` ext-ix sends. */
|
|
102
|
+
export declare const MAX_PURPOSE = 200;
|
|
103
|
+
/** Longest session TTL ext-ix asks for, in hours (a year). */
|
|
104
|
+
export declare const MAX_TTL_HOURS = 8760;
|
|
105
|
+
export type MemoryCall = "help" | "note-create" | "note-show" | "session-create" | "session-show";
|
|
106
|
+
/**
|
|
107
|
+
* Which memory call `argv` is, when it is exactly one of the forms ext-ix runs; undefined for
|
|
108
|
+
* anything else (another subcommand, an extra or repeated flag, a positional note text: the text
|
|
109
|
+
* only ever goes on stdin, never into argv where `ps` shows it):
|
|
110
|
+
* ix --help which commands answer (memorySupport)
|
|
111
|
+
* ix note --json show <id> read a note (--ix-note)
|
|
112
|
+
* ix session --json show <ref> is a remembered session still there
|
|
113
|
+
* ix note --tag=<t> [--session=<ref>] [--actor=<a>] --json write a note, text on stdin
|
|
114
|
+
* ix session --json create <p2p-name> --purpose=<p> --actor=<a> --ttl=<h> a session record
|
|
115
|
+
*/
|
|
116
|
+
export declare function memoryCall(argv: readonly string[]): MemoryCall | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Which `ix note` / `ix session` this Ix has, from `ix --help` (the capability, never a trial write):
|
|
119
|
+
* - "oss": the OSS commands against the local backend (Ix after 0.13.0, ix-infrastructure/Ix#916).
|
|
120
|
+
* Ix registers them only when Ix Pro did not load, and lists them in a "Memory:" section of the
|
|
121
|
+
* help only then.
|
|
122
|
+
* - "pro": Ix Pro loaded (its "Pro:" section). Its `ix note` and `ix session` always go to the
|
|
123
|
+
* active cloud org, whatever IX_ENDPOINT says.
|
|
124
|
+
* - "none": neither (an Ix from before #916 without Pro, or not Ix at all).
|
|
125
|
+
* Anything that isn't plainly the first is not it.
|
|
126
|
+
*/
|
|
127
|
+
export type MemorySupport = "oss" | "pro" | "none";
|
|
128
|
+
export declare function parseMemorySupport(help: string): MemorySupport;
|
|
129
|
+
/** Why a memory call can't run with this Ix, for a person: what to do about it. */
|
|
130
|
+
export declare function memoryRefusal(support: Exclude<MemorySupport, "oss">, target: IxTarget): IxExtError;
|
|
131
|
+
/** `ix --help` through `ix`, read as a MemorySupport; "none" when it fails. */
|
|
132
|
+
export declare function memorySupport(ix: IxRunner): Promise<MemorySupport>;
|
|
133
|
+
/** Whether a write's stderr says it went to `endpoint`, the local backend (OSS `ix note`/`ix session` print `→ local backend <origin+path>`). */
|
|
134
|
+
export declare function confirmsLocalWrite(stderr: string, endpoint: string): boolean;
|
|
135
|
+
/** The refusal for a command a target doesn't allow. */
|
|
136
|
+
export declare function refuseForTarget(argv: readonly string[], target: IxTarget): IxExtError | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Wraps a runner so every call is checked against its target first (refuseForTarget). `cwd`: the
|
|
139
|
+
* folder a call runs in when it names none. A memory call (`ix note`, `ix session`) also needs:
|
|
140
|
+
* - the target's port to be held by this user's process only (root's too only with the person's
|
|
141
|
+
* `ixTrustRootListener`, listener.ts), checked before every write and once per guard for a read,
|
|
142
|
+
* else `ix_listener`;
|
|
143
|
+
* - the OSS commands (memorySupport): asked once per guard, and again right before every
|
|
144
|
+
* `ix session create`;
|
|
145
|
+
* - for a write, stderr saying it went to the target's local endpoint, whatever the exit code:
|
|
146
|
+
* else `ix_unconfirmed` (whatever answered was not the OSS command against that backend).
|
|
147
|
+
*/
|
|
148
|
+
export declare function guardRunner(inner: IxRunner, target: TargetFn | (() => Promise<IxTarget>), cwd?: string, opts?: {
|
|
149
|
+
listener?: ListenerCheck;
|
|
150
|
+
}): IxRunner;
|
|
14
151
|
export declare function ixRunner(opts?: {
|
|
15
152
|
env?: Record<string, string | undefined>;
|
|
16
153
|
cwd?: string;
|
|
154
|
+
target?: IxTarget | TargetFn;
|
|
17
155
|
}): IxRunner;
|
|
18
156
|
export declare function ixAvailable(ix: IxRunner): Promise<boolean>;
|
|
19
157
|
/** Runs and parses JSON output; a failure is an IxExtError naming the command. */
|