@acepaste/ingress 0.9.6 → 0.9.22

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 (74) hide show
  1. package/dist/src/adapters.d.ts +9 -0
  2. package/dist/src/adapters.js +76 -6
  3. package/dist/src/agent-hooks.d.ts +112 -0
  4. package/dist/src/agent-hooks.js +533 -0
  5. package/dist/src/approvers.d.ts +16 -0
  6. package/dist/src/approvers.js +50 -0
  7. package/dist/src/audio.d.ts +70 -0
  8. package/dist/src/audio.js +224 -0
  9. package/dist/src/audit-changes.d.ts +46 -0
  10. package/dist/src/audit-changes.js +110 -0
  11. package/dist/src/audit-local.d.ts +57 -0
  12. package/dist/src/audit-local.js +231 -0
  13. package/dist/src/audit-parsers.d.ts +1 -1
  14. package/dist/src/audit.js +48 -0
  15. package/dist/src/broker.d.ts +92 -1
  16. package/dist/src/broker.js +222 -3
  17. package/dist/src/calendar.d.ts +36 -0
  18. package/dist/src/calendar.js +227 -0
  19. package/dist/src/captions.d.ts +44 -0
  20. package/dist/src/captions.js +209 -0
  21. package/dist/src/changes.d.ts +105 -0
  22. package/dist/src/changes.js +174 -0
  23. package/dist/src/character.js +15 -1
  24. package/dist/src/classifier-model.d.ts +53 -0
  25. package/dist/src/classifier-model.js +3 -0
  26. package/dist/src/classifier.d.ts +41 -0
  27. package/dist/src/classifier.js +213 -0
  28. package/dist/src/cli.js +501 -1
  29. package/dist/src/egress.d.ts +71 -0
  30. package/dist/src/egress.js +242 -0
  31. package/dist/src/email.d.ts +42 -0
  32. package/dist/src/email.js +424 -0
  33. package/dist/src/engine.d.ts +36 -12
  34. package/dist/src/engine.js +88 -37
  35. package/dist/src/image-meta.d.ts +33 -0
  36. package/dist/src/image-meta.js +433 -0
  37. package/dist/src/image.d.ts +110 -0
  38. package/dist/src/image.js +353 -0
  39. package/dist/src/index.d.ts +50 -5
  40. package/dist/src/index.js +28 -3
  41. package/dist/src/localguard.d.ts +33 -0
  42. package/dist/src/localguard.js +61 -0
  43. package/dist/src/meaning.d.ts +2 -0
  44. package/dist/src/meaning.js +77 -22
  45. package/dist/src/messages.d.ts +79 -0
  46. package/dist/src/messages.js +431 -0
  47. package/dist/src/nearby.d.ts +52 -0
  48. package/dist/src/nearby.js +186 -0
  49. package/dist/src/netpolicy.js +50 -19
  50. package/dist/src/provenance.d.ts +56 -0
  51. package/dist/src/provenance.js +114 -0
  52. package/dist/src/qr.d.ts +25 -0
  53. package/dist/src/qr.js +113 -0
  54. package/dist/src/safeguards.d.ts +61 -0
  55. package/dist/src/safeguards.js +199 -0
  56. package/dist/src/served.d.ts +20 -0
  57. package/dist/src/served.js +53 -0
  58. package/dist/src/shell-commands.d.ts +39 -0
  59. package/dist/src/shell-commands.js +291 -0
  60. package/dist/src/shortcuts.d.ts +45 -0
  61. package/dist/src/shortcuts.js +220 -0
  62. package/dist/src/stream.d.ts +88 -0
  63. package/dist/src/stream.js +119 -0
  64. package/dist/src/terminal.d.ts +29 -0
  65. package/dist/src/terminal.js +313 -0
  66. package/dist/src/tooldefs.d.ts +84 -0
  67. package/dist/src/tooldefs.js +122 -0
  68. package/dist/src/types.d.ts +50 -6
  69. package/dist/src/types.js +15 -2
  70. package/dist/src/visibility.d.ts +23 -3
  71. package/dist/src/visibility.js +285 -78
  72. package/native/ingress-presence.swift +48 -0
  73. package/native/ingress-vision.swift +417 -0
  74. package/package.json +3 -1
@@ -5,6 +5,8 @@
5
5
  * HTML goes through visibility.ts. Everything else comes through here.
6
6
  */
7
7
  import type { ContentKind, Finding, TextSegment } from "./types.js";
8
+ import { type CaptionHints } from "./captions.js";
9
+ import { type NearbyHints } from "./nearby.js";
8
10
  export declare function detectKind(contentType: string, body: string, urlHint?: string): ContentKind;
