Skip to content
Merged
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
6 changes: 3 additions & 3 deletions app/mcp/admin_mcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# |---|---|---|
# | Read | admin_summary, find_people, get_person, find_projects, get_project, find_ships, get_ship, list_orders, list_extensions, metrics, nudges, public_stats | Tools::Overview, People, Projects, Ships, Orders, Extensions, Numbers |
# | Analytics | describe_schema, query_sql, funnel, audit_log | Tools::Analytics, Tools::Audit |
# | Write | save_review_draft, set_lapse_coding, set_reviewer_ai, set_checklist_item, set_hours_start, edit_snapshot, edit_review_text, send_verdict_dm, mark_order_ordered, decide_extension | The same model methods the admin pages call (Nudge::ChangesNeeded and Nudge::Rejected for send_verdict_dm, Order#ordered!, Extension#decide!) |
# | Write | save_review_draft, set_lapse_coding, set_reviewer_ai, set_checklist_item, set_hours_start, edit_snapshot, edit_review_text, send_verdict_dm, mark_order_ordered, decide_extension, set_ship_until | The same model methods the admin pages call (Nudge::ChangesNeeded and Nudge::Rejected for send_verdict_dm, Order#ordered!, Extension#decide!) |
#
# Before a tool runs, AdminMcp::Tool writes an AdminAuditEvent. A tool whose audit row fails does not run.
module AdminMcp
INSTRUCTIONS = <<~TEXT.squish.freeze
Save Point admin tools. Most people in this data are teenagers: share only what the task needs.
Start with describe_schema, or a typed finder (find_people, find_projects, find_ships) before query_sql.
Every call is written to the admin log, with the tool and the IDs it names.
Write tools (save_review_draft, set_lapse_coding, set_reviewer_ai, set_checklist_item, set_hours_start, edit_snapshot, edit_review_text, send_verdict_dm, mark_order_ordered, decide_extension)
Write tools (save_review_draft, set_lapse_coding, set_reviewer_ai, set_checklist_item, set_hours_start, edit_snapshot, edit_review_text, send_verdict_dm, mark_order_ordered, decide_extension, set_ship_until)
change real data, and ordering, deciding an extension or send_verdict_dm sends the participant a Slack DM: confirm each with the human first.
Everything on the ship review page saves through a tool except the verdict and the screenshots:
set_lapse_coding and set_reviewer_ai change the limits at once. No tool gives a verdict (D-136): the reviewer presses it on the page.
Expand All @@ -29,7 +29,7 @@ class Refused < StandardError; end
# Every tool, for the server to offer.
def self.tools
[ Tools::Overview::AdminSummary, Tools::People::FindPeople, Tools::People::GetPerson,
Tools::Projects::FindProjects, Tools::Projects::GetProject,
Tools::Projects::FindProjects, Tools::Projects::GetProject, Tools::Projects::SetShipUntil,
Tools::Ships::FindShips, Tools::Ships::GetShip, Tools::Ships::SaveReviewDraft,
Tools::Ships::SetLapseCoding, Tools::Ships::SetReviewerAi, Tools::Ships::SetChecklistItem, Tools::Ships::SetHoursStart, Tools::Ships::EditSnapshot, Tools::Ships::EditReviewText,
Tools::Ships::SendVerdictDm,
Expand Down
44 changes: 44 additions & 0 deletions app/mcp/admin_mcp/tools/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,48 @@ def self.run(args, _caller)
)
end
end

# D-155: a private ship window for one project. No DM, no post: the admin tells the person.
class SetShipUntil < AdminMcp::Tool
writes "set_ship_until", "Give one project a private ship window",
"Gives one project a private window to ship after the public end (D-155): the project may ship until ship_until, and only Hackatime time from before the public end (Program::ENDS_AT) counts on that ship. " \
"Send user_id or project_id, and ship_until as a UTC date and time like 2026-11-06T21:00, or null to clear it. It never shortens the public end or a Changes needed window, and an unset project is unchanged. " \
"Sends no DM and posts nothing: tell the person yourself. Answers { project_id, user_id, ship_until, ship_closes_at }.",
{ user_id: { type: "integer", description: "The participant's user ID. Use this or project_id." },
project_id: { type: "integer", description: "The project ID. Use this or user_id." },
ship_until: { type: %w[string null], description: "A UTC date and time, or null to clear the window." } },
required: %w[ship_until]

