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>
233 lines
4.7 KiB
JavaScript
233 lines
4.7 KiB
JavaScript
/**
|
|
* @import {
|
|
* Construct,
|
|
* State,
|
|
* TokenizeContext,
|
|
* Tokenizer
|
|
* } from 'micromark-util-types'
|
|
*/
|
|
|
|
import { asciiAlphanumeric, asciiAlpha, asciiAtext, asciiControl } from 'micromark-util-character';
|
|
/** @type {Construct} */
|
|
export const autolink = {
|
|
name: 'autolink',
|
|
tokenize: tokenizeAutolink
|
|
};
|
|
|
|
/**
|
|
* @this {TokenizeContext}
|
|
* Context.
|
|
* @type {Tokenizer}
|
|
*/
|
|
function tokenizeAutolink(effects, ok, nok) {
|
|
let size = 0;
|
|
return start;
|
|
|
|
/**
|
|
* Start of an autolink.
|
|
*
|
|
* ```markdown
|
|
* > | a<https://example.com>b
|
|
* ^
|
|
* > | a<user@example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function start(code) {
|
|
effects.enter("autolink");
|
|
effects.enter("autolinkMarker");
|
|
effects.consume(code);
|
|
effects.exit("autolinkMarker");
|
|
effects.enter("autolinkProtocol");
|
|
return open;
|
|
}
|
|
|
|
/**
|
|
* After `<`, at protocol or atext.
|
|
*
|
|
* ```markdown
|
|
* > | a<https://example.com>b
|
|
* ^
|
|
* > | a<user@example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function open(code) {
|
|
if (asciiAlpha(code)) {
|
|
effects.consume(code);
|
|
return schemeOrEmailAtext;
|
|
}
|
|
if (code === 64) {
|
|
return nok(code);
|
|
}
|
|
return emailAtext(code);
|
|
}
|
|
|
|
/**
|
|
* At second byte of protocol or atext.
|
|
*
|
|
* ```markdown
|
|
* > | a<https://example.com>b
|
|
* ^
|
|
* > | a<user@example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function schemeOrEmailAtext(code) {
|
|
// ASCII alphanumeric and `+`, `-`, and `.`.
|
|
if (code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) {
|
|
// Count the previous alphabetical from `open` too.
|
|
size = 1;
|
|
return schemeInsideOrEmailAtext(code);
|
|
}
|
|
return emailAtext(code);
|
|
}
|
|
|
|
/**
|
|
* In ambiguous protocol or atext.
|
|
*
|
|
* ```markdown
|
|
* > | a<https://example.com>b
|
|
* ^
|
|
* > | a<user@example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function schemeInsideOrEmailAtext(code) {
|
|
if (code === 58) {
|
|
effects.consume(code);
|
|
size = 0;
|
|
return urlInside;
|
|
}
|
|
|
|
// ASCII alphanumeric and `+`, `-`, and `.`.
|
|
if ((code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) && size++ < 32) {
|
|
effects.consume(code);
|
|
return schemeInsideOrEmailAtext;
|
|
}
|
|
size = 0;
|
|
return emailAtext(code);
|
|
}
|
|
|
|
/**
|
|
* After protocol, in URL.
|
|
*
|
|
* ```markdown
|
|
* > | a<https://example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function urlInside(code) {
|
|
if (code === 62) {
|
|
effects.exit("autolinkProtocol");
|
|
effects.enter("autolinkMarker");
|
|
effects.consume(code);
|
|
effects.exit("autolinkMarker");
|
|
effects.exit("autolink");
|
|
return ok;
|
|
}
|
|
|
|
// ASCII control, space, or `<`.
|
|
if (code === null || code === 32 || code === 60 || asciiControl(code)) {
|
|
return nok(code);
|
|
}
|
|
effects.consume(code);
|
|
return urlInside;
|
|
}
|
|
|
|
/**
|
|
* In email atext.
|
|
*
|
|
* ```markdown
|
|
* > | a<user.name@example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function emailAtext(code) {
|
|
if (code === 64) {
|
|
effects.consume(code);
|
|
return emailAtSignOrDot;
|
|
}
|
|
if (asciiAtext(code)) {
|
|
effects.consume(code);
|
|
return emailAtext;
|
|
}
|
|
return nok(code);
|
|
}
|
|
|
|
/**
|
|
* In label, after at-sign or dot.
|
|
*
|
|
* ```markdown
|
|
* > | a<user.name@example.com>b
|
|
* ^ ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function emailAtSignOrDot(code) {
|
|
return asciiAlphanumeric(code) ? emailLabel(code) : nok(code);
|
|
}
|
|
|
|
/**
|
|
* In label, where `.` and `>` are allowed.
|
|
*
|
|
* ```markdown
|
|
* > | a<user.name@example.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function emailLabel(code) {
|
|
if (code === 46) {
|
|
effects.consume(code);
|
|
size = 0;
|
|
return emailAtSignOrDot;
|
|
}
|
|
if (code === 62) {
|
|
// Exit, then change the token type.
|
|
effects.exit("autolinkProtocol").type = "autolinkEmail";
|
|
effects.enter("autolinkMarker");
|
|
effects.consume(code);
|
|
effects.exit("autolinkMarker");
|
|
effects.exit("autolink");
|
|
return ok;
|
|
}
|
|
return emailValue(code);
|
|
}
|
|
|
|
/**
|
|
* In label, where `.` and `>` are *not* allowed.
|
|
*
|
|
* Though, this is also used in `emailLabel` to parse other values.
|
|
*
|
|
* ```markdown
|
|
* > | a<user.name@ex-ample.com>b
|
|
* ^
|
|
* ```
|
|
*
|
|
* @type {State}
|
|
*/
|
|
function emailValue(code) {
|
|
// ASCII alphanumeric or `-`.
|
|
if ((code === 45 || asciiAlphanumeric(code)) && size++ < 63) {
|
|
const next = code === 45 ? emailValue : emailLabel;
|
|
effects.consume(code);
|
|
return next;
|
|
}
|
|
return nok(code);
|
|
}
|
|
} |