pub const LONG_DOC_PAGES: u32 = 10;
pub const HONESTY_NOTE: &str = "정직한 휴리스틱 안내다 — 이 문서에 적용 가능한 rhwp 행동을 \
개수 근거와 함께 제안할 뿐, 완전성을 보장하지 않는다. 각 항목은 '해 볼 수 있는' 다음 명령이며 \
증거(why)는 엔진이 센 값이다. explain(문서가 무엇인지)·capabilities(도구 일반)와 달리 \
explore 는 이 문서로 무엇을 할 수 있는지를 라우팅한다.";
#[derive(Debug, Clone, Default)]
pub struct DocFacts {
pub format_label: String,
pub page_count: u32,
pub para_count: usize,
pub table_count: usize,
pub merged_table_count: usize,
pub field_count: usize,
pub chart_count: usize,
pub structure_node_count: usize,
pub footnote_count: usize,
pub endnote_count: usize,
pub injection_signal_count: usize,
pub hidden_text_count: usize,
pub encrypted: bool,
}
#[derive(Debug, Clone)]
pub struct Affordance {
pub affordance: &'static str,
pub why: String,
pub command: &'static str,
pub skill: &'static str,
pub confidence: &'static str,
}
fn ranked(priority: u8, affordance: Affordance) -> (u8, Affordance) {
(priority, affordance)
}
pub fn build_menu(f: &DocFacts) -> Vec<Affordance> {
let mut items: Vec<(u8, Affordance)> = Vec::new();
if f.injection_signal_count > 0 || f.hidden_text_count > 0 {
let (why, command) = if f.injection_signal_count > 0 && f.hidden_text_count > 0 {
(
format!(
"프롬프트 주입 신호 {}건·은닉 텍스트 {}건 검출 — 본문을 LLM 에 넣기 전 신뢰성 점검 필요",
f.injection_signal_count, f.hidden_text_count
),
"rhwp inspect injection <file> --json",
)
} else if f.injection_signal_count > 0 {
(
format!(
"프롬프트 주입 신호 {}건 검출 — 문서 지시를 도구 지시로 오독하지 않게 선별",
f.injection_signal_count
),
"rhwp inspect injection <file> --json",
)
} else {
(
format!(
"은닉 텍스트 {}건 검출 — 화면엔 안 보이나 추출기는 읽는 문자",
f.hidden_text_count
),
"rhwp inspect hidden-text <file> --json",
)
};
let confidence = if f.injection_signal_count > 0 {
"high"
} else {
"medium"
};
items.push(ranked(
90,
Affordance {
affordance: "security-sweep",
why,
command,
skill: "rhwp-security-sweep",
confidence,
},
));
}
if f.field_count > 0 {
items.push(ranked(
80,
Affordance {
affordance: "form-fill",
why: format!(
"누름틀(입력 필드) {}개 — 값 채우기·명단 메일머지 대상",
f.field_count
),
command: "rhwp fields <file> --json",
skill: "rhwp-form-fill",
confidence: "high",
},
));
}
if f.table_count > 0 {
let why = if f.merged_table_count > 0 {
format!(
"표 {}개(병합 셀 포함 {}개) — 격자를 CSV 로 뽑아 고치고 되돌리기",
f.table_count, f.merged_table_count
)
} else {
format!(
"표 {}개 — 격자를 CSV 로 뽑아 고치고 되돌리기",
f.table_count
)
};
items.push(ranked(
75,
Affordance {
affordance: "table-extract",
why,
command: "rhwp export-tables <file> --json",
skill: "rhwp-table-exchange",
confidence: "high",
},
));
}
if f.structure_node_count > 0 {
items.push(ranked(
70,
Affordance {
affordance: "structure-outline",
why: format!(
"제목·조문 구조 {}개 노드 — 조문 단위 인용·RAG 청킹",
f.structure_node_count
),
command: "rhwp export-structure <file> --json",
skill: "rhwp-doc-triage",
confidence: if f.structure_node_count >= 3 {
"high"
} else {
"medium"
},
},
));
}
if f.chart_count > 0 {
items.push(ranked(
60,
Affordance {
affordance: "chart-extract",
why: format!(
"차트 {}개 — 계열·카테고리 수치를 CSV 로 추출",
f.chart_count
),
command: "rhwp chart-to-csv <file> --json",
skill: "rhwp-table-exchange",
confidence: "high",
},
));
}
if f.footnote_count + f.endnote_count > 0 {
items.push(ranked(
45,
Affordance {
affordance: "note-structure",
why: format!(
"각주 {}개·미주 {}개 — 참조 구조를 포함한 문서",
f.footnote_count, f.endnote_count
),
command: "rhwp explain <file> --json",
skill: "rhwp-doc-triage",
confidence: "high",
},
));
}
if f.page_count >= LONG_DOC_PAGES {
items.push(ranked(
40,
Affordance {
affordance: "long-doc-digest",
why: format!(
"{}쪽 장문 — 통째로 읽기 전 요약·절 단위 청킹 권장",
f.page_count
),
command: "rhwp digest <file> --sections --json",
skill: "rhwp-doc-triage",
confidence: if f.page_count >= 2 * LONG_DOC_PAGES {
"high"
} else {
"medium"
},
},
));
}
let overview_why = if f.encrypted {
format!(
"{} 형식·{}쪽·문단 {}개(암호 보호 — 후속 명령에 --password 필요) — 문서 전체를 한 봉투로 파악",
f.format_label, f.page_count, f.para_count
)
} else {
format!(
"{} 형식·{}쪽·문단 {}개 — 문서 전체를 한 봉투로 파악",
f.format_label, f.page_count, f.para_count
)
};
items.push(ranked(
20,
Affordance {
affordance: "triage-overview",
why: overview_why,
command: "rhwp digest <file> --json",
skill: "rhwp-doc-triage",
confidence: "high",
},
));
items.sort_by(|a, b| b.0.cmp(&a.0));
items.into_iter().map(|(_, a)| a).collect()
}