Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,071 changes: 1,071 additions & 0 deletions benchmarks/usercases/pack.py

Large diffs are not rendered by default.

1,079 changes: 1,079 additions & 0 deletions benchmarks/usercases/pack_flow_test.py

Large diffs are not rendered by default.

107 changes: 105 additions & 2 deletions crates/dim-cli/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use base64::{Engine, engine::general_purpose::STANDARD};
use dim_agent_types::{BranchCreateFailedData, ModelId, ModelOutputOutcome};
use jiff::Timestamp;
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use sha2::{Digest, Sha256};

use crate::wire::{Event, EventContent};

Expand Down Expand Up @@ -75,6 +77,7 @@ pub enum Action {
Plan {
draft: Draft,
redact: bool,
include_conversation: bool,
instructions: String,
},
Generate(Draft),
Expand Down Expand Up @@ -117,16 +120,52 @@ pub struct Plan {
pub plan_id: String,
pub evidence: Evidence,
pub instructions_status: String,
pub files: Option<ReportFiles>,
}

#[derive(Deserialize)]
#[derive(Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct ReportFiles {
#[serde(rename = "report.md")]
pub report: String,
#[serde(rename = "diagnostics.json")]
pub diagnostics: String,
}

impl ReportFiles {
pub fn preview(&self) -> String {
let mut text = String::new();
for (name, content) in [
("report.md", &self.report),
("diagnostics.json", &self.diagnostics),
] {
text.push_str(&format!("--- {name} ---\n"));
for ch in content.chars() {
if ch != '\n'
&& (ch.is_control()
|| matches!(ch, '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}'))
{
text.extend(ch.escape_debug());
} else {
text.push(ch);
}
}
text.push_str("\n\n");
}
text
}
}

#[derive(Deserialize, Serialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
enum LocalGeneration {
pub(crate) enum LocalGeneration {
Local,
}

#[derive(Deserialize)]
pub struct Evidence {
#[serde(default)]
pub conversation: Vec<serde::de::IgnoredAny>,
pub timeline: Option<TimelineEvidence>,
pub unavailable: Option<EvidenceUnavailable>,
}
Expand All @@ -149,10 +188,74 @@ pub enum EvidenceUnavailable {
#[derive(Deserialize)]
pub struct GeneratedReport {
pub title: String,
pub files: Option<ReportFiles>,
pub archive: Archive,
pub sharing: Sharing,
}

impl GeneratedReport {
pub fn zip_bytes(&self) -> crate::Result<Vec<u8>> {
const LIMIT: usize = 64 * 1024;
if self.archive.base64.len() > LIMIT.div_ceil(3) * 4 {
return Err(crate::ui::i18n::t("Invalid report ZIP").into());
}
let bytes = STANDARD.decode(&self.archive.base64)?;
if bytes.len() > LIMIT || !bytes.starts_with(b"PK\x03\x04") {
return Err(crate::ui::i18n::t("Invalid report ZIP").into());
}
Ok(bytes)
}
}

pub const EMAIL: &str = "feedback@arcships.ai";
pub const EMAIL_SUBJECT: &str = "Dim report";

#[derive(Clone, Copy, Default)]
pub enum MailScope {
#[default]
ReportOnly,
InternalRegression,
}

impl MailScope {
fn purpose(self) -> &'static str {
match self {
Self::ReportOnly => "Issue investigation only; no evaluation authorization.",
Self::InternalRegression => {
"Issue investigation and team-internal regression evaluation of this ZIP only. No external model providers, training, or publication."
}
}
}

pub fn body(self, bytes: &[u8]) -> String {
format!(
"Purpose: {}\r\nSHA-256: {:x}",
self.purpose(),
Sha256::digest(bytes)
)
}
}

pub fn mailto(body: &str) -> String {
fn encode(text: &str) -> String {
use std::fmt::Write as _;
let mut encoded = String::new();
for byte in text.bytes() {
if byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'.' | b'_' | b'~') {
encoded.push(char::from(byte));
} else {
write!(encoded, "%{byte:02X}").expect("writing to a string");
}
}
encoded
}
format!(
"mailto:{EMAIL}?subject={}&body={}",
encode(EMAIL_SUBJECT),
encode(body)
)
}

