jackline 0.0.0-stage → 0.1.0-alpha.2

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.
@@ -0,0 +1,62 @@
1
+ /** Human approvals (spec G5) and in-doubt receipts (spec G8). */
2
+ import type { Finding } from "./errors.js";
3
+ import type { Label } from "./policy.js";
4
+ /**
5
+ * What a human is asked to approve. `summary` is written by the kernel from
6
+ * the real call and its labels, never by the model (spec G5).
7
+ */
8
+ export interface ApprovalRequest {
9
+ readonly id: string;
10
+ readonly tool: string;
11
+ readonly args: Record<string, unknown>;
12
+ readonly summary: string;
13
+ /** Each argument's label: whether it's trusted and where it came from. */
14
+ readonly argLabels: Record<string, Label>;
15
+ /** The run's context label when the call was decided. */
16
+ readonly callLabel: Label;
17
+ readonly findings: Finding[];
18
+ /** Binds the decision to these exact arguments and labels. */
19
+ readonly digest: string;
20
+ /** When the request expires, in milliseconds since the epoch. */
21
+ readonly expiresAt: number;
22
+ }
23
+ /** @internal */
24
+ export declare function approvalRequestFromKernel(r: Record<string, unknown>): ApprovalRequest;
25
+ export interface Decision {
26
+ readonly kind: "approve" | "deny" | "pause";
27
+ readonly by: string;
28
+ readonly reason: string;
29
+ }
30
+ /** Allow this one call. It is single-use: it covers only this exact call. */
31
+ export declare function approve(options?: {
32
+ by?: string;
33
+ reason?: string;
34
+ }): Decision;
35
+ /** Refuse this call. The agent gets `ApprovalDenied`. */
36
+ export declare function deny(options?: {
37
+ reason?: string;
38
+ by?: string;
39
+ }): Decision;
40
+ /** Pause the run: `start` returns with status `"paused"` and the pending request. */
41
+ export declare function pauseDecision(): Decision;
42
+ export type Approver = (request: ApprovalRequest) => Decision | Promise<Decision>;
43
+ /**
44
+ * An approver that pauses the run. `start` returns with status `"paused"` and
45
+ * the pending requests; continue later with
46
+ * `resume(..., { approvals: { [request.id]: approve({ by }) } })`.
47
+ */
48
+ export declare function pause(): Approver;
49
+ /** An approver that always gives the same answer. For tests. */
50
+ export declare function always(decision: Decision): Approver;
51
+ /** @internal */
52
+ export declare function ask(approver: Approver, request: ApprovalRequest): Promise<Decision>;
53
+ export interface Receipt {
54
+ readonly kind: "committed" | "not_committed" | "unknown";
55
+ readonly value: unknown;
56
+ }
57
+ /** The call did happen; `value` is what it returned. */
58
+ export declare function committed(value?: unknown): Receipt;
59
+ /** The call didn't happen. It may run again, with the same idempotency key. */
60
+ export declare function notCommitted(): Receipt;
61
+ /** Can't tell. The run stops with status `"in_doubt"` for a person to settle. */
62
+ export declare function unknown(): Receipt;
@@ -0,0 +1,60 @@
1
+ /** Human approvals (spec G5) and in-doubt receipts (spec G8). */
2
+ /** @internal */
3
+ export function approvalRequestFromKernel(r) {
4
+ return Object.freeze({
5
+ id: r.approval_id,
6
+ tool: r.target,
7
+ args: r.args ?? {},
8
+ summary: r.summary ?? "",
9
+ argLabels: r.arg_labels ?? {},
10
+ callLabel: r.call_label ?? {},
11
+ findings: r.findings ?? [],
12
+ digest: r.digest ?? "",
13
+ expiresAt: r.expires_ms ?? 0,
14
+ });
15
+ }
16
+ /** Allow this one call. It is single-use: it covers only this exact call. */
17
+ export function approve(options = {}) {
18
+ return { kind: "approve", by: options.by ?? "", reason: options.reason ?? "" };
19
+ }
20
+ /** Refuse this call. The agent gets `ApprovalDenied`. */
21
+ export function deny(options = {}) {
22
+ return { kind: "deny", by: options.by ?? "", reason: options.reason ?? "" };
23
+ }
24
+ /** Pause the run: `start` returns with status `"paused"` and the pending request. */
25
+ export function pauseDecision() {
26
+ return { kind: "pause", by: "", reason: "" };
27
+ }
28
+ /**
29
+ * An approver that pauses the run. `start` returns with status `"paused"` and
30
+ * the pending requests; continue later with
31
+ * `resume(..., { approvals: { [request.id]: approve({ by }) } })`.
32
+ */
33
+ export function pause() {
34
+ return () => pauseDecision();
35
+ }
36
+ /** An approver that always gives the same answer. For tests. */
37
+ export function always(decision) {
38
+ return () => decision;
39
+ }
40
+ /** @internal */
41
+ export async function ask(approver, request) {
42
+ const d = await approver(request);
43
+ if (d === null || typeof d !== "object" || !["approve", "deny", "pause"].includes(d.kind)) {
44
+ throw new TypeError("an approver must return approve(), deny() or pause()");
45
+ }
46
+ return d;
47
+ }
48
+ /** The call did happen; `value` is what it returned. */
49
+ export function committed(value = null) {
50
+ return { kind: "committed", value };
51
+ }
52
+ /** The call didn't happen. It may run again, with the same idempotency key. */
53
+ export function notCommitted() {
54
+ return { kind: "not_committed", value: null };
55
+ }
56
+ /** Can't tell. The run stops with status `"in_doubt"` for a person to settle. */
57
+ export function unknown() {
58
+ return { kind: "unknown", value: null };
59
+ }
60
+ //# sourceMappingURL=approvals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approvals.js","sourceRoot":"","sources":["../src/approvals.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAyBjE,gBAAgB;AAChB,MAAM,UAAU,yBAAyB,CAAC,CAA0B;IAClE,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,CAAC,CAAC,WAAqB;QAC3B,IAAI,EAAE,CAAC,CAAC,MAAgB;QACxB,IAAI,EAAG,CAAC,CAAC,IAAuC,IAAI,EAAE;QACtD,OAAO,EAAG,CAAC,CAAC,OAA8B,IAAI,EAAE;QAChD,SAAS,EAAG,CAAC,CAAC,UAA2C,IAAI,EAAE;QAC/D,SAAS,EAAG,CAAC,CAAC,UAA2B,IAAK,EAAY;QAC1D,QAAQ,EAAG,CAAC,CAAC,QAA6B,IAAI,EAAE;QAChD,MAAM,EAAG,CAAC,CAAC,MAA6B,IAAI,EAAE;QAC9C,SAAS,EAAG,CAAC,CAAC,UAA4B,IAAI,CAAC;KAChD,CAAC,CAAC;AACL,CAAC;AAQD,6EAA6E;AAC7E,MAAM,UAAU,OAAO,CAAC,UAA4C,EAAE;IACpE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC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D,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,OAAO;IACrB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Jackline errors. They mirror `jackline.errors` in Python: the same classes,
3
+ * the same hierarchy and the same fields (in camelCase).
4
+ */
5
+ /** A finding from the policy: which rule matched, and why. */
6
+ export interface Finding {
7
+ rule: string;
8
+ message: string;
9
+ [key: string]: unknown;
10
+ }
11
+ /** A refusal as the kernel records it. */
12
+ export interface RefusalData {
13
+ code: string;
14
+ message: string;
15
+ dimension?: string | null;
16
+ needed?: number | null;
17
+ available?: number | null;
18
+ findings?: Finding[] | null;
19
+ model_message?: string | null;
20
+ [key: string]: unknown;
21
+ }
22
+ /** Base class for Jackline errors. */
23
+ export declare class JacklineError extends Error {
24
+ constructor(message: string, options?: ErrorOptions);
25
+ }
26
+ /** A replay doesn't match its recording. */
27
+ export declare class Divergence extends JacklineError {
28
+ }
29
+ /** A run with this ID is already in the journal. */
30
+ export declare class RunExists extends JacklineError {
31
+ }
32
+ /** No run with this ID is in the journal. */
33
+ export declare class RunNotFound extends JacklineError {
34
+ }
35
+ /** A journal's hash chain is broken: it was damaged or edited. */
36
+ export declare class JournalTampered extends JacklineError {
37
+ }
38
+ /** The run was recorded with different code (spec G9). */
39
+ export declare class CodeChanged extends JacklineError {
40
+ }
41
+ /** The run already finished and can't be resumed. */
42
+ export declare class RunFinished extends JacklineError {
43
+ }
44
+ /**
45
+ * An LLM call or tool failed.
46
+ *
47
+ * Thrown the same way live and in replay, so agent code that handles a
48
+ * failure behaves identically when the run is replayed. In a live run the
49
+ * original error is available as `cause`.
50
+ */
51
+ export declare class EffectFailed extends JacklineError {
52
+ readonly errorType: string;
53
+ readonly identity: string;
54
+ /** The failure's message, without the error type and call identity. */
55
+ readonly detail: string;
56
+ constructor(errorType: string, message: string, identity: string, options?: ErrorOptions);
57
+ }
58
+ /** `run.agent()` reached `maxSteps` while the model was still calling tools. */
59
+ export declare class StepLimit extends JacklineError {
60
+ }
61
+ /** A handle was used as if it were a plain value. Use `run.reveal(handle)`. */
62
+ export declare class HandleMisuse extends JacklineError {
63
+ }
64
+ /**
65
+ * The kernel refused an effect before it ran. Nothing was sent or charged.
66
+ *
67
+ * Refusals are journaled, and a replay refuses at the same point in the same way.
68
+ */
69
+ export declare class Refused extends JacklineError {
70
+ readonly code: string;
71
+ readonly dimension: string | null;
72
+ readonly needed: number | null;
73
+ readonly available: number | null;
74
+ readonly findings: Finding[];
75
+ /** What to tell a model about this refusal: fixed text, never the arguments. */
76
+ readonly modelMessage: string;
77
+ readonly identity: string | null;
78
+ /** The refusal exactly as the kernel recorded it. */
79
+ readonly refusal: RefusalData;
80
+ constructor(refusal: RefusalData, identity?: string | null);
81
+ }
82
+ /** The effect's worst-case cost doesn't fit in what's left of the budget. */
83
+ export declare class BudgetExceeded extends Refused {
84
+ }
85
+ /** The run's wall-clock deadline has passed, or a call ran past it. */
86
+ export declare class DeadlineExceeded extends BudgetExceeded {
87
+ }
88
+ /** A money budget is set, but no price is known for the model. Pass `prices`. */
89
+ export declare class NoPrice extends Refused {
90
+ }
91
+ /** The call's input may exceed the per-call `contextTokens` limit. */
92
+ export declare class ContextTooLarge extends BudgetExceeded {
93
+ }
94
+ /** A tool result larger than `maxToolResultTokens` was passed to a model. */
95
+ export declare class OversizedInput extends Refused {
96
+ }
97
+ /** The tool wasn't granted, or the call is outside what its capability allows. */
98
+ export declare class CapabilityError extends Refused {
99
+ }
100
+ /** A pinned tool (for example from an MCP server) changed its name, description or schema. */
101
+ export declare class ManifestChanged extends CapabilityError {
102
+ }
103
+ /** The policy refused the call. `explain()` says which rule and why. */
104
+ export declare class PolicyViolation extends Refused {
105
+ explain(): string;
106
+ }
107
+ /**
108
+ * The policy (or `cap.requiringApproval()`) wants a human to approve this
109
+ * call, and the run has no `approver`. Pass one to `start` or `resume`.
110
+ */
111
+ export declare class ApprovalRequired extends PolicyViolation {
112
+ }
113
+ /** A human said no to this call. */
114
+ export declare class ApprovalDenied extends Refused {
115
+ }
116
+ /** Nobody decided before the approval request expired. */
117
+ export declare class ApprovalExpired extends Refused {
118
+ }
119
+ /** `run.endorse` was refused: the check wasn't trusted, or didn't return true. */
120
+ export declare class EndorsementFailed extends Refused {
121
+ }
122
+ /** The right `Refused` subclass for a kernel refusal. */
123
+ export declare function refusedError(refusal: RefusalData, identity?: string | null): Refused;
124
+ /** Turn an error thrown by the native kernel into a typed Jackline error. */
125
+ export declare function fromNative(err: unknown): unknown;
package/dist/errors.js ADDED
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Jackline errors. They mirror `jackline.errors` in Python: the same classes,
3
+ * the same hierarchy and the same fields (in camelCase).
4
+ */
5
+ import { modelMessage } from "../native/index.js";
6
+ /** Base class for Jackline errors. */
7
+ export class JacklineError extends Error {
8
+ constructor(message, options) {
9
+ super(message, options);
10
+ this.name = new.target.name;
11
+ }
12
+ }
13
+ /** A replay doesn't match its recording. */
14
+ export class Divergence extends JacklineError {
15
+ }
16
+ /** A run with this ID is already in the journal. */
17
+ export class RunExists extends JacklineError {
18
+ }
19
+ /** No run with this ID is in the journal. */
20
+ export class RunNotFound extends JacklineError {
21
+ }
22
+ /** A journal's hash chain is broken: it was damaged or edited. */
23
+ export class JournalTampered extends JacklineError {
24
+ }
25
+ /** The run was recorded with different code (spec G9). */
26
+ export class CodeChanged extends JacklineError {
27
+ }
28
+ /** The run already finished and can't be resumed. */
29
+ export class RunFinished extends JacklineError {
30
+ }
31
+ /**
32
+ * An LLM call or tool failed.
33
+ *
34
+ * Thrown the same way live and in replay, so agent code that handles a
35
+ * failure behaves identically when the run is replayed. In a live run the
36
+ * original error is available as `cause`.
37
+ */
38
+ export class EffectFailed extends JacklineError {
39
+ errorType;
40
+ identity;
41
+ /** The failure's message, without the error type and call identity. */
42
+ detail;
43
+ constructor(errorType, message, identity, options) {
44
+ super(`${errorType} at ${identity}: ${message}`, options);
45
+ this.errorType = errorType;
46
+ this.detail = message;
47
+ this.identity = identity;
48
+ }
49
+ }
50
+ /** `run.agent()` reached `maxSteps` while the model was still calling tools. */
51
+ export class StepLimit extends JacklineError {
52
+ }
53
+ /** A handle was used as if it were a plain value. Use `run.reveal(handle)`. */
54
+ export class HandleMisuse extends JacklineError {
55
+ }
56
+ /**
57
+ * The kernel refused an effect before it ran. Nothing was sent or charged.
58
+ *
59
+ * Refusals are journaled, and a replay refuses at the same point in the same way.
60
+ */
61
+ export class Refused extends JacklineError {
62
+ code;
63
+ dimension;
64
+ needed;
65
+ available;
66
+ findings;
67
+ /** What to tell a model about this refusal: fixed text, never the arguments. */
68
+ modelMessage;
69
+ identity;
70
+ /** The refusal exactly as the kernel recorded it. */
71
+ refusal;
72
+ constructor(refusal, identity = null) {
73
+ super(refusal.message);
74
+ this.refusal = refusal;
75
+ this.code = refusal.code;
76
+ this.dimension = refusal.dimension ?? null;
77
+ this.needed = refusal.needed ?? null;
78
+ this.available = refusal.available ?? null;
79
+ this.findings = refusal.findings ?? [];
80
+ this.modelMessage = refusal.model_message ?? modelMessage(refusal.code);
81
+ this.identity = identity;
82
+ }
83
+ }
84
+ /** The effect's worst-case cost doesn't fit in what's left of the budget. */
85
+ export class BudgetExceeded extends Refused {
86
+ }
87
+ /** The run's wall-clock deadline has passed, or a call ran past it. */
88
+ export class DeadlineExceeded extends BudgetExceeded {
89
+ }
90
+ /** A money budget is set, but no price is known for the model. Pass `prices`. */
91
+ export class NoPrice extends Refused {
92
+ }
93
+ /** The call's input may exceed the per-call `contextTokens` limit. */
94
+ export class ContextTooLarge extends BudgetExceeded {
95
+ }
96
+ /** A tool result larger than `maxToolResultTokens` was passed to a model. */
97
+ export class OversizedInput extends Refused {
98
+ }
99
+ /** The tool wasn't granted, or the call is outside what its capability allows. */
100
+ export class CapabilityError extends Refused {
101
+ }
102
+ /** A pinned tool (for example from an MCP server) changed its name, description or schema. */
103
+ export class ManifestChanged extends CapabilityError {
104
+ }
105
+ /** The policy refused the call. `explain()` says which rule and why. */
106
+ export class PolicyViolation extends Refused {
107
+ explain() {
108
+ const lines = [this.message];
109
+ if (this.findings.length > 0) {
110
+ lines.push("", "To allow it: trust the data first (run.endorse with a check), get the value from a trusted", "tool instead, or change the rule (for example otherwise: 'approve').");
111
+ }
112
+ return lines.join("\n");
113
+ }
114
+ }
115
+ /**
116
+ * The policy (or `cap.requiringApproval()`) wants a human to approve this
117
+ * call, and the run has no `approver`. Pass one to `start` or `resume`.
118
+ */
119
+ export class ApprovalRequired extends PolicyViolation {
120
+ }
121
+ /** A human said no to this call. */
122
+ export class ApprovalDenied extends Refused {
123
+ }
124
+ /** Nobody decided before the approval request expired. */
125
+ export class ApprovalExpired extends Refused {
126
+ }
127
+ /** `run.endorse` was refused: the check wasn't trusted, or didn't return true. */
128
+ export class EndorsementFailed extends Refused {
129
+ }
130
+ const BY_CODE = {
131
+ budget: BudgetExceeded,
132
+ deadline: DeadlineExceeded,
133
+ no_price: NoPrice,
134
+ context_too_large: ContextTooLarge,
135
+ oversized_input: OversizedInput,
136
+ capability: CapabilityError,
137
+ manifest_changed: ManifestChanged,
138
+ policy: PolicyViolation,
139
+ approval_required: ApprovalRequired,
140
+ endorsement_failed: EndorsementFailed,
141
+ approval_denied: ApprovalDenied,
142
+ approval_expired: ApprovalExpired,
143
+ };
144
+ /** The right `Refused` subclass for a kernel refusal. */
145
+ export function refusedError(refusal, identity = null) {
146
+ const Cls = BY_CODE[refusal.code] ?? Refused;
147
+ return new Cls(refusal, identity);
148
+ }
149
+ const BY_NATIVE_CODE = {
150
+ JACKLINE_DIVERGENCE: Divergence,
151
+ JACKLINE_RUN_EXISTS: RunExists,
152
+ JACKLINE_RUN_NOT_FOUND: RunNotFound,
153
+ JACKLINE_JOURNAL_TAMPERED: JournalTampered,
154
+ JACKLINE_CODE_CHANGED: CodeChanged,
155
+ JACKLINE_RUN_FINISHED: RunFinished,
156
+ JACKLINE_ERROR: JacklineError,
157
+ };
158
+ /** Turn an error thrown by the native kernel into a typed Jackline error. */
159
+ export function fromNative(err) {
160
+ if (!(err instanceof Error))
161
+ return err;
162
+ const code = err.code;
163
+ if (code === "JACKLINE_REFUSED") {
164
+ return refusedError(JSON.parse(err.message));
165
+ }
166
+ if (code === "JACKLINE_INVALID") {
167
+ return new TypeError(err.message);
168
+ }
169
+ const Cls = typeof code === "string" ? BY_NATIVE_CODE[code] : undefined;
170
+ return Cls ? new Cls(err.message) : err;
171
+ }
172
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAqBlD,sCAAsC;AACtC,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,4CAA4C;AAC5C,MAAM,OAAO,UAAW,SAAQ,aAAa;CAAG;AAEhD,oDAAoD;AACpD,MAAM,OAAO,SAAU,SAAQ,aAAa;CAAG;AAE/C,6CAA6C;AAC7C,MAAM,OAAO,WAAY,SAAQ,aAAa;CAAG;AAEjD,kEAAkE;AAClE,MAAM,OAAO,eAAgB,SAAQ,aAAa;CAAG;AAErD,0DAA0D;AAC1D,MAAM,OAAO,WAAY,SAAQ,aAAa;CAAG;AAEjD,qDAAqD;AACrD,MAAM,OAAO,WAAY,SAAQ,aAAa;CAAG;AAEjD;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IACpC,SAAS,CAAS;IAClB,QAAQ,CAAS;IAC1B,uEAAuE;IAC9D,MAAM,CAAS;IAExB,YAAY,SAAiB,EAAE,OAAe,EAAE,QAAgB,EAAE,OAAsB;QAC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 -0,0 +1,26 @@
1
+ /**
2
+ * Jackline: a safety line for AI agents.
3
+ *
4
+ * Every LLM call, tool call, approval and sub-agent goes through the Rust
5
+ * kernel, which enforces budgets, capabilities, data-flow policy and human
6
+ * approvals, and writes a hash-chained journal so runs can be replayed
7
+ * offline and resumed safely after a crash.
8
+ *
9
+ * ```ts
10
+ * import * as jl from "jackline";
11
+ * ```
12
+ *
13
+ * See https://fakiolinho.github.io/jackline/typescript/
14
+ */
15
+ export * as approvals from "./approvals.js";
16
+ export * as journal from "./journal.js";
17
+ export * as mcp from "./mcp.js";
18
+ export * as mock from "./mock.js";
19
+ export * as models from "./models.js";
20
+ export { approve, committed, deny, notCommitted, pauseDecision as pause, unknown, type ApprovalRequest, type Approver, type Decision, type Receipt, } from "./approvals.js";
21
+ export { ApprovalDenied, ApprovalExpired, ApprovalRequired, BudgetExceeded, CapabilityError, CodeChanged, ContextTooLarge, DeadlineExceeded, Divergence, EffectFailed, EndorsementFailed, HandleMisuse, JacklineError, JournalTampered, ManifestChanged, NoPrice, OversizedInput, PolicyViolation, Refused, RunExists, RunFinished, RunNotFound, StepLimit, type Finding, type RefusalData, } from "./errors.js";
22
+ export { Journal, type JournalEntry, type JournalLike } from "./journal.js";
23
+ export { PRICE_TABLE_VERSION, canonicalHex, kernelVersion as version } from "./native.js";
24
+ export { LabelSpec, Policy, approveIfUntrusted, atLeast, atMost, equals, fields, noFlow, oneOf, prefix, readers, requiresTrusted, trusted, untrusted, type Constraint, type Label, type Readers, type Rule, } from "./policy.js";
25
+ export { Capability, Model, Run, SubRun, Tool, assistant, estimateInputTokens, isHandle, replay, resolve, resume, start, system, tool, user, type Agent, type AgentOptions, type Budget, type CallArgs, type CostBound, type EffectClass, type EffectContext, type Handle, type InDoubtCall, type LlmOptions, type MaybeHandle, type Message, type ModelResult, type NarrowOptions, type Reconcile, type ResumeOptions, type RunResult, type RunStatus, type Spend, type StartOptions, type ToolCall, type ToolOptions, type Usage, } from "./run.js";
26
+ export { ValidationError, strictSchema, type JsonSchema } from "./schema.js";
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Jackline: a safety line for AI agents.
3
+ *
4
+ * Every LLM call, tool call, approval and sub-agent goes through the Rust
5
+ * kernel, which enforces budgets, capabilities, data-flow policy and human
6
+ * approvals, and writes a hash-chained journal so runs can be replayed
7
+ * offline and resumed safely after a crash.
8
+ *
9
+ * ```ts
10
+ * import * as jl from "jackline";
11
+ * ```
12
+ *
13
+ * See https://fakiolinho.github.io/jackline/typescript/
14
+ */
15
+ export * as approvals from "./approvals.js";
16
+ export * as journal from "./journal.js";
17
+ export * as mcp from "./mcp.js";
18
+ export * as mock from "./mock.js";
19
+ export * as models from "./models.js";
20
+ export { approve, committed, deny, notCommitted, pauseDecision as pause, unknown, } from "./approvals.js";
21
+ export { ApprovalDenied, ApprovalExpired, ApprovalRequired, BudgetExceeded, CapabilityError, CodeChanged, ContextTooLarge, DeadlineExceeded, Divergence, EffectFailed, EndorsementFailed, HandleMisuse, JacklineError, JournalTampered, ManifestChanged, NoPrice, OversizedInput, PolicyViolation, Refused, RunExists, RunFinished, RunNotFound, StepLimit, } from "./errors.js";
22
+ export { Journal } from "./journal.js";
23
+ export { PRICE_TABLE_VERSION, canonicalHex, kernelVersion as version } from "./native.js";
24
+ export { LabelSpec, Policy, approveIfUntrusted, atLeast, atMost, equals, fields, noFlow, oneOf, prefix, readers, requiresTrusted, trusted, untrusted, } from "./policy.js";
25
+ export { Capability, Model, Run, SubRun, Tool, assistant, estimateInputTokens, isHandle, replay, resolve, resume, start, system, tool, user, } from "./run.js";
26
+ export { ValidationError, strictSchema } from "./schema.js";
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EACL,OAAO,EACP,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,aAAa,IAAI,KAAK,EACtB,OAAO,GAKR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,eAAe,EACf,OAAO,EACP,cAAc,EACd,eAAe,EACf,OAAO,EACP,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,GAGV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAuC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EACL,SAAS,EACT,MAAM,EACN,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,EACP,eAAe,EACf,OAAO,EACP,SAAS,GAKV,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,UAAU,EACV,KAAK,EACL,GAAG,EACH,MAAM,EACN,IAAI,EACJ,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,IAAI,EACJ,IAAI,GAwBL,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAmB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,44 @@
1
+ /** Journals: where runs are recorded, and reading them back. */
2
+ import { type NativeKernel } from "./native.js";
3
+ /**
4
+ * An open journal. Pass it as `journal` to `start`, `replay` and `resume`, or
5
+ * pass a file path instead (the default is `jackline.db`).
6
+ */
7
+ export declare class Journal {
8
+ readonly kernel: NativeKernel;
9
+ /** @internal */
10
+ constructor(kernel: NativeKernel);
11
+ /** A run's journal entries, oldest first. Throws `JournalTampered` if the hash chain is broken. */
12
+ entries(runId: string): JournalEntry[];
13
+ /** IDs of all runs in this journal. */
14
+ runs(): string[];
15
+ }
16
+ /** Where a run is recorded: a SQLite file path, or an open journal. */
17
+ export type JournalLike = string | Journal;
18
+ /**
19
+ * A journal entry, in the shared journal format (the same as Python's, so the
20
+ * `jackline` CLI can inspect it). Keys are the format's own snake_case names.
21
+ */
22
+ export interface JournalEntry {
23
+ kind: string;
24
+ seq: number;
25
+ hash: string;
26
+ [key: string]: unknown;
27
+ }
28
+ /** Open (or create) a SQLite journal file. */
29
+ export declare function open(path: string): Journal;
30
+ /** An in-memory journal, for tests. */
31
+ export declare function memory(): Journal;
32
+ /** @internal */
33
+ export declare function openJournal(journal: JournalLike | undefined): Journal;
34
+ /**
35
+ * A run's journal entries, oldest first. Throws `JournalTampered` if the hash
36
+ * chain is broken.
37
+ */
38
+ export declare function entries(runId: string, options?: {
39
+ journal?: JournalLike;
40
+ }): JournalEntry[];
41
+ /** IDs of all runs in a journal. */
42
+ export declare function runs(options?: {
43
+ journal?: JournalLike;
44
+ }): string[];
@@ -0,0 +1,47 @@
1
+ /** Journals: where runs are recorded, and reading them back. */
2
+ import { memoryKernel, openKernel } from "./native.js";
3
+ /**
4
+ * An open journal. Pass it as `journal` to `start`, `replay` and `resume`, or
5
+ * pass a file path instead (the default is `jackline.db`).
6
+ */
7
+ export class Journal {
8
+ kernel;
9
+ /** @internal */
10
+ constructor(kernel) {
11
+ this.kernel = kernel;
12
+ }
13
+ /** A run's journal entries, oldest first. Throws `JournalTampered` if the hash chain is broken. */
14
+ entries(runId) {
15
+ return this.kernel.entries(runId);
16
+ }
17
+ /** IDs of all runs in this journal. */
18
+ runs() {
19
+ return this.kernel.listRuns();
20
+ }
21
+ }
22
+ /** Open (or create) a SQLite journal file. */
23
+ export function open(path) {
24
+ return new Journal(openKernel(path));
25
+ }
26
+ /** An in-memory journal, for tests. */
27
+ export function memory() {
28
+ return new Journal(memoryKernel());
29
+ }
30
+ /** @internal */
31
+ export function openJournal(journal) {
32
+ if (journal instanceof Journal)
33
+ return journal;
34
+ return open(journal ?? "jackline.db");
35
+ }
36
+ /**
37
+ * A run's journal entries, oldest first. Throws `JournalTampered` if the hash
38
+ * chain is broken.
39
+ */
40
+ export function entries(runId, options = {}) {
41
+ return openJournal(options.journal).entries(runId);
42
+ }
43
+ /** IDs of all runs in a journal. */
44
+ export function runs(options = {}) {
45
+ return openJournal(options.journal).runs();
46
+ }
47
+ //# sourceMappingURL=journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.js","sourceRoot":"","sources":["../src/journal.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAqB,MAAM,aAAa,CAAC;AAE1E;;;GAGG;AACH,MAAM,OAAO,OAAO;IAEG;IADrB,gBAAgB;IAChB,YAAqB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IAAG,CAAC;IAE7C,mGAAmG;IACnG,OAAO,CAAC,KAAa;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAmB,CAAC;IACtD,CAAC;IAED,uCAAuC;IACvC,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;CACF;AAgBD,8CAA8C;AAC9C,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,OAAgC;IAC1D,IAAI,OAAO,YAAY,OAAO;QAAE,OAAO,OAAO,CAAC;IAC/C,OAAO,IAAI,CAAC,OAAO,IAAI,aAAa,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,UAAqC,EAAE;IAC5E,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED,oCAAoC;AACpC,MAAM,UAAU,IAAI,CAAC,UAAqC,EAAE;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7C,CAAC"}
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * MCP servers as Jackline tools (spec G3).
3
+ *
4
+ * Each MCP tool becomes a Jackline tool whose manifest (name, description,
5
+ * input schema) is pinned when granted. If the server later changes it,
6
+ * calls are refused with `ManifestChanged` until the tool is granted again.
7
+ * Output is untrusted by default, like any tool.
8
+ *
9
+ * Works with a `Client` from the official `@modelcontextprotocol/sdk`, or any
10
+ * object with the same `listTools()` and `callTool()` methods.
11
+ */
12
+ import type { LabelSpec } from "./policy.js";
13
+ import { Tool, type EffectClass } from "./run.js";
14
+ type Json = Record<string, unknown>;
15
+ /** The parts of an MCP client this adapter uses. */
16
+ export interface McpSession {
17
+ listTools(): Promise<{
18
+ tools: {
19
+ name: string;
20
+ description?: string;
21
+ inputSchema?: Json;
22
+ }[];
23
+ }>;
24
+ callTool(params: {
25
+ name: string;
26
+ arguments: Json;
27
+ }): Promise<{
28
+ content?: {
29
+ type: string;
30
+ text?: string;
31
+ }[];
32
+ isError?: boolean;
33
+ structuredContent?: unknown;
34
+ }>;
35
+ }
36
+ /** A connected MCP server. Use `server.tool(name)` to get a Jackline tool. */
37
+ export declare class Server {
38
+ readonly session: McpSession;
39
+ readonly name: string;
40
+ private manifests;
41
+ constructor(session: McpSession, name: string);
42
+ /**
43
+ * Re-read the server's tool list (for example after a
44
+ * `notifications/tools/list_changed` message).
45
+ */
46
+ refresh(): Promise<void>;
47
+ /** A Jackline tool that calls `name` on this server. */
48
+ tool(name: string, options?: {
49
+ effect?: EffectClass;
50
+ output?: LabelSpec;
51
+ }): Tool;
52
+ get toolNames(): string[];
53
+ }
54
+ /** Wrap an initialized MCP client and read its tool list. */
55
+ export declare function connect(session: McpSession, name: string): Promise<Server>;
56
+ export {};