def self.audit_extra(args)
project = find_project(args)
project ? { "project_id" => project.id } : {}
rescue StandardError
{}
end

def self.run(args, _caller)
raise AdminMcp::Refused, "Send ship_until: a UTC date and time, or null to clear it." unless args.key?(:ship_until)

project = find_project(args) || raise(AdminMcp::Refused, "Send user_id or project_id of a project that exists.")
value = args[:ship_until].nil? ? nil : parse_time(args[:ship_until])
raise AdminMcp::Refused, "Send ship_until as a UTC date and time like 2026-11-06T21:00, or null." if value == :invalid

project.update!(ship_until: value)
{ project_id: project.id, user_id: project.user_id, ship_until: project.ship_until, ship_closes_at: project.ship_closes_at }
end

def self.find_project(args)
if args[:project_id] then Project.find_by(id: args[:project_id])
elsif args[:user_id] then Project.find_by(user_id: args[:user_id])
end
end

def self.parse_time(text)
return :invalid if text.blank?

Time.find_zone!("UTC").parse(text.to_s) || :invalid
rescue ArgumentError
:invalid
end
end
end
15 changes: 12 additions & 3 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,18 @@ def hours_logged(refresh: false)
@hours_logged = nil if refresh
@hours_logged ||= begin
refresh_hours if refresh
user.hours_in(Program::FIRST_STREAK_DATE..)
user.hours_in(Program::FIRST_STREAK_DATE..hours_last_day)
end
end

# D-155: a project with an admin-set ship window (ship_until) counts only time from before the public end once that
# end has passed: the streak day the end falls on, in the person's zone, is the last one. nil (no limit) for everyone else.
def hours_last_day
return unless ship_until && Time.current > Program::ENDS_AT

StreakActivity.streak_date_for(Program::ENDS_AT, user.timezone)
end

# D-065: Hackatime time counts from the later of Save Point's start and your sign-up, unless a reviewer set a start on
# this project (hours_start_override). D-066: a jame gam submission of this game moves it later still, whatever its review
# status. Nothing counts earlier, so the streak sync clips every span here and the ship's hours, the Airtable dates and
Expand Down Expand Up @@ -740,9 +748,10 @@ def changes_needed_until
[ latest.reviewed_at + CHANGES_NEEDED_WINDOW, Program::ENDS_AT ].max
end

# The last moment this person may ship: the cutoff (Program::ENDS_AT), or their Changes needed deadline (D-140) when it runs later.
# The last moment this person may ship: the cutoff (Program::ENDS_AT), or their Changes needed deadline (D-140) or the
# private window an admin set (ship_until, D-155) when it runs later.
def ship_closes_at
[ ship_cutoff, changes_needed_until ].compact.max
[ ship_cutoff, changes_needed_until, ship_until ].compact.max
end

# Until then, unless an admin banned the account or rejected the newest ship for good (D-063).
Expand Down
12 changes: 9 additions & 3 deletions app/models/ship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ def by?(user) = project.user_id == user.id
def counted_hours
return 0 unless project&.user

project.user.hours_in(Program::FIRST_STREAK_DATE..(created_at || Time.current).to_date).to_d.clamp(0, hours)
last_day = [ (created_at || Time.current).to_date, project.hours_last_day ].compact.min
project.user.hours_in(Program::FIRST_STREAK_DATE..last_day).to_d.clamp(0, hours)
end