#[derive(Deserialize)]
pub struct Archive {
pub base64: String,
Expand Down
100 changes: 90 additions & 10 deletions crates/dim-cli/src/session_host/report.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
use super::Worker;
use crate::model::session::Update;
use crate::report::{Action, Captured, Draft, Reply, Request, Target, session_admission_failed};
use crate::report::{
Action, Captured, Draft, LocalGeneration, Reply, Request, Target, session_admission_failed,
};
use serde::Serialize;
use serde_json::{Value, json};

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct PlanParams<'a> {
report_id: &'a str,
generation: LocalGeneration,
redact: bool,
#[serde(skip_serializing_if = "Option::is_none")]
include_conversation: Option<bool>,
instructions: &'a str,
}

impl Worker {
pub(super) fn report_available(&self) -> bool {
self.client.offers("report.prepare") || self.methods.contains("session.report.prepare")
Expand All @@ -23,17 +37,25 @@ impl Worker {
Action::Plan {
draft,
redact,
include_conversation,
instructions,
} => {
let (method, params) = report_call(
&draft,
"plan",
json!({
"reportId": draft.report_id, "generation": {"kind":"local"},
"redact": redact, "instructions": instructions,
}),
);
self.client.typed(&method, params).await.map(Reply::Plan)
let params = PlanParams {
report_id: &draft.report_id,
generation: LocalGeneration::Local,
redact,
include_conversation: (include_conversation
|| (!redact && draft.session.is_some()))
.then_some(include_conversation),
instructions: &instructions,
};
match serde_json::to_value(params) {
Ok(params) => {
let (method, params) = report_call(&draft, "plan", params);
self.client.typed(&method, params).await.map(Reply::Plan)
}
Err(error) => Err(error.into()),
}
}
Action::Generate(draft) => {
let (method, params) = report_call(
Expand Down Expand Up @@ -196,6 +218,34 @@ mod tests {
)
.await;
assert_eq!(params, json!({"sessionId":"shown"}));
let plan = json!({"result":{
"planId":"p2", "generation":{"kind":"local"},
"evidence":{"timeline":{"recent":[]}}, "instructionsStatus":"none"
}});
for (method, redact, flag) in [
("session.report.plan", true, None),
("session.report.plan", false, Some(false)),
("session.report.plan", true, Some(true)),
("report.plan", false, None),
] {
let result = if flag == Some(false) {
json!({"error":{"code":-32602,"message":"unknown field includeConversation"}})
} else {
plan.clone()
};
let params = exchange(method, result).await;
let mut expected = json!({
"reportId":"r1", "generation":{"kind":"local"},
"redact":redact, "instructions":""
});
if method == "session.report.plan" {
expected["sessionId"] = json!("shown");
}
if let Some(flag) = flag {
expected["includeConversation"] = json!(flag);
}
assert_eq!(params, expected);
}
// A classified refusal, the shape `session.attach` answers with
// for a branch that still needs the explicit prompt migration
// (recovery.rs): a producer's message under its own code.
Expand Down Expand Up @@ -288,6 +338,36 @@ mod tests {
assert!(
matches!(receiver.try_recv().unwrap(), Update::ReportReply { panel: 2, reply: Reply::Prepared(Some(session), _) } if session == "shown")
);
for (session, redact, include_conversation) in [
(Some("shown"), true, false),
(Some("shown"), false, false),
(Some("shown"), true, true),
(None, false, false),
] {
worker
.report_request(Request {
panel: 2,
action: Action::Plan {
draft: Draft {
session: session.map(String::from),
report_id: "r1".into(),
plan_id: "p1".into(),
},
redact,
include_conversation,
instructions: String::new(),
},
})
.await;
let Update::ReportReply { panel: 2, reply } = receiver.try_recv().unwrap() else {
panic!("expected report plan reply");
};
if session.is_some() && !redact && !include_conversation {
assert!(matches!(reply, Reply::Failed { .. }));
} else {
assert!(matches!(reply, Reply::Plan(plan) if plan.plan_id == "p2"));
}
}
// The classified refusal does not route into the report flow: the
// report's fallback is for an unclassified internal fault, and a
// message the user can act on is not that. It reaches the caller with
Expand Down
61 changes: 61 additions & 0 deletions crates/dim-cli/src/ui/i18n/de/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,67 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Running…" => "Läuft…",
"Save ZIP" => "ZIP speichern",
"Saved ZIP" => "ZIP gespeichert",
"Diagnostics only; no conversation." => "Nur Diagnosedaten; kein Gespräch.",
"No conversation excerpts in this plan." => "Dieser Plan enthält keine Gesprächsauszüge.",
"Conversation included; redaction does not remove all sensitive text." => {
"Gespräch einbezogen; Schwärzen entfernt nicht den gesamten sensiblen Text."
}
"Conversation included without redaction." => "Gespräch ohne Schwärzung einbezogen.",
"Conversation requested; check the updated preview." => {
"Gespräch angefordert; prüfe die aktualisierte Vorschau."
}
"Report plan included conversation without permission." => {
"Der Berichtsplan enthielt ein Gespräch ohne Berechtigung."
}
"[ ] Include conversation" => "[ ] Gespräch einbeziehen",
"[x] Include conversation" => "[x] Gespräch einbeziehen",
"Check the preview for sensitive text before sharing." => {
"Prüfe vor dem Teilen die Vorschau auf sensiblen Text."
}
"Preview ZIP files" => "ZIP-Dateien anzeigen",
"Preview pending" => "Vorschau wird vorbereitet",
"Preview unavailable" => "Vorschau nicht verfügbar",
"↑↓/PgUp/PgDn scroll · Esc back" => "↑↓/PgUp/PgDn scrollen · Esc zurück",
"PgUp/PgDn details · ↑↓ move · Enter select · Esc close" => {
"PgUp/PgDn Details · ↑↓ bewegen · Enter auswählen · Esc schließen"
}
"Generated files differ from the plan preview. Email is unavailable." => {
"Erzeugte Dateien weichen von der Planvorschau ab. E-Mail ist nicht verfügbar."
}
"Email unavailable without matching plan and ZIP previews." => {
"E-Mail ist ohne übereinstimmende Plan- und ZIP-Vorschauen nicht verfügbar."
}
"(o) Investigation only" => "(o) Nur zur Fehlersuche",
"( ) Investigation only" => "( ) Nur zur Fehlersuche",
"(o) Team-internal regression of this ZIP only" => {
"(o) Nur teaminterne Regression dieses ZIPs"
}
"( ) Team-internal regression of this ZIP only" => {
"( ) Nur teaminterne Regression dieses ZIPs"
}
"Local attachment preview" => "Lokale Anhangsvorschau",
"Email is for investigating this report only, not evaluation." => {
"E-Mail dient nur der Untersuchung dieses Berichts, nicht der Evaluierung."
}
"Team-internal regression of this ZIP only. No external providers, training, or publication." => {
"Nur teaminterne Regression dieses ZIPs. Keine externen Anbieter, kein Training, keine Veröffentlichung."
}
"Open email draft" => "E-Mail-Entwurf öffnen",
"Email details" => "E-Mail-Angaben",
"To: {email}" => "An: {email}",
"Subject: {subject}" => "Betreff: {subject}",
"Attach the saved ZIP manually. If no draft opens, use these details. Nothing was sent." => {
"Hänge das gespeicherte ZIP manuell an. Wenn kein Entwurf geöffnet wird, nutze diese Angaben. Es wurde nichts gesendet."
}
"Could not launch email. Compose manually and attach the saved ZIP." => {
"E-Mail konnte nicht geöffnet werden. Verfasse die Nachricht manuell und hänge das gespeicherte ZIP an."
}
"Compose manually and attach the saved ZIP. Nothing was sent." => {
"Verfasse die Nachricht manuell und hänge das gespeicherte ZIP an. Es wurde nichts gesendet."
}
"Saved ZIP missing, unreadable, or changed. Save a new copy." => {
"Gespeichertes ZIP fehlt, ist nicht lesbar oder wurde geändert. Speichere eine neue Kopie."
}
"Session model" => "Sitzungsmodell",
"Skills instructions" => "Skills-Anweisungen",
"Some options were unsupported." => "Einige Optionen werden nicht unterstützt.",
Expand Down
Loading