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>
115 lines
3.0 KiB
JavaScript
115 lines
3.0 KiB
JavaScript
'use strict';
|
|
/*
|
|
Copyright 2012-2015, Yahoo Inc.
|
|
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
|
|
*/
|
|
function InsertionText(text, consumeBlanks) {
|
|
this.text = text;
|
|
this.origLength = text.length;
|
|
this.offsets = [];
|
|
this.consumeBlanks = consumeBlanks;
|
|
this.startPos = this.findFirstNonBlank();
|
|
this.endPos = this.findLastNonBlank();
|
|
}
|
|
|
|
const WHITE_RE = /[ \f\n\r\t\v\u00A0\u2028\u2029]/;
|
|
|
|
InsertionText.prototype = {
|
|
findFirstNonBlank() {
|
|
let pos = -1;
|
|
const text = this.text;
|
|
const len = text.length;
|
|
let i;
|
|
for (i = 0; i < len; i += 1) {
|
|
if (!text.charAt(i).match(WHITE_RE)) {
|
|
pos = i;
|
|
break;
|
|
}
|
|
}
|
|
return pos;
|
|
},
|
|
findLastNonBlank() {
|
|
const text = this.text;
|
|
const len = text.length;
|
|
let pos = text.length + 1;
|
|
let i;
|
|
for (i = len - 1; i >= 0; i -= 1) {
|
|
if (!text.charAt(i).match(WHITE_RE)) {
|
|
pos = i;
|
|
break;
|
|
}
|
|
}
|
|
return pos;
|
|
},
|
|
originalLength() {
|
|
return this.origLength;
|
|
},
|
|
|
|
insertAt(col, str, insertBefore, consumeBlanks) {
|
|
consumeBlanks =
|
|
typeof consumeBlanks === 'undefined'
|
|
? this.consumeBlanks
|
|
: consumeBlanks;
|
|
col = col > this.originalLength() ? this.originalLength() : col;
|
|
col = col < 0 ? 0 : col;
|
|
|
|
if (consumeBlanks) {
|
|
if (col <= this.startPos) {
|
|
col = 0;
|
|
}
|
|
if (col > this.endPos) {
|
|
col = this.origLength;
|
|
}
|
|
}
|
|
|
|
const len = str.length;
|
|
const offset = this.findOffset(col, len, insertBefore);
|
|
const realPos = col + offset;
|
|
const text = this.text;
|
|
this.text = text.substring(0, realPos) + str + text.substring(realPos);
|
|
return this;
|
|
},
|
|
|
|
findOffset(pos, len, insertBefore) {
|
|
const offsets = this.offsets;
|
|
let offsetObj;
|
|
let cumulativeOffset = 0;
|
|
let i;
|
|
|
|
for (i = 0; i < offsets.length; i += 1) {
|
|
offsetObj = offsets[i];
|
|
if (
|
|
offsetObj.pos < pos ||
|
|
(offsetObj.pos === pos && !insertBefore)
|
|
) {
|
|
cumulativeOffset += offsetObj.len;
|
|
}
|
|
if (offsetObj.pos >= pos) {
|
|
break;
|
|
}
|
|
}
|
|
if (offsetObj && offsetObj.pos === pos) {
|
|
offsetObj.len += len;
|
|
} else {
|
|
offsets.splice(i, 0, { pos, len });
|
|
}
|
|
return cumulativeOffset;
|
|
},
|
|
|
|
wrap(startPos, startText, endPos, endText, consumeBlanks) {
|
|
this.insertAt(startPos, startText, true, consumeBlanks);
|
|
this.insertAt(endPos, endText, false, consumeBlanks);
|
|
return this;
|
|
},
|
|
|
|
wrapLine(startText, endText) {
|
|
this.wrap(0, startText, this.originalLength(), endText);
|
|
},
|
|
|
|
toString() {
|
|
return this.text;
|
|
}
|
|
};
|
|
|
|
module.exports = InsertionText;
|