9
11
  /**
10
12
  * Decode numeric and the common named entities so entity-smuggled
@@ -26,5 +28,12 @@ export declare function adaptMarkdown(raw: string): AdapterResult;
26
28
  /** JSON: every string value is a segment; keys hint at intent. Nothing is "hidden" in JSON, but long strings in unusual keys are attribute-like. */
27
29
  export declare function adaptJson(raw: string): AdapterResult;
28
30
  export declare function adaptText(raw: string): AdapterResult;
31
+ /**
32
+ * One adapter per content kind. HTML is not here: it goes through visibility.ts, which needs the stylesheet
33
+ * rules the engine fetched. A kind without an adapter yet is read as plain text, so nothing is skipped.
34
+ */
35
+ export declare function adaptByKind(kind: ContentKind, raw: string, hints?: CaptionHints & NearbyHints): AdapterResult;
36
+ /** kinds whose adapters parse HTML themselves: entities in them must reach that parser undecoded */
37
+ export declare const KINDS_WITH_MARKUP: ReadonlySet<ContentKind>;
29
38
  /** Plain JavaScript fetched directly (a module, a bundle): the whole thing is a script; any string literals are visible text. */
30
39
  export declare function adaptJavascript(raw: string): AdapterResult;
@@ -4,25 +4,73 @@
4
4
  *
5
5
  * HTML goes through visibility.ts. Everything else comes through here.
6
6
  */