# D-155: where this ship's Hackatime time stops: now, or the public end for a project with a private ship window (ship_until).
def hours_end
project.ship_until && Time.current > Program::ENDS_AT ? Program::ENDS_AT : Time.current
end

# D-063: the seconds on each linked Hackatime project from the hours start (D-065) to now, kept as hackatime_seconds when the
Expand All @@ -180,7 +186,7 @@ def capture_hackatime_seconds
user = project&.user
return unless user&.hackatime_linked? && hackatime_projects.any?

self.hackatime_seconds = Hackatime.project_seconds(user, hackatime_projects, project.hours_start..Time.current)
self.hackatime_seconds = Hackatime.project_seconds(user, hackatime_projects, project.hours_start..hours_end)
rescue Hackatime::NotLinked, Hackatime::Expired, Hackatime::Unavailable
nil
end
Expand Down Expand Up @@ -441,7 +447,7 @@ def fetch_hackatime_categories!
user = project&.user
return unless user&.hackatime_linked?

window = { from: project.hours_start, to: created_at.utc }
window = { from: project.hours_start, to: [ created_at.utc, hours_end ].min }
ai = Hackatime.category_seconds(user, hackatime_projects, AI_CODING_CATEGORY, **window)
art_parts = ART_CATEGORIES.map { |category| Hackatime.category_seconds(user, hackatime_projects, category, **window) }
art = art_parts.sum unless art_parts.any?(&:nil?) # one unknown part leaves the art time unknown
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</div>
<% else %>
<p class="project__schedule-note"><%= project_schedule_note(@project) %></p>
<% if @project.latest_standing_ship && @project.may_ship? && (Time.current < Program::ENDS_AT || @project.changes_needed_until) %><%= render "projects/ship_counter", project: @project %><% end %>
<% if @project.latest_standing_ship && @project.may_ship? && (Time.current < Program::ENDS_AT || @project.changes_needed_until || @project.ship_until) %><%= render "projects/ship_counter", project: @project %><% end %>
<% end %>
<%# D-112: what the reviewer wrote on your latest approved ship, whatever the next step is. %>
<% if (reviewer_note = project_reviewer_note(@project)) %><%= render "projects/reviewer_note", note: reviewer_note %><% end %>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20261105210000_add_ship_until_to_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# D-155: a deadline an admin sets for one project, so a person gets a private window to ship after the public end.
class AddShipUntilToProjects < ActiveRecord::Migration[8.1]
def change
add_column :projects, :ship_until, :datetime
end
end
5 changes: 3 additions & 2 deletions db/schema.rb

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

23 changes: 21 additions & 2 deletions test/controllers/admin/mcp_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Admin::McpControllerTest < ActionDispatch::IntegrationTest
tools = response.parsed_body.dig("result", "tools").index_by { it["name"] }

assert_equal %w[admin_summary audit_log decide_extension describe_schema edit_review_text edit_snapshot find_people find_projects find_ships funnel get_person get_project get_ship
list_extensions list_orders mark_order_ordered metrics nudges public_stats query_sql save_review_draft send_verdict_dm set_checklist_item set_hours_start set_lapse_coding set_reviewer_ai], tools.keys.sort
writes = %w[save_review_draft set_lapse_coding set_reviewer_ai set_checklist_item set_hours_start edit_snapshot edit_review_text send_verdict_dm mark_order_ordered decide_extension]
list_extensions list_orders mark_order_ordered metrics nudges public_stats query_sql save_review_draft send_verdict_dm set_checklist_item set_hours_start set_lapse_coding set_reviewer_ai set_ship_until], tools.keys.sort
writes = %w[save_review_draft set_lapse_coding set_reviewer_ai set_checklist_item set_hours_start edit_snapshot edit_review_text send_verdict_dm mark_order_ordered decide_extension set_ship_until]
writes.each do |name|
assert tools[name]["description"].start_with?("Changes real data: confirm with the human first."), name
assert_equal false, tools[name].dig("annotations", "readOnlyHint")
Expand Down Expand Up @@ -461,6 +461,25 @@ class Admin::McpControllerTest < ActionDispatch::IntegrationTest
assert_includes AdminAuditEvent.where(tool: "set_hours_start").map(&:ids), { "ship_id" => ship.id, "project_id" => project.id }
end

