Implements Phases 1-8 of the TFTSR implementation plan. Rust backend (Tauri 2.x, src-tauri/): - Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama - PII detection engine: 11 regex patterns with overlap resolution - SQLCipher AES-256 encrypted database with 10 versioned migrations - 28 Tauri IPC commands for triage, analysis, document, and system ops - Ollama: hardware probe, model recommendations, pull/delete with events - RCA and blameless post-mortem Markdown document generators - PDF export via printpdf - Audit log: SHA-256 hash of every external data send - Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2) Frontend (React 18 + TypeScript + Vite, src/): - 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings - 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives - 3 Zustand stores: session, settings (persisted), history - Type-safe tauriCommands.ts matching Rust backend types exactly - 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs) DevOps: - .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push - .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload Verified: - cargo check: zero errors - tsc --noEmit: zero errors - vitest run: 13/13 unit tests passing Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
225 lines
4.7 KiB
JavaScript
225 lines
4.7 KiB
JavaScript
/**
|
||
* @import {
|
||
* Construct,
|
||
* Previous,
|
||
* Resolver,
|
||
* State,
|
||
* TokenizeContext,
|
||
* Tokenizer,
|
||
* Token
|
||
* } from 'micromark-util-types'
|
||
*/
|
||
|
||
import { markdownLineEnding } from 'micromark-util-character';
|
||
/** @type {Construct} */
|
||
export const codeText = {
|
||
name: 'codeText',
|
||
previous,
|
||
resolve: resolveCodeText,
|
||
tokenize: tokenizeCodeText
|
||
};
|
||
|
||
// To do: next major: don’t resolve, like `markdown-rs`.
|
||
/** @type {Resolver} */
|
||
function resolveCodeText(events) {
|
||
let tailExitIndex = events.length - 4;
|
||
let headEnterIndex = 3;
|
||
/** @type {number} */
|
||
let index;
|
||
/** @type {number | undefined} */
|
||
let enter;
|
||
|
||
// If we start and end with an EOL or a space.
|
||
if ((events[headEnterIndex][1].type === "lineEnding" || events[headEnterIndex][1].type === 'space') && (events[tailExitIndex][1].type === "lineEnding" || events[tailExitIndex][1].type === 'space')) {
|
||
index = headEnterIndex;
|
||
|
||
// And we have data.
|
||
while (++index < tailExitIndex) {
|
||
if (events[index][1].type === "codeTextData") {
|
||
// Then we have padding.
|
||
events[headEnterIndex][1].type = "codeTextPadding";
|
||
events[tailExitIndex][1].type = "codeTextPadding";
|
||
headEnterIndex += 2;
|
||
tailExitIndex -= 2;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// Merge adjacent spaces and data.
|
||
index = headEnterIndex - 1;
|
||
tailExitIndex++;
|
||
while (++index <= tailExitIndex) {
|
||
if (enter === undefined) {
|
||
if (index !== tailExitIndex && events[index][1].type !== "lineEnding") {
|
||
enter = index;
|
||
}
|
||
} else if (index === tailExitIndex || events[index][1].type === "lineEnding") {
|
||
events[enter][1].type = "codeTextData";
|
||
if (index !== enter + 2) {
|
||
events[enter][1].end = events[index - 1][1].end;
|
||
events.splice(enter + 2, index - enter - 2);
|
||
tailExitIndex -= index - enter - 2;
|
||
index = enter + 2;
|
||
}
|
||
enter = undefined;
|
||
}
|
||
}
|
||
return events;
|
||
}
|
||
|
||
/**
|
||
* @this {TokenizeContext}
|
||
* Context.
|
||
* @type {Previous}
|
||
*/
|
||
function previous(code) {
|
||
// If there is a previous code, there will always be a tail.
|
||
return code !== 96 || this.events[this.events.length - 1][1].type === "characterEscape";
|
||
}
|
||
|
||
/**
|
||
* @this {TokenizeContext}
|
||
* Context.
|
||
* @type {Tokenizer}
|
||
*/
|
||
function tokenizeCodeText(effects, ok, nok) {
|
||
const self = this;
|
||
let sizeOpen = 0;
|
||
/** @type {number} */
|
||
let size;
|
||
/** @type {Token} */
|
||
let token;
|
||
return start;
|
||
|
||
/**
|
||
* Start of code (text).
|
||
*
|
||
* ```markdown
|
||
* > | `a`
|
||
* ^
|
||
* > | \`a`
|
||
* ^
|
||
* ```
|
||
*
|
||
* @type {State}
|
||
*/
|
||
function start(code) {
|
||
effects.enter("codeText");
|
||
effects.enter("codeTextSequence");
|
||
return sequenceOpen(code);
|
||
}
|
||
|
||
/**
|
||
* In opening sequence.
|
||
*
|
||
* ```markdown
|
||
* > | `a`
|
||
* ^
|
||
* ```
|
||
*
|
||
* @type {State}
|
||
*/
|
||
function sequenceOpen(code) {
|
||
if (code === 96) {
|
||
effects.consume(code);
|
||
sizeOpen++;
|
||
return sequenceOpen;
|
||
}
|
||
effects.exit("codeTextSequence");
|
||
return between(code);
|
||
}
|
||
|
||
/**
|
||
* Between something and something else.
|
||
*
|
||
* ```markdown
|
||
* > | `a`
|
||
* ^^
|
||
* ```
|
||
*
|
||
* @type {State}
|
||
*/
|
||
function between(code) {
|
||
// EOF.
|
||
if (code === null) {
|
||
return nok(code);
|
||
}
|
||
|
||
// To do: next major: don’t do spaces in resolve, but when compiling,
|
||
// like `markdown-rs`.
|
||
// Tabs don’t work, and virtual spaces don’t make sense.
|
||
if (code === 32) {
|
||
effects.enter('space');
|
||
effects.consume(code);
|
||
effects.exit('space');
|
||
return between;
|
||
}
|
||
|
||
// Closing fence? Could also be data.
|
||
if (code === 96) {
|
||
token = effects.enter("codeTextSequence");
|
||
size = 0;
|
||
return sequenceClose(code);
|
||
}
|
||
if (markdownLineEnding(code)) {
|
||
effects.enter("lineEnding");
|
||
effects.consume(code);
|
||
effects.exit("lineEnding");
|
||
return between;
|
||
}
|
||
|
||
// Data.
|
||
effects.enter("codeTextData");
|
||
return data(code);
|
||
}
|
||
|
||
/**
|
||
* In data.
|
||
*
|
||
* ```markdown
|
||
* > | `a`
|
||
* ^
|
||
* ```
|
||
*
|
||
* @type {State}
|
||
*/
|
||
function data(code) {
|
||
if (code === null || code === 32 || code === 96 || markdownLineEnding(code)) {
|
||
effects.exit("codeTextData");
|
||
return between(code);
|
||
}
|
||
effects.consume(code);
|
||
return data;
|
||
}
|
||
|
||
/**
|
||
* In closing sequence.
|
||
*
|
||
* ```markdown
|
||
* > | `a`
|
||
* ^
|
||
* ```
|
||
*
|
||
* @type {State}
|
||
*/
|
||
function sequenceClose(code) {
|
||
// More.
|
||
if (code === 96) {
|
||
effects.consume(code);
|
||
size++;
|
||
return sequenceClose;
|
||
}
|
||
|
||
// Done!
|
||
if (size === sizeOpen) {
|
||
effects.exit("codeTextSequence");
|
||
effects.exit("codeText");
|
||
return ok(code);
|
||
}
|
||
|
||
// More or less accents: mark as data.
|
||
token.type = "codeTextData";
|
||
return data(code);
|
||
}
|
||
} |