7
+ import { adaptTerminal } from "./terminal.js";
8
+ import { adaptEmail, looksLikeEmailJson, looksLikeRawEmail } from "./email.js";
9
+ import { adaptCalendar, looksLikeCalendarJson } from "./calendar.js";
10
+ import { adaptMessages, adaptNotifications, looksLikeMessagesJson, looksLikeNotificationJson } from "./messages.js";
11
+ import { adaptCaptions, looksLikeCaptions, looksLikeTranscriptJson } from "./captions.js";
12
+ import { adaptNearby, looksLikeNearbyJson } from "./nearby.js";
13
+ import { adaptShortcut, looksLikeShortcut } from "./shortcuts.js";
14
+ /** JSON whose shape is a known channel (a mail message, a calendar event) is read as that channel */
15
+ function jsonChannel(body) {
16
+ let doc;
17
+ try {
18
+ doc = JSON.parse(body);
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ if (looksLikeEmailJson(doc))
24
+ return "email";
25
+ if (looksLikeCalendarJson(doc))
26
+ return "calendar";
27
+ if (looksLikeMessagesJson(doc))
28
+ return "message";
29
+ if (looksLikeNotificationJson(doc))
30
+ return "notification";
31
+ if (looksLikeTranscriptJson(doc))
32
+ return "captions";
33
+ if (looksLikeShortcut(doc))
34
+ return "automation";
35
+ if (looksLikeNearbyJson(doc))
36
+ return "nearby";
37
+ return "json";
38
+ }
7
39
  export function detectKind(contentType, body, urlHint = "") {
8
40
  const ct = contentType.toLowerCase();
41
+ if (/x-log|x-terminal|x-ansi/.test(ct) || /\.log(\?|#|$)/i.test(urlHint))
42
+ return "log";
43
+ if (/message\/rfc822|message\/global/.test(ct) || /\.eml(\?|#|$)/i.test(urlHint))
44
+ return "email";
45
+ if (/text\/calendar|application\/ics/.test(ct) || /\.ics(\?|#|$)/i.test(urlHint))
46
+ return "calendar";
47
+ if (/text\/vtt|application\/x-subrip/.test(ct) || /\.(vtt|srt)(\?|#|$)/i.test(urlHint) || looksLikeCaptions(body))
48
+ return "captions";
49
+ // terminal control sequences anywhere in the first part: replay it as a terminal would, whatever it claims to be
50
+ if (/\x1b[\[\]]/.test(body.slice(0, 65_536)) && !/html|xhtml/.test(ct))
51
+ return "log";
9
52
  if (/html|xhtml/.test(ct))
10
53
  return "html";
11
54
  if (/markdown/.test(ct) || /\.(md|markdown)(\?|#|$)/i.test(urlHint))
12
55
  return "markdown";
13
56
  if (/json/.test(ct))
14
- return "json";
57
+ return jsonChannel(body) ?? "json";
15
58
  if (/javascript|ecmascript/.test(ct) || /\.(m?js|cjs)(\?|#|$)/i.test(urlHint))
16
59
  return "javascript";
17
60
  const head = body.slice(0, 2048);
61
+ if (/^\s*BEGIN:VCALENDAR\b/i.test(head))
62
+ return "calendar";
63
+ // a shortcut saved as an XML property list
64
+ if (/^\s*(?:<\?xml|<!DOCTYPE plist|<plist)/i.test(head) && /<key>WFWorkflowActions<\/key>/.test(body.slice(0, 200_000)))
65
+ return "automation";
66
+ if (looksLikeRawEmail(body))
67
+ return "email";
18
68
  if (/^\s*<(!doctype|html|head|body|div|p|span|article|main|table)/i.test(head))
19
69
  return "html";
20
70
  if (/^\s*[\[{]/.test(head)) {
21
- try {
22
- JSON.parse(body);
23
- return "json";
24
- }
25
- catch { /* not json */ }
71
+ const k = jsonChannel(body);
72
+ if (k)
73
+ return k;
26
74
  }
27
75
  if (/^(#{1,6}\s|\*\*|- |\d+\. |```|\[.+\]\(.+\))/m.test(head) && /\n/.test(head))
28
76
  return "markdown";
@@ -152,6 +200,28 @@ export function adaptJson(raw) {
152
200
  export function adaptText(raw) {
153
201
  return { segments: [{ text: raw, visibility: "visible", path: "text" }], findings: [] };
154
202
  }
203
+ /**
204
+ * One adapter per content kind. HTML is not here: it goes through visibility.ts, which needs the stylesheet
205
+ * rules the engine fetched. A kind without an adapter yet is read as plain text, so nothing is skipped.
206
+ */
207
+ export function adaptByKind(kind, raw, hints = {}) {
208
+ switch (kind) {
209
+ case "captions": return adaptCaptions(raw, hints);
210
+ case "markdown": return adaptMarkdown(raw);
211
+ case "json": return adaptJson(raw);
212
+ case "javascript": return adaptJavascript(raw);
213
+ case "log": return adaptTerminal(raw);
214
+ case "email": return adaptEmail(raw);
215
+ case "calendar": return adaptCalendar(raw);
216
+ case "message": return adaptMessages(raw);
217
+ case "notification": return adaptNotifications(raw);
218
+ case "nearby": return adaptNearby(raw, hints);
219
+ case "automation": return adaptShortcut(raw);
220
+ default: return adaptText(raw);
221
+ }
222
+ }
223
+ /** kinds whose adapters parse HTML themselves: entities in them must reach that parser undecoded */
224
+ export const KINDS_WITH_MARKUP = new Set(["html", "email", "calendar", "message", "notification", "captions", "nearby", "automation"]);
155
225
  /** Plain JavaScript fetched directly (a module, a bundle): the whole thing is a script; any string literals are visible text. */
156
226
  export function adaptJavascript(raw) {
157
227
  const strings = raw.match(/(["'`])(?:\\.|(?!\1)[^\\\n])*\1/g) ?? [];
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Hooks for coding agents (written against Claude Code's hook contract; see integrations/claude-code).
3
+ *
4
+ * An agent's harness calls a hook with a JSON event on stdin and reads a JSON reply. These handlers are the
5
+ * replies: pure functions of the event and a gate, so they can be tested without a harness.
6
+ *
7
+ * PostToolUse Outside content a tool brought back is replaced by what the gate lets through:
8
+ * WebFetch (re-fetched by the gate, with the cloaking check), WebSearch, MCP tools,
9
+ * shell commands that reach the network, background-task output files.
10
+ * UserPromptSubmit The paste gate. Text a person pasted is outside content; characters nobody can see are
11
+ * never something a person meant to type. Hostile pastes and hidden characters stop the
12
+ * prompt and are shown to the person; a suspect paste goes through with a warning to
13
+ * the model.
14
+ * PreCompact Asks the summariser to keep outside content marked as outside content.
15
+ * PostCompact The summary gate: the summary is scanned, because an instruction planted in earlier
16
+ * content can ride into the next context as if the agent or the person had written it.
17
+ * SessionStart After a compaction whose summary was flagged, tells the model so. Also says when a
18
+ * person has stopped all agent actions, and states the session's marker.
19
+ * PreToolUse The egress gate: what a command, a file write or a tool call would send out or leave
20
+ * behind, judged with what the session has read (see egress.ts). Replies "ask" or "deny".
21
+ *
22
+ * Everything that gates fails closed: if the gate cannot run, the content is withheld with the reason.
23
+ */
24
+ import { type BurstPolicy } from "./safeguards.js";
25
+ import { Blocklist } from "./egress.js";
26
+ import type { ContentKind, IngressResult, SourceInfo } from "./types.js";
27
+ /** What a hook needs from Ingress: the engine in this process, or the local service over HTTP. */
28
+ export interface HookGate {
29
+ fetch(url: string): Promise<IngressResult>;
30
+ scan(content: string, opts: {
31
+ url?: string;
32
+ contentType?: string;
33
+ kind?: ContentKind;
34
+ source?: SourceInfo;
35
+ }): Promise<IngressResult>;
36
+ /** read a picture (see image.ts); when absent, pictures pass through unread, as before 0.9.18 */
37
+ scanImage?(bytes: Uint8Array, opts: {
38
+ url?: string;
39
+ source?: SourceInfo;
40
+ caption?: string;
41
+ }): Promise<IngressResult>;
42
+ }
43
+ export interface HookOptions {
44
+ /** characters of delivered page text handed to the model per WebFetch call (default 100,000) */
45
+ cap?: number;
46
+ /** MCP server names whose results are already gated (default: ["acepaste-ingress"]) */
47
+ gatedServers?: string[];
48
+ /** loopback port of the Ingress service, so requests to it are not gated twice */
49
+ ownPort?: number;
50
+ /** where flags are kept between hook calls (default: Ingress's state folder) */
51
+ dir?: string;
52
+ /** set false to start sessions without the marker the egress gate watches for */
53
+ marker?: boolean;
54
+ /** set false to neither mark what a session writes after reading outside content nor judge files by origin when read */
55
+ provenance?: boolean;
56
+ /** where the operating system says a file came from (default: the macOS quarantine attribute) */
57
+ fileOrigin?: (path: string) => {
58
+ agent?: string;
59
+ from?: string;
60
+ } | undefined;
61
+ }
62
+ type Json = Record<string, unknown>;
63
+ export declare function withheld(source: string, why: string): string;
64
+ /**
65
+ * The reply to a PostToolUse event: `hookSpecificOutput` with the replaced tool output, or undefined when the
66
+ * tool's result stands as it is.
67
+ */
68
+ export declare function postToolUse(event: Json, gate: HookGate, o?: HookOptions): Promise<Json | undefined>;
69
+ /** a person typing this, outside any pasted block, sends the prompt as it is */
70
+ export declare const PASTE_OVERRIDE = "[ingress: send as is]";
71
+ /**
72
+ * The reply to a UserPromptSubmit event.
73
+ * - hidden characters anywhere in the prompt (tag characters, bidi overrides, a zero-width run or split
74
+ * word, an encoded payload): block, and show the person what was hidden
75
+ * - a pasted block the gate rates hostile: block
76
+ * - a pasted block rated suspect: let it through, and tell the model it is outside content
77
+ * Typed text is never judged for what it asks: a person may tell their own agent anything.
78
+ */
79
+ export declare function userPromptSubmit(event: Json, gate: HookGate, o?: HookOptions): Promise<Json | undefined>;
80
+ /** What a PreCompact hook prints: instructions for whoever writes the summary. */
81
+ export declare function preCompact(): string;
82
+ /**
83
+ * PostCompact cannot change the summary, so it scans it and leaves a flag for SessionStart, which runs next
84
+ * with source "compact" and can speak to the model.
85
+ */
86
+ export declare function postCompact(event: Json, gate: HookGate, o?: HookOptions): Promise<void>;
87
+ /** The reply to a SessionStart event: context for the model, or undefined when there is nothing to say. */
88
+ export declare function sessionStart(event: Json, o?: HookOptions): Json | undefined;
89
+ /** The program listening on a local TCP port, by asking lsof. Undefined when nothing can be learned. */
90
+ export declare function localPortProgram(port: number): string | undefined;
91
+ /**
92
+ * The reply to a PreToolUse event: nothing (the harness's own permissions decide), "ask" with the reasons
93
+ * (the harness asks the person: that prompt is the approval channel, and the model cannot answer it), or
94
+ * "deny". A coding agent's harness already asks before commands run, so reading outside content does not by
95
+ * itself make every later command need approval here; the specific checks do the work:
96
+ * persistence, credentials or a verification code leaving, the session's marker leaving, data-bearing
97
+ * requests, blocklisted hosts, printing and removable drives, tunnels behind localhost, bursts, the stop switch.
98
+ */
99
+ export interface EgressHookOptions extends HookOptions {
100
+ blocklist?: Blocklist;
101
+ portProgram?: (port: number) => string | undefined;
102
+ burst?: BurstPolicy;
103
+ callHomeLimit?: number;
104
+ /** hosts data may go to without a question (a leading dot covers subdomains) */
105
+ allowHosts?: string[];
106
+ /** the clock (tests, and replaying a recorded session) */
107
+ now?: () => number;
108
+ }
109
+ export declare function preToolUse(event: Json, o?: EgressHookOptions): Json | undefined;
110
+ /** A gate backed by the Ingress HTTP service, so its receipts and audit trail record what hooks gated. */
111
+ export declare function remoteGate(base: string, key: string, timeoutMs?: number): HookGate;
112
+ export {};