test "set_ship_until sets and clears a private ship window, logs the project, and sends nothing (D-155)" do
project = projects(:ana)
window = "2026-11-06T04:00"
assert_no_enqueued_jobs only: SlackMessageJob do
done = mcp_tool(@token, "set_ship_until", { user_id: project.user_id, ship_until: window })
assert_equal project.id, done["project_id"]
assert_equal Time.utc(2026, 11, 6, 4), project.reload.ship_until
assert_equal Time.utc(2026, 11, 6, 4), project.ship_closes_at

mcp_tool(@token, "set_ship_until", { project_id: project.id, ship_until: "nonsense" })
assert mcp_error?
assert_equal Time.utc(2026, 11, 6, 4), project.reload.ship_until

mcp_tool(@token, "set_ship_until", { project_id: project.id, ship_until: nil })
assert_nil project.reload.ship_until
end
assert_includes AdminAuditEvent.where(tool: "set_ship_until").map(&:ids), { "user_id" => project.user_id, "project_id" => project.id }
end

test "send_verdict_dm sends the verdict DM once, returns its text, and can leave the note out (D-139)" do
sent = []
dm = SlackBot.method(:dm)
Expand Down
45 changes: 45 additions & 0 deletions test/models/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,51 @@ class ProjectDeadlineTest < ActiveSupport::TestCase
assert_not project.may_ship?(now: Program::SHOP_CLOSES_AT - 1.minute), "D-138: the open shop does not reopen shipping"
end

test "a private ship window (D-155) lets one project ship after the end and leaves everyone else alone" do
project = projects(:orpheus)
window = Program::ENDS_AT + 24.hours
assert_nil project.ship_until
assert_equal Program::ENDS_AT, project.ship_closes_at
assert_not project.may_ship?(now: Program::ENDS_AT + 1.hour), "no window, no shipping after the end"

project.update!(ship_until: window)
assert_equal window, project.ship_closes_at
assert project.may_ship?(now: Program::ENDS_AT + 1.hour)
assert project.may_ship?(now: window)
assert_not project.may_ship?(now: window + 1.second)

project.update!(ship_until: Program::ENDS_AT - 1.day)
assert_equal Program::ENDS_AT, project.ship_closes_at, "a window never shortens the public end"
project.update!(ship_until: nil)
assert_equal Program::ENDS_AT, project.ship_closes_at
end

test "with a ship window only time before the end counts, and without one nothing changes (D-155)" do
project = projects(:ana)
user = project.user
user.update!(timezone: "America/New_York")
Hackatime.stubbed_users = { "token-ana" => 99 }
link_hackatime(user)
project.update!(hackatime_projects: [ "pong" ])
last_day = StreakActivity.streak_date_for(Program::ENDS_AT, user.timezone)
user.streak_activities.create!(activity_date: last_day - 1, coded_seconds: 3 * 3600)
user.streak_activities.create!(activity_date: last_day + 1, coded_seconds: 2 * 3600) # logged after the end

travel_to(Program::ENDS_AT + 2.hours) do
assert_nil project.hours_last_day
assert_equal 5.0, project.hours_logged, "no window: the open-ended count is kept"
assert_equal 5.0, Project.find(project.id).hours_logged

project.update!(ship_until: Program::ENDS_AT + 24.hours)
assert_equal last_day, project.hours_last_day
assert_equal 3.0, Project.find(project.id).hours_logged, "the window counts only time from before the end"
end

travel_to(Program::ENDS_AT - 2.hours) do
assert_nil project.hours_last_day, "before the end nothing is capped"
end
end

test "nobody can ask for more time any more" do
project = projects(:orpheus)
link_hackatime(users(:orpheus))
Expand Down
Loading