@pinta-ai/mcp-logger 0.4.0 → 0.4.2-dev.1010
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 +12 -0
- package/dist/cli/index.js +1 -1
- package/node_modules/@pinta-ai/core/README.md +180 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.d.ts +9 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.js +20 -0
- package/node_modules/@pinta-ai/core/dist/atomic-write.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.d.ts +20 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.js +156 -0
- package/node_modules/@pinta-ai/core/dist/credential-semantics.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/env-file.d.ts +17 -0
- package/node_modules/@pinta-ai/core/dist/env-file.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/env-file.js +81 -0
- package/node_modules/@pinta-ai/core/dist/env-file.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.d.ts +26 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.js +202 -0
- package/node_modules/@pinta-ai/core/dist/export-mask.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/guard.d.ts +196 -0
- package/node_modules/@pinta-ai/core/dist/guard.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/guard.js +275 -0
- package/node_modules/@pinta-ai/core/dist/guard.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/index.d.ts +23 -0
- package/node_modules/@pinta-ai/core/dist/index.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/index.js +85 -0
- package/node_modules/@pinta-ai/core/dist/index.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/json-text.d.ts +45 -0
- package/node_modules/@pinta-ai/core/dist/json-text.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/json-text.js +116 -0
- package/node_modules/@pinta-ai/core/dist/json-text.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.d.ts +143 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.js +20 -0
- package/node_modules/@pinta-ai/core/dist/lifecycle.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/matches.d.ts +24 -0
- package/node_modules/@pinta-ai/core/dist/matches.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/matches.js +39 -0
- package/node_modules/@pinta-ai/core/dist/matches.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.d.ts +15 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.js +375 -0
- package/node_modules/@pinta-ai/core/dist/mysql-password.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.d.ts +41 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.js +7 -0
- package/node_modules/@pinta-ai/core/dist/otlp-types.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp.d.ts +142 -0
- package/node_modules/@pinta-ai/core/dist/otlp.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/otlp.js +638 -0
- package/node_modules/@pinta-ai/core/dist/otlp.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.d.ts +69 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.js +105 -0
- package/node_modules/@pinta-ai/core/dist/output-denial.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/redact.d.ts +65 -0
- package/node_modules/@pinta-ai/core/dist/redact.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/redact.js +193 -0
- package/node_modules/@pinta-ai/core/dist/redact.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.d.ts +47 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.js +177 -0
- package/node_modules/@pinta-ai/core/dist/retry-queue.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.d.ts +47 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.js +377 -0
- package/node_modules/@pinta-ai/core/dist/secret-shapes.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.d.ts +50 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.js +103 -0
- package/node_modules/@pinta-ai/core/dist/session-trace.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.d.ts +117 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.js +592 -0
- package/node_modules/@pinta-ai/core/dist/shape-rules.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/trace.d.ts +17 -0
- package/node_modules/@pinta-ai/core/dist/trace.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/trace.js +78 -0
- package/node_modules/@pinta-ai/core/dist/trace.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/transport.d.ts +75 -0
- package/node_modules/@pinta-ai/core/dist/transport.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/transport.js +260 -0
- package/node_modules/@pinta-ai/core/dist/transport.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.d.ts +46 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.js +279 -0
- package/node_modules/@pinta-ai/core/dist/value-copies.js.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.d.ts +22 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.d.ts.map +1 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.js +243 -0
- package/node_modules/@pinta-ai/core/dist/value-masking.js.map +1 -0
- package/node_modules/@pinta-ai/core/package.json +50 -0
- package/package.json +3 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session trace correlation keyed by `sessionId` (a `{ [sessionId]: traceId }`
|
|
3
|
+
* map), as opposed to the single-trace {@link TraceManager}. Concurrent host
|
|
4
|
+
* sessions (e.g. CLI + IDE extension) each get their own trace so they don't
|
|
5
|
+
* collide. Shared by copilot/gemini (disk) and opencode (memory).
|
|
6
|
+
*
|
|
7
|
+
* `newTrace(sessionId)` rotates a fresh ULID at a turn boundary; subsequent
|
|
8
|
+
* hooks in the same turn reuse it via `currentTrace(sessionId)`.
|
|
9
|
+
*/
|
|
10
|
+
export interface SessionTraceManager {
|
|
11
|
+
newTrace(sessionId?: string): string;
|
|
12
|
+
currentTrace(sessionId?: string): string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Disk-backed per-session trace store for the short-lived hook adapters
|
|
16
|
+
* (copilot/gemini). Persists the session→traceId map to a JSON file so
|
|
17
|
+
* successive hook processes in a turn share one trace.
|
|
18
|
+
*
|
|
19
|
+
* - Back-compat: a legacy bare `{ traceId }` single-trace file is treated as
|
|
20
|
+
* "no sessions" (returns an empty map) rather than mis-keyed.
|
|
21
|
+
* - The map is capped to `maxSessions` (default 200) on write to bound file
|
|
22
|
+
* growth — keeps the most-recently-written entries.
|
|
23
|
+
* - Writes are best-effort: a telemetry write failure must never break the host.
|
|
24
|
+
*/
|
|
25
|
+
export declare class DiskSessionTraceManager implements SessionTraceManager {
|
|
26
|
+
private tracePath;
|
|
27
|
+
private maxSessions;
|
|
28
|
+
constructor(tracePath: string, opts?: {
|
|
29
|
+
maxSessions?: number;
|
|
30
|
+
});
|
|
31
|
+
private read;
|
|
32
|
+
private write;
|
|
33
|
+
newTrace(sessionId?: string): string;
|
|
34
|
+
currentTrace(sessionId?: string): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* In-memory per-session trace store for the long-lived opencode plugin (one
|
|
38
|
+
* instance per process; verified H-C1). No file persistence — the map lives for
|
|
39
|
+
* the instance lifetime and is capped FIFO to `maxSessions` (default 200).
|
|
40
|
+
*/
|
|
41
|
+
export declare class MemorySessionTraceManager implements SessionTraceManager {
|
|
42
|
+
private map;
|
|
43
|
+
private maxSessions;
|
|
44
|
+
constructor(opts?: {
|
|
45
|
+
maxSessions?: number;
|
|
46
|
+
});
|
|
47
|
+
newTrace(sessionId?: string): string;
|
|
48
|
+
currentTrace(sessionId?: string): string;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=session-trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-trace.d.ts","sourceRoot":"","sources":["../src/session-trace.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1C;AAED;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;gBAEhB,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO;IAKlE,OAAO,CAAC,IAAI;IAaZ,OAAO,CAAC,KAAK;IAeb,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IASpC,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;CAMzC;AAED;;;;GAIG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IACnE,OAAO,CAAC,GAAG,CAA6B;IACxC,OAAO,CAAC,WAAW,CAAS;gBAEhB,IAAI,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO;IAI/C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IAYpC,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;CAIzC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MemorySessionTraceManager = exports.DiskSessionTraceManager = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const trace_js_1 = require("./trace.js");
|
|
10
|
+
const atomic_write_js_1 = require("./atomic-write.js");
|
|
11
|
+
const DEFAULT_MAX_SESSIONS = 200;
|
|
12
|
+
/**
|
|
13
|
+
* Disk-backed per-session trace store for the short-lived hook adapters
|
|
14
|
+
* (copilot/gemini). Persists the session→traceId map to a JSON file so
|
|
15
|
+
* successive hook processes in a turn share one trace.
|
|
16
|
+
*
|
|
17
|
+
* - Back-compat: a legacy bare `{ traceId }` single-trace file is treated as
|
|
18
|
+
* "no sessions" (returns an empty map) rather than mis-keyed.
|
|
19
|
+
* - The map is capped to `maxSessions` (default 200) on write to bound file
|
|
20
|
+
* growth — keeps the most-recently-written entries.
|
|
21
|
+
* - Writes are best-effort: a telemetry write failure must never break the host.
|
|
22
|
+
*/
|
|
23
|
+
class DiskSessionTraceManager {
|
|
24
|
+
tracePath;
|
|
25
|
+
maxSessions;
|
|
26
|
+
constructor(tracePath, opts = {}) {
|
|
27
|
+
this.tracePath = tracePath;
|
|
28
|
+
this.maxSessions = opts.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
|
29
|
+
}
|
|
30
|
+
read() {
|
|
31
|
+
try {
|
|
32
|
+
const data = JSON.parse(fs_1.default.readFileSync(this.tracePath, "utf-8"));
|
|
33
|
+
// Back-compat: a bare { traceId } single-trace file → treat as no sessions.
|
|
34
|
+
if (data && typeof data === "object" && !("traceId" in data)) {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// no/invalid file
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
write(map) {
|
|
44
|
+
try {
|
|
45
|
+
fs_1.default.mkdirSync(path_1.default.dirname(this.tracePath), { recursive: true });
|
|
46
|
+
const entries = Object.entries(map);
|
|
47
|
+
// Cap stored sessions to avoid unbounded growth (keep most recent ~N).
|
|
48
|
+
const capped = entries.length > this.maxSessions
|
|
49
|
+
? Object.fromEntries(entries.slice(-this.maxSessions))
|
|
50
|
+
: map;
|
|
51
|
+
(0, atomic_write_js_1.atomicWriteFileSync)(this.tracePath, JSON.stringify(capped));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// best-effort: telemetry trace persistence must never break the host
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
newTrace(sessionId) {
|
|
58
|
+
const key = sessionId || "default";
|
|
59
|
+
const traceId = (0, trace_js_1.generateUlid)();
|
|
60
|
+
const map = this.read();
|
|
61
|
+
map[key] = traceId;
|
|
62
|
+
this.write(map);
|
|
63
|
+
return traceId;
|
|
64
|
+
}
|
|
65
|
+
currentTrace(sessionId) {
|
|
66
|
+
const key = sessionId || "default";
|
|
67
|
+
const existing = this.read()[key];
|
|
68
|
+
if (existing)
|
|
69
|
+
return existing;
|
|
70
|
+
return this.newTrace(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.DiskSessionTraceManager = DiskSessionTraceManager;
|
|
74
|
+
/**
|
|
75
|
+
* In-memory per-session trace store for the long-lived opencode plugin (one
|
|
76
|
+
* instance per process; verified H-C1). No file persistence — the map lives for
|
|
77
|
+
* the instance lifetime and is capped FIFO to `maxSessions` (default 200).
|
|
78
|
+
*/
|
|
79
|
+
class MemorySessionTraceManager {
|
|
80
|
+
map = new Map();
|
|
81
|
+
maxSessions;
|
|
82
|
+
constructor(opts = {}) {
|
|
83
|
+
this.maxSessions = opts.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
|
84
|
+
}
|
|
85
|
+
newTrace(sessionId) {
|
|
86
|
+
const key = sessionId || "default";
|
|
87
|
+
const traceId = (0, trace_js_1.generateUlid)();
|
|
88
|
+
this.map.set(key, traceId);
|
|
89
|
+
// Cap to avoid unbounded growth over a long-lived instance.
|
|
90
|
+
if (this.map.size > this.maxSessions) {
|
|
91
|
+
const oldest = this.map.keys().next().value;
|
|
92
|
+
if (oldest !== undefined)
|
|
93
|
+
this.map.delete(oldest);
|
|
94
|
+
}
|
|
95
|
+
return traceId;
|
|
96
|
+
}
|
|
97
|
+
currentTrace(sessionId) {
|
|
98
|
+
const key = sessionId || "default";
|
|
99
|
+
return this.map.get(key) ?? this.newTrace(key);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.MemorySessionTraceManager = MemorySessionTraceManager;
|
|
103
|
+
//# sourceMappingURL=session-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-trace.js","sourceRoot":"","sources":["../src/session-trace.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,yCAA0C;AAC1C,uDAAwD;AAExD,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAgBjC;;;;;;;;;;GAUG;AACH,MAAa,uBAAuB;IAC1B,SAAS,CAAS;IAClB,WAAW,CAAS;IAE5B,YAAY,SAAiB,EAAE,OAAiC,EAAE;QAChE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC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AG,SAAS,IAAI,SAAS,CAAC;QACnC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC;CACF;AAxBD,8DAwBC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a newly masked value may sit (PTA-735, design contract 4 ①-④).
|
|
3
|
+
*
|
|
4
|
+
* The three shapes (a value in quotes, the line after a header/YAML key, the
|
|
5
|
+
* piece after a `\`+newline) are only values when the shell would not run them
|
|
6
|
+
* and the text around them agrees:
|
|
7
|
+
*
|
|
8
|
+
* ① a command word, or a value the shell expands (`$NAME`, `${`, `$(`,
|
|
9
|
+
* backtick; inside the body of a heredoc whose delimiter is not quoted even
|
|
10
|
+
* in quotes), is not a value; a value that is just `$NAME` is a reference
|
|
11
|
+
* even in single quotes;
|
|
12
|
+
* ② a value on a later line needs its key at the start of its line, nothing
|
|
13
|
+
* after the colon, and (unquoted) nothing but a comment after the value;
|
|
14
|
+
* ③ a quote that closes a string opened earlier does not start a value;
|
|
15
|
+
* ④ after a flag, the only line break that goes on is `\`+newline.
|
|
16
|
+
*
|
|
17
|
+
* ③ is decided by the shell state for the text of a command (the value of a
|
|
18
|
+
* tool input's `command`/`cmd`), and by "an odd number of the same quote
|
|
19
|
+
* earlier on this line" for everything else (heredoc bodies included).
|
|
20
|
+
*
|
|
21
|
+
* The comparison tool that checks the result against the real sample uses the
|
|
22
|
+
* same rules, so a change here is a change of the contract: keep them equal.
|
|
23
|
+
* Every function is linear in the text it reads; the per-position questions
|
|
24
|
+
* are answered from tables built once per text.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ROLE: {
|
|
27
|
+
readonly NORMAL: 0;
|
|
28
|
+
readonly OPEN: 1;
|
|
29
|
+
readonly CLOSE: 2;
|
|
30
|
+
readonly LIT: 3;
|
|
31
|
+
readonly COMMENT: 4;
|
|
32
|
+
readonly BODY: 5;
|
|
33
|
+
readonly BODY_EXP: 6;
|
|
34
|
+
};
|
|
35
|
+
export declare const STR: {
|
|
36
|
+
readonly NONE: 0;
|
|
37
|
+
readonly SQ: 1;
|
|
38
|
+
readonly DQ: 2;
|
|
39
|
+
readonly ANSI: 3;
|
|
40
|
+
};
|
|
41
|
+
export interface ShellState {
|
|
42
|
+
/** What each character is to the shell (see `ROLE`). */
|
|
43
|
+
role: Uint8Array;
|
|
44
|
+
/** The kind of string that holds each character (see `STR`). */
|
|
45
|
+
str: Uint8Array;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Follow a shell command from its first character and give every character its
|
|
49
|
+
* role: quotes that open or close a string, escaped characters, comments, and
|
|
50
|
+
* the bodies of heredocs. `$(...)`, backticks and `${...}` count as plain
|
|
51
|
+
* syntax, also inside double quotes.
|
|
52
|
+
*/
|
|
53
|
+
export declare function analyzeShell(o: string): ShellState;
|
|
54
|
+
/**
|
|
55
|
+
* Is `line` (no line break, no trailing blank) a key and nothing else: indent,
|
|
56
|
+
* optional `- ` markers, a key, a colon, and at most a block-scalar marker?
|
|
57
|
+
* Written as a scan: the same rule as one regular expression would be, but that
|
|
58
|
+
* expression backtracks without bound on a long line of blanks.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isKeyLine(line: string): boolean;
|
|
61
|
+
export type Shape = "quoted" | "next-line" | "continuation";
|
|
62
|
+
export type Violation = "①" | "②" | "③" | "④";
|
|
63
|
+
/**
|
|
64
|
+
* One text and the answers about its positions. The tables behind the answers
|
|
65
|
+
* (the shell state of a command, the quote parity of each line) are built the
|
|
66
|
+
* first time they are asked for.
|
|
67
|
+
*/
|
|
68
|
+
export declare class ShapeText {
|
|
69
|
+
readonly text: string;
|
|
70
|
+
private readonly command;
|
|
71
|
+
private shellState;
|
|
72
|
+
private parity;
|
|
73
|
+
/**
|
|
74
|
+
* @param command the text is the value of a tool input's `command`/`cmd`:
|
|
75
|
+
* follow it as shell. Any other text is read line by line.
|
|
76
|
+
*/
|
|
77
|
+
constructor(text: string, command: boolean);
|
|
78
|
+
get shell(): ShellState | null;
|
|
79
|
+
/**
|
|
80
|
+
* `parity.sq[i]` is the number (mod 2) of single quotes earlier on the line of
|
|
81
|
+
* position `i` that count as quotes: not after a backslash, and for the single
|
|
82
|
+
* quote not an apostrophe between two letters. `dq` is the same for `"`.
|
|
83
|
+
*/
|
|
84
|
+
private tables;
|
|
85
|
+
/** The quote at `pos` closes a string opened earlier on its line. */
|
|
86
|
+
lineParityCloses(pos: number): boolean;
|
|
87
|
+
/** The quote at `pos` closes a string opened before it (so it does not start a value, ③). */
|
|
88
|
+
isClosingQuote(pos: number): boolean;
|
|
89
|
+
/** A value the shell would expand (or that is only a variable) is not a value (①). */
|
|
90
|
+
expansionBlocksValue(s: number, e: number): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* The value stands where the shell reads a command word: outside any string,
|
|
93
|
+
* after a line start, `;`, `|`, `&`, `(`, or `then`/`do`/`else`/`elif`, looking
|
|
94
|
+
* over line continuations. Text that is not a command has no command words.
|
|
95
|
+
*/
|
|
96
|
+
commandWordAt(s: number): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* `text[floor..end)` ends with `then`, `do`, `else` or `elif`, which starts at
|
|
99
|
+
* `floor` or follows a character matching `before`.
|
|
100
|
+
*/
|
|
101
|
+
private endsWithKeyword;
|
|
102
|
+
/**
|
|
103
|
+
* Which of the three shapes the value `[s, e)` stands in, and the first of
|
|
104
|
+
* ①-④ it breaks. `shape` is null when it stands in none.
|
|
105
|
+
*/
|
|
106
|
+
evalShape(s: number, e: number): {
|
|
107
|
+
shape: Shape | null;
|
|
108
|
+
violation: Violation | null;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* May a literal copy of a value be replaced where it stands at `[s, e)`? The
|
|
112
|
+
* copy is looked at as a new value in the place it landed (⑤): a place in one
|
|
113
|
+
* of the three shapes must keep ①-④, any other place only ①.
|
|
114
|
+
*/
|
|
115
|
+
copyAllowed(s: number, e: number): boolean;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=shape-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape-rules.d.ts","sourceRoot":"","sources":["../src/shape-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,eAAO,MAAM,IAAI;;;;;;;;CAAsF,CAAC;AACxG,eAAO,MAAM,GAAG;;;;;CAA8C,CAAC;AAE/D,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,IAAI,EAAE,UAAU,CAAC;IACjB,gEAAgE;IAChE,GAAG,EAAE,UAAU,CAAC;CACjB;AAcD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAkPlD;AAKD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAc/C;AAkCD,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,WAAW,GAAG,cAAc,CAAC;AAC5D,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAE9C;;;;GAIG;AACH,qBAAa,SAAS;IAQR,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,OAAO,CAAC,QAAQ,CAAC,OAAO;IAP3D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,MAAM,CAAiD;IAE/D;;;OAGG;gBACkB,IAAI,EAAE,MAAM,EAAmB,OAAO,EAAE,OAAO;IAEpE,IAAI,KAAK,IAAI,UAAU,GAAG,IAAI,CAG7B;IAED;;;;OAIG;IACH,OAAO,CAAC,MAAM;IA2Bd,qEAAqE;IACrE,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKtC,6FAA6F;IAC7F,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAYpC,sFAAsF;IACtF,oBAAoB,CAAC,CAA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